ATLAS Offline Software
Loading...
Searching...
No Matches
MonitoringFile_TgcHistogramDivision.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3 */
4
6//Methods to Divide TGC Histograms to calculate efficiency and occupancy after merging.
7//Author: Akimasa Ishikawa (akimasa.ishikawa@cern.ch)
8//Date: Aug 2009
10
12
13#include <iostream>
14#include <iomanip>
15#include <algorithm>
16#include <fstream>
17#include <cmath>
18#include <cstdlib>
19#include <sstream>
20#include <vector>
21#include <utility>
22#include <map>
23#include <string>
24
25#include "TH1F.h"
26#include "TH2F.h"
27#include "TFile.h"
28#include "TClass.h"
29#include "TKey.h"
30#include "TMath.h"
31#include "TF1.h"
32#include "TTree.h"
33#include "TCanvas.h"
34#include "TBranch.h"
35#include "TGraphAsymmErrors.h"
36
37namespace{
38 const std::string smuid[2] = {
39 "_Muid", "_Staco"
40 };
41 const std::string spna[3] = {
42 "_Posi", "_Nega", ""
43 };
44
45 const std::string sbc[3] = {
46 "_Previous", "", "_Next"
47 };
48}
49
50namespace dqutils {
51 void
52 MonitoringFile::TGCRawHistogramDivision(const std::string& inFilename) {
53 PostProcessorFileWrapper mf(inFilename, "TGC Raw Histogram Division");
54
55 if (!mf.IsOpen()) {
56 //std::cerr << "TGCPostProcess(): "
57 // << "Input file not opened \n";
58 return;
59 }
60 if (mf.GetSize() < 1000.) {
61 //std::cerr << "TGCPostProcess(): "
62 // << "Input file empty \n";
63 return;
64 }
65
66 std::stringstream ss;
67 static const std::string sac[2] = {
68 "_A", "_C"
69 };
70 static const std::string sws[2] = {
71 "Wire_", "Strip_"
72 };
73
74 TIter next_run(mf.GetListOfKeys());
75 TKey* key_run(0);
76
77 while ((key_run = dynamic_cast<TKey*> (next_run())) != 0) {
78 if (!key_run->IsFolder()) continue;
79 std::string run_dir = key_run->GetName();
80 if (run_dir.find("run") == std::string::npos) continue;
81
82 std::string run_dir2 = run_dir;
83 //int run_number = atoi( (run_dir2.substr(4, run_dir2.size()-4 )).c_str() );
84
85 std::string seff;
86 std::string snum;
87 std::string sden;
88
89 TH1F* h1eff(0);
90 TH1F* h1num(0);
91 TH1F* h1den(0);
92 TH2F* h2eff(0);
93 TH2F* h2num(0);
94 TH2F* h2den(0);
95
96 //===TGCRaw
97 std::string tgc_dir = run_dir + "/Muon/MuonRawDataMonitoring/TGC/";
98
99 std::string tgc_global_dir = tgc_dir + "Global/";
100 std::string tgc_sub_dir[2] = {
101 tgc_dir + "TGCEA/", tgc_dir + "TGCEC/"
102 };
103
104 for (int ac = 0; ac < 2; ac++) {
105 std::string eff_dir = tgc_sub_dir[ac] + "Efficiency/";
106 TDirectory* dir = mf.GetDirectory(eff_dir.c_str());
107 if (!dir) {
108 //std::cerr<< "TGCHistogramDivision: directory "<<eff_dir<<" not found"<<std::endl;
109 return;
110 }
111
112 ss.str("");
113 ss << "Efficiency" << sac[ac];
114 seff = eff_dir + ss.str();
115 ss.str("");
116 ss << "Efficiency" << sac[ac] << "_Numerator";
117 snum = eff_dir + "NumDenom/" + ss.str();
118 ss.str("");
119 ss << "Efficiency" << sac[ac] << "_Denominator";
120 sden = eff_dir + "NumDenom/" + ss.str();
121
122 h1eff = 0;
123 mf.get(seff.c_str(), h1eff);
124 h1num = 0;
125 mf.get(snum.c_str(), h1num);
126 h1den = 0;
127 mf.get(sden.c_str(), h1den);
128
129 if (h1eff && h1num && h1den) {
130 TGCResetContents(h1eff);
131 h1eff->Divide(h1num, h1den, 1., 1., "B");
132
133 // save the summary histogram
134 dir->cd();
135 h1eff->Write("", TObject::kOverwrite);
136 } else {
137 //std::cerr <<"TGC PostProcessing: no such histogram (or num/denom)!! "<< seff << std::endl;
138 continue;
139 }
140
141 for (int ws = 0; ws < 2; ws++) {
142 ss.str("");
143 ss << sws[ws] << "Efficiency" << sac[ac];
144 seff = eff_dir + ss.str();
145 ss.str("");
146 ss << sws[ws] << "Efficiency" << sac[ac] << "_Numerator";
147 snum = eff_dir + "NumDenom/" + ss.str();
148 ss.str("");
149 ss << sws[ws] << "Efficiency" << sac[ac] << "_Denominator";
150 sden = eff_dir + "NumDenom/" + ss.str();
151
152 h1eff = 0;
153 mf.get(seff.c_str(), h1eff);
154 h1num = 0;
155 mf.get(snum.c_str(), h1num);
156 h1den = 0;
157 mf.get(sden.c_str(), h1den);
158
159 if (h1eff && h1num && h1den) {
160 TGCResetContents(h1eff);
161 h1eff->Divide(h1num, h1den, 1., 1., "B");
162
163 // save the summary histogram
164 dir->cd();
165 h1eff->Write("", TObject::kOverwrite);
166 } else {
167 //std::cerr <<"TGC PostProcessing: no such histogram (or num/denom)!! "<< seff << std::endl;
168 continue;
169 }
170 mf.Write();
171
172
173 for (int bc = 0; bc < 3; bc++) {
174 ss.str("");
175 ss << sws[ws] << "Efficiency_Map" << sbc[bc] << sac[ac];
176 seff = eff_dir + ss.str();
177 ss.str("");
178 ss << sws[ws] << "Efficiency_Map" << sbc[bc] << sac[ac] << "_Numerator";
179 snum = eff_dir + "NumDenom/" + ss.str();
180 ss.str("");
181 ss << sws[ws] << "Efficiency_Map" << sac[ac] << "_Denominator";
182 sden = eff_dir + "NumDenom/" + ss.str();
183
184 h2eff = 0;
185 mf.get(seff.c_str(), h2eff);
186 h2num = 0;
187 mf.get(snum.c_str(), h2num);
188 h2den = 0;
189 mf.get(sden.c_str(), h2den);
190
191 if (h2eff && h2num && h2den) {
192 TGCResetContents(h2eff);
193 h2eff->Divide(h2num, h2den, 1., 1., "B");
194
195 // save the summary histogram
196 dir->cd();
197 h2eff->Write("", TObject::kOverwrite);
198 } else {
199 //std::cerr <<"TGC PostProcessing: no such histogram (or num/denom)!! "<< seff << std::endl;
200 continue;
201 }
202 }//bc
203 }//ws
204 }//ac
205 //===End TGCRaw
206 }// run_dir loop
207
208 mf.Write();
209 }
210
211 void
212 MonitoringFile::TGCLV1HistogramDivision(const std::string& inFilename) {
213 PostProcessorFileWrapper mf(inFilename, "TGC LV1 Histogram Division");
214
215 if (!mf.IsOpen()) {
216 //std::cerr << "TGCPostProcess(): "
217 // << "Input file not opened \n";
218 return;
219 }
220 if (mf.GetSize() < 1000.) {
221 //std::cerr << "TGCPostProcess(): "
222 // << "Input file empty \n";
223 return;
224 }
225 /*
226 // get run directory name
227 //Seemingly unnecessary lines are necessary
228 TIter nextcd0(gDirectory->GetListOfKeys());
229 TKey *key0 = (TKey*)nextcd0();
230 TDirectory *dir0= dynamic_cast<TDirectory*> (key0->ReadObj());
231 dir0->cd();
233 */
234 std::stringstream ss;
235 static const std::string sac[2] = {
236 "_A", "_C"
237 };
238 //std::string sws[2]={"Wire_","Strip_"};
239
240 TIter next_run(mf.GetListOfKeys());
241 TKey* key_run(0);
242 while ((key_run = dynamic_cast<TKey*> (next_run())) != 0) {
243 if (!key_run->IsFolder()) continue;
244 std::string run_dir = key_run->GetName();
245 if (run_dir.find("run") == std::string::npos) continue;
246
247 std::string run_dir2 = run_dir;
248 //int run_number = atoi( (run_dir2.substr(4, run_dir2.size()-4 )).c_str() );
249
250 std::string seff;
251 std::string snum;
252 std::string sden;
253 std::string seffg;
254
255 TH1F* h1eff(0);
256 TH1F* h1num(0);
257 TH1F* h1den(0);
258 TH2F* h2eff(0);
259 TH2F* h2num(0);
260 TH2F* h2den(0);
261 TGraphAsymmErrors* geff(0);
262
263 //===TGCLV1
264 std::string tgc_dir = run_dir + "/Muon/MuonRawDataMonitoring/TGCLV1/";
265
266 std::string tgc_global_dir = tgc_dir + "Global/";
267 std::string tgc_sub_dir[2] = {
268 tgc_dir + "TGCEA/", tgc_dir + "TGCEC/"
269 };
270
271
272
273 for (int ac = 0; ac < 2; ac++) {
274 std::string eff_dir = tgc_sub_dir[ac] + "Eff/";
275 TDirectory* dir = mf.GetDirectory(eff_dir.c_str());
276 if (!dir) {
277 //std::cerr<< "TGCHistogramDivision: directory "<<eff_dir<<" not found"<<std::endl;
278 return;
279 }
280
281 for (int pt = 1; pt <= 6; pt++) {
282 for (int pna = 0; pna < 3; pna++) {
283 for (int muid = 0; muid < 2; muid++) {
284 for (int pcn = 0; pcn < 3; pcn++) {
285 std::string tempeff, tempnum, tempden;
286 //Efficiency
287 ss.str("");
288 ss << "Trigger_Efficiency" << spna[pna] << sbc[pcn] << "_PT" << pt << smuid[muid] << sac[ac];
289 seff = eff_dir + ss.str();
290 tempeff = ss.str();
291 ss.str("");
292 ss << "Trigger_Efficiency" << spna[pna] << sbc[pcn] << "_PT" << pt << smuid[muid] << sac[ac] <<
293 "_Numerator";
294 snum = eff_dir + "NumDenom/" + ss.str();
295 tempnum = ss.str();
296 ss.str("");
297 ss << "Trigger_Efficiency" << spna[pna] << "_PT" << pt << smuid[muid] << sac[ac] << "_Denominator";
298 sden = eff_dir + "NumDenom/" + ss.str();
299 tempden = ss.str();
300
301 h2eff = 0;
302 mf.get(seff.c_str(), h2eff);
303 h2num = 0;
304 mf.get(snum.c_str(), h2num);
305 h2den = 0;
306 mf.get(sden.c_str(), h2den);
307 if (h2eff && h2num && h2den) {
308 TGCResetContents(h2eff);
309 h2eff->Divide(h2num, h2den, 1., 1., "B");
310
311 // save the summary histogram
312 dir = mf.GetDirectory(eff_dir.c_str());
313 dir->cd();
314 h2eff->Write("", TObject::kOverwrite);
315 } else {
316 //std::cerr <<"TGC PostProcessing: no such histogram (or num/denom)!! "<< seff << std::endl;
317 continue;
318 }
319 mf.Write();
320 }//pcn
321
322 //Turn on
323 ss.str("");
324 ss << "Trigger_Turn_On_Curve" << spna[pna] << "_PT" << pt << smuid[muid] << sac[ac];
325 seff = eff_dir + ss.str();
326 ss << "_Fit";
327 seffg = eff_dir + ss.str();
328 ss.str("");
329 ss << "Trigger_Turn_On_Curve" << spna[pna] << "_PT" << pt << smuid[muid] << sac[ac] << "_Numerator";
330 snum = eff_dir + "NumDenom/" + ss.str();
331 ss.str("");
332 ss << "Trigger_Turn_On_Curve" << spna[pna] << "_PT" << pt << smuid[muid] << sac[ac] << "_Denominator";
333 sden = eff_dir + "NumDenom/" + ss.str();
334
335 h1eff = 0;
336 mf.get(seff.c_str(), h1eff);
337 h1num = 0;
338 mf.get(snum.c_str(), h1num);
339 h1den = 0;
340 mf.get(sden.c_str(), h1den);
341 geff = 0;
342 mf.get(seffg.c_str(), geff);
343
344 if (h1eff && h1num && h1den) {
345 TGCResetContents(h1eff);
346 h1eff->Divide(h1num, h1den, 1., 1., "B");
347
348 // save the summary histogram
349 dir = mf.GetDirectory(eff_dir.c_str());
350 dir->cd();
351 h1eff->Write("", TObject::kOverwrite);
352
353 if (geff) {
354 geff->BayesDivide(h1num, h1den);
355
356 // save the summary histogram
357 dir = mf.GetDirectory(eff_dir.c_str());
358 dir->cd();
359 geff->Write("", TObject::kOverwrite);
360 }
361 } else {
362 //std::cerr <<"TGC PostProcessing: no such histogram (or num/denom)!! "<< seff << std::endl;
363 continue;
364 }
365 mf.Write();
366 }//muid
367 }//pna
368 mf.Write();
369
370 //Rate Ratio
371 std::string grate_dir = tgc_global_dir + "Rate/";
372 std::string rate_dir = tgc_sub_dir[ac] + "Rate/";
373 std::string rr_dir = tgc_sub_dir[ac] + "Rate/Ratio/";
374 dir = mf.GetDirectory(rr_dir.c_str());
375 if (!dir) {
376 //std::cerr<< "TGCHistogramDivision: directory "<<rr_dir<<" not found"<<std::endl;
377 return;
378 }
379
380 // trigger/10BCID
381 ss.str("");
382 ss << "Number_Of_PT" << pt << "_Triggers_Per_Event_Vs_10BCID" << sac[ac];
383 seff = rr_dir + ss.str();
384 ss.str("");
385 ss << "Number_Of_PT" << pt << "_Triggers_In_10BCID" << sac[ac];
386 snum = rate_dir + ss.str();
387 ss.str("");
388 ss << "Number_Of_Events_In_10BCID";
389 sden = grate_dir + ss.str();
390
391 h1eff = 0;
392 mf.get(seff.c_str(), h1eff);
393 h1num = 0;
394 mf.get(snum.c_str(), h1num);
395 h1den = 0;
396 mf.get(sden.c_str(), h1den);
397
398 if (h1eff && h1num && h1den) {
399 TGCResetContents(h1eff);
400 h1eff->Divide(h1num, h1den);
401
402 // save the summary histogram
403 dir->cd();
404 h1eff->Write("", TObject::kOverwrite);
405 } else {
406 //std::cerr <<"TGC PostProcessing: no such histogram (or num/denom)!! "<< seff << std::endl;
407 continue;
408 }
409
410 //trigger/2LB
411 ss.str("");
412 ss << "Number_Of_PT" << pt << "_Triggers_Per_Event_Vs_2LB" << sac[ac];
413 seff = rr_dir + ss.str();
414 ss.str("");
415 ss << "Number_Of_PT" << pt << "_Triggers_In_2LB" << sac[ac];
416 snum = rate_dir + ss.str();
417 ss.str("");
418 ss << "Number_Of_Events_In_2LB";
419 sden = grate_dir + ss.str();
420
421 h1eff = 0;
422 mf.get(seff.c_str(), h1eff);
423 h1num = 0;
424 mf.get(snum.c_str(), h1num);
425 h1den = 0;
426 mf.get(sden.c_str(), h1den);
427
428 if (h1eff && h1num && h1den) {
429 TGCResetContents(h1eff);
430 h1eff->Divide(h1num, h1den);
431
432 // save the summary histogram
433 dir->cd();
434 h1eff->Write("", TObject::kOverwrite);
435 } else {
436 //std::cerr <<"TGC PostProcessing: no such histogram (or num/denom)!! "<< seff << std::endl;
437 continue;
438 }
439 mf.Write();
440 }//pt
441
442 //Rate Ratio
443 std::string grate_dir = tgc_global_dir + "Rate/";
444 std::string rate_dir = tgc_sub_dir[ac] + "Rate/";
445 std::string rr_dir = tgc_sub_dir[ac] + "Rate/Ratio/";
446
447 // trigger/10BCID
448 ss.str("");
449 ss << "Number_Of_SL_Triggers_Per_Event_Vs_10BCID" << sac[ac];
450 seff = rr_dir + ss.str();
451 ss.str("");
452 ss << "Number_Of_SL_Triggers_In_10BCID" << sac[ac];
453 snum = rate_dir + ss.str();
454 ss.str("");
455 ss << "Number_Of_Events_In_10BCID";
456 sden = grate_dir + ss.str();
457
458 h1eff = 0;
459 mf.get(seff.c_str(), h1eff);
460 h1num = 0;
461 mf.get(snum.c_str(), h1num);
462 h1den = 0;
463 mf.get(sden.c_str(), h1den);
464
465 if (h1eff && h1num && h1den) {
466 TGCResetContents(h1eff);
467 h1eff->Divide(h1num, h1den);
468
469 // save the summary histogram
470 dir = mf.GetDirectory(rr_dir.c_str());
471 dir->cd();
472 h1eff->Write("", TObject::kOverwrite);
473 } else {
474 //std::cerr <<"TGC PostProcessing: no such histogram (or num/denom)!! "<< seff << std::endl;
475 continue;
476 }
477
478 //trigger/2LB
479 ss.str("");
480 ss << "Number_Of_SL_Triggers_Per_Event_Vs_2LB" << sac[ac];
481 seff = rr_dir + ss.str();
482 ss.str("");
483 ss << "Number_Of_SL_Triggers_In_2LB" << sac[ac];
484 snum = rate_dir + ss.str();
485 ss.str("");
486 ss << "Number_Of_Events_In_2LB";
487 sden = grate_dir + ss.str();
488
489 h1eff = 0;
490 mf.get(seff.c_str(), h1eff);
491 h1num = 0;
492 mf.get(snum.c_str(), h1num);
493 h1den = 0;
494 mf.get(sden.c_str(), h1den);
495
496 if (h1eff && h1num && h1den) {
497 TGCResetContents(h1eff);
498 h1eff->Divide(h1num, h1den);
499
500 // save the summary histogram
501 dir->cd();
502 h1eff->Write("", TObject::kOverwrite);
503 } else {
504 //std::cerr <<"TGC PostProcessing: no such histogram (or num/denom)!! "<< seff << std::endl;
505 continue;
506 }
507 mf.Write();
508 }//ac
509 //====End TGCLV1
510 }
511
512 mf.Write();
513 }
514}//namespace
static Double_t ss
static void TGCLV1HistogramDivision(const std::string &inFilename)
static void TGCRawHistogramDivision(const std::string &inFilename)