Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EventInfoSummary.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EventInfoSummary.cc
1 #include "EventInfoSummary.h"
2 
3 #include "RawTower_Prototype4.h"
4 
5 #include <calobase/RawTower.h> // for RawTower
6 #include <calobase/RawTowerContainer.h>
7 
8 #include <phparameter/PHParameters.h>
9 
10 #include <pdbcalbase/PdbParameterMap.h>
11 
12 #include <fun4all/Fun4AllBase.h> // for Fun4AllB...
14 #include <fun4all/SubsysReco.h> // for SubsysReco
15 
16 #include <phool/PHCompositeNode.h>
17 #include <phool/PHIODataNode.h> // for PHIOData...
18 #include <phool/PHNodeIterator.h> // for PHNodeIt...
19 #include <phool/getClass.h>
20 
21 #include <Event/Event.h>
22 #include <Event/EventTypes.h>
23 #include <Event/packet.h>
24 
25 #include <boost/accumulators/accumulators.hpp>
26 #include <boost/accumulators/statistics.hpp>
27 
28 #include <cassert>
29 #include <cmath> // for NAN
30 #include <iostream>
31 #include <string>
32 #include <utility> // for pair
33 
34 // with the exception of std, please no using namespaces
35 // it severely muddies the ability to figure out
36 // where things come from
37 using namespace std;
38 
39 //____________________________________
41  : SubsysReco("EventInfoSummary")
42  , eventinfo_node_name("EVENT_INFO")
43 {
44 }
45 
46 //_____________________________________
48 {
49  CreateNodeTree(topNode);
51 }
52 
53 //____________________________________
55 {
56  Event *event = findNode::getClass<Event>(topNode, "PRDF");
57  if (!event)
58  {
59  if (Verbosity() >= VERBOSITY_SOME)
60  cout << "EventInfoSummary::Process_Event - Event not found" << endl;
62  }
63 
64  // search for run info
65  if (event->getEvtType() != DATAEVENT)
67  else // DATAEVENT
68  {
69  if (Verbosity() >= VERBOSITY_SOME)
70  {
71  cout << "EventInfoSummary::process_event - with DATAEVENT events ";
72  event->identify();
73  }
74 
75  map<int, Packet *> packet_list;
76 
77  PHParameters Params("EventInfo");
78 
79  // spill indicator
80  {
81  RawTowerContainer *TOWER_RAW_SPILL_WARBLER =
82  findNode::getClass<RawTowerContainer>(topNode,
83  "TOWER_RAW_SPILL_WARBLER");
84  assert(TOWER_RAW_SPILL_WARBLER);
85 
86  RawTower_Prototype4 *raw_tower = dynamic_cast<RawTower_Prototype4 *>(
87  TOWER_RAW_SPILL_WARBLER->getTower(0));
88  assert(raw_tower);
89 
90  boost::accumulators::accumulator_set<double, boost::accumulators::features<boost::accumulators::tag::variance>> acc;
91 
92  for (int i = 0; i < RawTower_Prototype4::NSAMPLES; i++)
93  {
94  acc(raw_tower->get_signal_samples(i));
95  }
96 
97  const double warbler_rms = boost::accumulators::variance(acc);
98  const bool is_in_spill = warbler_rms > (1000 * 1000);
99  Params.set_double_param("beam_SPILL_WARBLER_RMS", warbler_rms);
100  Params.set_double_param("beam_Is_In_Spill", is_in_spill);
101  Params.set_int_param("beam_Is_In_Spill", is_in_spill);
102  }
103 
104  // energy sums
105  {
106  RawTowerContainer *TOWER_CALIB_CEMC =
107  findNode::getClass<RawTowerContainer>(topNode, "TOWER_CALIB_CEMC");
108  assert(TOWER_CALIB_CEMC);
109 
110  RawTowerContainer *TOWER_CALIB_LG_HCALIN =
111  findNode::getClass<RawTowerContainer>(topNode,
112  "TOWER_CALIB_LG_HCALIN");
113 
114  RawTowerContainer *TOWER_CALIB_LG_HCALOUT =
115  findNode::getClass<RawTowerContainer>(topNode,
116  "TOWER_CALIB_LG_HCALOUT");
117 
118  // process inner HCAL
119  if (TOWER_CALIB_CEMC)
120  {
121  double sum_energy_calib = 0;
122 
123  auto range = TOWER_CALIB_CEMC->getTowers();
124  for (auto it = range.first; it != range.second; ++it)
125  {
126  RawTower *tower = it->second;
127  assert(tower);
128 
129  const int col = tower->get_bineta();
130  const int row = tower->get_binphi();
131 
132  if (col < 0 or col >= 8)
133  continue;
134  if (row < 0 or row >= 8)
135  continue;
136 
137  const double energy_calib = tower->get_energy();
138  sum_energy_calib += energy_calib;
139 
140  } // for (auto it = range.first; it != range.second; ++it)
141  Params.set_double_param("CALIB_CEMC_Sum", sum_energy_calib);
142  } // process inner HCAL
143 
144  // process inner HCAL
145  if (TOWER_CALIB_LG_HCALIN)
146  {
147  double sum_energy_calib = 0;
148 
149  auto range = TOWER_CALIB_LG_HCALIN->getTowers();
150  for (auto it = range.first; it != range.second; ++it)
151  {
152  RawTower *tower = it->second;
153  assert(tower);
154 
155  const int col = tower->get_bineta();
156  const int row = tower->get_binphi();
157 
158  if (col < 0 or col >= 4)
159  continue;
160  if (row < 0 or row >= 4)
161  continue;
162 
163  const double energy_calib = tower->get_energy();
164  sum_energy_calib += energy_calib;
165 
166  } // for (auto it = range.first; it != range.second; ++it)
167  Params.set_double_param("CALIB_LG_HCALIN_Sum", sum_energy_calib);
168  } // process inner HCAL
169 
170  // process outer HCAL
171  if (TOWER_CALIB_LG_HCALOUT)
172  {
173  double sum_energy_calib = 0;
174 
175  auto range = TOWER_CALIB_LG_HCALOUT->getTowers();
176  for (auto it = range.first; it != range.second; ++it)
177  {
178  RawTower *tower = it->second;
179  assert(tower);
180 
181  const int col = tower->get_bineta();
182  const int row = tower->get_binphi();
183 
184  if (col < 0 or col >= 4)
185  continue;
186  if (row < 0 or row >= 4)
187  continue;
188 
189  const double energy_calib = tower->get_energy();
190  sum_energy_calib += energy_calib;
191 
192  } // for (auto it = range.first; it != range.second; ++it)
193 
194  Params.set_double_param("CALIB_LG_HCALOUT_Sum", sum_energy_calib);
195  } // process outer HCAL
196  }
197 
198  // generic packets
199  for (typ_channel_map::const_iterator it = channel_map.begin();
200  it != channel_map.end(); ++it)
201  {
202  const string &name = it->first;
203  const channel_info &info = it->second;
204 
205  if (packet_list.find(info.packet_id) == packet_list.end())
206  {
207  packet_list[info.packet_id] = event->getPacket(info.packet_id);
208  }
209 
210  Packet *packet = packet_list[info.packet_id];
211 
212  if (!packet)
213  {
214  // if (Verbosity() >= VERBOSITY_SOME)
215  cout << "EventInfoSummary::process_event - failed to locate packet "
216  << info.packet_id << " from ";
217  event->identify();
218 
219  Params.set_double_param(name, NAN);
220  continue;
221  }
222 
223  const int ivalue = packet->iValue(info.offset);
224 
225  const double dvalue = ivalue * info.calibration_const;
226 
227  if (Verbosity() >= VERBOSITY_SOME)
228  {
229  cout << "EventInfoSummary::process_event - " << name << " = " << dvalue
230  << ", raw = " << ivalue << " @ packet " << info.packet_id
231  << ", offset " << info.offset << endl;
232  }
233 
234  Params.set_double_param(name, dvalue);
235  }
236 
237  for (map<int, Packet *>::iterator it = packet_list.begin();
238  it != packet_list.end(); ++it)
239  {
240  if (it->second)
241  delete it->second;
242  }
243 
244  Params.SaveToNodeTree(topNode, eventinfo_node_name);
245 
246  if (Verbosity() >= VERBOSITY_SOME)
247  Params.Print();
248  }
250 }
251 
252 //_______________________________________
254 {
255  PHNodeIterator nodeItr(topNode);
256 
257  PHNodeIterator iter(topNode);
258 
259  // DST node
260  PHCompositeNode *dst_node =
261  static_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
262  if (!dst_node)
263  {
264  cout << "PHComposite node created: DST" << endl;
265  dst_node = new PHCompositeNode("DST");
266  topNode->addNode(dst_node);
267  }
268 
269  PdbParameterMap *nodeparams =
270  findNode::getClass<PdbParameterMap>(dst_node, eventinfo_node_name);
271  if (not nodeparams)
272  {
273  dst_node->addNode(new PHIODataNode<PdbParameterMap>(new PdbParameterMap(),
275  }
276 }
277 
279  const std::string &name,
280  const int packet_id,
281  const unsigned int offset,
282  const double calibration_const
283 
284 )
285 {
286  channel_map.insert(
287  make_pair(name, channel_info(packet_id, offset, calibration_const)));
288 }