Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CaloTowerCalib.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CaloTowerCalib.cc
1 #include "CaloTowerCalib.h"
2 #include "CaloTowerDefs.h"
3 
4 #include <calobase/TowerInfo.h> // for TowerInfo
5 #include <calobase/TowerInfo.h>
6 #include <calobase/TowerInfoContainer.h>
7 #include <calobase/TowerInfoContainerv1.h>
8 #include <calobase/TowerInfoContainerv2.h>
9 #include <calobase/TowerInfov1.h>
10 #include <calobase/TowerInfov2.h>
11 
12 #include <cdbobjects/CDBTTree.h> // for CDBTTree
13 
15 
16 #include <ffaobjects/EventHeader.h>
17 
19 #include <fun4all/SubsysReco.h> // for SubsysReco
20 
21 #include <phool/PHCompositeNode.h>
22 #include <phool/PHIODataNode.h> // for PHIODataNode
23 #include <phool/PHNode.h> // for PHNode
24 #include <phool/PHNodeIterator.h> // for PHNodeIterator
25 #include <phool/PHObject.h> // for PHObject
26 #include <phool/getClass.h>
27 #include <phool/phool.h>
28 #include <phool/recoConsts.h>
29 
30 #include <TSystem.h>
31 
32 #include <cstdlib> // for exit
33 #include <exception> // for exception
34 #include <iostream> // for operator<<, basic_ostream
35 #include <stdexcept> // for runtime_error
36 
37 //____________________________________________________________________________..
39  : SubsysReco(name)
40  , m_dettype(CaloTowerDefs::HCALOUT)
41  , m_detector("HCALOUT")
42  , m_DETECTOR(TowerInfoContainer::HCAL)
43  , m_fieldname("")
44  , m_runNumber(-1)
45 {
46  if (Verbosity() > 0) std::cout << "CaloTowerCalib::CaloTowerCalib(const std::string &name) Calling ctor" << std::endl;
47 }
48 
49 //____________________________________________________________________________..
51 {
52  delete cdbttree;
53  if (Verbosity() > 0) std::cout << "CaloTowerCalib::~CaloTowerCalib() Calling dtor" << std::endl;
54 }
55 
56 //____________________________________________________________________________..
58 {
59  PHNodeIterator nodeIter(topNode);
60 
61  EventHeader *evtHeader = findNode::getClass<EventHeader>(topNode, "EventHeader");
62 
63  if (evtHeader)
64  {
65  m_runNumber = evtHeader->get_RunNumber();
66  }
67  else
68  {
69  m_runNumber = -1;
70  }
71 
73  {
74  m_detector = "CEMC";
76  std::string default_time_independent_calib = "cemc_pi0_twrSlope_v1_default";
77 
79  {
80  m_calibName = "cemc_pi0_twrSlope_v1";
81  }
83  {
84  m_fieldname = "Femc_datadriven_qm1_correction";
85  }
87  if (!calibdir.empty())
88  {
89  cdbttree = new CDBTTree(calibdir);
90  }
91  else
92  {
93  calibdir = CDBInterface::instance()->getUrl(default_time_independent_calib);
94 
95  if (calibdir.empty())
96  {
97  std::cout << "CaloTowerCalib::::InitRun No EMCal Calibration NOT even a default" << std::endl;
98  exit(1);
99  }
100  cdbttree = new CDBTTree(calibdir);
101  std::cout << "CaloTowerCalib::::InitRun No specific file for " << m_calibName << " found, using default calib " << default_time_independent_calib << std::endl;
102  }
103  }
104  else if (m_dettype == CaloTowerDefs::HCALIN)
105  {
106  m_detector = "HCALIN";
108 
109  if (!m_overrideCalibName)
110  {
111  m_calibName = "ihcal_abscalib_cosmic";
112  }
113  if (!m_overrideFieldName)
114  {
115  m_fieldname = "ihcal_abscalib_mip";
116  }
118  if (!calibdir.empty())
119  {
120  cdbttree = new CDBTTree(calibdir);
121  }
122  else
123  {
124  std::cout << "CaloTowerCalib::::InitRun No calibration file for domain " << m_calibName << " found" << std::endl;
125  exit(1);
126  }
127  }
128  else if (m_dettype == CaloTowerDefs::HCALOUT)
129  {
130  m_detector = "HCALOUT";
132 
133  if (!m_overrideCalibName)
134  {
135  m_calibName = "ohcal_abscalib_cosmic";
136  }
137  if (!m_overrideFieldName)
138  {
139  m_fieldname = "ohcal_abscalib_mip";
140  }
142  if (!calibdir.empty())
143  {
144  cdbttree = new CDBTTree(calibdir);
145  }
146  else
147  {
148  std::cout << "CaloTowerCalib::::InitRun No calibration file for domain " << m_calibName << " found" << std::endl;
149  exit(1);
150  }
151  }
152  else if (m_dettype == CaloTowerDefs::ZDC)
153  {
154  m_detector = "ZDC";
156 
157  if (!m_overrideCalibName)
158  {
159  m_calibName = "data_driven_zdc_calib";
160  }
161  if (!m_overrideFieldName)
162  {
163  m_fieldname = "zdc_calib";
164  }
166  if (!calibdir.empty())
167  {
168  cdbttree = new CDBTTree(calibdir);
169  }
170  else
171  {
172  std::cout << "CaloTowerCalib::::InitRun No calibration file for domain " << m_calibName << " found" << std::endl;
173  exit(1);
174  }
175  }
176 
177  else if (m_dettype == CaloTowerDefs::SEPD)
178  {
179  m_detector = "SEPD";
181  if (!m_overrideCalibName)
182  {
183  m_calibName = "noCalibYet";
184  }
185  if (!m_overrideFieldName)
186  {
187  m_fieldname = "noCalibYet";
188  }
190  if (!calibdir.empty())
191  {
192  cdbttree = new CDBTTree(calibdir);
193  }
194  else
195  {
196  std::cout << "CaloTowerCalib::::InitRun No calibration file for domain " << m_calibName << " found" << std::endl;
197  exit(1);
198  }
199  }
200 
201  if (m_giveDirectURL)
202  {
204  }
205 
206  PHNodeIterator iter(topNode);
207 
208  // Looking for the DST node
209  PHCompositeNode *dstNode;
210  dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
211  if (!dstNode)
212  {
213  std::cout << Name() << "::" << m_detector << "::" << __PRETTY_FUNCTION__
214  << "DST Node missing, doing nothing." << std::endl;
215  exit(1);
216  }
217  try
218  {
219  CreateNodeTree(topNode);
220  }
221  catch (std::exception &e)
222  {
223  std::cout << e.what() << std::endl;
225  }
226  if (Verbosity() > 0) topNode->print();
228 }
229 
230 //____________________________________________________________________________..
232 {
233  TowerInfoContainer *_raw_towers = findNode::getClass<TowerInfoContainer>(topNode, RawTowerNodeName);
234  TowerInfoContainer *_calib_towers = findNode::getClass<TowerInfoContainer>(topNode, CalibTowerNodeName);
235  unsigned int ntowers = _raw_towers->size();
236 
237  for (unsigned int channel = 0; channel < ntowers; channel++)
238  {
239  unsigned int key = _raw_towers->encode_key(channel);
240  TowerInfo *caloinfo_raw = _raw_towers->get_tower_at_channel(channel);
241  _calib_towers->get_tower_at_channel(channel)->copy_tower(caloinfo_raw);
242  float raw_amplitude = caloinfo_raw->get_energy();
243  float calibconst = cdbttree->GetFloatValue(key, m_fieldname);
244  _calib_towers->get_tower_at_channel(channel)->set_energy(raw_amplitude * calibconst);
245  if (calibconst==0)
246  {
247  _calib_towers->get_tower_at_channel(channel)->set_isNoCalib(true);
248  }
249  }
251 }
252 
254 {
255  PHNodeIterator iter(topNode);
256  PHCompositeNode *dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
257  if (!dstNode)
258  {
259  std::cerr << Name() << "::" << m_detector << "::" << __PRETTY_FUNCTION__
260  << "DST Node missing, doing nothing." << std::endl;
261  throw std::runtime_error("Failed to find DST node in RawTowerCalibration::CreateNodes");
262  }
263  // detector node
264 
265  PHCompositeNode *DetNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", m_detector));
266 
267  if (!DetNode)
268  {
269  DetNode = new PHCompositeNode(m_detector);
270  dstNode->addNode(DetNode);
271  }
272 
273  // towers
275  TowerInfoContainer *_raw_towers = findNode::getClass<TowerInfoContainer>(dstNode, RawTowerNodeName);
276  if (!_raw_towers)
277  {
278  std::cout << Name() << "::" << m_detector << "::" << __PRETTY_FUNCTION__
279  << " " << RawTowerNodeName << " Node missing, doing bail out!"
280  << std::endl;
281  throw std::runtime_error(
282  "Failed to find " + RawTowerNodeName + " node in RawTowerCalibration::CreateNodes");
283  }
284 
286  TowerInfoContainer *_calib_towers = findNode::getClass<TowerInfoContainer>(dstNode, CalibTowerNodeName);
287  if (!_calib_towers)
288  {
289  _calib_towers = dynamic_cast<TowerInfoContainer *>(_raw_towers->CloneMe());
290  }
291  PHIODataNode<PHObject> *calibtowerNode = new PHIODataNode<PHObject>(_calib_towers, CalibTowerNodeName, "PHObject");
292  DetNode->addNode(calibtowerNode);
293  return;
294 }