ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RawTowerCalibration.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file RawTowerCalibration.cc
1 #include "RawTowerCalibration.h"
2 
3 #include <calobase/RawTower.h>
4 #include <calobase/RawTowerContainer.h>
5 #include <calobase/RawTowerDefs.h>
6 #include <calobase/RawTowerGeom.h>
7 #include <calobase/RawTowerGeomContainer.h>
8 #include <calobase/RawTowerv1.h>
9 #include <calobase/RawTowerv2.h>
10 
11 #include <phparameter/PHParameters.h>
12 
14 #include <fun4all/SubsysReco.h>
15 
16 #include <phool/PHCompositeNode.h>
17 #include <phool/PHIODataNode.h>
18 #include <phool/PHNode.h>
19 #include <phool/PHNodeIterator.h>
20 #include <phool/PHObject.h>
21 #include <phool/getClass.h>
22 
23 #include <cassert>
24 #include <cmath>
25 #include <cstdlib>
26 #include <exception>
27 #include <iostream>
28 #include <map>
29 #include <stdexcept>
30 #include <string>
31 #include <utility>
32 
33 using namespace std;
34 
36  : SubsysReco(name)
37  , _calib_algorithm(kNo_calibration)
38  , //
39  _calib_towers(nullptr)
40  , _raw_towers(nullptr)
41  , //
42  rawtowergeom(nullptr)
43  , //
44  detector("NONE")
45  , //
46  _calib_tower_node_prefix("CALIB")
47  , _raw_tower_node_prefix("RAW")
48  , //
50  _pedstal_ADC(NAN)
51  ,
53  _pedestal_file(false)
54  ,
56  _calib_const_GeV_ADC(NAN)
57  , //
59  _GeV_ADC_file(false)
60  , _tower_type(-1)
61  , _tower_calib_params(name)
62 {
63 }
64 
66 {
67  PHNodeIterator iter(topNode);
68 
69  // Looking for the DST node
70  PHCompositeNode *dstNode;
71  dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode",
72  "DST"));
73  if (!dstNode)
74  {
75  std::cout << Name() << "::" << detector << "::" << __PRETTY_FUNCTION__
76  << "DST Node missing, doing nothing." << std::endl;
77  exit(1);
78  }
79 
80  try
81  {
82  CreateNodes(topNode);
83  }
84  catch (std::exception &e)
85  {
86  std::cout << e.what() << std::endl;
88  }
90 }
91 
93 {
94  if (Verbosity())
95  {
96  std::cout << Name() << "::" << detector << "::" << __PRETTY_FUNCTION__
97  << "Process event entered" << std::endl;
98  }
99 
102  for (rtiter = begin_end.first; rtiter != begin_end.second; ++rtiter)
103  {
104  const RawTowerDefs::keytype key = rtiter->first;
105 
106  const RawTower *raw_tower = rtiter->second;
107  assert(raw_tower);
108 
109  RawTowerGeom *raw_tower_geom = rawtowergeom->get_tower_geometry(
110  raw_tower->get_id());
111  assert(raw_tower_geom);
112 
113  if (_tower_type >= 0)
114  {
115  // Skip towers that don't match the type we are supposed to calibrate
116  if (_tower_type != raw_tower_geom->get_tower_type())
117  {
118  continue;
119  }
120  }
121 
123  {
124  _calib_towers->AddTower(key, new RawTowerv2(*raw_tower));
125  }
127  {
128  const double raw_energy = raw_tower->get_energy();
129  const double calib_energy = (raw_energy - _pedstal_ADC) * _calib_const_GeV_ADC;
130 
131  RawTower *calib_tower = new RawTowerv2(*raw_tower);
132  calib_tower->set_energy(calib_energy);
133  _calib_towers->AddTower(key, calib_tower);
134  }
136  {
138  const int eta = raw_tower->get_bineta();
139  const int phi = raw_tower->get_binphi();
140 
141  double tower_by_tower_calib = 1.;
142  if (caloid == RawTowerDefs::LFHCAL)
143  {
144  const int l = raw_tower->get_binl();
145  const string calib_const_name("calib_const_eta" + to_string(eta) + "_phi" + to_string(phi) + "_l" + to_string(l));
146 
147  tower_by_tower_calib = _tower_calib_params.get_double_param(calib_const_name);
148 
149  if (_pedestal_file == true)
150  {
151  const string pedstal_name("PedCentral_ADC_eta" + to_string(eta) + "_phi" + to_string(phi)+ "_l" + to_string(l));
152  _pedstal_ADC =
154  }
155 
156  if (_GeV_ADC_file == true)
157  {
158  const string GeVperADCname("GeVperADC_eta" + to_string(eta) + "_phi" + to_string(phi)+ "_l" + to_string(l));
160  _tower_calib_params.get_double_param(GeVperADCname);
161  }
162  }
163  else
164  {
165  const string calib_const_name("calib_const_eta" + to_string(eta) + "_phi" + to_string(phi));
166 
167  tower_by_tower_calib = _tower_calib_params.get_double_param(calib_const_name);
168 
169  if (_pedestal_file == true)
170  {
171  const string pedstal_name("PedCentral_ADC_eta" + to_string(eta) + "_phi" + to_string(phi));
172  _pedstal_ADC =
174  }
175 
176  if (_GeV_ADC_file == true)
177  {
178  const string GeVperADCname("GeVperADC_eta" + to_string(eta) + "_phi" + to_string(phi));
180  _tower_calib_params.get_double_param(GeVperADCname);
181  }
182 
183  }
184  const double raw_energy = raw_tower->get_energy();
185  const double calib_energy = (raw_energy - _pedstal_ADC) * _calib_const_GeV_ADC * tower_by_tower_calib;
186 
187 
188  RawTower *calib_tower = new RawTowerv2(*raw_tower);
189  calib_tower->set_energy(calib_energy);
190  _calib_towers->AddTower(key, calib_tower);
191  }
192  else
193  {
194  std::cout << Name() << "::" << detector << "::" << __PRETTY_FUNCTION__
195  << " invalid calibration algorithm #" << _calib_algorithm
196  << std::endl;
197 
199  }
200  } // for (rtiter = begin_end.first; rtiter != begin_end.second; ++rtiter)
201 
202  if (Verbosity())
203  {
204  std::cout << Name() << "::" << detector << "::" << __PRETTY_FUNCTION__
205  << "input sum energy = " << _raw_towers->getTotalEdep()
206  << ", output sum digitalized value = "
207  << _calib_towers->getTotalEdep() << std::endl;
208  }
210 }
211 
213 {
215 }
216 
218 {
219  PHNodeIterator iter(topNode);
220  PHCompositeNode *runNode = static_cast<PHCompositeNode *>(iter.findFirst(
221  "PHCompositeNode", "RUN"));
222  if (!runNode)
223  {
224  std::cerr << Name() << "::" << detector << "::" << __PRETTY_FUNCTION__
225  << "Run Node missing, doing nothing." << std::endl;
226  throw std::runtime_error(
227  "Failed to find Run node in RawTowerCalibration::CreateNodes");
228  }
229 
230  TowerGeomNodeName = "TOWERGEOM_" + detector;
231  rawtowergeom = findNode::getClass<RawTowerGeomContainer>(topNode,
233  if (!rawtowergeom)
234  {
235  std::cerr << Name() << "::" << detector << "::" << __PRETTY_FUNCTION__
236  << " " << TowerGeomNodeName << " Node missing, doing bail out!"
237  << std::endl;
238  throw std::runtime_error(
239  "Failed to find " + TowerGeomNodeName + " node in RawTowerCalibration::CreateNodes");
240  }
241 
242  if (Verbosity() >= 1)
243  {
245  }
246 
247  PHCompositeNode *dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst(
248  "PHCompositeNode", "DST"));
249  if (!dstNode)
250  {
251  std::cerr << Name() << "::" << detector << "::" << __PRETTY_FUNCTION__
252  << "DST Node missing, doing nothing." << std::endl;
253  throw std::runtime_error(
254  "Failed to find DST node in RawTowerCalibration::CreateNodes");
255  }
256 
257  RawTowerNodeName = "TOWER_" + _raw_tower_node_prefix + "_" + detector;
258  _raw_towers = findNode::getClass<RawTowerContainer>(dstNode,
260  if (!_raw_towers)
261  {
262  std::cerr << Name() << "::" << detector << "::" << __PRETTY_FUNCTION__
263  << " " << RawTowerNodeName << " Node missing, doing bail out!"
264  << std::endl;
265  throw std::runtime_error(
266  "Failed to find " + RawTowerNodeName + " node in RawTowerCalibration::CreateNodes");
267  }
268 
269  // Create the tower nodes on the tree
270  PHNodeIterator dstiter(dstNode);
271  PHCompositeNode *DetNode = dynamic_cast<PHCompositeNode *>(dstiter.findFirst(
272  "PHCompositeNode", detector));
273  if (!DetNode)
274  {
275  DetNode = new PHCompositeNode(detector);
276  dstNode->addNode(DetNode);
277  }
278 
279  // Be careful as a previous calibrator may have been registered for this detector
281  _calib_towers = findNode::getClass<RawTowerContainer>(DetNode,
283  if (!_calib_towers)
284  {
287  DetNode->addNode(towerNode);
288  }
289  return;
290 }