Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LEDTowerBuilder.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file LEDTowerBuilder.cc
1 #include "LEDTowerBuilder.h"
2 //____________________________________________________________________________..
4  SubsysReco(name)
5  , m_dettype(LEDTowerBuilder::CEMC)
6  , m_detector("CEMC")
7  , m_packet_low(6001) // 6001
8  , m_packet_high(6128) // 6128
9  , m_nsamples(32)
10  , m_nchannels(192)
11  , m_isdata(true)
12  , m_event(0)
13  , m_adc(0)
14  , m_ped(0)
15  , m_time(0)
16  , m_chan(0)
17  , m_waveforms(0)
18  , m_outputFilename(name) {
19  std::cout << "LEDTowerBuilder::LEDTowerBuilder(const std::string &name) Calling ctor" << std::endl;
20 
21  tOut = new TTree("W","W");
22 
23  tOut -> Branch("time",&m_time);
24  tOut -> Branch("adc",&m_adc);
25  tOut -> Branch("ped",&m_ped);
26  tOut -> Branch("waveforms",&m_waveforms);
27  tOut -> Branch("chan",&m_chan);
28 }
29 
30 //____________________________________________________________________________..
32  std::cout << "LEDTowerBuilder::~LEDTowerBuilder() Calling dtor" << std::endl;
33 }
34 
35 //____________________________________________________________________________..
39 
41  m_detector = "CEMC";
42  m_packet_low = 6001;
43  m_packet_high = 6128;
44  m_nchannels = 192;
45  WaveformProcessing->set_template_file("testbeam_cemc_template.root");
46  }
47  else if (m_dettype == LEDTowerBuilder::HCALIN) {
48  m_detector = "HCALIN";
49  m_packet_low = 7001;
50  m_packet_high = 7008;
51  m_nchannels = 192;
52  WaveformProcessing->set_template_file("testbeam_ihcal_template.root");
53  }
54  else if (m_dettype == LEDTowerBuilder::HCALOUT) {
55  m_detector = "HCALOUT";
56  m_packet_low = 8001;
57  m_packet_high = 8008;
58  m_nchannels = 192;
59  WaveformProcessing->set_template_file("testbeam_ohcal_template.root");
60  }
61  else if (m_dettype == LEDTowerBuilder::EPD) {
62  m_detector = "EPD";
63  m_packet_low = 9001;
64  m_packet_high = 9016;
65  WaveformProcessing->set_template_file("testbeam_cemc_template.root"); // place holder until we have EPD templates
66  }
68  //CreateNodeTree(topNode);
69  topNode->print();
71 }
72 
73 //____________________________________________________________________________..
75  if(m_event % 100 == 0) std::cout << "Event: " << m_event << std::endl;
76  ++m_event;
77 
78  if (m_isdata) {
79  Event *_event = findNode::getClass<Event>(topNode, "PRDF");
80  if (_event == 0) {
81  std::cout << "CaloUnpackPRDF::Process_Event - Event not found" << std::endl;
82  return -1;
83  }
84  // special event where we do not read out the calorimeters
85  if ( _event->getEvtType() >= 8) {
86  std::cout << "Event Type >= 8!!" << std::endl;
88  }
89  for (int pid = m_packet_low; pid <= m_packet_high; pid++) {
90  // there are 192 channels in a packet
91  // Determine the channel id offset
92  UInt_t channel_offset = (pid-m_packet_low)*m_nchannels;
93  Packet* packet = _event->getPacket(pid);
94  if (!packet) {
95  // std::cout << "No packet!!, pid: " << pid << std::endl;
96  continue;
97  }
98  int nchannels = packet->iValue(0,"CHANNELS");
99 
100  // ensure that there are at most 192 channels in the packet
101  // packet is corrupted if it reports too many channels
102  if(nchannels > m_nchannels) {
104  }
105 
106  for (int channel = 0; channel < nchannels; ++channel) {
107  std::vector<float> waveform;
108  waveform.reserve(m_nsamples);
109 
110  for (int samp = 0; samp < m_nsamples; samp++) {
111  waveform.push_back(packet->iValue(samp,channel));
112  }
113  m_waveforms.push_back(waveform);
114  m_chan.push_back(channel_offset+channel);
115  waveform.clear();
116  }
117  delete packet;
118  }
119  }
120  // placeholder for adding simulation
121  else {
122  std::cout << "m_isdata: false!!" << std::endl;
124  }
125  std::vector<std::vector<float>> processed_waveforms = WaveformProcessing->process_waveform(m_waveforms);
126 
127  int n_channels = processed_waveforms.size();
128  for (int i = 0 ; i < n_channels; i++) {
129  m_time.push_back(processed_waveforms.at(i).at(1));
130  m_adc.push_back(processed_waveforms.at(i).at(0));
131  m_ped.push_back(processed_waveforms.at(i).at(2));
132  }
133 
134  tOut -> Fill();
135 
136  m_time.clear();
137  m_adc.clear();
138  m_ped.clear();
139  m_chan.clear();
140  m_waveforms.clear();
141 
143 }
144 
146  std::cout << "LEDTowerBuilder opening output file: " << m_outputFilename << std::endl;
147  TFile output(m_outputFilename.c_str(),"recreate");
148  output.cd();
149  tOut -> Write();
150  output.Close();
151 
153 }