ATLAS Offline Software
Loading...
Searching...
No Matches
MonitoringFile_HLTJetCalcEfficiencyAndRate.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/* Methods to perform post-processing on run_nnnnnn/HLT/JetMon* histograms
6 * Author : Venkatesh Kaushik (venkat.kaushik@cern.ch)
7 * Date : Apr 2010
8 */
9
11
12#include <iostream>
13#include <iomanip>
14#include <algorithm>
15#include <fstream>
16#include <cmath>
17#include <cstdlib>
18#include <sstream>
19#include <vector>
20#include <utility>
21#include <map>
22#include <string>
23
24#include "TH1F.h"
25#include "TH2F.h"
26#include "TFile.h"
27#include "TClass.h"
28#include "TKey.h"
29#include "TMath.h"
30#include "TF1.h"
31#include "TTree.h"
32#include "TBranch.h"
33
34namespace{
35
36 //==Efficiency
37 const std::vector<std::string> effobs = {
38 "_Eff_vs_pt",
39 "_Eff_vs_eta",
40 "_Eff_vs_phi",
41 };
42
43 const std::vector<std::string> TrigItems = {
44 // EF_fj30(_a4_EFFS) <-- L2_fj25 <-- L1_FJ10
45 // EF_j30(_a4_EFFS) <-- L2_j25 <-- L1_J10
46 // EF_j240(_a4_EFFS) <-- L2_j95 <-- L1_J75
47
48 "EF_fj30",
49 "EF_j30",
50 "EF_j240",
51 //EF_fj50",
52 //EF_fj75",
53
54 //EF_j50",
55 //EF_j75",
56 //EF_j95",
57
58 "L1_FJ10",
59 "L1_J10",
60 "L1_J75",
61 //"L1_FJ55",
62 //"L1_FJ95",
63
64 //"L1_J30",
65 //"L1_J55",
66 //"L1_J75",
67
68 //"L2_fj45",
69 //"L2_fj70",
70
71 "L2_fj25",
72 "L2_j25",
73 "L2_j95",
74 //"L2_j30",
75 //"L2_j45",
76 //"L2_j70",
77 //"L2_j90",
78 };
79
80}
81
82namespace dqutils {
83 void
84 MonitoringFile::HLTJetCalcEfficiencyAndRate(TFile* f, std::string& run_dir) {
85 //bool dbgLevel = false;
86
87 //if (dbgLevel) std::cout << "--> HLTJetCalcEfficiencyAndRate: Calculate jet trigger efficiency and rate" << std::endl;
88
89 f->cd("/");
90 TIter next_run(f->GetListOfKeys());
91 TKey* key_run(0);
92 while ((key_run = dynamic_cast<TKey*> (next_run())) != 0) {
93 if (!key_run->IsFolder()) continue;
94 run_dir = key_run->GetName();
95 if (run_dir.find("run") == std::string::npos) {
96 continue;
97 }
98
99
100
101 std::string jetmon_dir = run_dir + "/HLT/JetMon";
102
103 //===HLTJet efficiency histograms
104 std::string akt4topo_dir = jetmon_dir + "/AntiKt4TopoJets/TrigEff";
105
106 TDirectory* dir(0);
107
108 if (!(dir = f->GetDirectory(akt4topo_dir.c_str()))) {
109 std::cerr << "--> HLTJetCalcEfficiencyAndRate: directory " << akt4topo_dir << " not found." << std::endl;
110 return;
111 }
112
113 TH1F* hnum(0);
114 TH1F* hden(0);
115
116
117
118
119 std::string snum, sden, hnumname;
120 for (const std::string& item : TrigItems) {
121 for (const std::string& eff : effobs) {
122 hnumname = item + eff + "_num";
123 snum = akt4topo_dir + "/" + hnumname;
124 sden = akt4topo_dir + "/" + item + eff + "_den";
125
126 //if (!f->Get(snum)) {
127 // if (dbgLevel) std::cerr << "--> HLTJetPostProcess: no such histogram " << snum << std::endl;
128 //}
129 //if (!f->Get(sden)) {
130 // if (dbgLevel) std::cerr << "--> HLTJetPostProcess: no such histogram " << sden << std::endl;
131 //}
132
133 if (f->Get(snum.c_str()) && f->Get(sden.c_str())) {
134 hnum = dynamic_cast<TH1F*>(f->Get(snum.c_str()));
135 if (not hnum){
136 std::cerr<<"MonitoringFile::HLTJetCalcEfficiencyAndRate: Dynamic cast of hnum failed"<<std::endl;
137 continue;
138 }
139 hnum->Sumw2();
140 hden = dynamic_cast<TH1F*>(f->Get(sden.c_str()));
141 if (not hden){
142 std::cerr<<"MonitoringFile::HLTJetCalcEfficiencyAndRate: Dynamic cast of hden failed"<<std::endl;
143 continue;
144 }
145 hden->Sumw2();
146
147 //Int_t nbins_num = hnum->GetNbinsX();
148 //Int_t nbins_den = hden->GetNbinsX();
149 //if (nbins_num != nbins_den) {
150 // if (dbgLevel) std::cerr << "--> HLTJetPostProcess: cannot divide histogram " << hnum->GetName()
151 // << " by " << hden->GetName() << ". Different number of bins." << std::endl;
152 //}
153
154 // divide num, den with binomial errors
155 // note: replacing the numerator by quotient
156 hnum->Divide(hnum, hden, 1., 1., "B");
157
158 dir->cd();
159 hnum->Write("", TObject::kOverwrite);
160 }
161 } // for effobs
162 } // for TrigItems
163
164 /*
165 if( !(dir = f->GetDirectory(akt6topo_dir)) ) {
166 std::cerr << "--> HLTJetCalcEfficiencyAndRate: directory " << akt6topo_dir << " not found." << std::endl;
167 return;
168 }
169
170 for( const std::string& item : TrigItems ) {
171 for( const std::string& eff : effobs ) {
172 hnumname = item + eff + "_num";
173 snum = akt6topo_dir + "/" + hnumname;
174 sden = akt6topo_dir + "/" + item + eff + "_den";
175
176 if( ! f->Get(snum) ){std::cerr <<"--> HLTJetPostProcess: no such histogram "<< snum << std::endl; }
177 if( ! f->Get(sden) ){std::cerr <<"--> HLTJetPostProcess: no such histogram "<< sden << std::endl; }
178
179 if( f->Get(snum) && f->Get(sden) ){
180 hnum = dynamic_cast<TH1F*>( f->Get(snum) );
181 hnum->Sumw2();
182 hden = dynamic_cast<TH1F*>( f->Get(sden) );
183 hden->Sumw2();
184
185 Int_t nbins_num = hnum->GetNbinsX();
186 Int_t nbins_den = hden->GetNbinsX();
187 if(nbins_num != nbins_den) {
188 std::cerr <<"--> HLTJetPostProcess: cannot divide histogram "<< hnum->GetName()
189 << " by " << hden->GetName() << ". Different number of bins." << std::endl;
190 }
191 // note: replacing the numerator by quotient
192 hnum->Divide(hnum, hden, 1., 1., "B");
193 dir->cd();
194 hnum->Write("",TObject::kOverwrite);
195 }
196 } // for effobs
197 } // for TrigItems
198 */
199 }//while
200 }//MonitoringFile::HLTJetCalcEfficiencyAndRate
201
202 // -------------------------------------------------------------------------------------------------------
203 // Compute bin errors a la Ullrich, Paterno and Xu (UPX) variance
204 // http://arxiv.org/abs/physics/0701199
205 // Input : Numerator, Denominator histograms and an empty std::vector<float> errors
206 // Return Value(s): Errors including Overflow/Underflow bins are returned in std::vector<float> errors
207 // Statuscode is returned as an int
208 // StatusCode = -1 => either numerator or denominator histogram doesn't exist
209 // = -2 => number of bins in numerator and denominator are not equal
210 // = -3 => denominator has zero entries
211 // = -4 => at least one of the bins has negative entries
212 // = 1 => ALL OK
213 // Alternative to "Binomial" variance used by TH1::Divide option "B"
214 // Thanks to D. Casadei for his macro which is implemented here with minor modifications
215 // -------------------------------------------------------------------------------------------------------
216 int MonitoringFile::ComputeUPXBinErrors(TH1F* hnum, TH1F* hden, std::vector<float>& errors) {
217 if (hnum == 0 || hden == 0) return -1;
218
219 Int_t nbins_num = hnum->GetNbinsX();
220 Int_t nbins_den = hden->GetNbinsX();
221
222 if (nbins_num != nbins_den) return -2;
223
224 if (hden->GetEntries() == 0) return -3;
225
226 errors.clear();
227 for (Int_t i = -1; i <= nbins_num; ++i) { // NB: loop includes under- & overflow
228 float n = hden->GetBinContent(i);
229 if (n == 0) continue;
230 float k = hnum->GetBinContent(i);
231 if (k < 0 || n < 0) {
232 if (MonitoringFile::getDebugLevel() > 0) std::cerr << "--> ComputeUPXBinErrors : ERROR: found negative entries in bin " << i
233 << " for histograms " << hnum->GetName() << " , " << hden->GetName() << std::endl;
234 break;
235 }
236 float num1 = (k + 1) * (k + 2);
237 float den1 = (n + 2) * (n + 3);
238 float num2 = (k + 1) * (k + 1);
239 float den2 = (n + 2) * (n + 2);
240 float variance = num1 / den1 - num2 / den2;
241 float err = sqrt(variance);
242 errors.push_back(err);
243 }
244 Int_t num_err = (Int_t) errors.size();
245 int retval = 1;
246 if (num_err != nbins_num) retval = -4;
247 return retval;
248 }
249}//namespace
static int ComputeUPXBinErrors(TH1F *hnum, TH1F *hden, std::vector< float > &errors)
static int getDebugLevel()
static void HLTJetCalcEfficiencyAndRate(TFile *f, std::string &run_dir)