Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CaloTowerStatus.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CaloTowerStatus.cc
1 #include "CaloTowerStatus.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 {
41  if (Verbosity() > 0)
42  {
43  std::cout << "CaloTowerStatus::CaloTowerStatus(const std::string &name) Calling ctor" << std::endl;
44  }
45 }
46 
47 //____________________________________________________________________________..
49 {
50  delete m_cdbttree_chi2;
51  delete m_cdbttree_time;
52  if (Verbosity() > 0)
53  {
54  std::cout << "CaloTowerStatus::~CaloTowerStatus() Calling dtor" << std::endl;
55  }
56 }
57 
58 //____________________________________________________________________________..
60 {
61  PHNodeIterator nodeIter(topNode);
62 
64  {
65  m_detector = "CEMC";
66  }
67  else if (m_dettype == CaloTowerDefs::HCALIN)
68  {
69  m_detector = "HCALIN";
70  }
72  {
73  m_detector = "HCALOUT";
74  }
75  else if (m_dettype == CaloTowerDefs::ZDC)
76  {
77  m_detector = "ZDC";
78  }
79 
80  else if (m_dettype == CaloTowerDefs::SEPD)
81  {
82  m_detector = "SEPD";
83  }
84 
85  m_calibName_chi2 = m_detector + "_hotTowers_fracBadChi2";
86  m_fieldname_chi2 = "fraction";
87 
89  if (!calibdir.empty())
90  {
91  m_cdbttree_chi2 = new CDBTTree(calibdir);
92  }
93  else
94  {
95  std::cout << "CaloTowerStatus::::InitRun No masking file for domain " << m_calibName_chi2 << " found, not doing isHot" << std::endl;
96  m_doHotChi2 = false;
97  }
98 
99  m_calibName_time = m_detector + "_meanTime";
100  m_fieldname_time = "time";
101 
103  if (!calibdir.empty())
104  {
105  m_cdbttree_time = new CDBTTree(calibdir);
106  }
107  else
108  {
109  std::cout << "CaloTowerStatus::::InitRun no timing info, " << m_calibName_time << " not found, not doing isHot" << std::endl;
110  m_doTime = false;
111  }
112 
113  m_calibName_hotMap = m_detector + "nome";
114  if (m_dettype == CaloTowerDefs::CEMC) m_calibName_hotMap = m_detector + "_BadTowerMap";
115  m_fieldname_hotMap = "status";
116 
118  if (!calibdir.empty())
119  {
120  m_cdbttree_hotMap = new CDBTTree(calibdir);
121  }
122  else
123  {
124  std::cout << "CaloTowerStatus::::InitRun hot map info, " << m_calibName_hotMap << " not found, not doing isHot" << std::endl;
125  m_doHotMap = false;
126  }
127 
128 
129  PHNodeIterator iter(topNode);
130 
131  // Looking for the DST node
132  PHCompositeNode *dstNode;
133  dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
134  if (!dstNode)
135  {
136  std::cout << Name() << "::" << m_detector << "::" << __PRETTY_FUNCTION__
137  << "DST Node missing, doing nothing." << std::endl;
138  exit(1);
139  }
140  try
141  {
142  CreateNodeTree(topNode);
143  }
144  catch (std::exception &e)
145  {
146  std::cout << e.what() << std::endl;
148  }
149  if (Verbosity() > 0)
150  {
151  topNode->print();
152  }
154 }
155 
156 //____________________________________________________________________________..
158 {
159  unsigned int ntowers = m_raw_towers->size();
160  float fraction_badChi2 = 0;
161  float mean_time = 0;
162  int hotMap_val = 0;
163  for (unsigned int channel = 0; channel < ntowers; channel++)
164  {
165  unsigned int key = m_raw_towers->encode_key(channel);
166  m_raw_towers->get_tower_at_channel(channel)->set_status(0); // resetting status
167 
168  if (m_doHotChi2)
169  {
170  fraction_badChi2 = m_cdbttree_chi2->GetFloatValue(key, m_fieldname_chi2);
171  }
172  if (m_doTime)
173  {
175  }
176  if (m_doHotMap)
177  {
179  }
182 
183  if (fraction_badChi2 > fraction_badChi2_threshold && m_doHotChi2)
184  {
186  }
187  if (fabs(time-mean_time) > time_cut && m_doTime)
188  {
190  }
191  if (hotMap_val != 0 && m_doHotMap)
192  {
194  }
195  if (chi2 > badChi2_treshold)
196  {
198  }
199  }
201 }
202 
204 {
205  std::string RawTowerNodeName = m_inputNodePrefix + m_detector;
206  m_raw_towers = findNode::getClass<TowerInfoContainer>(topNode, RawTowerNodeName);
207  if (!m_raw_towers)
208  {
209  std::cout << Name() << "::" << m_detector << "::" << __PRETTY_FUNCTION__
210  << " " << RawTowerNodeName << " Node missing, doing bail out!"
211  << std::endl;
212  throw std::runtime_error(
213  "Failed to find " + RawTowerNodeName + " node in CaloTowerStatus::CreateNodes");
214  }
215 
216  return;
217 }