Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
hcal_towerid.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file hcal_towerid.cc
1 #include "hcal_towerid.h"
4 
5 //Fun4All
10 #include <phool/getClass.h>
11 #include <phool/phool.h>
12 #include <ffaobjects/EventHeader.h>
13 
14 //ROOT
15 #include <TFile.h>
16 #include <TTree.h>
17 #include <TH1F.h>
18 #include <TH2F.h>
19 
20 //Tower stuff
21 #include <calobase/TowerInfoContainer.h>
22 #include <calobase/TowerInfo.h>
23 #include <calobase/TowerInfoDefs.h>
24 
25 #include <cdbobjects/CDBTTree.h>
26 
27 //________________________________
28 hcal_towerid::hcal_towerid(const std::string &name, const std::string &cdbtreename_i, const std::string &cdbtreename_o, float adccut_i, float adccut_o, float sigmas_lo, float sigmas_hi, float inner_f,float outer_f):
29 SubsysReco(name)
30  ,T(nullptr)
31  ,Outfile(name)
32  ,cdbtreename_i(cdbtreename_i)
33  ,cdbtreename_o(cdbtreename_o)
34  ,adccut_i(adccut_i)
35  ,adccut_o(adccut_o) // Minimum ADC for Kurary fibers to register a hit
36  ,sigmas_lo(sigmas_lo) // # of standard deviations from the mode for a cold tower
37  ,sigmas_hi(sigmas_hi) // # of standard deviations from the mode for a hot tower
38  ,inner_f(inner_f)
39  ,outer_f(outer_f) // Fiducial cut for Sectors and IBs
40 {
41  std::cout << "towerid::towerid(const std::string &name) Calling ctor" << std::endl;
42 }
43 //__________________________________
45 {
46  std::cout << "towerid::~towerid() Calling dtor" << std::endl;
47 }
48 //_____________________________
50 {
51  //initialize output file with hot channels
52  out = new TFile(Outfile.c_str(),"RECREATE");
53  T = new TTree("T_inner","T_inner");
54  T2 = new TTree("T_outer","T_outer");
55  T -> Branch("hot_channels",&m_hot_channels_i);
56  T2-> Branch("hot_channels",&m_hot_channels_o);
57 
58  std::cout << "towerid::Init(PHCompositeNode *topNode) Initializing" << std::endl;
60 
61 }
62 //_____________________________
64 {
65  std::cout << "towerid::InitRun(PHCompositeNode *topNode) Initializing for Run XXX" << std::endl;
67 }
68 //_____________________________
70 {
71 
72 //Get TowerInfoContainer
73 TowerInfoContainer *hcalTowerContainer_i;
74 TowerInfoContainer *hcalTowerContainer_o;
75 
76 hcalTowerContainer_i = findNode::getClass<TowerInfoContainer>(topNode,"TOWERS_HCALIN");
77 hcalTowerContainer_o = findNode::getClass<TowerInfoContainer>(topNode,"TOWERS_HCALOUT");
78  if(!hcalTowerContainer_o)
79  {
80  std::cout << PHWHERE << "towerid::process_event Could not find node TOWERS_CEMC" << std::endl;
82  }
83 //iterate through all towers, incrementing their Frequency arrays if they record a hit
84 
85  bool goodevent = false;
86  int tower_range_i = hcalTowerContainer_i->size();
87  int tower_range_o = hcalTowerContainer_o->size();
88  for(int j = 0; j < tower_range_i; j++){
89 
90  double energy = hcalTowerContainer_i -> get_tower_at_channel(j) -> get_energy();
91  if(energy > adccut_i){
92  itowerF[j]++;
93  goodevent = true; //counter of events with nonzero EMCal energy
94  }
95 
96  //std::cout << energy << std::endl;
97  itowerE[j]+=energy;
98 
99  }
100  for(int j = 0; j < tower_range_o; j++){
101 
102  double energy = hcalTowerContainer_o -> get_tower_at_channel(j) -> get_energy();
103  if(energy > adccut_o){
104  otowerF[j]++;
105  goodevent = true; //counter of events with nonzero EMCal energy
106  }
107 
108  //std::cout << energy << std::endl;
109  otowerE[j]+=energy;
110 
111  }
112  if(goodevent == true){goodevents++;}
114 }
115 //__________________________
117 {
119 }
120 
121 
122 //__________________________
124 {
125 
126  // initialize histograms: Initial frequency spectra, Energy spectrum, and Frequency spectrum with Fiducial cuts
127 
128  Fspeci_i->SetBins(goodevents,0,goodevents);
129  Fspeci_o->SetBins(goodevents,0,goodevents);
130 
131  Fspec_i->SetBins(goodevents,0,inner_f*goodevents);
132  Fspec_o->SetBins(goodevents,0,outer_f*goodevents);
133 
134  Espec_i->SetBins(goodevents,0,goodevents);
135  Espec_o->SetBins(goodevents,0,goodevents);
136  //fill histograms
137 
138  for(int i = 0; i < 1536; i++){
139 
140  Fspec_i->Fill(itowerF[i]);
141  Espec_i->Fill(itowerE[i]);
142  Fspeci_i->Fill(itowerF[i]);
143 
144  Fspec_o->Fill(otowerF[i]);
145  Espec_o->Fill(otowerE[i]);
146  Fspeci_o->Fill(otowerF[i]);
147  }
148 
149  //kill zeros:
150 
151  Fspec_i->SetBinContent(1,0);
152  Fspec_o->SetBinContent(1,0);
153 
154  float cutoffFreq_i;
155  float cutoffFreq_i_lo;
156  float cutoffFreq_o;
157  float cutoffFreq_o_lo;
158 
159  cutoffFreq_i = Fspec_i->GetStdDev()*sigmas_hi + Fspec_i->GetXaxis()->GetBinCenter(Fspec_i->GetMaximumBin());
160  cutoffFreq_i_lo = -1*Fspec_i->GetStdDev()*sigmas_lo + Fspec_i->GetXaxis()->GetBinCenter(Fspec_i->GetMaximumBin());
161  cutoffFreq_o = Fspec_o->GetStdDev()*sigmas_hi + Fspec_o->GetXaxis()->GetBinCenter(Fspec_o->GetMaximumBin());
162  cutoffFreq_o_lo = -1*Fspec_o->GetStdDev()*sigmas_lo + Fspec_o->GetXaxis()->GetBinCenter(Fspec_o->GetMaximumBin());
163 
164  std::cout << "towerid::EndRun(const int runnumber) Ending Run for Run " << runnumber << std::endl;
165  std::cout << "Inner hot tower cutoff: " << cutoffFreq_i << std::endl;
166  std::cout << "Inner cold tower cutoff: " << cutoffFreq_i_lo << std::endl;
167 
168  std::cout << "Outer hot tower cutoff: " << cutoffFreq_o << std::endl;
169  std::cout << "OUter cold tower cutoff: " << cutoffFreq_o_lo << std::endl;
170 
171  for(int i = 0; i < 1536; i++){
172 
173  if(itowerF[i] > cutoffFreq_i){
174  ihottowers[i]++;
175  }
176  if(otowerF[i]> cutoffFreq_o){
177  ohottowers[i]++;
178  }
179  if(itowerF[i]==0){
180  ideadtowers[i]++;
181  }
182  if(otowerF[i]==0){
183  odeadtowers[i]++;
184  }
185  if(itowerF[i] < cutoffFreq_i_lo && itowerF[i]>0){
186  icoldtowers[i]++;
187  }
188  if (otowerF[i] < cutoffFreq_o_lo && otowerF[i] > 0){
189  ocoldtowers[i]++;
190  }
191  }
192 
193  std::cout << "towerid::EndRun(const int runnumber) Ending Run for Run " << runnumber << std::endl;
195 }
196 
197 //____________________________________________________________________________..
199 {
200  std::cout << "towerid::End(PHCompositeNode *topNode) This is the End..." << std::endl;
201 
202  CDBTTree*icdbttree = new CDBTTree(cdbtreename_i);
203  CDBTTree*ocdbttree = new CDBTTree(cdbtreename_o);
204  std::string fieldname = "status";
205  for(int i = 0; i<1536; i++){
206 
207  if(ihottowers[i] >= 0.5){
208  m_hot_channels_i = 2;
209  T->Fill();
210  icdbttree->SetIntValue(i,fieldname,2);
211  }
212  else if(ideadtowers[i] >= 0.5){
213  m_hot_channels_i = 1;
214  T->Fill();
215  icdbttree->SetIntValue(i,fieldname,1);
216  }
217  else if(icoldtowers[i] > 0.5){
218  m_hot_channels_i = 3;
219  T->Fill();
220  icdbttree->SetIntValue(i,fieldname,3);
221  }
222  else{
223  m_hot_channels_i = 0;
224  T->Fill();
225  icdbttree->SetIntValue(i,fieldname,0);
226  }
227  }
228 
229  for(int j = 0; j<1536; j++){
230 
231  if(ohottowers[j] >= 0.5){
232  m_hot_channels_o = 2;
233  T2->Fill();
234  ocdbttree->SetIntValue(j,fieldname,2);
235  }
236  else if(odeadtowers[j] >= 0.5){
237  m_hot_channels_o = 1;
238  T2->Fill();
239  ocdbttree->SetIntValue(j,fieldname,1);
240  }
241  else if(ocoldtowers[j] > 0.5){
242  m_hot_channels_i = 3;
243  T2->Fill();
244  ocdbttree->SetIntValue(j,fieldname,3);
245  }
246  else{
247  m_hot_channels_i = 0;
248  T2->Fill();
249  ocdbttree->SetIntValue(j,fieldname,0);
250  }
251  }
252 
253  out -> cd();
254  Fspec_i->Write();
255  Fspeci_i->Write();
256  Espec_i->Write();
257  Fspec_o->Write();
258  Fspeci_o->Write();
259  Espec_o->Write();
260  T -> Write();
261  T2->Write();
262  out -> Close();
263  delete out;
264  icdbttree->Commit();
265  //icdbttree->Print();
266  icdbttree->WriteCDBTTree();
267  delete icdbttree;
268 
269  ocdbttree->Commit();
270  //ocdbttree->Print();
271  ocdbttree->WriteCDBTTree();
272  delete ocdbttree;
273 
275  }
276 
277  //____________________________________________________________________________..
279  {
280  std::cout << "towerid::Reset(PHCompositeNode *topNode) being Reset" << std::endl;
282  }
283 //____________________________________________________
284 void hcal_towerid::Print(const std::string &what) const
285 {
286  std::cout << "towerid::Print(const std::string &what) const Printing info for " << what << std::endl;
287 }
288 
289 //____________________________________________________
290 
291 
292 
293 
294 
295 
296