Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CaloUnpackPRDF.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CaloUnpackPRDF.cc
1 #include "CaloUnpackPRDF.h"
2 
3 #include "PROTOTYPE2_FEM.h"
4 #include "RawTower_Prototype2.h"
5 
6 #include <calobase/RawTower.h> // for RawTower
7 #include <calobase/RawTowerContainer.h>
8 #include <calobase/RawTowerDefs.h> // for HCALIN, HCALOUT, CEMC
9 
11 #include <fun4all/SubsysReco.h> // for SubsysReco
12 
13 #include <phool/PHCompositeNode.h>
14 #include <phool/PHIODataNode.h> // for PHIODataNode
15 #include <phool/PHNodeIterator.h> // for PHNodeIterator
16 #include <phool/PHObject.h> // for PHObject
17 #include <phool/getClass.h>
18 #include <phool/phool.h>
19 
20 #include <Event/Event.h>
21 #include <Event/packet.h>
22 
23 #include <cassert>
24 #include <cmath> // for NAN
25 #include <cstddef> // for NULL
26 #include <iostream>
27 #include <map> // for _Rb_tree_const_iterator
28 #include <utility> // for pair
29 
30 using namespace std;
31 
32 //____________________________________
34  : SubsysReco("CaloUnpackPRDF")
35  ,
36  /*Event**/ _event(NULL)
37  ,
38  /*Packet**/ _packet(NULL)
39  ,
40  /*int*/ _nevents(0)
41  ,
42  /*PHCompositeNode **/ dst_node(NULL)
43  ,
44  /*PHCompositeNode **/ data_node(NULL)
45  ,
46  /*RawTowerContainer**/ hcalin_towers_lg(NULL)
47  ,
48  /*RawTowerContainer**/ hcalout_towers_lg(NULL)
49  ,
50  /*RawTowerContainer**/ hcalin_towers_hg(NULL)
51  ,
52  /*RawTowerContainer**/ hcalout_towers_hg(NULL)
53  ,
54  /*RawTowerContainer**/ emcal_towers(NULL)
55 {
56 }
57 
58 //____________________________________
60 {
62 }
63 
64 //_____________________________________
66 {
67  CreateNodeTree(topNode);
69 }
70 
71 //____________________________________
73 {
74  _nevents++;
75  _event = findNode::getClass<Event>(topNode, "PRDF");
76  if (_event == 0)
77  {
78  cout << "CaloUnpackPRDF::Process_Event - Event not found" << endl;
79  return -1;
80  }
81 
82  if (Verbosity())
83  {
84  cout << PHWHERE << "Process event entered" << std::endl;
85  }
86 
87  if (Verbosity())
88  _event->identify();
90 
91  if (!_packet)
92  {
93  // They could be special events at the beginning or end of run
94  if (_event->getEvtType() == 1)
95  {
96  cout << "CaloUnpackPRDF::Process_Event - Packet not found" << endl;
97  _event->identify();
98  }
100  }
101 
103  RawTower_Prototype2 *tower_lg = NULL;
104  RawTower_Prototype2 *tower_hg = NULL;
105 
106  // HCALIN
109  for (int ibinz = 0; ibinz < PROTOTYPE2_FEM::NCH_IHCAL_ROWS; ibinz++)
110  {
111  for (int ibinphi = 0; ibinphi < PROTOTYPE2_FEM::NCH_IHCAL_COLUMNS;
112  ibinphi++)
113  {
114  tower_lg = dynamic_cast<RawTower_Prototype2 *>(
115  hcalin_towers_lg->getTower(ibinz, ibinphi));
116  if (!tower_lg)
117  {
118  tower_lg = new RawTower_Prototype2();
119  tower_lg->set_energy(NAN);
120  hcalin_towers_lg->AddTower(ibinz, ibinphi, tower_lg);
121  }
122  tower_hg = dynamic_cast<RawTower_Prototype2 *>(
123  hcalin_towers_hg->getTower(ibinz, ibinphi));
124  if (!tower_hg)
125  {
126  tower_hg = new RawTower_Prototype2();
127  tower_hg->set_energy(NAN);
128  hcalin_towers_hg->AddTower(ibinz, ibinphi, tower_hg);
129  }
130 
131  int ich = PROTOTYPE2_FEM::GetHBDCh("HCALIN", ibinz, ibinphi);
132  tower_lg->set_HBD_channel_number(ich);
133  tower_hg->set_HBD_channel_number(ich);
134  for (int isamp = 0; isamp < PROTOTYPE2_FEM::NSAMPLES; isamp++)
135  {
136  tower_hg->set_signal_samples(isamp, _packet->iValue(ich, isamp));
137  tower_lg->set_signal_samples(isamp, _packet->iValue(ich + 1, isamp));
138  }
139  }
140  }
141 
142  // HCALOUT
145  for (int ibinz = 0; ibinz < PROTOTYPE2_FEM::NCH_OHCAL_ROWS; ibinz++)
146  {
147  for (int ibinphi = 0; ibinphi < PROTOTYPE2_FEM::NCH_OHCAL_COLUMNS;
148  ibinphi++)
149  {
150  tower_lg = dynamic_cast<RawTower_Prototype2 *>(
151  hcalout_towers_lg->getTower(ibinz, ibinphi));
152  if (!tower_lg)
153  {
154  tower_lg = new RawTower_Prototype2();
155  tower_lg->set_energy(NAN);
156  hcalout_towers_lg->AddTower(ibinz, ibinphi, tower_lg);
157  }
158  tower_hg = dynamic_cast<RawTower_Prototype2 *>(
159  hcalout_towers_hg->getTower(ibinz, ibinphi));
160  if (!tower_hg)
161  {
162  tower_hg = new RawTower_Prototype2();
163  tower_hg->set_energy(NAN);
164  hcalout_towers_hg->AddTower(ibinz, ibinphi, tower_hg);
165  }
166  int ich = PROTOTYPE2_FEM::GetHBDCh("HCALOUT", ibinz, ibinphi);
167  tower_lg->set_HBD_channel_number(ich);
168  tower_hg->set_HBD_channel_number(ich);
169  for (int isamp = 0; isamp < PROTOTYPE2_FEM::NSAMPLES; isamp++)
170  {
171  tower_hg->set_signal_samples(isamp, _packet->iValue(ich, isamp));
172  tower_lg->set_signal_samples(isamp, _packet->iValue(ich + 1, isamp));
173  }
174  }
175  }
176 
177  // EMCAL
178  RawTower_Prototype2 *tower = NULL;
180  for (int ibinz = 0; ibinz < PROTOTYPE2_FEM::NCH_EMCAL_ROWS; ibinz++)
181  {
182  for (int ibinphi = 0; ibinphi < PROTOTYPE2_FEM::NCH_EMCAL_COLUMNS;
183  ibinphi++)
184  {
185  tower = dynamic_cast<RawTower_Prototype2 *>(
186  emcal_towers->getTower(ibinz, ibinphi));
187  if (!tower)
188  {
189  tower = new RawTower_Prototype2();
190  tower->set_energy(NAN);
191  emcal_towers->AddTower(ibinz, ibinphi, tower);
192  }
193  int ich = PROTOTYPE2_FEM::GetHBDCh("EMCAL", ibinz, ibinphi);
194  tower->set_HBD_channel_number(ich);
195  for (int isamp = 0; isamp < PROTOTYPE2_FEM::NSAMPLES; isamp++)
196  {
197  tower->set_signal_samples(isamp, _packet->iValue(ich, isamp));
198  }
199  }
200  }
201 
202  if (Verbosity())
203  {
204  cout << "HCALIN Towers: " << endl;
208  for (iter = begin_end.first; iter != begin_end.second; ++iter)
209  {
210  RawTower_Prototype2 *tower =
211  dynamic_cast<RawTower_Prototype2 *>(iter->second);
212  tower->identify();
213  cout << "Signal Samples: [" << endl;
214  for (int isamp = 0; isamp < PROTOTYPE2_FEM::NSAMPLES; isamp++)
215  {
216  cout << tower->get_signal_samples(isamp) << ", ";
217  }
218  cout << " ]" << endl;
219  }
220  }
221  delete _packet;
223 }
224 
225 //_______________________________________
227 {
228  PHNodeIterator nodeItr(topNode);
229  // DST node
230  dst_node = static_cast<PHCompositeNode *>(
231  nodeItr.findFirst("PHCompositeNode", "DST"));
232  if (!dst_node)
233  {
234  cout << "PHComposite node created: DST" << endl;
235  dst_node = new PHCompositeNode("DST");
236  topNode->addNode(dst_node);
237  }
238 
239  // DATA nodes
240  data_node = static_cast<PHCompositeNode *>(
241  nodeItr.findFirst("PHCompositeNode", "RAW_DATA"));
242  if (!data_node)
243  {
244  if (Verbosity())
245  cout << "PHComposite node created: RAW_DATA" << endl;
246  data_node = new PHCompositeNode("RAW_DATA");
248  }
249 
250  PHIODataNode<PHObject> *tower_node = NULL;
251 
252  // HCAL Towers
254  tower_node = new PHIODataNode<PHObject>(hcalin_towers_lg,
255  "TOWER_RAW_LG_HCALIN", "PHObject");
256  data_node->addNode(tower_node);
258  tower_node = new PHIODataNode<PHObject>(hcalin_towers_hg,
259  "TOWER_RAW_HG_HCALIN", "PHObject");
260  data_node->addNode(tower_node);
261 
263  tower_node = new PHIODataNode<PHObject>(hcalout_towers_lg,
264  "TOWER_RAW_LG_HCALOUT", "PHObject");
265  data_node->addNode(tower_node);
267  tower_node = new PHIODataNode<PHObject>(hcalout_towers_hg,
268  "TOWER_RAW_HG_HCALOUT", "PHObject");
269  data_node->addNode(tower_node);
270 
271  // EMCAL towers
273  PHIODataNode<PHObject> *emcal_towerNode =
274  new PHIODataNode<PHObject>(emcal_towers, "TOWER_RAW_CEMC", "PHObject");
275  data_node->addNode(emcal_towerNode);
276 }