ATLAS Offline Software
Loading...
Searching...
No Matches
MonitoringFile_HLTEgammaPostProcess.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4
5// **********************************************************************
6// HLT Egamma post processing jobs
7// 15/03/2012 initial file by Yan-Jie Schnellbach, based on HLT Tau
8// **********************************************************************
9
11
12#include <cmath>
13#include <vector>
14
15#include <TCanvas.h>
16#include <TF1.h>
17#include <TFile.h>
18#include <TH1.h>
19#include <TH2.h>
20#include <TKey.h>
21#include <TMath.h>
22#include <TProfile.h>
23
24namespace dqutils {
25 //--------------------------------------------------------------------------------
26 // main post processing function (opens file, detects trigger chains, calls
27 // individual efficiency calculations
28 //--------------------------------------------------------------------------------
29 void MonitoringFile::HLTEgammaPostProcess(const std::string& inFilename, bool /* isIncremental */) {
30 // std::cout << "--> HLTEgammaPostProcess: Begin HLT Egamma post-processing" << std::endl;
31
32 // ----- getting file -----
33
34 //open root file
35 TFile* f = TFile::Open(inFilename.c_str(), "UPDATE");
36
37 //check files are loaded.
38 if (f == 0 || !f->IsOpen()) {
39 std::cerr << "--> HLTEgammaPostProcess: Input file not opened" << std::endl;
40 delete f;
41 return;
42 }
43
44 //zombie files?
45 if (f->IsZombie()) {
46 std::cerr << "--> HLTEgammaPostProcess: Input file " << inFilename << " cannot be opened. " << std::endl;
47 delete f;
48 return;
49 }
50
51 //check file size is not too small.
52 if (f->GetSize() < 1000.) {
53 std::cerr << "--> HLTEgammaPostProcess: Input file empty" << std::endl;
54 f->Close();
55 delete f;
56 return;
57 }
58
59 //build iterator
60 TIter next_run(f->GetListOfKeys());
61 TKey* key_run(0);
62
63 //loop over keys in root directory
64 while ((key_run = dynamic_cast<TKey*>(next_run())) != 0) {
65 TObject* obj_run = key_run->ReadObj();
66 TDirectory* tdir_run = dynamic_cast<TDirectory*>(obj_run);
67
68 //check we have a valid pointer
69 if (tdir_run == 0) {
70 delete obj_run;
71 continue;
72 }
73
74 //check name
75 std::string runDirName(tdir_run->GetName());
76 //std::cout<<"Run_directory: "<<runDirName<<std::endl;
77
78 // check run directory
79 //(comment this out for local testing with the TrigEgammaMonitoring recipe)
80 if (runDirName.find("run") == std::string::npos) {
81 delete obj_run;
82 continue;
83 }
84
85 // ----- find egamma monitoring directory (EgammaSigTE) ------
86 std::string egammamonDirName = runDirName + "/HLT/EgammaSigTE";
87 TDirectory* egammamonDir(0);
88 if (!(egammamonDir = f->GetDirectory(egammamonDirName.c_str()))) {
89 std::cout << "--> HLTEgammaPostProcess: directory " << egammamonDirName << " not found." << std::endl;
90 delete obj_run;
91 return;
92 }
93
94 // ----- get handles for offline egamma object directories -----
95 std::string offgammaDirName = egammamonDirName + "/OfflinePhoton";
96 std::string offeleDirName = egammamonDirName + "/OfflineElectron";
97 TDirectory* offgammaDir(0);
98 TDirectory* offeleDir(0);
99 if (!(offgammaDir = f->GetDirectory(offgammaDirName.c_str()))) {
100 std::cout << "--> HLTEgammaPostProcess: offline directory " << offgammaDirName << " not found, will abort.\n";
101 delete obj_run;
102 return;
103 }
104 if (!(offeleDir = f->GetDirectory(offeleDirName.c_str()))) {
105 std::cout << "--> HLTEgammaPostProcess: offline directory " << offeleDirName << " not found, will abort.\n";
106 delete obj_run;
107 return;
108 }
109
110 // ----- list the histograms for offline efficiencies -----
111 // word of warning: hardcoded maximum of 3 in the efficiency functions
112 // if you add stages, increase the size of histo_matrix
113 // or histo_tensor respectively!
114 // note: offline effs use "egEt", "egEta" etc., this is hardcoded in the
115 // variable name formation in the offl. eff function.
116 // finally: use std::vector<std::string> varname = {"Et", "Eta", "Phi"}
117 // if we're ever going to use C++11 around this place...
118
119 static const std::vector<std::string> varName = {
120 "Et",
121 "Eta",
122 "Phi",
123 };
124
125 // ----- chain stages for relative effs -----
126 // word of warning: hardcoded maximum of 5 in the efficiency functions
127 // if you add stages, increase the size of histo_matrix
128 // or histo_tensor respectively!
129 // finally: use std::vector<std::string> phoStage = {"L1", "L2Calo", "EFCalo"}
130 // and std::vector<std::string> phoStage = {"L1", "L2Calo", "L2ID", "EFCalo", "EFID"}
131 // if we're ever going to use C++11 around this place...
132
133 //photons
134 static const std::vector<std::string> phoStage = {
135 "L1",
136 "L2Calo",
137 "EFCalo",
138 };
139
140 //electrons
141 static const std::vector<std::string> eleStage = {
142 "L1",
143 "L2Calo",
144 "L2ID",
145 "EFCalo",
146 "EFID",
147 };
148
149 // ----- loop over directories (i.e. trigger chains) ------
150 TIter next_trig(egammamonDir->GetListOfKeys());
151 TKey* key_trig(0);
152 while ((key_trig = dynamic_cast<TKey*>(next_trig())) != 0) {
153 //store chain specific info (and resets them)
154 bool photon_chain(false);
155 bool electron_chain(false);
156 TObject* obj_trig = key_trig->ReadObj();
157 TDirectory* dir_trig = dynamic_cast<TDirectory*>(obj_trig);
158
159 //check we have a valid pointer
160 if (dir_trig == 0) {
161 delete obj_trig;
162 continue;
163 }
164
165 //get name of the current trigger chain
166 std::string trigger_name = dir_trig->GetName();
167
168 //bow out of offline containers here (we don't monitor them, they're for bootstrapping)
169 if (trigger_name.find("Offline") != std::string::npos) {
170 delete obj_trig;
171 continue;
172 }
173
174 //detect photon/electron chains (checks chain name, skips unrecognised chains)
175 if (trigger_name.starts_with("g") || trigger_name.starts_with("2g")) photon_chain = true;
176 else if (trigger_name.starts_with("e") || trigger_name.starts_with("2e")) electron_chain = true;
177 else {
178 std::cout << "--> HLTEgammaPostProcess: Non-electron/photon chain detected, will be skipped!\n";
179 delete obj_trig;
180 continue;
181 }
182
183 //call photon post processing routine (no track directories, only Calo)
184 if (photon_chain) {
185 //std::cout<<"--> HLTEgammaPostProcess: calling photon functions for "<<egammamonDirName<<" and trigger
186 // item="<<dir_trig->GetName()<<" in directory: "<<getPath(dir_trig)<<endl;
187
188 //calling boostrap efficiency calcs
189 HLTEgammaEfficiencyOff(f, dir_trig, offgammaDir, "L1/MatchedOffPho/", "L1/EffPho/", varName);
190 HLTEgammaEfficiencyOff(f, dir_trig, offgammaDir, "L2Calo/MatchedOffPho/", "L2Calo/EffPho/", varName);
191 HLTEgammaEfficiencyOff(f, dir_trig, offgammaDir, "EFCalo/MatchedOffPho/", "EFCalo/EffPho/", varName);
192 HLTEgammaEfficiencyOff(f, dir_trig, offgammaDir, "EFeg/MatchedOffPho/", "EFeg/EffPho/", varName);
193
194 //calling relative efficiency calcs
195 HLTEgammaEfficiencyRel(f, dir_trig, "PreRejection/", "Rejection/", phoStage, varName);
196 }
197
198 //call electron post processing (the full thing)
199 if (electron_chain) {
200 //std::cout<<"--> HLTEgammaPostProcess: calling electron functions for "<<egammamonDirName<<" and trigger
201 // item="<<dir_trig->GetName()<<" in directory: "<<getPath(dir_trig)<<endl;
202
203 //calling bootstrap efficiency calcs
204 HLTEgammaEfficiencyOff(f, dir_trig, offeleDir, "L1/MatchedOffEle/", "L1/EffEle/", varName);
205 HLTEgammaEfficiencyOff(f, dir_trig, offeleDir, "L2Calo/MatchedOffEle/", "L2Calo/EffEle/", varName);
206 HLTEgammaEfficiencyOff(f, dir_trig, offeleDir, "L2ID/MatchedOffEle/", "L2ID/EffEle/", varName);
207 HLTEgammaEfficiencyOff(f, dir_trig, offeleDir, "EFCalo/MatchedOffEle/", "EFCalo/EffEle/", varName);
208 HLTEgammaEfficiencyOff(f, dir_trig, offeleDir, "EFID/MatchedOffEle/", "EFID/EffEle/", varName);
209 HLTEgammaEfficiencyOff(f, dir_trig, offeleDir, "EFeg/MatchedOffEle/", "EFeg/EffEle/", varName);
210
211 //calling relative efficiency calcs
212 HLTEgammaEfficiencyRel(f, dir_trig, "PreRejection/", "Rejection/", eleStage, varName);
213 }
214 }
215 }
216
217 //clean up after ourselves...
218 f->Close();
219 delete f;
220 //std::cout << "--> HLTEgammaPostProcess: finished HLT Egamma post-processing"<<std::endl;
221 }
222}
static void HLTEgammaEfficiencyOff(TFile *f, TDirectory *trig_dir, TDirectory *off_dir, const std::string &pathNum, const std::string &pathEff, const std::vector< std::string > &varName)
static void HLTEgammaPostProcess(const std::string &inFilename, bool isIncremental=false)
static void HLTEgammaEfficiencyRel(TFile *f, TDirectory *trig_dir, const std::string &pathPre, const std::string &pathRej, const std::vector< std::string > &objStage, const std::vector< std::string > &varName)