ATLAS Offline Software
Loading...
Searching...
No Matches
MonitoringFile_PixelPostProcess.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 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 std::string run_dir;
69 static constexpr int nlayer = 8;
70 static const std::string layerName[nlayer] = {
71 "IBL", "B0", "B1", "B2", "ECA", "ECC", "IBL2D", "IBL3D"
72 };
73 static const float npixel[nlayer] = {
74 26880, 46080, 46080, 46080, 46080, 46080, 26880, 26880
75 };
76 static const float nmodule[nlayer] = {
77 280., 286., 494., 676., 144., 144., 168., 112.
78 };
79
80 int times = 1;
81 while (times--) { // just once
82 run_dir = dir0->GetName();
83
84 std::string rno_dir = run_dir + "/Pixel/Hits/";
85 TDirectory* dir = infile->GetDirectory(rno_dir.c_str());
86 if (!dir) {
87 std::cerr << "--> PixelPostProcess: directory " << rno_dir << " not found " << std::endl;
88 return;
89 }
90
91 std::string clus_dir = run_dir + "/Pixel/Clusters/";
92 TDirectory* clusdir = infile->GetDirectory(clus_dir.c_str());
93 if (!clusdir) {
94 std::cerr << "--> PixelPostProcess: directory " << clus_dir << " not found " << std::endl;
95 return;
96 }
97
98 std::string err_dir = run_dir + "/Pixel/Errors/";
99 TDirectory* errdir = infile->GetDirectory(err_dir.c_str());
100 if (!errdir) {
101 std::cerr << "--> PixelPostProcess: directory " << err_dir << " not found " << std::endl;
102 return;
103 }
104
105 std::string status_dir = run_dir + "/Pixel/Status/";
106 TDirectory* statusdir = infile->GetDirectory(status_dir.c_str());
107 if (!statusdir) {
108 std::cerr << "--> PixelPostProcess: directory " << status_dir << " not found " << std::endl;
109 return;
110 }
111
112 std::string norm_histName = rno_dir + "num_hits";
113 TH1F* h_norm = (TH1F*) infile->Get(norm_histName.c_str());
114 if (!h_norm) {
115 std::cerr << "--> PixelPostProcess: could not find normalisation histogram " << norm_histName << std::endl;
116 return;
117 }
118
119
120 float nevents = h_norm->Integral(0, h_norm->GetNbinsX() + 1);
121
122
123 const static int nerror = 5;
124 //std::string errorName[nerror] = {"OpticalErrors_", "SEUErrors_", "SyncErrors_", "TimeoutErrors_", "TruncErrors_"};
125 std::string errorName[nerror] = {
126 "OpticalErrors_", "SEUErrors_", "SyncErrors_", "TimeoutErrors_", "TruncErrors_"
127 };
128
129 TH2F* h_occ[nlayer];
130 TH2F* h_occ_new[nlayer];
131 TH2F* h_clus[nlayer];
132 TH2F* h_clus_new[nlayer];
133 TH2F* h_err[nlayer][nerror];
134 TH2F* h_err_new[nlayer][nerror];
135 TH1F* h_disabled_per_lumi[nlayer];
136 TH1F* h_syncerr_per_lumi[nlayer];
137 TH1F* h_disabled_syncerr_per_lumi[nlayer];
138
139 for (int i = 0; i < nlayer; i++) {
141 h_occ[i] = 0;
142 h_occ_new[i] = 0;
143 h_clus[i] = 0;
144 h_clus_new[i] = 0;
145 h_disabled_per_lumi[i] = 0;
146 h_syncerr_per_lumi[i] = 0;
147 h_disabled_syncerr_per_lumi[i] = 0;
148
150
152 std::string keyname = "Occupancy_";
153 std::string histName = rno_dir + keyname + layerName[i];
154 h_occ[i] = (TH2F*) infile->Get(histName.c_str());
156 if (h_occ[i]) {
157 std::string tmpname = keyname + layerName[i] + "_byPostProcess";
158 h_occ_new[i] = (TH2F*) h_occ[i]->Clone(tmpname.c_str());
159 h_occ_new[i]->Scale(1.0 / (nevents * npixel[i]));
160 }
162 dir->cd();
163 if (h_occ_new[i]) h_occ_new[i]->Write();
164
166
168 keyname = "Cluster_Occupancy_";
169 histName = clus_dir + keyname + layerName[i];
170 h_clus[i] = (TH2F*) infile->Get(histName.c_str());
172 if (h_clus[i]) {
173 std::string tmpname = keyname + layerName[i] + "_byPostProcess";
174 h_clus_new[i] = (TH2F*) h_clus[i]->Clone(tmpname.c_str());
175 h_clus_new[i]->Scale(1.0 / nevents);
176 }
177 clusdir->cd();
178 if (h_clus_new[i]) h_clus_new[i]->Write();
179
181
182 for (int j = 0; j < nerror; j++) {
184 h_err[i][j] = 0;
185 h_err_new[i][j] = 0;
187 keyname = errorName[j];
188 histName = err_dir + keyname + layerName[i];
189 h_err[i][j] = (TH2F*) infile->Get(histName.c_str());
191 if (h_err[i][j]) {
192 std::string tmpname = keyname + layerName[i] + "_byPostProcess";
193 h_err_new[i][j] = (TH2F*) h_err[i][j]->Clone(tmpname.c_str());
194 h_err_new[i][j]->Scale(1.0 / nevents);
195 }
197 errdir->cd();
198 if (h_err_new[i][j]) h_err_new[i][j]->Write();
199 }
200
202 keyname = "SyncErrorsFrac_per_event_";
203 histName = err_dir + keyname + layerName[i];
204 h_syncerr_per_lumi[i] = (TH1F*) infile->Get(histName.c_str());
205 keyname = "DisabledModules_per_lumi_";
206 histName = status_dir + keyname + layerName[i];
207 h_disabled_per_lumi[i] = (TH1F*) infile->Get(histName.c_str());
209 if (h_disabled_per_lumi[i] && h_syncerr_per_lumi[i]) {
210 keyname = "DisabledAndSyncErrorsModules_per_lumi_";
211 std::string tmpname = keyname + layerName[i] + "_byPostProcess";
212 h_disabled_syncerr_per_lumi[i] = new TH1F(tmpname.c_str(),
213 "Disable and Sync error per module per event;Lumi block;Avg. fraction per event", 2500, 0,
214 2500);
215 //h_disabled_syncerr_per_lumi[i]->Scale( 1.0/nmodule[i] );
216 for (int ibin = 0; ibin < 2500 + 1; ibin++) {
217 Double_t cont1 = h_disabled_per_lumi[i]->GetBinContent(ibin) / nmodule[i];
218 Double_t err1 = h_disabled_per_lumi[i]->GetBinError(ibin) / nmodule[i];
219 Double_t cont2 = h_syncerr_per_lumi[i]->GetBinContent(ibin);
220 Double_t err2 = h_syncerr_per_lumi[i]->GetBinError(ibin);
221 h_disabled_syncerr_per_lumi[i]->SetBinContent(ibin, cont1 + cont2);
222 h_disabled_syncerr_per_lumi[i]->SetBinError(ibin, err1 + err2);
223 }
224 }
225 errdir->cd();
226 if (h_disabled_syncerr_per_lumi[i]) h_disabled_syncerr_per_lumi[i]->Write();
227 }
228
229
230 infile->Write();
231 }//while
232 }
233}//namespace
static void PixelPostProcess(const std::string &inFilename, bool isIncremental=false)
static const bool rno_debug