ATLAS Offline Software
MonitoringFile_MDTvsTGCPostProcess.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 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 
35 namespace dqutils {
36  void
37  MonitoringFile::MDTvsTGCPostProcess(const std::string& inFilename, bool /* isIncremental */) {
38  //start postprocessing
39  MDTvsTGCEfficiency(inFilename);
40  }
41 
42  void
43  MonitoringFile::MDTvsTGCEfficiency(const std::string& inFilename) {
44  PostProcessorFileWrapper mf(inFilename, "MDTvsTGC Efficiency");
45 
46  if (!mf.IsOpen()) {
47  //std::cerr << "MDTvsTGCEfficiency(): "
48  // << "Input file not opened \n";
49  return;
50  }
51  if (mf.GetSize() < 1000.) {
52  //std::cerr << "MDTvsTGCEfficiency(): "
53  // << "Input file empty \n";
54  return;
55  }
56 
57  std::stringstream ss;
58  TString sac[2] = {
59  "A", "C"
60  };
61  TString sws[2] = {
62  "Wire", "Strip"
63  };
64  TString smethod[3] = {
65  "SegmTrack", "MidOnly", ""
66  };
67 
68  TIter next_run(mf.GetListOfKeys());
69  TKey* key_run(0);
70  while ((key_run = dynamic_cast<TKey*> (next_run())) != 0) {
71  if (!key_run->IsFolder()) continue;
72  TString run_dir = key_run->GetName();
73  if (!run_dir.Contains("run")) continue;
74 
75  TString seff;
76  TString snum;
77  TString sden;
78  TString serr;
79 
80  TH2F* h2eff(0);
81  TH2F* h2num(0);
82  TH2F* h2den(0);
83  TH2F* h2err(0);
84 
85  TString mdtvstgc_dir = run_dir + "/Muon/MuonRawDataMonitoring/MDTvsTGC/";
86 
87  TString mdtvstgc_sub_dir[2] = {
88  mdtvstgc_dir + "TGCEA/", mdtvstgc_dir + "TGCEC/"
89  };
90 
91  if (mf.cd(mdtvstgc_dir)) mf.cd(mdtvstgc_dir);
92  else {
93  //std::cerr << "No MDTvsTGC Directory! " << std::endl; mf.error();
94  return;
95  }
96 
97  for (int ac = 0; ac < 2; ac++) {
98  TString eff_dir = mdtvstgc_sub_dir[ac];
99  TDirectory* dir = mf.GetDirectory(eff_dir);
100  if (!dir) {
101  //std::cerr<< "TGCHistogramDivision: directory "<<eff_dir<<" not found"<<std::endl;
102  return;
103  }
104 
105  for (int ws = 0; ws < 2; ws++) {
106  // Merge SegmTrack and Midstation-only method results together to make total histograms
107  bool oktomerge = true;
108 
109  TList* nummergelist = new TList();
110  for (int imethod = 0; imethod < 2; imethod++) {
111  ss << sws[ws] << "_EfficiencyAgainstMDT_Map" << smethod[imethod] << "num_" << sac[ac];
112  snum = ss.str();
113  ss.str("");
114  h2num = 0;
115  mf.get(snum, h2num, dir);
116  if (!h2num) {
117  //std::cerr <<"MDTvsTGC PostProcessing: no such histogram!! "<< snum << std::endl;
118  oktomerge = false;
119  }
120  nummergelist->Add(h2num);
121  }
122  ss << sws[ws] << "_EfficiencyAgainstMDT_Map" << smethod[2] << "num_" << sac[ac];
123  snum = ss.str();
124  ss.str("");
125  h2num = 0;
126  mf.get(snum, h2num, dir);
127  if (!h2num) {
128  //std::cerr <<"MDTvsTGC PostProcessing: no such histogram!! "<< snum << std::endl;
129  oktomerge = false;
130  }
131 
132  TList* denmergelist = new TList();
133  for (int imethod = 0; imethod < 2; imethod++) {
134  ss << sws[ws] << "_EfficiencyAgainstMDT_Map" << smethod[imethod] << "denom_" << sac[ac];
135  sden = ss.str();
136  ss.str("");
137  h2den = 0;
138  mf.get(sden, h2den, dir);
139  if (!h2den) {
140  //std::cerr <<"MDTvsTGC PostProcessing: no such histogram!! "<< sden << std::endl;
141  oktomerge = false;
142  }
143  denmergelist->Add(h2den);
144  }
145  ss << sws[ws] << "_EfficiencyAgainstMDT_Map" << smethod[2] << "denom_" << sac[ac];
146  sden = ss.str();
147  ss.str("");
148  h2den = 0;
149  mf.get(sden, h2den, dir);
150  if (!h2den) {
151  //std::cerr <<"MDTvsTGC PostProcessing: no such histogram!! "<< sden << std::endl;
152  oktomerge = false;
153  }
154 
155  if (oktomerge) {
156  MDTvsTGCResetContents(h2num);
157  MDTvsTGCResetContents(h2den);
158  h2num->Merge(nummergelist);
159  h2den->Merge(denmergelist);
160 
161  dir->cd();
162  h2num->Write("", TObject::kOverwrite);
163  h2den->Write("", TObject::kOverwrite);
164  }
165 
166  // Postprocess all methods
167  for (int imethod = 0; imethod < 3; imethod++) {
168  ss.str("");
169  ss << sws[ws] << "_EfficiencyAgainstMDT_Map" << smethod[imethod] << "_" << sac[ac];
170  seff = ss.str();
171  ss.str("");
172  ss << sws[ws] << "_EfficiencyAgainstMDT_Map" << smethod[imethod] << "num_" << sac[ac];
173  snum = ss.str();
174  ss.str("");
175  ss << sws[ws] << "_EfficiencyAgainstMDT_Map" << smethod[imethod] << "denom_" << sac[ac];
176  sden = ss.str();
177  ss.str("");
178  ss << sws[ws] << "_EfficiencyAgainstMDT_Map" << smethod[imethod] << "error_" << sac[ac];
179  serr = ss.str();
180  ss.str("");
181 
182  h2eff = 0;
183  mf.get(seff, h2eff, dir);
184  h2num = 0;
185  mf.get(snum, h2num, dir);
186  h2den = 0;
187  mf.get(sden, h2den, dir);
188  h2err = 0;
189  mf.get(serr, h2err, dir);
190 
191  if (h2eff && h2num && h2den) {
192  MDTvsTGCResetContents(h2eff);
193  h2eff->Divide(h2num, h2den, 1., 1., "B");
194 
195  // Make Error Histograms
196  int nX = h2eff->GetNbinsX();
197  int nY = h2eff->GetNbinsY();
198  int beff, bdenom, berror;
199  float feff, fdenom, ferror;
200  for (int x = 1; x <= nX; x++) {
201  for (int y = 1; y <= nY; y++) {
202  beff = h2eff->GetBin(x, y);
203  bdenom = h2den->GetBin(x, y);
204  feff = h2eff->GetBinContent(beff);
205  fdenom = h2den->GetBinContent(bdenom);
206  ferror = sqrt(feff * (1 - feff) / fdenom);
207 
208  if (h2err) {
209  berror = h2err->GetBin(x, y);
210  h2err->SetBinContent(berror, ferror);
211  }
212  h2eff->SetBinError(beff, ferror);
213  }
214  }
215  } else {
216  //std::cerr <<"TGC PostProcessing: no such histogram (or num/denom)!! "<< seff << std::endl;
217  continue;
218  }
219  // save histograms
220  dir->cd();
221  h2eff->Write("", TObject::kOverwrite);
222  if (h2err) h2err->Write("", TObject::kOverwrite);
223  }// method
224  }// wirestrip
225  mf.Write();
226  }// ac
227  }// run_dir
228  mf.Write();
229  }
230 
231  void
233  // copy all functions of histogram before resetting
234  TList* h_funcs;
235 
236  h_funcs = dynamic_cast<TList*> (h->GetListOfFunctions()->Clone());
237  h->Reset();
238  //now insert these functions back into the hist
239  TIter iterE(h_funcs);
240  while ((iterE())) {
241  h->GetListOfFunctions()->Add(*iterE);
242  }
243  delete h_funcs;
244  // are the functions still valid after list deletion?
245  //http://root.cern.ch/root/html/TList#TList:_TList should be!
246  // TIter iterTest(EffBCap->GetListOfFunctions());
247  // while( iterTest() ) std::cout << (*iterTest)->GetName() << std::endl;
248  }
249 }
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
dqutils::MonitoringFile::MDTvsTGCPostProcess
static void MDTvsTGCPostProcess(const std::string &inFilename, bool isIncremental=false)
Definition: MonitoringFile_MDTvsTGCPostProcess.cxx:37
dqutils::MonitoringFile::MDTvsTGCEfficiency
static void MDTvsTGCEfficiency(const std::string &inFilename)
Definition: MonitoringFile_MDTvsTGCPostProcess.cxx:43
python.TrigEgammaMonitorHelper.TH2F
def TH2F(name, title, nxbins, bins_par2, bins_par3, bins_par4, bins_par5=None, bins_par6=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:45
x
#define x
DQPostProcessTest.mf
mf
Definition: DQPostProcessTest.py:19
dqutils::MonitoringFile::PostProcessorFileWrapper
Definition: MonitoringFile.h:213
dqutils
Definition: CoolMdt.h:76
dqutils::MonitoringFile::MDTvsTGCResetContents
static void MDTvsTGCResetContents(TH1 *h)
Definition: MonitoringFile_MDTvsTGCPostProcess.cxx:232
beamspotman.dir
string dir
Definition: beamspotman.py:623
CoolTgc.h
MonitoringFile.h
y
#define y
h