ATLAS Offline Software
MonitoringFile_BJetTaggingAdjustRanges.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3  */
4 
5 /* Methods to perform post-processing on run_nnnnnn/HLT/JetMon* histograms
6  * Mainly to adjust the impact parameter ranges according to the recorded lumi blocks.
7  *
8  *
9  *
10  * Based on the HLTJetCalcEfficiencyAndRate code of Venkatesh Kaushik (venkat.kaushik@cern.ch).
11  *
12  * Author : Manuel Neumann (mneumann@cern.ch)
13  * Date : Aug 2011
14  */
15 
17 
18 #include <vector>
19 
20 #include "TH1F.h"
21 #include "TFile.h"
22 #include "TKey.h"
23 
24 namespace dqutils
25 {
26  void
29 
30  if (debugLevel > 1) {
31  std::cout << "--> BJetTaggingAdjustRanges: Adjusting ranges of d0, z0 and d0Sig, z0Sig"
32  << std::endl;
33  }
34  f->cd("/");
35  // get run directory name
36  TIter nextcd0(gDirectory->GetListOfKeys());
37  TKey* key0 = (TKey*) nextcd0();
38  TDirectory* dir0 = dynamic_cast<TDirectory*> (key0->ReadObj());
39 
40  if (dir0 != 0) {
41  dir0->cd();
42 
43  TIter next_run(f->GetListOfKeys());
44  TKey* key_run(0);
45 
46  // loop through runs in the file
47  while ((key_run = dynamic_cast<TKey*> (next_run())) != 0) {
48  if (debugLevel > 1) {
49  std::cout << "--> BJetTaggingAdjustRanges: Getting run " << key_run << std::endl;
50  }
51  TObject* obj_run = key_run->ReadObj();
52  TDirectory* tdir_run = dynamic_cast<TDirectory*> (obj_run);
53 
54  // Some checks of the run number
55  if (tdir_run != 0) {
56  //if (debugLevel > 0) {
57  // std::cerr << "--> BJetTaggingAdjustRanges: directory " << tdir_run
58  // << " not found." << std::endl;
59  //}
60  //continue;
61  //delete obj_run;
62 
63  TString run_dir = tdir_run->GetName();
64  if (!run_dir.Contains("run")) {
65  std::cerr << "--> BJetTaggingAdjustRanges: no run found" << std::endl;
66  return;
67  //delete obj_run;
68  }
69 
70  if (debugLevel > 1) {
71  std::cout << "--> BJetTaggingAdjustRanges: Getting run no. " << run_dir
72  << std::endl;
73  }
74 
75  // Setting the branch for the impact parameters
76  TString jetmon_dir = run_dir + "/JetTagging";
77 
78  TDirectory* dir(0);
79  //std::cout << "--> BJetTaggingAdjustRanges: directory " << diag_dir
80  // << std::endl;
81 
82  if (!(dir = f->GetDirectory(jetmon_dir))) {
83  if (debugLevel > 0) std::cerr << "--> BJetTaggingAdjustRanges: directory " << jetmon_dir
84  << " not found." << std::endl;
85  return;
86  }
87  // std::cout << "--> BJetTaggingAdjustRanges: Setting d0,z0,d0Sig,z0Sig vectors" << std::endl;
88  std::vector < TString > impactParameters;
89  impactParameters.push_back("d0Sig");
90  impactParameters.push_back("z0Sig");
91 
92  impactParameters.push_back("d0");
93  impactParameters.push_back("z0");
94 
95  std::vector < TString > etaAndPtRanges;
96  etaAndPtRanges.push_back("_EtaRange_0_PtRange_0");
97  etaAndPtRanges.push_back("_EtaRange_0_PtRange_1");
98  etaAndPtRanges.push_back("_EtaRange_0_PtRange_2");
99  etaAndPtRanges.push_back("_EtaRange_1_PtRange_0");
100  etaAndPtRanges.push_back("_EtaRange_1_PtRange_1");
101  etaAndPtRanges.push_back("_EtaRange_1_PtRange_2");
102  etaAndPtRanges.push_back("_EtaRange_2_PtRange_0");
103  etaAndPtRanges.push_back("_EtaRange_2_PtRange_1");
104  etaAndPtRanges.push_back("_EtaRange_2_PtRange_2");
105  etaAndPtRanges.push_back("_EtaRange_3_PtRange_0");
106  etaAndPtRanges.push_back("_EtaRange_3_PtRange_1");
107  etaAndPtRanges.push_back("_EtaRange_3_PtRange_2");
108  etaAndPtRanges.push_back("_EtaRange_4_PtRange_0");
109  etaAndPtRanges.push_back("_EtaRange_4_PtRange_1");
110  etaAndPtRanges.push_back("_EtaRange_4_PtRange_2");
111 
112  TH1F* workingHistogram(0);
113 
114  TString impactParameterHistos, workingHistogramName;
115 
116  for (std::vector<TString>::iterator itT = impactParameters.begin(); itT
117  != impactParameters.end(); ++itT) {
118  for (std::vector<TString>::iterator itO = etaAndPtRanges.begin(); itO
119  != etaAndPtRanges.end(); ++itO) {
120  workingHistogramName = (*itT) + (*itO);
121  impactParameterHistos = jetmon_dir + "/" + workingHistogramName;
122 
123  workingHistogram = dynamic_cast<TH1F*> (f->Get(impactParameterHistos));
124  if (workingHistogram != 0) {
125  if (debugLevel > 1) {
126  //std::cout << "--> BJetTaggingAdjustRanges: Really doing this stuff" <<
127  // workingHistogramName<<std::endl;
128  }
129 
130  /*
131  * Here the bins are initialised and the upper and lower end from the histogram data
132  * are used as new borders of the updated histogram.
133  * */
134 
135  int minimalBin = 0;
136  int maximalBin = 0;
137 
138  minimalBin = workingHistogram->FindFirstBinAbove(0.0, 1);
139  maximalBin = workingHistogram->FindLastBinAbove(0.0, 1);
140 
141  workingHistogram->SetAxisRange(TMath::Max(1, (minimalBin - 5)),
142  (maximalBin + 5), "X");
143 
144  dir->cd();
145  workingHistogram->Write("", TObject::kOverwrite);
146  } else {
147  if (debugLevel > 0) {
148  std::cerr << "Histogram " << impactParameterHistos << " not found."
149  << std::endl;
150  }
151  }
152  } // for eta/Pt range
153  } // for TrigItems
154  if (debugLevel > 1) {
155  std::cout << "--> BJetTaggingAdjustRanges: Finished" << std::endl;
156  }
157  }
158  } // if tdir_run!=0
159  }//while
160  }//MonitoringFile::BJetTaggingAdjustRanges
161 }//namespace
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
python.CaloRecoConfig.f
f
Definition: CaloRecoConfig.py:127
dqutils::MonitoringFile::getDebugLevel
static int getDebugLevel()
ParseInputs.gDirectory
gDirectory
Definition: Final2012/ParseInputs.py:133
DQHistogramMerge.debugLevel
debugLevel
Definition: DQHistogramMerge.py:40
dqutils
Definition: CoolMdt.h:76
beamspotman.dir
string dir
Definition: beamspotman.py:623
MonitoringFile.h
TH1F
Definition: rootspy.cxx:320
dqutils::MonitoringFile::BJetTaggingAdjustRanges
static void BJetTaggingAdjustRanges(TFile *f)
Definition: MonitoringFile_BJetTaggingAdjustRanges.cxx:27