ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RawTowerZDCCalibration.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file RawTowerZDCCalibration.cc
2 
9 
10 #include <phparameter/PHParameters.h>
11 
13 #include <fun4all/SubsysReco.h>
14 
15 #include <phool/PHCompositeNode.h>
16 #include <phool/PHIODataNode.h>
17 #include <phool/PHNode.h>
18 #include <phool/PHNodeIterator.h>
19 #include <phool/PHObject.h>
20 #include <phool/getClass.h>
21 
22 #include <cassert>
23 #include <cmath>
24 #include <cstdlib>
25 #include <exception>
26 #include <iostream>
27 #include <map>
28 #include <stdexcept>
29 #include <string>
30 #include <utility>
31 
32 using namespace std;
33 
35  : SubsysReco(name)
36  , _calib_algorithm(kNo_calibration)
37  , //
38  _calib_towers(nullptr)
39  , _raw_towers(nullptr)
40  , //
41  rawtowergeom(nullptr)
42  , //
43  detector("NONE")
44  , //
45  _calib_tower_node_prefix("CALIB")
46  , _raw_tower_node_prefix("RAW")
47  , //
49  _pedestal_ADC(NAN)
50  ,
52  _pedestal_file(false)
53  ,
55  _calib_const_GeV_ADC(NAN)
56  , //
58  _GeV_ADC_file(false)
59  , _tower_type(-1)
60  , _tower_calib_params(name)
61 {
62 }
63 
65 {
66  PHNodeIterator iter(topNode);
67 
68  // Looking for the DST node
69  PHCompositeNode *dstNode;
70  dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode",
71  "DST"));
72  if (!dstNode)
73  {
74  std::cout << Name() << "::" << detector << "::" << __PRETTY_FUNCTION__
75  << "DST Node missing, doing nothing." << std::endl;
76  exit(1);
77  }
78 
79  try
80  {
81  CreateNodes(topNode);
82  }
83  catch (std::exception &e)
84  {
85  std::cout << e.what() << std::endl;
87  }
89 }
90 
92 {
93  if (Verbosity())
94  {
95  std::cout << Name() << "::" << detector << "::" << __PRETTY_FUNCTION__
96  << "Process event entered" << std::endl;
97  }
98 
101  for (rtiter = begin_end.first; rtiter != begin_end.second; ++rtiter)
102  {
103  const RawTowerZDCDefs::keytype key = rtiter->first;
104 
105  const RawTowerZDC *raw_tower = rtiter->second;
106  assert(raw_tower);
107 
109  raw_tower->get_id());
110  assert(raw_tower_geom);
111 
112  if (_tower_type >= 0)
113  {
114  // Skip towers that don't match the type we are supposed to calibrate
115  if (_tower_type != raw_tower_geom->get_tower_type())
116  {
117  continue;
118  }
119  }
120 
122  {
123  _calib_towers->AddTower(key, new RawTowerZDCv1(*raw_tower));
124  }
126  {
127  const double raw_energy = raw_tower->get_energy();
128  const double calib_energy = (raw_energy - _pedestal_ADC) * _calib_const_GeV_ADC;
129 
130  RawTowerZDC *calib_tower = new RawTowerZDCv1(*raw_tower);
131  calib_tower->set_energy(calib_energy);
132  _calib_towers->AddTower(key, calib_tower);
133  }
135  {
136  // RawTowerZDCDefs::CalorimeterId caloid = RawTowerZDCDefs::decode_caloid(key);
137  const int eta = raw_tower->get_bineta();
138  const int phi = raw_tower->get_binphi();
139  const int twr = raw_tower->get_binl();
140 
141  double tower_by_tower_calib = 1.;
142  const string calib_const_name("calib_const_eta" + to_string(eta) + "_phi" + to_string(phi) + "_twr" + to_string(twr));
143 
144  tower_by_tower_calib = _tower_calib_params.get_double_param(calib_const_name);
145 
146  if (_pedestal_file == true)
147  {
148  const string pedestal_name("PedCentral_ADC_eta" + to_string(eta) + "_phi" + to_string(phi)+ "_twr" + to_string(twr));
150  }
151 
152  if (_GeV_ADC_file == true)
153  {
154  const string GeVperADCname("GeVperADC_eta" + to_string(eta) + "_phi" + to_string(phi)+ "_twr" + to_string(twr));
156  }
157 
158  const double raw_energy = raw_tower->get_energy();
159  const double calib_energy = (raw_energy - _pedestal_ADC) * _calib_const_GeV_ADC * tower_by_tower_calib;
160 
161 
162  RawTowerZDC *calib_tower = new RawTowerZDCv1(*raw_tower);
163  calib_tower->set_energy(calib_energy);
164  _calib_towers->AddTower(key, calib_tower);
165  }
166  else
167  {
168  std::cout << Name() << "::" << detector << "::" << __PRETTY_FUNCTION__
169  << " invalid calibration algorithm #" << _calib_algorithm
170  << std::endl;
171 
173  }
174  } // for (rtiter = begin_end.first; rtiter != begin_end.second; ++rtiter)
175 
176  if (Verbosity())
177  {
178  std::cout << Name() << "::" << detector << "::" << __PRETTY_FUNCTION__
179  << "input sum energy = " << _raw_towers->getTotalEdep()
180  << ", output sum digitalized value = "
181  << _calib_towers->getTotalEdep() << std::endl;
182  }
184 }
185 
187 {
189 }
190 
192 {
193  PHNodeIterator iter(topNode);
194  PHCompositeNode *runNode = static_cast<PHCompositeNode *>(iter.findFirst(
195  "PHCompositeNode", "RUN"));
196  if (!runNode)
197  {
198  std::cerr << Name() << "::" << detector << "::" << __PRETTY_FUNCTION__
199  << "Run Node missing, doing nothing." << std::endl;
200  throw std::runtime_error(
201  "Failed to find Run node in RawTowerZDCCalibration::CreateNodes");
202  }
203 
204  TowerGeomNodeName = "TOWERGEOM_" + detector;
205  rawtowergeom = findNode::getClass<RawTowerZDCGeomContainer>(topNode,
207  if (!rawtowergeom)
208  {
209  std::cerr << Name() << "::" << detector << "::" << __PRETTY_FUNCTION__
210  << " " << TowerGeomNodeName << " Node missing, doing bail out!"
211  << std::endl;
212  throw std::runtime_error(
213  "Failed to find " + TowerGeomNodeName + " node in RawTowerZDCCalibration::CreateNodes");
214  }
215 
216  if (Verbosity() >= 1)
217  {
219  }
220 
221  PHCompositeNode *dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst(
222  "PHCompositeNode", "DST"));
223  if (!dstNode)
224  {
225  std::cerr << Name() << "::" << detector << "::" << __PRETTY_FUNCTION__
226  << "DST Node missing, doing nothing." << std::endl;
227  throw std::runtime_error(
228  "Failed to find DST node in RawTowerZDCCalibration::CreateNodes");
229  }
230 
231  RawTowerNodeName = "TOWER_" + _raw_tower_node_prefix + "_" + detector;
232  _raw_towers = findNode::getClass<RawTowerZDCContainer>(dstNode,
234  if (!_raw_towers)
235  {
236  std::cerr << Name() << "::" << detector << "::" << __PRETTY_FUNCTION__
237  << " " << RawTowerNodeName << " Node missing, doing bail out!"
238  << std::endl;
239  throw std::runtime_error(
240  "Failed to find " + RawTowerNodeName + " node in RawTowerZDCCalibration::CreateNodes");
241  }
242 
243  // Create the tower nodes on the tree
244  PHNodeIterator dstiter(dstNode);
245  PHCompositeNode *DetNode = dynamic_cast<PHCompositeNode *>(dstiter.findFirst(
246  "PHCompositeNode", detector));
247  if (!DetNode)
248  {
249  DetNode = new PHCompositeNode(detector);
250  dstNode->addNode(DetNode);
251  }
252 
253  // Be careful as a previous calibrator may have been registered for this detector
255  _calib_towers = findNode::getClass<RawTowerZDCContainer>(DetNode,
257  if (!_calib_towers)
258  {
261  DetNode->addNode(towerNode);
262  }
263  return;
264 }