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