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 "PROTOTYPE4_FEM.h"
4 #include "RawTower_Prototype4.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/EventTypes.h>
22 #include <Event/packet.h>
23 
24 #include <cassert>
25 #include <cmath> // for NAN
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(nullptr)
37  ,
38  /*Packet_hbd_fpgashort**/ _packet(nullptr)
39  ,
40  /*int*/ _nevents(0)
41  ,
42  /*PHCompositeNode **/ dst_node(nullptr)
43  ,
44  /*PHCompositeNode **/ data_node(nullptr)
45  ,
46  /*RawTowerContainer**/ hcalin_towers_lg(nullptr)
47  ,
48  /*RawTowerContainer**/ hcalout_towers_lg(nullptr)
49  ,
50  /*RawTowerContainer**/ hcalin_towers_hg(nullptr)
51  ,
52  /*RawTowerContainer**/ hcalout_towers_hg(nullptr)
53  ,
54  /*RawTowerContainer**/ emcal_towers(nullptr)
55 {
56 }
57 
58 //_____________________________________
60 {
61  CreateNodeTree(topNode);
63 }
64 
65 //____________________________________
67 {
68  _nevents++;
69  _event = findNode::getClass<Event>(topNode, "PRDF");
70  if (_event == 0)
71  {
72  cout << "CaloUnpackPRDF::Process_Event - Event not found" << endl;
73  return -1;
74  }
75 
76  if (Verbosity())
77  {
78  cout << PHWHERE << "Process event entered" << std::endl;
79  }
80 
81  if (Verbosity())
82  _event->identify();
83 
85 
86  if (!_packet)
87  {
88  // They could be special events at the beginning or end of run
89  if (_event->getEvtType() == DATAEVENT)
90  {
91  cout << "CaloUnpackPRDF::Process_Event - Packet not found" << endl;
92  _event->identify();
93  }
95  }
96  RawTower_Prototype4 *tower_lg = nullptr;
97  RawTower_Prototype4 *tower_hg = nullptr;
98 
99  // HCALIN
101  // assert(hcalin_towers_hg);
102  for (int ibinz = 0; ibinz < PROTOTYPE4_FEM::NCH_IHCAL_ROWS; ibinz++)
103  {
104  for (int ibinphi = 0; ibinphi < PROTOTYPE4_FEM::NCH_IHCAL_COLUMNS;
105  ibinphi++)
106  {
107  tower_lg = dynamic_cast<RawTower_Prototype4 *>(
108  hcalin_towers_lg->getTower(ibinz, ibinphi));
109  if (!tower_lg)
110  {
111  tower_lg = new RawTower_Prototype4();
112  tower_lg->set_energy(NAN);
113  hcalin_towers_lg->AddTower(ibinz, ibinphi, tower_lg);
114  }
115  // tower_hg =
116  // dynamic_cast<RawTower_Prototype4
117  // *>(hcalin_towers_hg->getTower(
118  // ibinz, ibinphi));
119  // if (!tower_hg)
120  // {
121  // tower_hg = new RawTower_Prototype4();
122  // tower_hg->set_energy(NAN);
123  // hcalin_towers_hg->AddTower(ibinz, ibinphi, tower_hg);
124  // }
125 
126  int ich = PROTOTYPE4_FEM::GetChannelNumber("HCALIN", ibinz, ibinphi);
127  tower_lg->set_HBD_channel_number(ich);
128  // tower_hg->set_HBD_channel_number(ich);
129  for (int isamp = 0; isamp < PROTOTYPE4_FEM::NSAMPLES; isamp++)
130  {
131  // tower_hg->set_signal_samples(isamp, _packet->iValue(isamp,
132  // ich) & PROTOTYPE4_FEM::ADC_DATA_MASK);
133  tower_lg->set_signal_samples(isamp, _packet->iValue(isamp, ich) &
135  }
136  }
137  }
138 
139  // HCALOUT
142  for (int ibinz = 0; ibinz < PROTOTYPE4_FEM::NCH_OHCAL_ROWS; ibinz++)
143  {
144  for (int ibinphi = 0; ibinphi < PROTOTYPE4_FEM::NCH_OHCAL_COLUMNS;
145  ibinphi++)
146  {
147  tower_lg = dynamic_cast<RawTower_Prototype4 *>(
148  hcalout_towers_lg->getTower(ibinz, ibinphi));
149  if (!tower_lg)
150  {
151  tower_lg = new RawTower_Prototype4();
152  tower_lg->set_energy(NAN);
153  hcalout_towers_lg->AddTower(ibinz, ibinphi, tower_lg);
154  }
155  tower_hg = dynamic_cast<RawTower_Prototype4 *>(
156  hcalout_towers_hg->getTower(ibinz, ibinphi));
157  if (!tower_hg)
158  {
159  tower_hg = new RawTower_Prototype4();
160  tower_hg->set_energy(NAN);
161  hcalout_towers_hg->AddTower(ibinz, ibinphi, tower_hg);
162  }
163  int ich = PROTOTYPE4_FEM::GetChannelNumber("HCALOUT", ibinz, ibinphi);
164  tower_lg->set_HBD_channel_number(ich);
165  tower_hg->set_HBD_channel_number(ich);
166  for (int isamp = 0; isamp < PROTOTYPE4_FEM::NSAMPLES; isamp++)
167  {
168  tower_lg->set_signal_samples(isamp, _packet->iValue(isamp, ich) &
170  tower_hg->set_signal_samples(isamp, _packet->iValue(isamp, ich + 1) &
172  }
173  }
174  }
175 
176  // EMCAL
177  RawTower_Prototype4 *tower = nullptr;
179  for (int ibinz = 0; ibinz < PROTOTYPE4_FEM::NCH_EMCAL_ROWS; ibinz++)
180  {
181  for (int ibinphi = 0; ibinphi < PROTOTYPE4_FEM::NCH_EMCAL_COLUMNS;
182  ibinphi++)
183  {
184  tower = dynamic_cast<RawTower_Prototype4 *>(
185  emcal_towers->getTower(ibinz, ibinphi));
186  if (!tower)
187  {
188  tower = new RawTower_Prototype4();
189  tower->set_energy(NAN);
190  emcal_towers->AddTower(ibinz, ibinphi, tower);
191  }
192 
193  int ich = PROTOTYPE4_FEM::GetChannelNumber("EMCAL", ibinz, ibinphi);
194  tower->set_HBD_channel_number(ich);
195  for (int isamp = 0; isamp < PROTOTYPE4_FEM::NSAMPLES; isamp++)
196  {
197  tower->set_signal_samples(isamp, _packet->iValue(isamp, ich) &
199  }
200  }
201  }
202 
203  if (Verbosity())
204  {
205  cout << "HCALIN Towers: " << endl;
209  for (iter = begin_end.first; iter != begin_end.second; ++iter)
210  {
211  RawTower_Prototype4 *tower =
212  dynamic_cast<RawTower_Prototype4 *>(iter->second);
213  tower->identify();
214  cout << "Signal Samples: [" << endl;
215  for (int isamp = 0; isamp < PROTOTYPE4_FEM::NSAMPLES; isamp++)
216  {
217  cout << tower->get_signal_samples(isamp) << ", ";
218  }
219  cout << " ]" << endl;
220  }
221  }
222  delete _packet;
224 }
225 
226 //_______________________________________
228 {
229  PHNodeIterator nodeItr(topNode);
230  // DST node
231  dst_node = static_cast<PHCompositeNode *>(
232  nodeItr.findFirst("PHCompositeNode", "DST"));
233  if (!dst_node)
234  {
235  cout << "PHComposite node created: DST" << endl;
236  dst_node = new PHCompositeNode("DST");
237  topNode->addNode(dst_node);
238  }
239 
240  // DATA nodes
241  data_node = static_cast<PHCompositeNode *>(
242  nodeItr.findFirst("PHCompositeNode", "RAW_DATA"));
243  if (!data_node)
244  {
245  if (Verbosity())
246  cout << "PHComposite node created: RAW_DATA" << endl;
247  data_node = new PHCompositeNode("RAW_DATA");
249  }
250 
251  // HCAL Towers
254  hcalin_towers_lg, "TOWER_RAW_LG_HCALIN", "PHObject");
255  data_node->addNode(tower_node);
257  tower_node = new PHIODataNode<PHObject>(hcalin_towers_hg,
258  "TOWER_RAW_HG_HCALIN", "PHObject");
259  data_node->addNode(tower_node);
260 
262  tower_node = new PHIODataNode<PHObject>(hcalout_towers_lg,
263  "TOWER_RAW_LG_HCALOUT", "PHObject");
264  data_node->addNode(tower_node);
266  tower_node = new PHIODataNode<PHObject>(hcalout_towers_hg,
267  "TOWER_RAW_HG_HCALOUT", "PHObject");
268  data_node->addNode(tower_node);
269 
270  // EMCAL towers
272  PHIODataNode<PHObject> *emcal_towerNode =
273  new PHIODataNode<PHObject>(emcal_towers, "TOWER_RAW_CEMC", "PHObject");
274  data_node->addNode(emcal_towerNode);
275 }