Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HCalCalibTree.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file HCalCalibTree.cc
1 #include "HCalCalibTree.h"
2 
3 #include <calobase/TowerInfoContainerv2.h>
4 #include <calobase/TowerInfov2.h>
5 
9 
10 #include <phool/getClass.h>
11 
12 #include <TFile.h>
13 #include <TH1F.h>
14 
15 #include <Event/Event.h>
16 #include <Event/packet.h>
17 #include <cassert>
18 #include <sstream>
19 #include <string>
20 
21 using namespace std;
22 
24  : SubsysReco(name), detector("HCALIN"), prefix(prefix), outfilename(filename)
25 {
26 }
27 
29  delete hm;
30 }
31 
33  std::cout << std::endl << "HCalCalibTree::Init" << std::endl;
34  hm = new Fun4AllHistoManager(Name());
35  outfile = new TFile(outfilename.c_str(), "RECREATE");
36 
37  for (int ieta = 0; ieta < n_etabin; ++ieta) {
38  for (int iphi = 0; iphi < n_phibin; ++iphi) {
39  std::string channel_histname = "h_channel_" + std::to_string(ieta) + "_" + std::to_string(iphi);
40  h_channel_hist[ieta][iphi] = new TH1F(channel_histname.c_str(), "", 200, 0, 10000);
41  }
42  }
43  h_waveformchi2 = new TH2F("h_waveformchi2", "", 1000, 0, 10000, 1000, 0, 100000);
44  h_waveformchi2->GetXaxis()->SetTitle("peak (ADC)");
45  h_waveformchi2->GetYaxis()->SetTitle("chi2");
46 
47  h_check = new TH1F("h_check", "", 1000, 0, 0.01);
48  h_eventnumber_record = new TH1F("h_eventnumber_record", "", 2, 0, 2);
49 
50  if (prefix == "TOWERINFO_SIM_") {
54  } else {
58  }
59  std::cout << "Offline cut applied: " << std::endl;
60  std::cout << "tower_threshold = " << tower_threshold << std::endl;
61  std::cout << "vert_threshold = " << vert_threshold << std::endl;
62  std::cout << "veto_threshold = " << veto_threshold << std::endl;
63 
65  se -> registerHistoManager(hm);
66 
67  event = 0;
68  goodevent = 0;
69  return 0;
70 }
71 
73  if (event % 100 == 0) std::cout << "HCalCalibTree::process_event " << event << std::endl;
74  goodevent_check = 0;
75  process_towers(topNode);
76  event++;
77  if (goodevent_check == 1) goodevent++;
79 }
80 
82  ostringstream nodenamev2;
83  nodenamev2.str("");
84  nodenamev2 << prefix << detector;
85 
86  TowerInfoContainer *towers = findNode::getClass<TowerInfoContainer>(topNode, nodenamev2.str());
87  if (!towers ) {
88  std::cout << std::endl << "Didn't find node " << nodenamev2.str() << std::endl;
90  }
91 
92  int size = towers->size();
93  for (int channel = 0; channel < size; channel++) {
95  float energy = tower->get_energy();
96  float chi2 = tower->get_chi2();
97  unsigned int towerkey = towers->encode_key(channel);
98  int ieta = towers->getTowerEtaBin(towerkey);
99  int iphi = towers->getTowerPhiBin(towerkey);
100  m_peak[ieta][iphi] = energy;
101  m_chi2[ieta][iphi] = chi2;
102  h_waveformchi2->Fill(m_peak[ieta][iphi], m_chi2[ieta][iphi]);
103  h_check->Fill(m_peak[ieta][iphi]);
104  if (m_chi2[ieta][iphi] > 10000) m_peak[ieta][iphi] = 0;
105  }
106 
107  // Apply cut
108  for (int ieta = 0; ieta < n_etabin; ++ieta) {
109  for (int iphi = 0; iphi < n_phibin; ++iphi) {
110  if (m_peak[ieta][iphi] < tower_threshold) continue; //tower cut
111  int up = iphi + 1;
112  int down = iphi - 1;
113  if (up > 63) up -= 64;
114  if (down < 0) down += 64;
115  if (m_peak[ieta][up] < vert_threshold || m_peak[ieta][down] < vert_threshold) continue; //vert cut
116  if (ieta != 0 && (m_peak[ieta-1][up] > veto_threshold || m_peak[ieta-1][iphi] > veto_threshold || m_peak[ieta-1][down] > veto_threshold)) continue; // left veto cut
117  if (ieta != 23 && (m_peak[ieta+1][up] > veto_threshold || m_peak[ieta+1][iphi] > veto_threshold || m_peak[ieta+1][down] > veto_threshold)) continue; //right veto cut
118  h_channel_hist[ieta][iphi]->Fill(m_peak[ieta][iphi]);
119  goodevent_check = 1;
120  }
121  }
123 }
124 
127 }
128 
130  std::cout << "HCalCalibTree::End" << std::endl;
131  std::cout << "Number of events: " << event << std::endl;
132  std::cout << "Number of good events: " << goodevent << std::endl;
133  h_eventnumber_record->SetBinContent(1, event);
134  h_eventnumber_record->SetBinContent(2, goodevent);
135  outfile->cd();
136  for (int ieta = 0; ieta < n_etabin; ++ieta) {
137  for (int iphi = 0; iphi < n_phibin; ++iphi) {
138  h_channel_hist[ieta][iphi]->Write();
139  delete h_channel_hist[ieta][iphi];
140  }
141  }
142  h_waveformchi2->Write();
143  h_check->Write();
144  h_eventnumber_record->Write();
145  outfile->Close();
146  delete outfile;
147  hm->dumpHistos(outfilename, "UPDATE");
148  return 0;
149 }