ATLAS Offline Software
Loading...
Searching...
No Matches
MonitoringFile_HLTTauPostProcess.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 Tau post processing jobs
7// 01/03/2011: update by ccuenca
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 process
27 //--------------------------------------------------------------------------------
28 void MonitoringFile::HLTTauPostProcess(const std::string& inFilename, bool /* isIncremental */) {
29 //std::cout << "--> HLTTauPostProcess: Begin HLT Tau post-processing" << std::endl;
30
31 //open root file
32 TFile* f = TFile::Open(inFilename.c_str(), "UPDATE");
33
34 //check files are loaded.
35 if (f == 0 || !f->IsOpen()) {
36 //std::cerr << "--> HLTTauPostProcess: Input file not opened" << std::endl;
37 delete f;
38 return;
39 }
40
41 //zombie files?
42 if (f->IsZombie()) {
43 //std::cerr << "--> HLTTauPostProcess: Input file " << inFilename << " cannot be opened. " << std::endl;
44 delete f;
45 return;
46 }
47
48 //check file size is not too small.
49 if (f->GetSize() < 1000.) {
50 //std::cerr << "--> HLTTauPostProcess: Input file empty" << std::endl;
51 f->Close();
52 delete f;
53 return;
54 }
55
56
57 //making sure we are in the right directory
58 // f->cd("/");
59 // f->pwd();
60 // f->ls();
61
62 //build iterator
63 TIter next_run(f->GetListOfKeys());
64 TKey* key_run(0);
65
66 //loop over keys in root directory
67 while ((key_run = dynamic_cast<TKey*>(next_run())) != 0) {
68 TObject* obj_run = key_run->ReadObj();
69 TDirectory* tdir_run = dynamic_cast<TDirectory*>(obj_run);
70
71 //check we have a valid pointer
72 if (tdir_run == 0) {
73 delete obj_run;
74 continue;
75 }
76
77 //check name
78 std::string runDirName(tdir_run->GetName());
79 //std::cout<<"Run_directory: "<<runDirName<<std::endl;
80
81 if (runDirName.find("run") == std::string::npos) {
82 delete obj_run;
83 continue;
84 }
85
86 //find tauMon dir
87 std::string taumonDirName = runDirName + "/HLT/TauMon";
88 TDirectory* taumonDir(0);
89 if (!(taumonDir = f->GetDirectory(taumonDirName.c_str()))) {
90 //std::cerr << "--> HLTTauPostProcess: directory " << taumonDirName << " not found." << std::endl;
91 return;
92 }
93
94
95 std::vector<std::string> varName;
96 varName.push_back("Et");
97 varName.push_back("Eta");
98 varName.push_back("Phi");
99
100 std::vector<std::string> lvlName;
101 lvlName.push_back("L1");
102 lvlName.push_back("L2");
103 lvlName.push_back("EF");
104
105 std::vector< std::pair< int, int > > ratioIndex;
106 ratioIndex.push_back(std::make_pair(2, 0)); // EF vs L1
107 ratioIndex.push_back(std::make_pair(1, 0)); // L2 vs L1
108 ratioIndex.push_back(std::make_pair(2, 1)); // EF vs L2
109
110
111
112 std::vector<std::string> varName0;
113 varName0.push_back("Pt");
114 varName0.push_back("Eta");
115 varName0.push_back("Phi");
116 varName0.push_back("Nvtx");
117
118 std::vector<std::string> lvlNameO;
119 lvlNameO.push_back("L1");
120 lvlNameO.push_back("L2");
121 lvlNameO.push_back("EF");
122 lvlNameO.push_back("");//offline
123
124 std::vector< std::pair< int, int > > ratioIndexO;
125 ratioIndexO.push_back(std::make_pair(0, 3)); // L1 vs off
126 ratioIndexO.push_back(std::make_pair(1, 3)); // L2 vs off
127 ratioIndexO.push_back(std::make_pair(2, 3)); // EF vs off
128
129
130 //loop over directories
131 TIter next_trig(taumonDir->GetListOfKeys());
132 TKey* key_trig(0);
133 static const std::string relEffStr{"/RelativeEfficiency"};
134 static const std::string relEffPathStr{"/RelativeEfficiency/Efficiency"};
135 //
136 static const std::string offlineRatStr{"/OfflineRatio"};
137 static const std::string offlineRatPathStr{"/OfflineRatio/Ratio"};
138 //
139 static const std::string bdtMedStr{"/OfflineRatio/BDTMedium"};
140 static const std::string bdtMedPathStr{"/OfflineRatio/Ratio/BDTMedium"};
141 static const std::string bdtMed2Str{"BDTMedium"};
142 //
143 while ((key_trig = dynamic_cast<TKey*>(next_trig())) != 0) {
144 TObject* obj_trig = key_trig->ReadObj();
145 TDirectory* dir_trig = dynamic_cast<TDirectory*>(obj_trig);
146 if (!dir_trig) continue;
147 //std::cout<<"--> HLTTauPostProcess: calling functions for " << dir_trig->GetName() << endl;
148 // "<<runDirName<<" and trigger item="<<dir_trig->GetName()<<endl;
149
150 HLTTauPostProcess(f, dir_trig, relEffStr, relEffPathStr,
151 lvlName, varName, ratioIndex, 1);//name style : 1 (relative eff)
152 HLTTauPostProcess(f, dir_trig, offlineRatStr, offlineRatPathStr,
153 lvlNameO, varName0, ratioIndexO, 2);//name style : 2 (offline eff)
154 HLTTauPostProcess(f, dir_trig, bdtMedStr, bdtMedPathStr,
155 lvlNameO, varName0, ratioIndexO, 2, bdtMed2Str);//name style : 2 (offline eff)
156 }
157 }
158
159 f->Close();
160 delete f;
161 }
162
163 void MonitoringFile::HLTTauPostProcess(TFile* f, TDirectory* dir,
164 const std::string& pathApp,
165 const std::string& pathAppEff,
166 const std::vector<std::string>& lvlN,
167 const std::vector<std::string>& varN,
168 const std::vector< std::pair< int, int > >& ratioIndex, int nameStyle,
169 const std::string& nameApp) {
170 std::string path = getPath(dir);
171
172
173
174 std::string basePath = path + pathApp + "/";
175 if (f->cd(basePath.c_str()) == 0) {
176 return;
177 }
178
179 //coverity[STACK_USE]
180 TH1F* hRoI[100][100];
181 for (unsigned int iLvl = 0; iLvl < lvlN.size(); iLvl++) {
182 for (unsigned int iVar = 0; iVar < varN.size(); iVar++) {
183 std::string hName;
184 if (nameStyle == 1) hName = basePath + "h" + lvlN[iLvl] + "RoI" + varN[iVar] + (iLvl == 0 ? "Denom" : "Num") + nameApp;
185 if (nameStyle == 2) hName = basePath + "hTau" + varN[iVar] + lvlN[iLvl] + nameApp;
186 if (!CheckHistogram(f, hName.c_str())) {
187 return;
188 }
189 hRoI[iLvl][iVar] = (TH1F*) (f->Get(hName.c_str()))->Clone();
190 }
191 }
192
193
194 basePath += path + pathAppEff + "/";
195 f->cd(basePath.c_str());
196 for (unsigned int iVar = 0; iVar < varN.size(); iVar++) {
197 for (unsigned int iRatio = 0; iRatio < ratioIndex.size(); iRatio++) {
198 std::string hName;
199 if (nameStyle == 1)
200 hName = basePath + "h" +
201 lvlN[ ratioIndex[ iRatio ].first ] + "vs" + lvlN[ ratioIndex[ iRatio ].second ] +
202 varN[iVar] + "Efficiency" + nameApp;
203
204 if (nameStyle == 2)
205 hName = basePath + "h" +
206 lvlN[ ratioIndex[ iRatio ].first ] + "OfflineRatio" +
207 varN[iVar] + nameApp;
208
209 if (!CheckHistogram(f, hName.c_str())) return;
210
211 TH1F* hEff = (TH1F*) (f->Get(hName.c_str()));
212 hEff->Divide(hRoI[ ratioIndex[ iRatio ].first ][iVar],
213 hRoI[ ratioIndex[ iRatio ].second ][iVar],
214 1.0, 1.0, "b");
215
216 hEff->Write("", TObject::kOverwrite);
217 }
218 }
219
220 f->Write();
221 }
222}
static void HLTTauPostProcess(const std::string &inFilename, bool isIncremental=false)
static bool CheckHistogram(TFile *f, const char *HistoName)
static std::string getPath(TDirectory *dir)