ATLAS Offline Software
Loading...
Searching...
No Matches
MonitoringFile_HLTMinBiasMonPostProcess.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// **********************************************************************
6// HLT MinBias post processing jobs
7// 09/06/2015: update by Andrzej Zemla <azemla@cern.ch>
8// **********************************************************************
9
11
12#include <cmath>
13#include <vector>
14
15#include <TF1.h>
16#include <TFile.h>
17#include <TH1.h>
18#include <TKey.h>
19#include <TMath.h>
20#include <TROOT.h>
21#include <TCanvas.h>
22
23namespace dqutils {
24 //--------------------------------------------------------------------------------
25 // main process
26 //--------------------------------------------------------------------------------
27 void MonitoringFile::HLTMinBiasMonPostProcess(const std::string& inFilename, bool /* isIncremental */) {
28 // std::cout << "--> HLTMinBiasMonPostProcess: Begin HLT MinBias post-processing" << std::endl;
29
30 //open root file
31 TFile* f = TFile::Open(inFilename.c_str(), "READ");
32
33 //check files are loaded.
34 if (f == 0 || !f->IsOpen()) {
35 // std::cerr << "--> HLTMinBiasMonPostProcess: Input file not opened" << std::endl;
36 delete f;
37 return;
38 }
39
40 //zombie files?
41 if (f->IsZombie()) {
42 // std::cerr << "--> HLTMinBiasMonPostProcess: Input file " << inFilename << " cannot be opened. " <<
43 // std::endl;
44 delete f;
45 return;
46 }
47
48 //check file size is not too small.
49 if (f->GetSize() < 1000.) {
50 // std::cerr << "--> HLTMinBiasMonPostProcess: Input file empty" << std::endl;
51 f->Close();
52 delete f;
53 return;
54 }
55 //build iterator
56 TIter next_run(f->GetListOfKeys());
57 TKey* key_run(0);
58 std::string minbiasmonDirName;
59
60 std::vector< std::pair<std::string, std::string> >* v_targetNames = new std::vector< std::pair<std::string, std::string> >(0);
61
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 // 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 //find MinBiasMon dir
84 minbiasmonDirName = runDirName + "/HLT/MinBiasMon";
85 TDirectory* minbiasmonDir(0);
86 if (!(minbiasmonDir = f->GetDirectory(minbiasmonDirName.c_str()))) {
87// std::cerr << "--> HLTMinBiasMonPostProcess: directory " << minbiasmonDirName << " not found." << std::endl;
88 delete v_targetNames;
89 return;
90 }
91 HLTMinBiasMonGetTargetHistos(gDirectory, *v_targetNames);
92 }
93
94 f->Close();
95 f = 0;
96
97 f = TFile::Open(inFilename.c_str(), "UPDATE");
98
99 const std::string repPath = std::string(f->GetPath());
100
101 //first update global efficiency
102 f->cd(minbiasmonDirName.c_str());
103
104 TH1F* h_triggEffic = dynamic_cast<TH1F*>(gDirectory->Get("TriggerEfficiencies"));
105 TH1F* h_triggEfficPass = dynamic_cast<TH1F*>(gDirectory->Get("TriggerEfficienciesPassed"));
106 TH1F* h_triggEfficAll = dynamic_cast<TH1F*>(gDirectory->Get("TriggerEfficienciesAll"));
107 if (!h_triggEffic or !h_triggEfficPass or !h_triggEfficAll) {
108 std::cerr << "Dynamic cast failed in MonitoringFile::HLTMinBiasMonPostProcess\n";
109 f->Close();
110 delete f;
111 delete v_targetNames;
112 return;
113 }
114
115 h_triggEffic->Divide(h_triggEfficPass, h_triggEfficAll, 1., 1., "B");
116 h_triggEffic->GetYaxis()->SetRangeUser(0., 1.2);
117 h_triggEffic->Write("", TObject::kOverwrite);
118
119 for (uint k = 0; k < v_targetNames->size(); k++) {
120 TString stmp = v_targetNames->at(k).first;
121 stmp.ReplaceAll(repPath, "");
122 v_targetNames->at(k).first = stmp.Data();
123
124 f->cd(v_targetNames->at(k).first.c_str());
125
126 TH1F* h_target = dynamic_cast<TH1F*>(gDirectory->Get(v_targetNames->at(k).second.c_str()));
127 TH1F* h_num = dynamic_cast<TH1F*>(gDirectory->Get((v_targetNames->at(k).second + "Passed").c_str()));
128 TH1F* h_den = dynamic_cast<TH1F*>(gDirectory->Get((v_targetNames->at(k).second + "All").c_str()));
129
130 if (h_target != 0 && h_num != 0 && h_den != 0) {
131 h_target->Divide(h_num, h_den, 1., 1., "B");
132 h_target->GetYaxis()->SetRangeUser(0., 1.2);
133 h_target->Write("", TObject::kOverwrite);
134 }
135 }
136 v_targetNames->clear();
137 delete v_targetNames;
138 v_targetNames = 0;
139
140 f->Close();
141 delete f;
142 }
143
144 void MonitoringFile::HLTMinBiasMonGetTargetHistos(TDirectory* source, std::vector< std::pair< std::string,
145 std::string > >& targetNames)
146 {
147 TKey* key;
148 TIter nextkey(source->GetListOfKeys());
149
150 while ((key = (TKey*) nextkey())) {
151 const char* classname = key->GetClassName();
152 TClass* cl = gROOT->GetClass(classname);
153 if (!cl) continue;
154 if (cl->InheritsFrom(TDirectory::Class())) {
155 source->cd(key->GetName());
156 TDirectory* nextdir = gDirectory;
157 HLTMinBiasMonGetTargetHistos(nextdir, targetNames);
158 }
159 if (cl->InheritsFrom(TH1F::Class())) {
160 std::string cRatio = std::string(key->GetName());
161 if (cRatio == "Efficiency" ||
162 cRatio == "Purity" ||
163 cRatio == "EfficienciesTrigger" ||
164 cRatio == "EfficiencyTracks" ||
165 cRatio ==
166 "TriggerPurities") targetNames.push_back(std::pair<std::string, std::string>(std::string(gDirectory->GetPath()),
167 std::string(key->GetName())));
168 }
169 }
170 }
171}
unsigned int uint
static void HLTMinBiasMonGetTargetHistos(TDirectory *source, std::vector< std::pair< std::string, std::string > > &targetNames)
static void HLTMinBiasMonPostProcess(const std::string &inFileName, bool isIncremental=false)