File indexing completed on 2024-04-06 11:58:52
0001 #include <TStyle.h>
0002 #include <TCanvas.h>
0003 #include <TROOT.h>
0004 #include <TChain.h>
0005 #include <TFile.h>
0006 #include <TFitResult.h>
0007 #include <TFitResultPtr.h>
0008 #include <TTree.h>
0009 #include <TH1.h>
0010 #include <TGraph.h>
0011 #include <TProfile.h>
0012 #include <algorithm>
0013 #include <vector>
0014 #include <string>
0015 #include <iomanip>
0016 #include <iostream>
0017 #include <fstream>
0018 #include <sstream>
0019
0020 class CalibTreeExtended {
0021 public :
0022
0023 CalibTreeExtended(const char* infile, const char* outfile,
0024 bool debug=false);
0025 virtual ~CalibTreeExtended();
0026 virtual Int_t Cut(Long64_t entry);
0027 virtual Int_t GetEntry(Long64_t entry);
0028 virtual Long64_t LoadTree(Long64_t entry);
0029 virtual void Init(TTree *tree);
0030 virtual void Loop();
0031 virtual Bool_t Notify();
0032 virtual void Show(Long64_t entry = -1);
0033
0034 private:
0035 void BookHisto(const char* outfile);
0036 void Close();
0037
0038 TTree *fChain;
0039 Int_t fCurrent;
0040
0041
0042
0043 Int_t t_Run;
0044 Int_t t_Event;
0045 Int_t t_DataType;
0046 Int_t t_ieta;
0047 Int_t t_iphi;
0048 Double_t t_EventWeight;
0049 Int_t t_nVtx;
0050 Int_t t_nTrk;
0051 Int_t t_goodPV;
0052 Double_t t_l1pt;
0053 Double_t t_l1eta;
0054 Double_t t_l1phi;
0055 Double_t t_l3pt;
0056 Double_t t_l3eta;
0057 Double_t t_l3phi;
0058 Double_t t_p;
0059 Double_t t_pt;
0060 Double_t t_phi;
0061 std::vector<double> *t_mapP;
0062 std::vector<double> *t_mapPt;
0063 std::vector<double> *t_mapEta;
0064 std::vector<double> *t_mapPhi;
0065 Double_t t_mindR1;
0066 Double_t t_mindR2;
0067 Double_t t_eMipDR;
0068 Double_t t_eHcal;
0069 Double_t t_eHcal10;
0070 Double_t t_eHcal30;
0071 Double_t t_hmaxNearP;
0072 Double_t t_emaxNearP;
0073 Double_t t_eAnnular;
0074 Double_t t_hAnnular;
0075 Double_t t_rhoh;
0076 Bool_t t_selectTk;
0077 Bool_t t_qltyFlag;
0078 Bool_t t_qltyMissFlag;
0079 Bool_t t_qltyPVFlag;
0080 Double_t t_gentrackP;
0081 Double_t t_gentrackE;
0082 std::vector<unsigned int> *t_DetIds;
0083 std::vector<double> *t_HitEnergies;
0084 std::vector<bool> *t_trgbits;
0085 std::vector<unsigned int> *t_DetIds1;
0086 std::vector<double> *t_HitEnergies1;
0087 std::vector<unsigned int> *t_DetIds3;
0088 std::vector<double> *t_HitEnergies3;
0089 std::vector<unsigned int> *t_DetIdEC;
0090 std::vector<double> *t_HitEnergyEC;
0091 std::vector<double> *t_HitDistEC;
0092 std::vector<unsigned int> *t_DetIdHC;
0093 std::vector<double> *t_HitEnergyHC;
0094 std::vector<double> *t_HitDistHC;
0095
0096
0097 TBranch *b_t_Run;
0098 TBranch *b_t_Event;
0099 TBranch *b_t_DataType;
0100 TBranch *b_t_ieta;
0101 TBranch *b_t_iphi;
0102 TBranch *b_t_EventWeight;
0103 TBranch *b_t_nVtx;
0104 TBranch *b_t_nTrk;
0105 TBranch *b_t_goodPV;
0106 TBranch *b_t_l1pt;
0107 TBranch *b_t_l1eta;
0108 TBranch *b_t_l1phi;
0109 TBranch *b_t_l3pt;
0110 TBranch *b_t_l3eta;
0111 TBranch *b_t_l3phi;
0112 TBranch *b_t_p;
0113 TBranch *b_t_pt;
0114 TBranch *b_t_phi;
0115 TBranch *b_t_mapP;
0116 TBranch *b_t_mapPt;
0117 TBranch *b_t_mapEta;
0118 TBranch *b_t_mapPhi;
0119 TBranch *b_t_mindR1;
0120 TBranch *b_t_mindR2;
0121 TBranch *b_t_eMipDR;
0122 TBranch *b_t_eHcal;
0123 TBranch *b_t_eHcal10;
0124 TBranch *b_t_eHcal30;
0125 TBranch *b_t_hmaxNearP;
0126 TBranch *b_t_emaxNearP;
0127 TBranch *b_t_eAnnular;
0128 TBranch *b_t_hAnnular;
0129 TBranch *b_t_rhoh;
0130 TBranch *b_t_selectTk;
0131 TBranch *b_t_qltyFlag;
0132 TBranch *b_t_qltyMissFlag;
0133 TBranch *b_t_qltyPVFlag;
0134 TBranch *b_t_gentrackP;
0135 TBranch *b_t_gentrackE;
0136 TBranch *b_t_DetIds;
0137 TBranch *b_t_HitEnergies;
0138 TBranch *b_t_trgbits;
0139 TBranch *b_t_DetIds1;
0140 TBranch *b_t_HitEnergies1;
0141 TBranch *b_t_DetIds3;
0142 TBranch *b_t_HitEnergies3;
0143 TBranch *b_t_DetIdEC;
0144 TBranch *b_t_HitEnergyEC;
0145 TBranch *b_t_HitDistEC;
0146 TBranch *b_t_DetIdHC;
0147 TBranch *b_t_HitEnergyHC;
0148 TBranch *b_t_HitDistHC;
0149
0150 bool debug_;
0151 TFile *output_file;
0152 };
0153
0154 CalibTreeExtended::CalibTreeExtended(const char *infile, const char *outfile,
0155 const bool debug) : debug_(debug) {
0156 TFile *file = new TFile(infile);
0157 TDirectory *dir = (TDirectory*)(file->FindObjectAny("hcalIsoTrackStudy"));
0158 TTree *tree = (TTree*)(dir->FindObjectAny("CalibTreeExtended"));
0159 std::cout << "Attaches tree CalibTreeExtended at " << tree << " in file "
0160 << infile << std::endl;
0161
0162 BookHisto(outfile);
0163 Init(tree);
0164 }
0165
0166 CalibTreeExtended::~CalibTreeExtended() {
0167 Close();
0168 if (!fChain) return;
0169 delete fChain->GetCurrentFile();
0170 }
0171
0172 Int_t CalibTreeExtended::GetEntry(Long64_t entry) {
0173
0174 if (!fChain) return 0;
0175 return fChain->GetEntry(entry);
0176 }
0177
0178 Long64_t CalibTreeExtended::LoadTree(Long64_t entry) {
0179
0180 if (!fChain) return -5;
0181 Long64_t centry = fChain->LoadTree(entry);
0182 if (centry < 0) return centry;
0183 if (fChain->GetTreeNumber() != fCurrent) {
0184 fCurrent = fChain->GetTreeNumber();
0185 Notify();
0186 }
0187 return centry;
0188 }
0189
0190 void CalibTreeExtended::Init(TTree *tree) {
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200 t_mapP = 0;
0201 t_mapPt = 0;
0202 t_mapEta = 0;
0203 t_mapPhi = 0;
0204 t_DetIds = 0;
0205 t_HitEnergies = 0;
0206 t_trgbits = 0;
0207 t_DetIds1 = 0;
0208 t_HitEnergies1 = 0;
0209 t_DetIds3 = 0;
0210 t_HitEnergies3 = 0;
0211 t_DetIdEC = 0;
0212 t_HitEnergyEC = 0;
0213 t_HitDistEC = 0;
0214 t_DetIdHC = 0;
0215 t_HitEnergyHC = 0;
0216 t_HitDistHC = 0;
0217
0218 if (!tree) return;
0219 fChain = tree;
0220 fCurrent = -1;
0221 fChain->SetMakeClass(1);
0222
0223 fChain->SetBranchAddress("t_Run", &t_Run, &b_t_Run);
0224 fChain->SetBranchAddress("t_Event", &t_Event, &b_t_Event);
0225 fChain->SetBranchAddress("t_DataType", &t_DataType, &b_t_DataType);
0226 fChain->SetBranchAddress("t_ieta", &t_ieta, &b_t_ieta);
0227 fChain->SetBranchAddress("t_iphi", &t_iphi, &b_t_iphi);
0228 fChain->SetBranchAddress("t_EventWeight", &t_EventWeight, &b_t_EventWeight);
0229 fChain->SetBranchAddress("t_nVtx", &t_nVtx, &b_t_nVtx);
0230 fChain->SetBranchAddress("t_nTrk", &t_nTrk, &b_t_nTrk);
0231 fChain->SetBranchAddress("t_goodPV", &t_goodPV, &b_t_goodPV);
0232 fChain->SetBranchAddress("t_l1pt", &t_l1pt, &b_t_l1pt);
0233 fChain->SetBranchAddress("t_l1eta", &t_l1eta, &b_t_l1eta);
0234 fChain->SetBranchAddress("t_l1phi", &t_l1phi, &b_t_l1phi);
0235 fChain->SetBranchAddress("t_l3pt", &t_l3pt, &b_t_l3pt);
0236 fChain->SetBranchAddress("t_l3eta", &t_l3eta, &b_t_l3eta);
0237 fChain->SetBranchAddress("t_l3phi", &t_l3phi, &b_t_l3phi);
0238 fChain->SetBranchAddress("t_p", &t_p, &b_t_p);
0239 fChain->SetBranchAddress("t_pt", &t_pt, &b_t_pt);
0240 fChain->SetBranchAddress("t_phi", &t_phi, &b_t_phi);
0241 fChain->SetBranchAddress("t_mapP", &t_mapP, &b_t_mapP);
0242 fChain->SetBranchAddress("t_mapPt", &t_mapPt, &b_t_mapPt);
0243 fChain->SetBranchAddress("t_mapEta", &t_mapEta, &b_t_mapEta);
0244 fChain->SetBranchAddress("t_mapPhi", &t_mapPhi, &b_t_mapPhi);
0245 fChain->SetBranchAddress("t_mindR1", &t_mindR1, &b_t_mindR1);
0246 fChain->SetBranchAddress("t_mindR2", &t_mindR2, &b_t_mindR2);
0247 fChain->SetBranchAddress("t_eMipDR", &t_eMipDR, &b_t_eMipDR);
0248 fChain->SetBranchAddress("t_eHcal", &t_eHcal, &b_t_eHcal);
0249 fChain->SetBranchAddress("t_eHcal10", &t_eHcal10, &b_t_eHcal10);
0250 fChain->SetBranchAddress("t_eHcal30", &t_eHcal30, &b_t_eHcal30);
0251 fChain->SetBranchAddress("t_hmaxNearP", &t_hmaxNearP, &b_t_hmaxNearP);
0252 fChain->SetBranchAddress("t_emaxNearP", &t_emaxNearP, &b_t_emaxNearP);
0253 fChain->SetBranchAddress("t_eAnnular", &t_eAnnular, &b_t_eAnnular);
0254 fChain->SetBranchAddress("t_hAnnular", &t_hAnnular, &b_t_hAnnular);
0255 fChain->SetBranchAddress("t_rhoh", &t_rhoh, &b_t_rhoh);
0256 fChain->SetBranchAddress("t_selectTk", &t_selectTk, &b_t_selectTk);
0257 fChain->SetBranchAddress("t_qltyFlag", &t_qltyFlag, &b_t_qltyFlag);
0258 fChain->SetBranchAddress("t_qltyMissFlag", &t_qltyMissFlag, &b_t_qltyMissFlag);
0259 fChain->SetBranchAddress("t_qltyPVFlag", &t_qltyPVFlag, &b_t_qltyPVFlag);
0260 fChain->SetBranchAddress("t_gentrackP", &t_gentrackP, &b_t_gentrackP);
0261 fChain->SetBranchAddress("t_gentrackE", &t_gentrackE, &b_t_gentrackE);
0262 fChain->SetBranchAddress("t_DetIds", &t_DetIds, &b_t_DetIds);
0263 fChain->SetBranchAddress("t_HitEnergies", &t_HitEnergies, &b_t_HitEnergies);
0264 fChain->SetBranchAddress("t_trgbits", &t_trgbits, &b_t_trgbits);
0265 fChain->SetBranchAddress("t_DetIds1", &t_DetIds1, &b_t_DetIds1);
0266 fChain->SetBranchAddress("t_HitEnergies1", &t_HitEnergies1, &b_t_HitEnergies1);
0267 fChain->SetBranchAddress("t_DetIds3", &t_DetIds3, &b_t_DetIds3);
0268 fChain->SetBranchAddress("t_HitEnergies3", &t_HitEnergies3, &b_t_HitEnergies3);
0269 fChain->SetBranchAddress("t_DetIdEC", &t_DetIdEC, &b_t_DetIdEC);
0270 fChain->SetBranchAddress("t_HitEnergyEC", &t_HitEnergyEC, &b_t_HitEnergyEC);
0271 fChain->SetBranchAddress("t_HitDistEC", &t_HitDistEC, &b_t_HitDistEC);
0272 fChain->SetBranchAddress("t_DetIdHC", &t_DetIdHC, &b_t_DetIdHC);
0273 fChain->SetBranchAddress("t_HitEnergyHC", &t_HitEnergyHC, &b_t_HitEnergyHC);
0274 fChain->SetBranchAddress("t_HitDistHC", &t_HitDistHC, &b_t_HitDistHC);
0275 Notify();
0276 }
0277
0278 Bool_t CalibTreeExtended::Notify() {
0279
0280
0281
0282
0283
0284
0285 return kTRUE;
0286 }
0287
0288 void CalibTreeExtended::Show(Long64_t entry) {
0289
0290
0291 if (!fChain) return;
0292 fChain->Show(entry);
0293 }
0294
0295 Int_t CalibTreeExtended::Cut(Long64_t) {
0296
0297
0298
0299 return 1;
0300 }
0301
0302 void CalibTreeExtended::Loop() {
0303
0304
0305
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319
0320
0321
0322
0323
0324
0325
0326 if (fChain == 0) return;
0327
0328 Long64_t nentries = fChain->GetEntriesFast();
0329
0330 Long64_t nbytes = 0, nb = 0;
0331 for (Long64_t jentry=0; jentry<nentries;jentry++) {
0332 Long64_t ientry = LoadTree(jentry);
0333 if (ientry < 0) break;
0334 nb = fChain->GetEntry(jentry); nbytes += nb;
0335
0336 }
0337 }
0338
0339 void CalibTreeExtended::BookHisto(const char* fname) {
0340 output_file = TFile::Open(fname,"RECREATE");
0341 }
0342
0343 void CalibTreeExtended::Close() {
0344 output_file->cd();
0345 if (debug_) std::cout << "file yet to be Written" << std::endl;
0346 output_file->Write();
0347 std::cout << "output file Written" << std::endl;
0348 output_file->Close();
0349 if (debug_) std::cout << "now doing return" << std::endl;
0350 }