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