Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CaloTowerBuilder.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CaloTowerBuilder.cc
1 #include "CaloTowerBuilder.h"
2 #include "CaloTowerDefs.h"
3 
4 #include <calobase/TowerInfo.h>
5 #include <calobase/TowerInfoContainer.h>
6 #include <calobase/TowerInfoContainerv1.h>
7 #include <calobase/TowerInfoContainerv2.h>
8 #include <calobase/TowerInfoContainerv3.h>
9 
11 #include <fun4all/SubsysReco.h> // for SubsysReco
12 
13 #include <phool/PHCompositeNode.h>
14 #include <phool/PHIODataNode.h> // for PHIODataNode
15 #include <phool/PHNode.h> // for PHNode
16 #include <phool/PHNodeIterator.h> // for PHNodeIterator
17 #include <phool/PHObject.h> // for PHObject
18 #include <phool/getClass.h>
19 
20 #include <Event/Event.h>
21 #include <Event/EventTypes.h>
22 #include <Event/packet.h>
23 
24 #include <TSystem.h>
25 
26 #include <climits>
27 #include <iostream> // for operator<<, endl, basic...
28 #include <memory> // for allocator_traits<>::val...
29 #include <vector> // for vector
30 
31 //____________________________________________________________________________..
33  : SubsysReco(name)
34 {
36 }
37 
38 //____________________________________________________________________________..
40 {
41  delete WaveformProcessing;
42 }
43 
44 //____________________________________________________________________________..
46 {
49 
51  {
52  m_detector = "CEMC";
53  m_packet_low = 6001;
54  m_packet_high = 6128;
55  m_nchannels = 192;
56  WaveformProcessing->set_template_name("CEMC_TEMPLATE");
58  {
60  }
61  }
62  else if (m_dettype == CaloTowerDefs::HCALIN)
63  {
64  m_packet_low = 7001;
65  m_packet_high = 7008;
66  m_detector = "HCALIN";
67  m_nchannels = 192;
68  WaveformProcessing->set_template_name("IHCAL_TEMPLATE");
70  {
72  }
73  }
75  {
76  m_detector = "HCALOUT";
77  m_packet_low = 8001;
78  m_packet_high = 8008;
79  m_nchannels = 192;
80  WaveformProcessing->set_template_name("OHCAL_TEMPLATE");
82  {
84  }
85  }
86  else if (m_dettype == CaloTowerDefs::SEPD)
87  {
88  m_detector = "SEPD";
89  m_packet_low = 9001;
90  m_packet_high = 9006;
91  m_nchannels = 128;
93  {
94  WaveformProcessing->set_processing_type(CaloWaveformProcessing::FAST); // default the EPD to fast processing
95  }
96  }
97  else if (m_dettype == CaloTowerDefs::ZDC)
98  {
99  m_detector = "ZDC";
100  m_packet_low = 12001;
101  m_packet_high = 12001;
102  m_nchannels = 16;
104  {
105  WaveformProcessing->set_processing_type(CaloWaveformProcessing::FAST); // default the ZDC to fast processing
106  }
107  }
109  CreateNodeTree(topNode);
111 }
112 
114 {
115  std::vector<std::vector<float>> waveforms;
116 
117  for (int ich = 0; ich < (int) m_CalowaveformContainer->size(); ich++)
118  {
120  std::vector<float> waveform;
121  waveform.reserve(m_nsamples);
122  for (int samp = 0; samp < m_nsamples; samp++)
123  {
124  waveform.push_back(towerinfo->get_waveform_value(samp));
125  }
126  waveforms.push_back(waveform);
127  waveform.clear();
128  }
129 
130  std::vector<std::vector<float>> processed_waveforms = WaveformProcessing->process_waveform(waveforms);
131  int n_channels = processed_waveforms.size();
132  for (int i = 0; i < n_channels; i++)
133  {
135  towerinfo->set_time(processed_waveforms.at(i).at(1));
136  towerinfo->set_energy(processed_waveforms.at(i).at(0));
137  towerinfo->set_time_float(processed_waveforms.at(i).at(1));
138  towerinfo->set_pedestal(processed_waveforms.at(i).at(2));
139  towerinfo->set_chi2(processed_waveforms.at(i).at(3));
140  int n_samples = waveforms.at(i).size();
141  if (n_samples == m_nzerosuppsamples) towerinfo->set_isNotInstr(true);
142  for (int j = 0; j < n_samples; j++)
143  {
144  towerinfo->set_waveform_value(j, waveforms.at(i).at(j));
145  }
146  }
147  waveforms.clear();
148 
150 }
151 
152 
153 //____________________________________________________________________________..
155 {
156  if (!m_isdata)
157  {
158  return process_sim();
159  }
160  std::vector<std::vector<float>> waveforms;
161  // if we are going from prdf
162  Event *_event = findNode::getClass<Event>(topNode, "PRDF");
163  if (_event == nullptr)
164  {
165  std::cout << PHWHERE << " Event not found" << std::endl;
167  }
168  if (_event->getEvtType() != DATAEVENT)
169  {
171  }
172  for (int pid = m_packet_low; pid <= m_packet_high; pid++)
173  {
174  Packet *packet = _event->getPacket(pid);
175  if (packet)
176  {
177  int nchannels = packet->iValue(0, "CHANNELS");
179  { // special condition during zdc commisioning
180  if (nchannels < m_nchannels)
181  {
183  }
184  nchannels = m_nchannels;
185  }
186  if (nchannels > m_nchannels) // packet is corrupted and reports too many channels
187  {
189  }
190  // int sector = 0;
191 
192  for (int channel = 0; channel < nchannels; channel++)
193  {
194  // mask empty channels
195 
197  {
198  int sector = ((channel + 1) / 32);
199  if (channel == (14 + 32 * sector))
200  {
201  continue;
202  }
203  }
204  std::vector<float> waveform;
205  waveform.reserve(m_nsamples);
206  if (packet->iValue(channel,"SUPPRESSED")){
207  waveform.push_back(packet->iValue(channel,"PRE"));
208  waveform.push_back(packet->iValue(channel,"POST"));
209  }
210  else {
211  for (int samp = 0; samp < m_nsamples; samp++)
212  {
213  waveform.push_back(packet->iValue(samp, channel));
214  }
215  }
216  waveforms.push_back(waveform);
217  waveform.clear();
218  }
219  if (nchannels < m_nchannels)
220  {
221  for (int channel = 0; channel < m_nchannels - nchannels; channel++)
222  {
224  {
225  int sector = ((channel + 1) / 32);
226 
227  if (channel == (14 + 32 * sector))
228  {
229  continue;
230  }
231  }
232  std::vector<float> waveform;
233  waveform.reserve(m_nsamples);
234 
235  for (int samp = 0; samp < m_nzerosuppsamples; samp++)
236  {
237  waveform.push_back(0);
238  }
239  waveforms.push_back(waveform);
240  waveform.clear();
241  }
242  }
243  delete packet;
244  }
245  else // if the packet is missing treat constitutent channels as zero suppressed
246  {
247  for (int channel = 0; channel < m_nchannels; channel++)
248  {
250  {
251  int sector = ((channel + 1) / 32);
252  if (channel == (14 + 32 * sector))
253  {
254  continue;
255  }
256  }
257  std::vector<float> waveform;
258  waveform.reserve(2);
259  for (int samp = 0; samp < m_nzerosuppsamples; samp++)
260  {
261  waveform.push_back(0);
262  }
263  waveforms.push_back(waveform);
264  waveform.clear();
265  }
266  }
267  }
268 
269  // waveform vector is filled here, now fill our output. methods from the base class make sure
270  // we only fill what the chosen container version supports
271  std::vector<std::vector<float>> processed_waveforms = WaveformProcessing->process_waveform(waveforms);
272  int n_channels = processed_waveforms.size();
273  for (int i = 0; i < n_channels; i++)
274  {
276  towerinfo->set_time(processed_waveforms.at(i).at(1));
277  towerinfo->set_energy(processed_waveforms.at(i).at(0));
278  towerinfo->set_time_float(processed_waveforms.at(i).at(1));
279  towerinfo->set_pedestal(processed_waveforms.at(i).at(2));
280  towerinfo->set_chi2(processed_waveforms.at(i).at(3));
281  int n_samples = waveforms.at(i).size();
282  if (n_samples == m_nzerosuppsamples) towerinfo->set_isNotInstr(true);
283  for (int j = 0; j < n_samples; j++)
284  {
285  towerinfo->set_waveform_value(j, waveforms.at(i).at(j));
286  }
287  }
288  waveforms.clear();
289 
291 }
292 
294 {
295  PHNodeIterator topNodeItr(topNode);
296  // DST node
297  PHCompositeNode *dstNode = dynamic_cast<PHCompositeNode *>(topNodeItr.findFirst("PHCompositeNode", "DST"));
298  if (!dstNode)
299  {
300  std::cout << "PHComposite node created: DST" << std::endl;
301  dstNode = new PHCompositeNode("DST");
302  topNode->addNode(dstNode);
303  }
304  if (!m_isdata)
305  {
306  std::string waveformNodeName = m_inputNodePrefix + m_detector;
307  m_CalowaveformContainer = findNode::getClass<TowerInfoContainer>(topNode, waveformNodeName);
309  {
310  std::cout << PHWHERE << "simulation waveform container " << waveformNodeName << " not found" << std::endl;
311  gSystem->Exit(1);
312  exit(1);
313  }
314  }
315 
316  // towers
317  PHNodeIterator nodeItr(dstNode);
318  PHCompositeNode *DetNode;
319  // enum CaloTowerDefs::DetectorSystem and TowerInfoContainer::DETECTOR are different!!!!
321  std::string DetectorNodeName;
323  {
324  DetectorEnum = TowerInfoContainer::DETECTOR::EMCAL;
325  DetectorNodeName = "CEMC";
326  }
327  else if (m_dettype == CaloTowerDefs::SEPD)
328  {
329  DetectorEnum = TowerInfoContainer::DETECTOR::SEPD;
330  DetectorNodeName = "SEPD";
331  }
332  else if (m_dettype == CaloTowerDefs::ZDC)
333  {
334  DetectorEnum = TowerInfoContainer::DETECTOR::ZDC;
335  DetectorNodeName = "ZDC";
336  }
337  else if (m_dettype == CaloTowerDefs::HCALIN)
338  {
339  DetectorEnum = TowerInfoContainer::DETECTOR::HCAL;
340  DetectorNodeName = "HCALIN";
341  }
342  else if (m_dettype == CaloTowerDefs::HCALOUT)
343  {
344  DetectorEnum = TowerInfoContainer::DETECTOR::HCAL;
345  DetectorNodeName = "HCALOUT";
346  }
347  else
348  {
349  std::cout << PHWHERE << " Invalid detector type " << m_dettype << std::endl;
350  gSystem->Exit(1);
351  exit(1);
352  }
353  DetNode = dynamic_cast<PHCompositeNode *>(nodeItr.findFirst("PHCompositeNode", DetectorNodeName));
354  if (!DetNode)
355  {
356  DetNode = new PHCompositeNode(DetectorNodeName);
357  dstNode->addNode(DetNode);
358  }
360  {
361  m_CaloInfoContainer = new TowerInfoContainerv1(DetectorEnum);
362  }
364  {
365  m_CaloInfoContainer = new TowerInfoContainerv3(DetectorEnum);
366  }
368  {
369  m_CaloInfoContainer = new TowerInfoContainerv2(DetectorEnum);
370  }
371  else
372  {
373  std::cout << PHWHERE << "invalid builder type " << m_buildertype << std::endl;
374  gSystem->Exit(1);
375  exit(1);
376  }
379  DetNode->addNode(newTowerNode);
380 }