ATLAS Offline Software
Loading...
Searching...
No Matches
MonitoringFile_L1CaloPostProcess.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// **********************************************************************
6// L1Calo post processing jobs
7// Author: Peter Faulkner
8// **********************************************************************
9
11
12#include <string>
13
14#include <TDirectory.h>
15#include <TFile.h>
16#include <TH1.h>
17#include <TKey.h>
18#include <TObject.h>
19#include <TString.h>
20
21#ifndef L1CALOPOSTPROCESSDEBUG
22#define L1CALOPOSTPROCESSDEBUG false
23#endif
24
25namespace dqutils {
26 //--------------------------------------------------------------------------------
27 // main process
28 //--------------------------------------------------------------------------------
29 void MonitoringFile::L1CaloPostProcess(const std::string& inFilename, bool /* isIncremental */) {
30 //bool debug = L1CALOPOSTPROCESSDEBUG;
31
32 //if (debug) std::cout << "--> L1CaloPostProcess: Begin L1Calo post-processing" << std::endl;
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 << "--> L1CaloPostProcess: Input file not opened" << std::endl;
40 delete f;
41 return;
42 }
43
44 //zombie files?
45 if (f->IsZombie()) {
46 std::cerr << "--> L1CaloPostProcess: 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 << "--> L1CaloPostProcess: 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 //if (debug) std::cout << "Run_directory: " << runDirName << std::endl;
77
78 if (runDirName.find("run") == std::string::npos) {
79 delete obj_run;
80 continue;
81 }
82
83 // Stability RMS histograms
84 TString stabilityDirName = runDirName + "/L1Calo/PPM/Stability";
85 L1CaloStabilityRMS(f, stabilityDirName + "/FineTime", "fineTime");
86 L1CaloStabilityRMS(f, stabilityDirName + "/Pedestal", "pedestal");
87 L1CaloStabilityRMS(f, stabilityDirName + "/EtCorrelation", "etCorrelation");
88
89 // Trigger efficiency eta-phi histograms
90 int items = 16;
91 int binSkip = 8;
92 double threshold[6] = {
93 3., 3., 3., 6., 4., 2.
94 };
95 TString energies[6] = {
96 "10", "20", "30", "50", "100", "200"
97 };
98 for (int i = 0; i < 3; ++i) {
99 TString effDir = runDirName + "/L1Calo/Reco/EmEfficiencies/ClusterRaw_"
100 + energies[i] + "GeV_EtaVsPhi";
101 TString nameDen = "ClusterRaw_" + energies[i] + "GeV_Eta_vs_Phi";
102 TString nameEff = nameDen + "_trig_Eff";
103 L1CaloResetEfficiencies(f, effDir, nameDen, nameEff, items, threshold[i], binSkip);
104 }
105 items = 8;
106 binSkip = 6;
107 int itemsF = 4;
108 int binSkipF = 0;
109 for (int i = 3; i < 6; ++i) {
110 TString effDir = runDirName + "/L1Calo/Reco/JetEfficiencies/JetEmScale_"
111 + energies[i] + "GeV_EtaVsPhi";
112 TString nameDen = "JetEmScale_" + energies[i] + "GeV_Eta_vs_Phi";
113 TString nameEff = nameDen + "_J_Eff_item";
114 TString nameEffF = nameDen + "_FJ_J_Eff_item";
115 L1CaloResetEfficiencies(f, effDir, nameDen, nameEff, items, threshold[i], binSkip);
116 L1CaloResetEfficiencies(f, effDir, nameDen, nameEffF, itemsF, threshold[i], binSkipF);
117 }
118 }
119
120 f->Close();
121 delete f;
122 //if (debug) std::cout << "--> L1CaloPostProcess: finished L1Calo post-processing"
123 // << std::endl;
124 }
125
126 // Get RMS from stability profiles
127
128 void MonitoringFile::L1CaloStabilityRMS(TFile* f, const TString& nameDir,
129 const TString& nameTag) {
130 TString nameData("ppm_em_2d_profile_etaPhi_adc_" + nameTag);
131 TString nameError("ppm_em_2d_etaPhi_adc_" + nameTag + "RMS");
132
133 L1CaloFillWithError(f, nameDir, nameData, nameError);
134 nameData = "ppm_had_2d_profile_etaPhi_adc_" + nameTag;
135 nameError = "ppm_had_2d_etaPhi_adc_" + nameTag + "RMS";
136 L1CaloFillWithError(f, nameDir, nameData, nameError);
137 }
138
139 // Fill second histogram with error from first
140
141 void MonitoringFile::L1CaloFillWithError(TFile* f, const TString& nameDir,
142 const TString& nameData, const TString& nameError) {
143 //const bool debug = L1CALOPOSTPROCESSDEBUG;
144
145 // Check directory
146 if (!(f->GetDirectory(nameDir))) {
147 //if (debug) std::cout << "--> L1CaloPostProcess: directory "
148 // << nameDir << " not found." << std::endl;
149 return;
150 }
151 if (f->cd(nameDir.Data()) == 0) {
152 //if (debug) std::cout << "dir " << nameDir << " isn't there!" << std::endl;
153 return;
154 }
155
156 // Data histogram
157 TString p1 = nameDir + "/" + nameData;
158 if (!CheckHistogram(f, p1.Data())) {
159 //if (debug) std::cout << " histo " << p1.Data() << " is not in file "
160 // << f->GetName() << std::endl;
161 return;
162 }
163 TH1* h1 = (TH1*) (f->Get(p1.Data()));
164
165 // Error histogram
166 TString p2 = nameDir + "/" + nameError;
167 if (!CheckHistogram(f, p2.Data())) {
168 //if (debug) std::cout << " histo " << p2.Data() << " is not in file "
169 // << f->GetName() << std::endl;
170 return;
171 }
172 TH1* h2 = (TH1*) (f->Get(p2.Data()));
173
174 // Consistency checks
175 const int dim = h1->GetDimension();
176 if (dim != h2->GetDimension()) {
177 //if (debug) std::cout << "Histograms have different dimension" << std::endl;
178 return;
179 }
180 if (h1->GetNbinsX() != h2->GetNbinsX() ||
181 ((dim == 2) && (h1->GetNbinsY() != h2->GetNbinsY()))) {
182 //if (debug) std::cout << "Histograms have different number of bins" << std::endl;
183 return;
184 }
185
186 // Fill error histogram
187 h2->Reset();
188 int nbins = h1->GetNbinsX() + 2;
189 if (dim == 2) nbins *= (h1->GetNbinsY() + 2);
190 for (int bin = 0; bin < nbins; ++bin) {
191 double error = h1->GetBinError(bin);
192 if (error != 0.) h2->SetBinContent(bin, error);
193 }
194
195 // And save
196 h2->Write("", TObject::kOverwrite);
197 f->Write();
198 }
199
200 // Reset efficiencies to 100% for bins with low stats
201
202 void MonitoringFile::L1CaloResetEfficiencies(TFile* f, const TString& effDir,
203 const TString& nameDen, const TString& nameEff,
204 int items, double threshold, int binSkip) {
205 //const bool debug = L1CALOPOSTPROCESSDEBUG;
206
207 // Check directory
208 if (!(f->GetDirectory(effDir))) {
209 //if (debug) std::cout << "--> L1CaloPostProcess: directory "
210 // << effDir << " not found." << std::endl;
211 return;
212 }
213 if (f->cd(effDir.Data()) == 0) {
214 //if (debug) std::cout << "dir " << effDir << " isn't there!" << std::endl;
215 return;
216 }
217
218 // Denominator histogram
219 TString denPath = effDir + "/denominator/" + nameDen;
220 TH1* h1 = (TH1*) (f->Get(denPath.Data()));
221 if (!h1) {
222 //if (debug) std::cout << " histo " << denPath << " is not in file "
223 // << f->GetName() << std::endl;
224 return;
225 }
226 if (h1->GetDimension() != 2) {
227 //if (debug) std::cout << " histo " << denPath << " has unexpected dimension"
228 // << std::endl;
229 return;
230 }
231
232 // Efficiency histograms
233 int xbins = h1->GetNbinsX();
234 int ybins = h1->GetNbinsY();
235 std::vector<TH1*> effVec;
236 TString str;
237 TString effBase = effDir + "/" + nameEff;
238 for (int i = 0; i < items; ++i) {
239 str.Form("_%i", i);
240 TString effPath = effBase + str;
241 TH1* h2 = (TH1*) (f->Get(effPath.Data()));
242 if (!h2) {
243 //if (debug) std::cout << " histo " << effPath << " is not in file "
244 // << f->GetName() << std::endl;
245 continue;
246 }
247 if (h2->GetDimension() != 2) {
248 //if (debug) std::cout << " histo " << effPath << " has unexpected dimension"
249 // << std::endl;
250 continue;
251 }
252 if (xbins != h2->GetNbinsX() || ybins != h2->GetNbinsY()) {
253 //if (debug) std::cout << " histos " << denPath << " and " << effPath
254 // << " have different number of bins" << std::endl;
255 continue;
256 }
257 effVec.push_back(h2);
258 }
259 if (effVec.empty()) {
260 //if (debug) std::cout << "No valid histograms in " << effDir << std::endl;
261 return;
262 }
263 std::vector<TH1*>::iterator iter;
264 std::vector<TH1*>::iterator iterEnd = effVec.end();
265
266 // Loop over bins in denominator looking for entries below threshold
267 for (int x = 1 + binSkip; x <= xbins - binSkip; ++x) {
268 for (int y = 1; y <= ybins; ++y) {
269 if (h1->GetBinContent(x, y) < threshold) {
270 // Loop over efficiency histograms and set bin to 100% efficiency
271 for (iter = effVec.begin(); iter != iterEnd; ++iter) {
272 (*iter)->SetBinContent(x, y, 100.0);
273 }
274 }
275 }
276 }
277
278 // Save the updated histograms
279 for (iter = effVec.begin(); iter != iterEnd; ++iter) {
280 (*iter)->Write("", TObject::kOverwrite);
281 }
282 f->Write();
283 }
284}
285
286#undef L1CALOPOSTPROCESSDEBUG
#define y
#define x
static void L1CaloPostProcess(const std::string &inFileName, bool isIncremental=false)
static void L1CaloResetEfficiencies(TFile *f, const TString &effDir, const TString &nameDen, const TString &nameEff, int items, double threshold, int binSkip)
static void L1CaloFillWithError(TFile *f, const TString &nameDir, const TString &nameData, const TString &nameError)
static void L1CaloStabilityRMS(TFile *f, const TString &nameDir, const TString &nameTag)
static bool CheckHistogram(TFile *f, const char *HistoName)