ATLAS Offline Software
Loading...
Searching...
No Matches
MonitoringFile_TGCPostProcess.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 Process TGC Histograms after merging.
7//Author: Akimasa Ishikawa (akimasa.ishikawa@cern.ch)
8//Date: Aug 2009
10
13
14#include <iostream>
15#include <iomanip>
16#include <algorithm>
17#include <fstream>
18#include <cmath>
19#include <cstdlib>
20#include <sstream>
21#include <vector>
22#include <utility>
23#include <map>
24#include <string>
25
26#include "TH1F.h"
27#include "TH2F.h"
28#include "TFile.h"
29#include "TClass.h"
30#include "TKey.h"
31#include "TMath.h"
32#include "TTree.h"
33#include "TBranch.h"
34#include "TGraph.h"
35
36namespace dqutils {
37 static const float TGCChamberLowOccupancyCut = 1.0e-6;
38 static const float TGCChamberHighOccupancyCut = 0.005;
39 static const float TGCChannelOccupancyCut = 0.01;
40 static const float TGCChamberEfficiencyCut = 0.7;
41 static const float TGCChamberTimingCut = 0.95;
42
43 static const bool tgc_debug = false;
44
45 void
46 MonitoringFile::TGCPostProcess(const std::string& inFilename, bool /* isIncremental */) {
47 //start postprocessing
48 std::vector< std::pair< std::string, float > > NoisyChambers;
49 std::vector< std::pair< std::string, float > > DeadChambers;
50
51 std::vector< std::pair< std::string, float > > NoisyChannels;
52
53 std::vector< std::pair< std::string, float > > LowEfficiencyChambers;
54
55 std::vector< std::pair< std::string, float > > ReadoutTimingChambers;
56 std::vector< std::pair< std::string, float > > TriggerTimingChambers;
57
58 TGCLV1HistogramDivision(inFilename);
59 TGCRawHistogramDivision(inFilename);
60 TGCChamberOccupancy(inFilename, NoisyChambers, DeadChambers);
61 // TGCChannelOccupancy( inFilename, run_dir, NoisyChannels );
62
63 TGCChamberEfficiency(inFilename, LowEfficiencyChambers);
64 TGCChamberTiming(inFilename, ReadoutTimingChambers, TriggerTimingChambers);
65 //DQA results to COOL
66
67 return;
68 }//MonitoringFile::TGCPostProcess
69
70 bool
71 MonitoringFile::TGCCheckHistogram(TFile* f, const std::string& hname) {
72 if (!(f->Get(hname.c_str()))) {
73 //std::cerr << "TGC PostProcessing: no such histogram!! : "<< hname << std::endl;
74 gDirectory->pwd();
75 gDirectory->ls();
76 return false;
77 }
78 return true;
79 }//MonitoringFile::TGCCheckHistogram
80
81 void
82 MonitoringFile::TGCChamberOccupancy(const std::string& inFilename,
83 std::vector< std::pair< std::string, float > >& noisychambers,
84 std::vector< std::pair< std::string, float > >& deadchambers) {
85 PostProcessorFileWrapper mf(inFilename, "TGC ChamberOcc Calculations");
86
87 if (!mf.IsOpen()) {
88 //std::cerr << "TGCPostProcess(): "
89 // << "Input file not opened \n";
90 return;
91 }
92 if (mf.GetSize() < 1000.) {
93 //std::cerr << "TGCPostProcess(): "
94 // << "Input file empty \n";
95 return;
96 }
97 /*
98 // get run directory name
99 //Seemingly unnecessary lines are necessary
100 TIter nextcd0(gDirectory->GetListOfKeys());
101 TKey *key0 = (TKey*)nextcd0();
102 TDirectory *dir0= dynamic_cast<TDirectory*> (key0->ReadObj());
103 dir0->cd();
105 */
106 TIter next_run(mf.GetListOfKeys());
107 TKey* key_run(0);
108 static const std::string sac[2] = {
109 "_A", "_C"
110 };
111 static const std::string side[2] = {
112 "A", "C"
113 };
114 static const std::string sws[2] = {
115 "Wire_", "Strip_"
116 };
117 static const std::string type[17] = {
118 "_F_T1", "_E4_T3", "_E3_T6", "_E2_T7", "_E1_T8",
119 "_F_T2", "_E5_T4", "_E4_T6", "_E3_T7", "_E2_T8", "_E1_T9",
120 "_F_T2", "_E5_T5", "_E4_T6", "_E3_T7", "_E2_T8", "_E1_T9"
121 };
122 while ((key_run = dynamic_cast<TKey*> (next_run())) != 0) {
123 if (!key_run->IsFolder()) continue;
124 std::string run_dir = key_run->GetName();
125 if (run_dir.find("run") == std::string::npos) continue;
126
127 std::string run_dir2 = run_dir;
128 //int run_number = atoi( (run_dir2.substr(4, run_dir2.size()-4 )).c_str() );
129 //run_number=run_number;
130
131 std::string tgc_dir = run_dir + "/Muon/MuonRawDataMonitoring/TGC/";
132
133 std::string tgc_global_dir = tgc_dir + "Global/";
134
135 std::string tgc_sub_dir[2] = {
136 tgc_dir + "TGCEA/", tgc_dir + "TGCEC/"
137 };
138
139
140
141 std::stringstream ss;
142
143 //Summary histograms
144 std::string schambertypesummary[2][4][6];//[ws][station][eta]
145 TH1F* chambertypesummary[2][4][6];//
146
147 std::string schambersummary[2][2];//[ac][ws]
148 TH1F* chambersummary[2][2];//
149
150
151
152 //get summary histograms
153 for (int ws = 0; ws < 2; ws++) {
154 int ntype = 0;
155 for (int station = 0; station < 3; station++) {
156 for (int eta = 0; eta < 6; eta++) {
157 if (eta == 5 && station == 0) continue;
158 if (eta < 2 && station == 3) continue;
159
160 ss.str("");
161 ss << "Station" << station + 1 << type[ntype];
162 schambertypesummary[ws][station][eta] = tgc_dir + "Global/Summary/"
163 + "Summary_Of_Log10_" + sws[ws] + "Occupancy_Per_Chamber_Type_" +
164 ss.str();
165 if (tgc_debug) std::cout << schambertypesummary[ws][station][eta] << std::endl;
166
167 chambertypesummary[ws][station][eta] = 0;
168 mf.get(schambertypesummary[ws][station][eta].c_str(), chambertypesummary[ws][station][eta]);
169 if (!chambertypesummary[ws][station][eta]) {
170 //std::cerr <<"TGC PostProcessing: no such histogram!! "<< schambertypesummary[ws][station][eta] <<
171 // std::endl;
172 continue;
173 }
174 TGCResetContents(chambertypesummary[ws][station][eta]);
175
176 ntype++;
177 }//eta
178 }//station
179
180 for (int ac = 0; ac < 2; ac++) {
181 schambersummary[ac][ws] = tgc_sub_dir[ac] + "Summary/"
182 + "Summary_Of_Log10_" + sws[ws] + "Occupancy_Per_GasGap" + sac[ac];
183 if (tgc_debug) std::cout << schambersummary[ac][ws] << std::endl;
184
185 chambersummary[ac][ws] = 0;
186 mf.get(schambersummary[ac][ws].c_str(), chambersummary[ac][ws]);
187 if (!chambersummary[ac][ws]) {
188 //std::cerr <<"TGC PostProcessing: no such histogram!! "<< schambersummary[ac][ws] << std::endl;
189 continue;
190 }
191 TGCResetContents(chambersummary[ac][ws]);
192 }// ac
193 }// ws
194
195 //get number of events processed
196 std::string sentries = tgc_global_dir + "Event_Counter";
197
198 TH1F* hentries = 0;
199 mf.get(sentries.c_str(), hentries);
200 if (!hentries) {
201 //std::cerr <<"TGC PostProcessing: no such histogram!! "<< sentries << std::endl;
202 continue;
203 }
204
205 double nentries = hentries->GetEntries();
206
207 //calculate occupancies
208 for (int ac = 0; ac < 2; ac++) {
209 for (int ws = 0; ws < 2; ws++) {
210 double min = 1.;
211 double max = 0.;
212
213 std::string sprof = tgc_sub_dir[ac] + "Profile/" + sws[ws] + "Profile_Map" + sac[ac];
214 std::string soccu = tgc_sub_dir[ac] + "Occupancy/" + sws[ws] + "Occupancy_Map" + sac[ac];
215
216 TH2F* hprof = 0;
217 mf.get(sprof.c_str(), hprof);
218 if (!hprof) {
219 //std::cerr <<"TGC PostProcessing: no such histogram!! "<< sprof << std::endl;
220 continue;
221 }
222
223 TH2F* hoccu = 0;
224 mf.get(soccu.c_str(), hoccu);
225 if (!hoccu) {
226 //std::cerr <<"TGC PostProcessing: no such histogram!! "<< soccu << std::endl;
227 continue;
228 }
229 TGCResetContents(hoccu);
230
231 int nbinx = hprof->GetXaxis()->GetNbins();
232 int nbiny = hprof->GetYaxis()->GetNbins();
233
234 for (int binx = 1; binx <= nbinx; binx++) {
235 for (int biny = 1; biny <= nbiny; biny++) {
236 if (ws == 1 && (binx == 2 || binx == 9 || binx == 16 || binx == 23 || binx == 34)) continue; //skip strip
237 // for layer2
238 if ((binx >= 33 && binx <= 43) &&
239 biny % 2 == 0) continue; // skip phi1,3 for forward region
240 if ((binx == 40 || binx == 41) &&
241 (biny == 19 || biny == 35 || biny == 43)) continue; //skip phi9,17,21 for EI
242
243 double num = hprof->GetBinContent(binx, biny);
244 double den = nentries * nTGCWireStripMap(ws, binx - 1, biny);
245 double occu = 0.;
246 double eoccu = 0.;
247 if (num > 0 && nentries > 0) {
248 occu = (double) num / den;
249 eoccu = sqrt(occu * (1. - occu) / den);
250 }
251 hoccu->SetBinContent(binx, biny, occu);
252 hoccu->SetBinError(binx, biny, eoccu);
253
254 // to set minimum and maximum
255 if (occu < min && occu > 1e-8) min = occu;
256 if (occu > max) max = occu;
257
258 if (occu < 1.e-8) {
259 occu = 1.e-8;
260 eoccu = 1.e-8;
261 }
262 if (chambersummary[ac][ws]) chambersummary[ac][ws]->Fill(log10(occu));
263
264 int station = 0;
265 int eta = -1;
266 if (binx < 16) {
267 station = 0;
268 eta = (binx - 1) % 5;
269 } else if (binx < 28) {
270 station = 1;
271 eta = (binx - 16) % 6;
272 } else if (binx < 40) {
273 station = 2;
274 eta = (binx - 28) % 6;
275 } else {
276 station = 3;
277 eta = (binx - 40) % 2;
278 }
279 if (station < 3 && eta >= 0)
280 if (chambertypesummary[ws][station][eta]) chambertypesummary[ws][station][eta]->Fill(log10(occu));
281
282 //high occupancy chamber
283 if (occu > TGCChamberHighOccupancyCut) {
284 ss.str("");
285 std::string schamber = hprof->GetXaxis()->GetBinLabel(binx);
286 int sector = (biny - 1) / 4 + 1;
287 int phi = (biny - 1) % 4;
288 ss << side[ac];
289 if (sector < 10) ss << "0";
290 ss << sector << "phi" << phi;
291 if (tgc_debug) std::cout << "TGC noisy channel : " << ss.str() << " " << occu << std::endl;
292
293 std::pair<std::string, float> p(ss.str(), occu);
294 noisychambers.push_back(std::move(p));
295 } else if (occu < TGCChamberLowOccupancyCut) {//too low occupancy
296 ss.str("");
297 std::string schamber = hprof->GetXaxis()->GetBinLabel(binx);
298 int sector = (biny - 1) / 4 + 1;
299 int phi = (biny - 1) % 4;
300 ss << side[ac];
301 if (sector < 10) ss << "0";
302 ss << sector << "phi" << phi;
303 if (tgc_debug) std::cout << "TGC low occupancy chamber : " << ss.str() << " " << occu << std::endl;
304
305 std::pair<std::string, float> p(ss.str(), occu);
306 deadchambers.push_back(std::move(p));
307 }
308 }//biny
309 }//binx
310
311 hoccu->SetMinimum(min * 0.95);
312 hoccu->SetMaximum(max * 1.05);
313
314 std::string occu_dir = tgc_sub_dir[ac] + "Occupancy/";
315 TDirectory* dir = mf.GetDirectory(occu_dir.c_str());
316
317 if (dir) {
318 dir->cd();
319 hoccu->Write("", TObject::kOverwrite);
320 } else {
321 //std::cerr<<"TGCChamberOccupancy: directory "<<occu_dir<<" not found"<<std::endl;
322 }
323 }//ws
324 }//ac
325 mf.Write();
326
327 // if directory is found, save the summary histogram
328 std::string sum_dir = tgc_dir + "Global/Summary";
329 TDirectory* dir = mf.GetDirectory(sum_dir.c_str());
330
331 if (dir) {
332 dir->cd();
333 for (int ws = 0; ws < 2; ws++) {
334 for (int station = 0; station < 3; station++) {
335 for (int eta = 0; eta < 6; eta++) {
336 if (eta == 5 && station == 0) continue;
337 if (eta < 2 && station == 3) continue;
338 if (chambertypesummary[ws][station][eta]) chambertypesummary[ws][station][eta]->Write("",
339 TObject::kOverwrite);
340
341 }//eta
342 }//station
343 }//ws
344 } else {
345 //std::cerr<<"TGCChamberOccupancy: directory "<<sum_dir<<" not found"<<std::endl;
346 }//if
347 mf.Write();
348
349 for (int ac = 0; ac < 2; ac++) {
350 // if directory is found, save the summary histogram
351 sum_dir = tgc_sub_dir[ac] + "Summary/";
352 dir = mf.GetDirectory(sum_dir.c_str());
353 if (dir) {
354 dir->cd();
355 for (int ws = 0; ws < 2; ws++) {
356 if (chambersummary[ac][ws]) chambersummary[ac][ws]->Write("", TObject::kOverwrite);
357 }//ws
358 } else {
359 //std::cerr<<"TGCChamberOccupancy: directory "<<sum_dir<<" not found"<<std::endl;
360 }//if
361 }//ac
362 mf.Write();
363 }//while
364
365 mf.Write();
366 }//MonitoringFile::TGCChamberOccupancy
367
368 void
369 MonitoringFile::TGCChamberEfficiency(const std::string& inFilename,
370 std::vector< std::pair< std::string,
371 float > >& loweffchambers) {
372 PostProcessorFileWrapper mf(inFilename, "TGC ChamberEff Calculations");
373
374 if (!mf.IsOpen()) {
375 //std::cerr << "TGCPostProcess(): "
376 // << "Input file not opened \n";
377 return;
378 }
379 if (mf.GetSize() < 1000.) {
380 //std::cerr << "TGCPostProcess(): "
381 // << "Input file empty \n";
382 return;
383 }
384 /*
385 // get run directory name
386 //Seemingly unnecessary lines are necessary
387 TIter nextcd0(gDirectory->GetListOfKeys());
388 TKey *key0 = (TKey*)nextcd0();
389 TDirectory *dir0= dynamic_cast<TDirectory*> (key0->ReadObj());
390 dir0->cd();
392 */
393 TIter next_run(mf.GetListOfKeys());
394 TKey* key_run(0);
395 static const std::string type[17] = {
396 "_F_T1", "_E4_T3", "_E3_T6", "_E2_T7", "_E1_T8",
397 "_F_T2", "_E5_T4", "_E4_T6", "_E3_T7", "_E2_T8", "_E1_T9",
398 "_F_T2", "_E5_T5", "_E4_T6", "_E3_T7", "_E2_T8", "_E1_T9"
399 };
400 while ((key_run = dynamic_cast<TKey*> (next_run())) != 0) {
401 if (!key_run->IsFolder()) continue;
402 std::string run_dir = key_run->GetName();
403 if (run_dir.find("run") == std::string::npos) continue;
404
405 std::string run_dir2 = run_dir;
406 //int run_number = atoi( (run_dir2.substr(4, run_dir2.size()-4 )).c_str() );
407 //run_number=run_number;
408
409 std::string tgc_dir = run_dir + "/Muon/MuonRawDataMonitoring/TGC/";
410
411 std::string tgc_sub_dir[2] = {
412 tgc_dir + "TGCEA/", tgc_dir + "TGCEC/"
413 };
414
415 static const std::string sac[2] = {
416 "_A", "_C"
417 };
418 static const std::string sws[2] = {
419 "Wire_", "Strip_"
420 };
421
422 std::stringstream ss;
423
424 //Summary histograms
425 std::string schambertypesummary[2][3][6];//[ws][station][eta]
426 TH1F* chambertypesummary[2][3][6];//
427
428 std::string schambersummary[2][2];//[ac][ws]
429 TH1F* chambersummary[2][2];//
430
431
432
433 //get summary histograms
434 for (int ws = 0; ws < 2; ws++) {
435 int ntype = 0;
436 for (int station = 0; station < 3; station++) {
437 for (int eta = 0; eta < 6; eta++) {
438 if (eta == 5 && station == 0) continue;
439 if (eta < 2 && station == 3) continue;
440
441 ss.str("");
442 ss << "Station" << station + 1 << type[ntype];
443 schambertypesummary[ws][station][eta] = tgc_dir + "Global/Summary/"
444 + "Summary_Of_" + sws[ws] + "Efficiency_Per_Chamber_Type_" +
445 ss.str();
446 if (tgc_debug) std::cout << schambertypesummary[ws][station][eta] << std::endl;
447
448 chambertypesummary[ws][station][eta] = 0;
449 mf.get(schambertypesummary[ws][station][eta].c_str(), chambertypesummary[ws][station][eta]);
450 if (!chambertypesummary[ws][station][eta]) {
451 //std::cerr <<"TGC PostProcessing: no such histogram!! "<< schambertypesummary[ws][station][eta] <<
452 // std::endl;
453 continue;
454 }
455 TGCResetContents(chambertypesummary[ws][station][eta]);
456
457 ntype++;
458 }//eta
459 }//station
460
461 for (int ac = 0; ac < 2; ac++) {
462 schambersummary[ac][ws] = tgc_sub_dir[ac] + "Summary/"
463 + "Summary_Of_" + sws[ws] + "Efficiency_Per_GasGap" + sac[ac];
464 if (tgc_debug) std::cout << schambersummary[ac][ws] << std::endl;
465
466 chambersummary[ac][ws] = 0;
467 mf.get(schambersummary[ac][ws].c_str(), chambersummary[ac][ws]);
468 if (!chambersummary[ac][ws]) {
469 //std::cerr <<"TGC PostProcessing: no such histogram!! "<< schambersummary[ac][ws] << std::endl;
470 continue;
471 }
472 TGCResetContents(chambersummary[ac][ws]);
473 }//ac
474 }//ws
475
476 for (int ac = 0; ac < 2; ac++) {
477 for (int ws = 0; ws < 2; ws++) {
478 std::string seff = tgc_sub_dir[ac] + "Efficiency/" + sws[ws] + "Efficiency_Map" + sac[ac];
479 std::string sden = tgc_sub_dir[ac] + "Efficiency/NumDenom/" + sws[ws] + "Efficiency_Map" + sac[ac] +
480 "_Denominator";
481
482 TH2F* heff = 0;
483 mf.get(seff.c_str(), heff);
484 if (!heff) {
485 //std::cerr <<"TGC PostProcessing: no such histogram!! "<< seff << std::endl;
486 continue;
487 }
488
489 TH2F* hden = 0;
490 mf.get(sden.c_str(), hden);
491 if (!hden) {
492 //std::cerr <<"TGC PostProcessing: no such histogram!! "<< sden << std::endl;
493 }
494
495 int nbinx = heff->GetXaxis()->GetNbins();
496 int nbiny = heff->GetYaxis()->GetNbins();
497
498 for (int binx = 1; binx <= nbinx; binx++) {
499 for (int biny = 1; biny <= nbiny; biny++) {
500 //if( ( binx==5 || binx==10 || binx==15 ||
501 // binx==21 || binx==27 || binx==33 || binx>=39 ) &&
502 // biny%2 == 0 )continue;// skip phi1,3 for forward region
503 //if( ( binx ==40 || binx==42 ) &&
504 // ( biny ==18 || biny==34 || biny==42 ) ) continue;//skip phi9,17,21 for EI
505 if ((binx >= 33 && binx <= 43) &&
506 biny % 2 == 0) continue; // skip phi1,3 for forward region
507 if ((binx == 40 || binx == 41) &&
508 (biny == 19 || biny == 35 || biny == 43)) continue; //skip phi9,17,21 for EI
509
510
511 double eff = heff->GetBinContent(binx, biny);
512 double denom = 1;
513 if (hden) {
514 denom = hden->GetBinContent(binx, biny);
515 }
516
517 if (chambersummary[ac][ws])
518 if (denom > 0) chambersummary[ac][ws]->Fill(eff);
519
520 int station = 0;
521 int eta = -1;
522 if (binx < 16) {
523 station = 0;
524 eta = (binx - 1) % 5;
525 } else if (binx < 28) {
526 station = 1;
527 eta = (binx - 16) % 6;
528 } else if (binx < 40) {
529 station = 2;
530 eta = (binx - 28) % 6;
531 } else {
532 station = 3;
533 eta = (binx - 40) % 2;
534 }
535 if (station < 3 && eta >= 0)
536 if (chambertypesummary[ws][station][eta])
537 if (denom > 0) chambertypesummary[ws][station][eta]->Fill(eff);
538
539 //low efficiency chambers
540 if (eff < TGCChamberEfficiencyCut) {
541 ss.str("");
542 std::string schamber = heff->GetXaxis()->GetBinLabel(binx);
543 int sector = (biny - 1) / 4 + 1;
544 int phi = (biny - 1) % 4;
545 ss << sac[ac];
546 if (sector < 10) ss << "0";
547 ss << sector << "phi" << phi;
548
549 if (tgc_debug) std::cout << "TGC low efficiency chamber : " << ss.str() << " " << eff << std::endl;
550
551 std::pair<std::string, float> p(ss.str(), eff);
552 loweffchambers.push_back(std::move(p));
553 }
554 }//biny
555 }//binx
556
557 std::string eff_dir = tgc_sub_dir[ac] + "Efficiency/";
558 TDirectory* dir = mf.GetDirectory(eff_dir.c_str());
559
560 if (dir) {
561 dir->cd();
562 heff->Write("", TObject::kOverwrite);
563 } else {
564 //std::cerr<<"TGCChamberEfficiency: directory "<<eff_dir<<" not found"<<std::endl;
565 }
566 }//ws
567 }//ac
568
569 mf.Write();
570 // if directory is found, save the summary histogram
571 std::string sum_dir = tgc_dir + "Global/Summary";
572 TDirectory* dir = mf.GetDirectory(sum_dir.c_str());
573
574
575 if (dir) {
576 dir->cd();
577 for (int ws = 0; ws < 2; ws++) {
578 for (int station = 0; station < 3; station++) {
579 for (int eta = 0; eta < 6; eta++) {
580 if (eta == 5 && station == 0) continue;
581 if (eta < 2 && station == 3) continue;
582 if (chambertypesummary[ws][station][eta]) chambertypesummary[ws][station][eta]->Write("",
583 TObject::kOverwrite);
584
585 }//eta
586 }//station
587 }//ws
588 } else {
589 //std::cerr<<"TGCChamberEfficiency: directory "<<sum_dir<<" not found"<<std::endl;
590 }//if
591 mf.Write();
592
593 for (int ac = 0; ac < 2; ac++) {
594 // if directory is found, save the summary histogram
595 sum_dir = tgc_sub_dir[ac] + "Summary/";
596 dir = mf.GetDirectory(sum_dir.c_str());
597 if (dir) {
598 dir->cd();
599 for (int ws = 0; ws < 2; ws++) {
600 if (chambersummary[ac][ws]) chambersummary[ac][ws]->Write("", TObject::kOverwrite);
601 }//ws
602 } else {
603 //std::cerr<<"TGCChamberEfficiency: directory "<<sum_dir<<" not found"<<std::endl;
604 }//if
605 }//ac
606 mf.Write();
607 }//while
608 mf.Write();
609 }//MonitoringFile::TGCChamberEfficiency
610
611 void
612 MonitoringFile::TGCChamberTiming(const std::string& inFilename,
613 std::vector< std::pair< std::string, float > >& badrotimingchambers,
614 std::vector< std::pair< std::string, float > >& badtrgtimingchambers) {
615 PostProcessorFileWrapper mf(inFilename, "TGC Chamber Timing Calculations");
616
617 if (!mf.IsOpen()) {
618 //std::cerr << "TGCPostProcess(): "
619 // << "Input file not opened \n";
620 return;
621 }
622 if (mf.GetSize() < 1000.) {
623 //std::cerr << "TGCPostProcess(): "
624 // << "Input file empty \n";
625 return;
626 }
627 /*
628 // get run directory name
629 //Seemingly unnecessary lines are necessary
630 TIter nextcd0(gDirectory->GetListOfKeys());
631 TKey *key0 = (TKey*)nextcd0();
632 TDirectory *dir0= dynamic_cast<TDirectory*> (key0->ReadObj());
633 dir0->cd();
635 */
636 TIter next_run(mf.GetListOfKeys());
637 TKey* key_run(0);
638 static const std::string type[6] = {
639 "_F_T2", "_E5_T5", "_E4_T6", "_E3_T7", "_E2_T8", "_E1_T9"
640 };
641 static const std::string sac[2] = {
642 "_A", "_C"
643 };
644
645 static const std::string ssllpt[2] = {
646 "SL_Timing", "Low_Pt_Timing"
647 };
648 while ((key_run = dynamic_cast<TKey*> (next_run())) != 0) {
649 if (!key_run->IsFolder()) continue;
650 std::string run_dir = key_run->GetName();
651 if (run_dir.find("run") == std::string::npos) continue;
652
653 std::string run_dir2 = run_dir;
654 //int run_number = atoi( (run_dir2.substr(4, run_dir2.size()-4 )).c_str() );
655 //run_number=run_number;
656
657 std::string tgc_dir = run_dir + "/Muon/MuonRawDataMonitoring/TGCLV1/";
658
659 std::string tgc_sub_dir[2] = {
660 tgc_dir + "TGCEA/", tgc_dir + "TGCEC/"
661 };
662
663
664
665 std::stringstream ss;
666 //Summary histograms
667 std::string schambertypesummary[6];//[station][eta]
668 TH1F* chambertypesummary[6];//
669
670
671
672 for (int sllpt = 0; sllpt < 2; sllpt++) {//loop over SL/LPT
673 for (int eta = 0; eta < 6; eta++) {
674 //get summary histograms
675 ss.str("");
676 ss << type[eta];
677 schambertypesummary[eta] = tgc_dir + "Global/Summary/"
678 + "Summary_Of_" + ssllpt[sllpt] + "_Per_Chamber_Type" + ss.str();
679
680 chambertypesummary[eta] = 0;
681 mf.get(schambertypesummary[eta].c_str(), chambertypesummary[eta]);
682 if (!chambertypesummary[eta]) {
683 //std::cerr <<"TGC PostProcessing: no such histogram!! "<< schambertypesummary[eta] << std::endl;
684 continue;
685 }
686 TGCResetContents(chambertypesummary[eta]);
687 }//eta
688
689 for (int ac = 0; ac < 2; ac++) {
690 //get summary histogram
691 std::string ssum = tgc_sub_dir[ac] + "Summary/Summary_Of_" + ssllpt[sllpt] + sac[ac];
692 std::string stmap = tgc_sub_dir[ac] + ssllpt[sllpt] + "_Map" + sac[ac];
693 std::string stfrac = tgc_sub_dir[ac] + ssllpt[sllpt] + "_Fraction_Map" + sac[ac];
694
695 TH1F* hsum = 0;
696 mf.get(ssum.c_str(), hsum);
697 if (!hsum) {
698 //std::cerr <<"TGC PostProcessing: no such histogram!! "<< ssum << std::endl;
699 continue;
700 }
701
702 TH2F* htmap = 0;
703 mf.get(stmap.c_str(), htmap);
704 if (!htmap) {
705 //std::cerr <<"TGC PostProcessing: no such histogram!! "<< stmap << std::endl;
706 continue;
707 }
708
709 TH2F* htfrac = 0;
710 mf.get(stfrac.c_str(), htfrac);
711 if (!htfrac) {
712 //std::cerr <<"TGC PostProcessing: no such histogram!! "<< stfrac << std::endl;
713 continue;
714 }
715
717 TGCResetContents(htfrac);
718
719 int nbinx = htmap->GetXaxis()->GetNbins();
720 int nbiny = htmap->GetYaxis()->GetNbins();
721
722 if (nbinx != 18 || nbiny != 48) continue;
723
724 for (int eta = 0; eta < 6; eta++) {
725 for (int phi48 = 0; phi48 < 48; phi48++) {
726 if (eta == 5 && phi48 % 2 == 1) continue; //Forward
727
728 float p = htmap->GetBinContent(eta + 1, phi48 + 1);
729 float c = htmap->GetBinContent(eta + 7, phi48 + 1);
730 float n = htmap->GetBinContent(eta + 13, phi48 + 1);
731 float tot = p + n + c;
732
733 float fp = 0;
734 float fc = 0;
735 float fn = 0;
736
737 float efp = 0;
738 float efc = 0;
739 float efn = 0;
740
741 if (tot != 0) {
742 fp = p / tot;
743 efp = sqrt(fp * (1. - fp) / tot);
744 fc = c / tot;
745 efc = sqrt(fc * (1. - fc) / tot);
746 fn = n / tot;
747 efn = sqrt(fn * (1. - fn) / tot);
748 }
749
750 htfrac->SetBinContent(eta + 1, phi48 + 1, fp);
751 htfrac->SetBinContent(eta + 7, phi48 + 1, fc);
752 htfrac->SetBinContent(eta + 13, phi48 + 1, fn);
753 htfrac->SetBinError(eta + 1, phi48 + 1, efp);
754 htfrac->SetBinError(eta + 7, phi48 + 1, efc);
755 htfrac->SetBinError(eta + 13, phi48 + 1, efn);
756
757 if (chambertypesummary[eta]) chambertypesummary[eta]->Fill(fc);
758 hsum->Fill(fc);
759
760 //low current fraction chambers
761 if (fc < TGCChamberTimingCut) {
762 ss.str("");
763 //std::string chamber = htiming->GetXaxis()->GetBinLabel(bin);
764 ss << sac[ac] << "phi" << phi48 + 1 << "Eta" << eta;
765
766 if (tgc_debug) std::cout << "TGC " << ssllpt[sllpt] << " low current BCID fraction chamber : " <<
767 ss.str() << " " << fc << std::endl;
768
769 std::pair<std::string, float> p(ss.str(), fc);
770 if (sllpt == 0) {
771 badtrgtimingchambers.push_back(std::move(p));
772 } else {
773 badrotimingchambers.push_back(std::move(p));
774 }
775 }
776 }//phi48
777 }//eta
778
779 //write timing fraction
780 std::string timing_dir = tgc_sub_dir[ac];
781 TDirectory* dir = mf.GetDirectory(timing_dir.c_str());
782
783 if (dir) {
784 dir->cd();
785 htfrac->Write("", TObject::kOverwrite);
786 } else {
787 //std::cerr<<"TGCChamberTiming : directory "<<timing_dir<<" not found"<<std::endl;
788 }
789
790 //write summary of timing for each side
791 std::string sum_dir = tgc_sub_dir[ac] + "Summary/";
792 dir = mf.GetDirectory(sum_dir.c_str());
793
794 if (dir) {
795 dir->cd();
796 hsum->Write("", TObject::kOverwrite);
797 } else {
798 //std::cerr<<"TGCChamberTiming : directory "<<sum_dir<<" not found"<<std::endl;
799 }
800 }//ac
801 mf.Write();
802
803 //write summary of timing for each eta
804 std::string sum_dir = tgc_dir + "Global/Summary/";
805 TDirectory* dir = mf.GetDirectory(sum_dir.c_str());
806
807 if (dir) {
808 dir->cd();
809 for (int eta = 0; eta < 6; eta++) {
810 if (chambertypesummary[eta]) chambertypesummary[eta]->Write("", TObject::kOverwrite);
811 }
812 } else {
813 //std::cerr<<"TGCChamberTiming : directory "<<sum_dir<<" not found"<<std::endl;
814 }
815 mf.Write();
816 }//sllpt
817 }//while
818 mf.Write();
819 }//MonitoringFile::TGCChamberTiming
820
821 void
822 MonitoringFile::TGCChannelOccupancy(const std::string& inFilename,
823 std::vector< std::pair< std::string,
824 float > >& noisychannels) {
825 PostProcessorFileWrapper mf(inFilename, "TGC ChannelOcc Calculations");
826
827 if (!mf.IsOpen()) {
828 //std::cerr << "TGCPostProcess(): "
829 // << "Input file not opened \n";
830 return;
831 }
832 if (mf.GetSize() < 1000.) {
833 //std::cerr << "TGCPostProcess(): "
834 // << "Input file empty \n";
835 return;
836 }
837 /*
838 // get run directory name
839 //Seemingly unnecessary lines are necessary
840 TIter nextcd0(gDirectory->GetListOfKeys());
841 TKey *key0 = (TKey*)nextcd0();
842 TDirectory *dir0= dynamic_cast<TDirectory*> (key0->ReadObj());
843 dir0->cd();
845 */
846 TIter next_run(mf.GetListOfKeys());
847 TKey* key_run(0);
848 static const std::string sac[2] = {
849 "_A", "_C"
850 };
851 static const std::string sws[2] = {
852 "Wire_", "Strip_"
853 };
854 static const std::string slay[7] = {
855 "1", "2", "3", "4", "5", "6", "7"
856 };
857 while ((key_run = dynamic_cast<TKey*> (next_run())) != 0) {
858 if (!key_run->IsFolder()) continue;
859 std::string run_dir = key_run->GetName();
860 if (run_dir.find("run") == std::string::npos) continue;
861
862 std::string run_dir2 = run_dir;
863 //int run_number = atoi( (run_dir2.substr(4, run_dir2.size()-4 )).c_str() );
864 //run_number=run_number;
865
866 std::string tgc_dir = run_dir + "/Muon/MuonRawDataMonitoring/TGC/";
867
868 std::string tgc_global_dir = tgc_dir + "Global/";
869 std::string tgc_sub_dir[2] = {
870 tgc_dir + "TGCEA/", tgc_dir + "TGCEC/"
871 };
872
873
874 std::stringstream ss;
875
876 //get number of events processed
877 std::string sentries = tgc_global_dir + "Event_Counter";
878
879 TH1F* hentries = 0;
880 mf.get(sentries.c_str(), hentries);
881 if (!hentries) {
882 //std::cerr <<"TGC PostProcessing: no such histogram!! "<< sentries << std::endl;
883 continue;
884 }
885
886 double nentries = hentries->GetEntries();
887
888 for (int ac = 0; ac < 2; ac++) {
889 for (int ws = 0; ws < 2; ws++) {
890 for (int lay = 0; lay < 7; lay++) {
891 if (ws == 1 && lay == 1) continue;
892 for (int subsect = 1; subsect <= 48; subsect++) {
893 //get each subsector histogram
894 int sector, phi4;
895 TGCsubsect2sectorphi(subsect, sector, phi4);
896
897 ss.str("");
898 if (sector < 10) ss << "0";
899 ss << sector << "_Layer" << slay[lay] << "_Phi" << phi4;
900 std::string sprof = tgc_sub_dir[ac] + "Profile/" + sws[ws] + "Hit_Profile" + sac[ac] + ss.str();
901
902 TH1F* hprof = 0;
903 mf.get(sprof.c_str(), hprof);
904 if (!hprof) {
905 //std::cerr <<"TGC PostProcessing: no such histogram!! "<< sprof << std::endl;
906 continue;
907 }
908
909 int nbin = hprof->GetXaxis()->GetNbins();
910
911 for (int bin = 1; bin <= nbin; bin++) {
912 double num = hprof->GetBinContent(bin);
913 float occu = 0.;
914 if (nentries > 0) occu = (float) num / nentries;
915 if (occu > TGCChannelOccupancyCut) {
916 ss.str("");
917 ss << hprof->GetName() << " " << bin;
918 if (tgc_debug) std::cout << "TGC noisy channel : " << ss.str() << " " << occu << std::endl;
919 noisychannels.emplace_back(ss.str(), occu);
920 }
921 }//bin
922 }//subsect
923 }//lay
924 }//loop over ws
925 }//loop over ac
926 }//while
927 }//MonitoringFile::TGCChannelOccupancy
928
929 void
930 MonitoringFile::TGCsubsectbin2stationeta(int subsect, int bin, int& station, int& eta) {
931 if (subsect % 2 == 1) {//including forward chamber
932 if (bin <= 15) {
933 station = 1;
934 eta = (bin - 1) % 5;
935 } else if (bin <= 27) {
936 station = 2;
937 eta = (bin - 16) % 6;
938 } else {
939 station = 3;
940 eta = (bin - 28) % 6;
941 }
942 } else {
943 if (bin <= 12) {
944 station = 1;
945 eta = (bin - 1) % 4 + 1;
946 } else if (bin <= 22) {
947 station = 2;
948 eta = (bin - 13) % 5 + 1;
949 } else {
950 station = 3;
951 eta = (bin - 23) % 5 + 1;
952 }
953 }
954 }//MonitoringFile::TGCsubsectbin2stationeta
955
956 void
957 MonitoringFile::TGCsubsect2sectorphi(int subsect, int& sector, int& phi4) {
958 sector = (subsect + 1) / 4 + 1;
959 if (sector > 12) sector = 1;
960 phi4 = (subsect + 1) % 4;
961 }//MonitoringFile::TGCsubsect2sectorphi
962
963 int
964 MonitoringFile::nTGCWireStripMap(int ws, int etac, int phi48) {//[0:1][0:42][1:48]
965 int layer = 0;
966 int eta = etac;
967 int st = 0;
968// if ( etac <= 4 ){ layer = 0; eta = 4 - etac; st = 42;}
969// else if ( etac <= 9 ){ layer = 1; eta = 9 - etac; st = 42;}
970// else if ( etac <= 14 ){ layer = 2; eta = 14 - etac; st = 42;}
971// else if ( etac <= 20 ){ layer = 3; eta = 20 - etac; st = 44;}
972// else if ( etac <= 26 ){ layer = 4; eta = 26 - etac; st = 44;}
973// else if ( etac <= 32 ){ layer = 5; eta = 32 - etac; st = 46;}
974// else if ( etac <= 38 ){ layer = 6; eta = 38 - etac; st = 46;}
975// else if ( etac <= 40 ){ layer = 7; eta = 40 - etac; st = 48;}
976// else if ( etac <= 42 ){ layer = 8; eta = 42 - etac; st = 48;}
977
978 int binx = etac + 1;
979
980 if (binx % 7 >= 1 && binx % 7 <= 3 && binx <= 28) {
981 layer = (binx - 1) % 7;
982 eta = 4 - (binx - 1) / 7;
983 st = 42;
984 } else if (binx % 7 >= 4 && binx % 7 <= 5 && binx <= 28) {
985 layer = (binx - 1) % 7;
986 eta = 5 - (binx - 1) / 7;
987 st = 44;
988 } else if ((binx - 1) % 7 >= 5 && binx <= 28) {
989 layer = (binx - 1) % 7;
990 eta = 5 - (binx - 1) / 7;
991 st = 46;
992 } else if (binx > 28 && binx <= 30) {
993 layer = binx - 28 + 3 - 1;
994 eta = 1;
995 st = 44;
996 } else if (binx > 30 && binx <= 32) {
997 layer = binx - 28 + 3 - 1;
998 eta = 1;
999 st = 46;
1000 } else if (binx > 32 && binx <= 35) {
1001 layer = binx - 32 - 1;
1002 eta = 0;
1003 st = 42;
1004 } else if (binx > 35 && binx <= 37) {
1005 layer = binx - 32 - 1;
1006 eta = 0;
1007 st = 44;
1008 } else if (binx > 37 && binx <= 39) {
1009 layer = binx - 32 - 1;
1010 eta = 0;
1011 st = 46;
1012 } else if (binx > 39 && binx <= 41) {
1013 layer = binx - 32 - 1;
1014 eta = 1;
1015 st = 48;
1016 } else if (binx > 41 && binx <= 43) {
1017 layer = binx - 34 - 1;
1018 eta = 0;
1019 st = 48;
1020 }
1021
1022
1023 if (eta == 0) st -= 1;
1024
1025
1026 int nwire = getTGCNumberOfWires(st, layer, eta, phi48);
1027
1028
1029 //number of strips is always 32 except no chamber region which should be nwire==0.
1030 if (ws == 1) {
1031 if (nwire == 0) return 0;
1032
1033 return 32;
1034 }
1035
1036 return nwire;
1037 }
1038
1039 int
1040 MonitoringFile::getTGCNumberOfWires(const int istationName, const int layer, const int istationEta,
1041 const int istationPhi) {
1042 int nWire = 0;
1043
1044 if (istationName == 42) { //TGC1 Endcap //41:T1F 42:T1E 43:T2F 44:T2E 45:T3F 46:T3E 47:T3F 48:T4E (T4 means inner
1045 // small wheel TGCs, EI/FI)
1046 if (layer == 0) {
1047 if (istationEta == 1) { // T3 (E4) wire 1ch-91ch (total 91ch)
1048 nWire = 92;
1049 } else if (istationEta == 2) { //T6 (E3) 91ch-152ch (62ch)
1050 nWire = 61;
1051 } else if (istationEta == 3) { //T7 (E2) 152ch-174ch (23ch)
1052 nWire = 23;
1053 } else if (istationEta == 4) { //T8 (E1) 173ch-196ch(24ch)
1054 nWire = 24;
1055 }
1056 } else if (layer == 1 || layer == 2) {
1057 if (istationEta == 1) { // T3 (E4) wire 1ch-91ch (total 91ch)
1058 nWire = 91;
1059 } else if (istationEta == 2) { //T6 (E3) 91ch-152ch (62ch)
1060 nWire = 62;
1061 } else if (istationEta == 3) { //T7 (E2) 152ch-174ch (23ch)
1062 nWire = 23;
1063 } else if (istationEta == 4) { //T8 (E1) 173ch-196ch(24ch)
1064 nWire = 24;
1065 }
1066 }
1067 } else if (istationName == 41) { // TGC1 Forward
1068 if (layer == 0 || layer == 2) nWire = 105;
1069 else if (layer == 1) nWire = 104;
1070 } else if (istationName == 44) { // TGC2 Endcap
1071 if (istationEta == 1) { // T4 (E5) wire 1ch-91ch (total 91ch)
1072 nWire = 110;
1073 } else if (istationEta == 2) { //T6 (E4) 109ch-211ch (103ch)
1074 nWire = 103;
1075 } else if (istationEta == 3) { //T7 (E3) 211ch-242ch (23ch)
1076 nWire = 32;
1077 } else if (istationEta == 4) { //T8 (E2) 241ch-272ch (32ch)
1078 nWire = 32;
1079 } else if (istationEta == 5) { //T9 (E1) 271ch-302ch(32ch)
1080 nWire = 32;
1081 }
1082 } else if (istationName == 43) { // TGC2 Forward
1083 nWire = 125;
1084 } else if (istationName == 46) { // TGC3 Endcap
1085 if (istationEta == 1) { // T5 (E5) wire 1ch-110ch (total 110ch)
1086 nWire = 96;
1087 } else if (istationEta == 2) { //T6 (E4) 95ch-200ch (106ch)
1088 nWire = 106;
1089 } else if (istationEta == 3) { //T7 (E3) 200ch-231ch (32ch)
1090 nWire = 32;
1091 } else if (istationEta == 4) { //T8 (E2) 231ch-2
1092 nWire = 30;
1093 } else if (istationEta == 5) { //T9 (E1) 260ch-290ch(31ch)
1094 nWire = 31;
1095 }
1096 } else if (istationName == 45) { // TGC3 Forward
1097 nWire = 122;
1098 } else if (istationName == 48) { // EI
1099 //stationPhi 1-8 -> 1-8
1100 // 9-15 -> 10-16
1101 // 16-18 -> 18-20
1102 // 19-21 -> 22-24
1103 if (istationPhi == 2 || istationPhi == 11 || istationPhi == 13 || istationPhi == 14 || istationPhi == 15 ||
1104 istationPhi == 16 || istationPhi == 20 || istationPhi == 21) {
1105 //short 16
1106 nWire = 16;
1107 } else {
1108 //long 24
1109 nWire = 24;
1110 }
1111 } else if (istationName == 47) { // FI
1112 if (istationPhi == 2 || istationPhi == 5 || istationPhi == 8 || istationPhi == 11 || istationPhi == 14 ||
1113 istationPhi == 17 || istationPhi == 20 || istationPhi == 23) {
1114 //short 30
1115 nWire = 30;
1116 } else {
1117 //long 32
1118 nWire = 32;
1119 }
1120 }
1121 return nWire;
1122 }
1123
1124 void
1126 // copy all functions of histogram before resetting
1127 TList* h_funcs;
1128
1129 h_funcs = dynamic_cast<TList*> (h->GetListOfFunctions()->Clone());
1130 h->Reset();
1131 //now insert these functions back into the hist
1132 TIter iterE(h_funcs);
1133 while ((iterE())) {
1134 h->GetListOfFunctions()->Add(*iterE);
1135 }
1136 delete h_funcs;
1137 // are the functions still valid after list deletion?
1138 //http://root.cern.ch/root/html/TList#TList:_TList should be!
1139 // TIter iterTest(EffBCap->GetListOfFunctions());
1140 // while( iterTest() ) std::cout << (*iterTest)->GetName() << std::endl;
1141 }
1142}//namespace
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
static Double_t ss
#define min(a, b)
Definition cfImp.cxx:40
#define max(a, b)
Definition cfImp.cxx:41
double hsum(TH1 *h)
sum the bin contents including the over and underflow bins
Definition chains.cxx:101
Header file for AthHistogramAlgorithm.
static void TGCLV1HistogramDivision(const std::string &inFilename)
static int getTGCNumberOfWires(const int istationName, const int layer, const int istationEta, const int istationPhi)
static void TGCPostProcess(const std::string &inFilename, bool isIncremental=false)
static bool TGCCheckHistogram(TFile *f, const std::string &hname)
static void TGCsubsectbin2stationeta(int subsect, int bin, int &station, int &eta)
static void TGCChannelOccupancy(const std::string &inFilename, std::vector< std::pair< std::string, float > > &p)
static void TGCChamberOccupancy(const std::string &inFilename, std::vector< std::pair< std::string, float > > &phigh, std::vector< std::pair< std::string, float > > &plow)
static void TGCChamberTiming(const std::string &inFilename, std::vector< std::pair< std::string, float > > &pro, std::vector< std::pair< std::string, float > > &ptrg)
static void TGCsubsect2sectorphi(int subsect, int &sector, int &phi4)
static void TGCChamberEfficiency(const std::string &inFilename, std::vector< std::pair< std::string, float > > &p)
static void TGCRawHistogramDivision(const std::string &inFilename)
static int nTGCWireStripMap(int ws, int etac, int phi48)
static const float TGCChamberHighOccupancyCut
static const bool tgc_debug
static const float TGCChamberTimingCut
static const float TGCChannelOccupancyCut
static const float TGCChamberEfficiencyCut
static const float TGCChamberLowOccupancyCut