ATLAS Offline Software
MonitoringFile_HLTEgammaPostProcess.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 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 
24 namespace 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  TString egammamonDirName = runDirName + "/HLT/EgammaSigTE";
87  TDirectory* egammamonDir(0);
88  if (!(egammamonDir = f->GetDirectory(egammamonDirName))) {
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  TString offgammaDirName = egammamonDirName + "/OfflinePhoton";
96  TString offeleDirName = egammamonDirName + "/OfflineElectron";
97  TDirectory* offgammaDir(0);
98  TDirectory* offeleDir(0);
99  if (!(offgammaDir = f->GetDirectory(offgammaDirName))) {
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))) {
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<TString> varname = {"Et", "Eta", "Phi"}
117  // if we're ever going to use C++11 around this place...
118 
119  std::vector<TString> varName;
120  varName.push_back("Et");
121  varName.push_back("Eta");
122  varName.push_back("Phi");
123 
124  // ----- chain stages for relative effs -----
125  // word of warning: hardcoded maximum of 5 in the efficiency functions
126  // if you add stages, increase the size of histo_matrix
127  // or histo_tensor respectively!
128  // finally: use std::vector<TString> phoStage = {"L1", "L2Calo", "EFCalo"}
129  // and std::vector<TString> phoStage = {"L1", "L2Calo", "L2ID", "EFCalo", "EFID"}
130  // if we're ever going to use C++11 around this place...
131 
132  //photons
133  std::vector<TString> phoStage;
134  phoStage.push_back("L1");
135  phoStage.push_back("L2Calo");
136  phoStage.push_back("EFCalo");
137 
138  //electrons
139  std::vector<TString> eleStage;
140  eleStage.push_back("L1");
141  eleStage.push_back("L2Calo");
142  eleStage.push_back("L2ID");
143  eleStage.push_back("EFCalo");
144  eleStage.push_back("EFID");
145 
146  // ----- loop over directories (i.e. trigger chains) ------
147  TIter next_trig(egammamonDir->GetListOfKeys());
148  TKey* key_trig(0);
149  while ((key_trig = dynamic_cast<TKey*>(next_trig())) != 0) {
150  //store chain specific info (and resets them)
151  bool photon_chain(false);
152  bool electron_chain(false);
153  TObject* obj_trig = key_trig->ReadObj();
154  TDirectory* dir_trig = dynamic_cast<TDirectory*>(obj_trig);
155 
156  //check we have a valid pointer
157  if (dir_trig == 0) {
158  delete obj_trig;
159  continue;
160  }
161 
162  //get name of the current trigger chain
163  TString trigger_name = dir_trig->GetName();
164 
165  //bow out of offline containers here (we don't monitor them, they're for bootstrapping)
166  if (trigger_name.Contains("Offline")) {
167  delete obj_trig;
168  continue;
169  }
170 
171  //detect photon/electron chains (checks chain name, skips unrecognised chains)
172  if (trigger_name.BeginsWith("g") || trigger_name.BeginsWith("2g")) photon_chain = true;
173  else if (trigger_name.BeginsWith("e") || trigger_name.BeginsWith("2e")) electron_chain = true;
174  else {
175  std::cout << "--> HLTEgammaPostProcess: Non-electron/photon chain detected, will be skipped!\n";
176  delete obj_trig;
177  continue;
178  }
179 
180  //call photon post processing routine (no track directories, only Calo)
181  if (photon_chain) {
182  //std::cout<<"--> HLTEgammaPostProcess: calling photon functions for "<<egammamonDirName<<" and trigger
183  // item="<<dir_trig->GetName()<<" in directory: "<<getPath(dir_trig)<<endl;
184 
185  //calling boostrap efficiency calcs
186  HLTEgammaEfficiencyOff(f, dir_trig, offgammaDir, "L1/MatchedOffPho/", "L1/EffPho/", varName);
187  HLTEgammaEfficiencyOff(f, dir_trig, offgammaDir, "L2Calo/MatchedOffPho/", "L2Calo/EffPho/", varName);
188  HLTEgammaEfficiencyOff(f, dir_trig, offgammaDir, "EFCalo/MatchedOffPho/", "EFCalo/EffPho/", varName);
189  HLTEgammaEfficiencyOff(f, dir_trig, offgammaDir, "EFeg/MatchedOffPho/", "EFeg/EffPho/", varName);
190 
191  //calling relative efficiency calcs
192  HLTEgammaEfficiencyRel(f, dir_trig, "PreRejection/", "Rejection/", phoStage, varName);
193  }
194 
195  //call electron post processing (the full thing)
196  if (electron_chain) {
197  //std::cout<<"--> HLTEgammaPostProcess: calling electron functions for "<<egammamonDirName<<" and trigger
198  // item="<<dir_trig->GetName()<<" in directory: "<<getPath(dir_trig)<<endl;
199 
200  //calling bootstrap efficiency calcs
201  HLTEgammaEfficiencyOff(f, dir_trig, offeleDir, "L1/MatchedOffEle/", "L1/EffEle/", varName);
202  HLTEgammaEfficiencyOff(f, dir_trig, offeleDir, "L2Calo/MatchedOffEle/", "L2Calo/EffEle/", varName);
203  HLTEgammaEfficiencyOff(f, dir_trig, offeleDir, "L2ID/MatchedOffEle/", "L2ID/EffEle/", varName);
204  HLTEgammaEfficiencyOff(f, dir_trig, offeleDir, "EFCalo/MatchedOffEle/", "EFCalo/EffEle/", varName);
205  HLTEgammaEfficiencyOff(f, dir_trig, offeleDir, "EFID/MatchedOffEle/", "EFID/EffEle/", varName);
206  HLTEgammaEfficiencyOff(f, dir_trig, offeleDir, "EFeg/MatchedOffEle/", "EFeg/EffEle/", varName);
207 
208  //calling relative efficiency calcs
209  HLTEgammaEfficiencyRel(f, dir_trig, "PreRejection/", "Rejection/", eleStage, varName);
210  }
211  }
212  }
213 
214  //clean up after ourselves...
215  f->Close();
216  delete f;
217  //std::cout << "--> HLTEgammaPostProcess: finished HLT Egamma post-processing"<<std::endl;
218  }
219 }
python.CaloRecoConfig.f
f
Definition: CaloRecoConfig.py:127
dqutils::MonitoringFile::HLTEgammaPostProcess
static void HLTEgammaPostProcess(const std::string &inFilename, bool isIncremental=false)
Definition: MonitoringFile_HLTEgammaPostProcess.cxx:29
dqutils::MonitoringFile::HLTEgammaEfficiencyOff
static void HLTEgammaEfficiencyOff(TFile *f, TDirectory *trig_dir, TDirectory *off_dir, const TString &pathNum, const TString &pathEff, const std::vector< TString > &varName)
Definition: MonitoringFile_HLTEgammaEfficiency.cxx:28
PixelAthClusterMonAlgCfg.varName
string varName
end cluster ToT and charge
Definition: PixelAthClusterMonAlgCfg.py:117
dqutils::MonitoringFile::HLTEgammaEfficiencyRel
static void HLTEgammaEfficiencyRel(TFile *f, TDirectory *trig_dir, const TString &pathPre, const TString &pathRej, const std::vector< TString > &objStage, const std::vector< TString > &varName)
Definition: MonitoringFile_HLTEgammaEfficiency.cxx:116
dqutils
Definition: CoolMdt.h:76
MonitoringFile.h