ATLAS Offline Software
Loading...
Searching...
No Matches
MonitoringFile_PixelPostProcess.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 Pixel histograms after merging.
7//Author: Masaki ENDO (masaki.endo@cern.ch)
8//Date: Aug 2012
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 "TProfile.h"
28#include "TFile.h"
29#include "TClass.h"
30#include "TKey.h"
31#include "TMath.h"
32#include "TF1.h"
33#include "TTree.h"
34#include "TBranch.h"
35
36
37namespace dqutils {
38 static const bool rno_debug = false;
39
40 void
41 MonitoringFile::PixelPostProcess(const std::string& inFilename, bool /* isIncremental */) {
42 if (rno_debug) std::cout << "Start Pixel post-processing" << std::endl;
43
44 TFile* infile = TFile::Open(inFilename.c_str(), "UPDATE");
45 if (infile == 0 || !infile->IsOpen()) {
46 std::cerr << "--> PixelPostProcess: Input file not opened" << std::endl;
47 return;
48 }
49 if (infile->IsZombie()) {
50 std::cerr << "--> PixelPostProcess: Input file " << inFilename << " cannot be opened" << std::endl;
51 return;
52 }
53 if (infile->GetSize() < 1000) {
54 std::cerr << "--> PixelPostProcess: Input file empty " << std::endl;
55 return;
56 }
57
58 //start postprocessing
59
60 TIter next_run(infile->GetListOfKeys());
61 TKey* key_run(0);
62 key_run = (TKey*) next_run();
63 TDirectory* dir0 = dynamic_cast<TDirectory*> (key_run->ReadObj());
64 if (!dir0) return; // should never fail
65
66 dir0->cd();
67
68 TString run_dir;
69 int times = 1;
70 while (times--) { // just once
71 run_dir = dir0->GetName();
72
73 TString rno_dir = run_dir + "/Pixel/Hits/";
74 TDirectory* dir = infile->GetDirectory(rno_dir);
75 if (!dir) {
76 std::cerr << "--> PixelPostProcess: directory " << rno_dir << " not found " << std::endl;
77 return;
78 }
79
80 TString clus_dir = run_dir + "/Pixel/Clusters/";
81 TDirectory* clusdir = infile->GetDirectory(clus_dir);
82 if (!clusdir) {
83 std::cerr << "--> PixelPostProcess: directory " << clus_dir << " not found " << std::endl;
84 return;
85 }
86
87 TString err_dir = run_dir + "/Pixel/Errors/";
88 TDirectory* errdir = infile->GetDirectory(err_dir);
89 if (!errdir) {
90 std::cerr << "--> PixelPostProcess: directory " << err_dir << " not found " << std::endl;
91 return;
92 }
93
94 TString status_dir = run_dir + "/Pixel/Status/";
95 TDirectory* statusdir = infile->GetDirectory(status_dir);
96 if (!statusdir) {
97 std::cerr << "--> PixelPostProcess: directory " << status_dir << " not found " << std::endl;
98 return;
99 }
100
101 TString norm_histName = rno_dir + "num_hits";
102 TH1F* h_norm = (TH1F*) infile->Get(norm_histName);
103 if (!h_norm) {
104 std::cerr << "--> PixelPostProcess: could not find normalisation histogram " << norm_histName << std::endl;
105 return;
106 }
107
108 const static int nlayer = 8;
109 float nevents = h_norm->Integral(0, h_norm->GetNbinsX() + 1);
110 TString layerName[nlayer] = {
111 "IBL", "B0", "B1", "B2", "ECA", "ECC", "IBL2D", "IBL3D"
112 };
113 float npixel[nlayer] = {
114 26880, 46080, 46080, 46080, 46080, 46080, 26880, 26880
115 };
116 float nmodule[nlayer] = {
117 280., 286., 494., 676., 144., 144., 168., 112.
118 };
119
120 const static int nerror = 5;
121 //TString errorName[nerror] = {"OpticalErrors_", "SEUErrors_", "SyncErrors_", "TimeoutErrors_", "TruncErrors_"};
122 TString errorName[nerror] = {
123 "OpticalErrors_", "SEUErrors_", "SyncErrors_", "TimeoutErrors_", "TruncErrors_"
124 };
125
126 TH2F* h_occ[nlayer];
127 TH2F* h_occ_new[nlayer];
128 TH2F* h_clus[nlayer];
129 TH2F* h_clus_new[nlayer];
130 TH2F* h_err[nlayer][nerror];
131 TH2F* h_err_new[nlayer][nerror];
132 TH1F* h_disabled_per_lumi[nlayer];
133 TH1F* h_syncerr_per_lumi[nlayer];
134 TH1F* h_disabled_syncerr_per_lumi[nlayer];
135
136 for (int i = 0; i < nlayer; i++) {
138 h_occ[i] = 0;
139 h_occ_new[i] = 0;
140 h_clus[i] = 0;
141 h_clus_new[i] = 0;
142 h_disabled_per_lumi[i] = 0;
143 h_syncerr_per_lumi[i] = 0;
144 h_disabled_syncerr_per_lumi[i] = 0;
145
147
149 TString keyname = "Occupancy_";
150 TString histName = rno_dir + keyname + layerName[i];
151 h_occ[i] = (TH2F*) infile->Get(histName);
153 if (h_occ[i]) {
154 TString tmpname = keyname + layerName[i] + "_byPostProcess";
155 h_occ_new[i] = (TH2F*) h_occ[i]->Clone(tmpname);
156 h_occ_new[i]->Scale(1.0 / (nevents * npixel[i]));
157 }
159 dir->cd();
160 if (h_occ_new[i]) h_occ_new[i]->Write();
161
163
165 keyname = "Cluster_Occupancy_";
166 histName = clus_dir + keyname + layerName[i];
167 h_clus[i] = (TH2F*) infile->Get(histName);
169 if (h_clus[i]) {
170 TString tmpname = keyname + layerName[i] + "_byPostProcess";
171 h_clus_new[i] = (TH2F*) h_clus[i]->Clone(tmpname);
172 h_clus_new[i]->Scale(1.0 / nevents);
173 }
174 clusdir->cd();
175 if (h_clus_new[i]) h_clus_new[i]->Write();
176
178
179 for (int j = 0; j < nerror; j++) {
181 h_err[i][j] = 0;
182 h_err_new[i][j] = 0;
184 keyname = errorName[j];
185 histName = err_dir + keyname + layerName[i];
186 h_err[i][j] = (TH2F*) infile->Get(histName);
188 if (h_err[i][j]) {
189 TString tmpname = keyname + layerName[i] + "_byPostProcess";
190 h_err_new[i][j] = (TH2F*) h_err[i][j]->Clone(tmpname);
191 h_err_new[i][j]->Scale(1.0 / nevents);
192 }
194 errdir->cd();
195 if (h_err_new[i][j]) h_err_new[i][j]->Write();
196 }
197
199 keyname = "SyncErrorsFrac_per_event_";
200 histName = err_dir + keyname + layerName[i];
201 h_syncerr_per_lumi[i] = (TH1F*) infile->Get(histName);
202 keyname = "DisabledModules_per_lumi_";
203 histName = status_dir + keyname + layerName[i];
204 h_disabled_per_lumi[i] = (TH1F*) infile->Get(histName);
206 if (h_disabled_per_lumi[i] && h_syncerr_per_lumi[i]) {
207 keyname = "DisabledAndSyncErrorsModules_per_lumi_";
208 TString tmpname = keyname + layerName[i] + "_byPostProcess";
209 h_disabled_syncerr_per_lumi[i] = new TH1F(tmpname,
210 "Disable and Sync error per module per event;Lumi block;Avg. fraction per event", 2500, 0,
211 2500);
212 //h_disabled_syncerr_per_lumi[i]->Scale( 1.0/nmodule[i] );
213 for (int ibin = 0; ibin < 2500 + 1; ibin++) {
214 Double_t cont1 = h_disabled_per_lumi[i]->GetBinContent(ibin) / nmodule[i];
215 Double_t err1 = h_disabled_per_lumi[i]->GetBinError(ibin) / nmodule[i];
216 Double_t cont2 = h_syncerr_per_lumi[i]->GetBinContent(ibin);
217 Double_t err2 = h_syncerr_per_lumi[i]->GetBinError(ibin);
218 h_disabled_syncerr_per_lumi[i]->SetBinContent(ibin, cont1 + cont2);
219 h_disabled_syncerr_per_lumi[i]->SetBinError(ibin, err1 + err2);
220 }
221 }
222 errdir->cd();
223 if (h_disabled_syncerr_per_lumi[i]) h_disabled_syncerr_per_lumi[i]->Write();
224 }
225
226
227 infile->Write();
228 }//while
229 }
230}//namespace
static void PixelPostProcess(const std::string &inFilename, bool isIncremental=false)
static const bool rno_debug