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