1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
|
#include "OOTMultiplicityPlotMacros.h"
#include "DPGAnalysis/SiStripTools/interface/CommonAnalyzer.h"
#include "TFile.h"
#include "TCanvas.h"
#include "TH1F.h"
#include "TF1.h"
#include "TProfile.h"
#include <iostream>
#include <algorithm>
#include <cmath>
OOTSummary* ComputeOOTFractionvsFill(TFile* ff,
const char* itmodule,
const char* ootmodule,
const char* etmodule,
const char* hname,
OOTSummary* ootsumm) {
if (ootsumm == nullptr) {
ootsumm = new OOTSummary;
}
if (ff) {
CommonAnalyzer ca(ff, "", itmodule);
std::vector<unsigned int> runs = ca.getFillList();
std::sort(runs.begin(), runs.end());
for (unsigned int i = 0; i < runs.size(); ++i) {
char runlabel[100];
sprintf(runlabel, "%d", runs[i]);
OOTResult* res = ComputeOOTFraction(ff, itmodule, ootmodule, etmodule, runs[i], hname, true);
if (res->ngoodbx != res->hratio->GetEntries())
std::cout << "Inconsistency in number of good bx" << std::endl;
ootsumm->hngoodbx->Fill(runlabel, res->ngoodbx);
int ibin = ootsumm->hootfracsum->Fill(runlabel, res->ootfracsum);
ootsumm->hootfracsum->SetBinError(ibin, res->ootfracsumerr);
int bin = ootsumm->hootfrac->Fill(runlabel, res->ootfrac);
ootsumm->hootfrac->SetBinError(bin, res->ootfracerr);
delete res;
}
} else {
std::cout << "File is not ok" << std::endl;
}
return ootsumm;
}
OOTSummary* ComputeOOTFractionvsRun(TFile* ff,
const char* itmodule,
const char* ootmodule,
const char* etmodule,
const char* hname,
OOTSummary* ootsumm) {
if (ootsumm == nullptr) {
ootsumm = new OOTSummary;
}
if (ff) {
CommonAnalyzer ca(ff, "", itmodule);
std::vector<unsigned int> runs = ca.getRunList();
std::sort(runs.begin(), runs.end());
for (unsigned int i = 0; i < runs.size(); ++i) {
char runlabel[100];
sprintf(runlabel, "%d", runs[i]);
OOTResult* res = ComputeOOTFraction(ff, itmodule, ootmodule, etmodule, runs[i], hname);
if (res->ngoodbx != res->hratio->GetEntries())
std::cout << "Inconsistency in number of good bx" << std::endl;
ootsumm->hngoodbx->Fill(runlabel, res->ngoodbx);
int ibin = ootsumm->hootfracsum->Fill(runlabel, res->ootfracsum);
ootsumm->hootfracsum->SetBinError(ibin, res->ootfracsumerr);
int bin = ootsumm->hootfrac->Fill(runlabel, res->ootfrac);
ootsumm->hootfrac->SetBinError(bin, res->ootfracerr);
delete res;
}
} else {
std::cout << "File is not ok" << std::endl;
}
return ootsumm;
}
OOTResult* ComputeOOTFraction(TFile* ff,
const char* itmodule,
const char* ootmodule,
const char* etmodule,
const int run,
const char* hname,
const bool& perFill) {
if (perFill) {
std::cout << "Processing fill " << run << std::endl;
} else {
std::cout << "Processing run " << run << std::endl;
}
char itpath[100];
char ootpath[100];
char etpath[100];
if (perFill) {
sprintf(itpath, "%s/fill_%d", itmodule, run);
sprintf(ootpath, "%s/fill_%d", ootmodule, run);
sprintf(etpath, "%s/fill_%d", etmodule, run);
} else {
sprintf(itpath, "%s/run_%d", itmodule, run);
sprintf(ootpath, "%s/run_%d", ootmodule, run);
sprintf(etpath, "%s/run_%d", etmodule, run);
}
OOTResult* res = new OOTResult;
std::vector<int> filledbx = FillingSchemeFromProfile(ff, itpath, hname);
res->nfilledbx = filledbx.size();
if (!perFill) {
std::vector<int> filledbxtest = FillingScheme(ff, etpath);
if (filledbx.size() != filledbxtest.size())
std::cout << "Inconsistency in number of filled BX " << run << " " << filledbx.size() << " "
<< filledbxtest.size() << std::endl;
}
TProfile* itmult = nullptr;
TProfile* ootmult = nullptr;
res->hratio = new TH1F("ratio", "ratio", 200, 0., 2.);
float rclzb = 0;
float rclrandom = 0;
float errclzb = 0;
float errclrandom = 0;
float nzb = 0;
float nrandom = 0;
if (ff) {
if (ff->cd(itpath)) {
itmult = (TProfile*)gDirectory->Get(hname);
} else {
std::cout << "In time path is not ok" << std::endl;
}
if (ff->cd(ootpath)) {
ootmult = (TProfile*)gDirectory->Get(hname);
} else {
std::cout << "out of time path is not ok" << std::endl;
}
if (itmult && ootmult) {
ootmult->SetLineColor(kRed);
ootmult->SetMarkerColor(kRed);
// ootmult->Draw();
// itmult->Draw("same");
for (std::vector<int>::const_iterator fbx = filledbx.begin(); fbx != filledbx.end(); ++fbx) {
nzb += itmult->GetBinEntries(*fbx);
nrandom += ootmult->GetBinEntries(*fbx + 1);
}
for (std::vector<int>::const_iterator fbx = filledbx.begin(); fbx != filledbx.end(); ++fbx) {
if (nzb > 0 && nrandom > 0) {
rclzb += (itmult->GetBinContent(*fbx) * itmult->GetBinEntries(*fbx)) / nzb;
errclzb += (itmult->GetBinError(*fbx) * itmult->GetBinEntries(*fbx)) *
(itmult->GetBinError(*fbx) * itmult->GetBinEntries(*fbx)) / (nzb * nzb);
rclrandom += (ootmult->GetBinContent(*fbx + 1) * ootmult->GetBinEntries(*fbx + 1)) / nrandom;
errclrandom += (ootmult->GetBinError(*fbx + 1) * ootmult->GetBinEntries(*fbx + 1)) *
(ootmult->GetBinError(*fbx + 1) * ootmult->GetBinEntries(*fbx + 1)) / (nrandom * nrandom);
}
if (itmult->GetBinContent(*fbx) == 0) {
std::cout << "No cluster in filled BX! " << *fbx << std::endl;
} else if (ootmult->GetBinEntries(*fbx + 1) ==
0) { /* std::cout << "No entry in OOT BX " << *fbx+1 << std::endl; */
} else {
float rat = ootmult->GetBinContent(*fbx + 1) / itmult->GetBinContent(*fbx);
res->hratio->Fill(rat);
}
}
} else {
std::cout << "histograms not found" << std::endl;
}
} else {
std::cout << "Input file pointer is not ok" << std::endl;
}
res->ngoodbx = res->hratio->GetEntries();
if (nzb > 0 && nrandom > 0 && rclzb > 0 && rclrandom > 0) {
res->ootfracsum = rclrandom / rclzb;
res->ootfracsumerr = rclrandom / rclzb * sqrt(errclzb / (rclzb * rclzb) + errclrandom / (rclrandom * rclrandom));
}
if (res->ngoodbx) {
res->hratio->Fit("gaus", "Q0", "", .01, 1.99);
if (res->hratio->GetFunction("gaus")) {
res->ootfrac = res->hratio->GetFunction("gaus")->GetParameter(1);
res->ootfracerr = res->hratio->GetFunction("gaus")->GetParError(1);
} else {
std::cout << "Missing fitting function" << std::endl;
}
} else {
std::cout << "No filled BX or strange filling scheme" << std::endl;
}
return res;
}
std::vector<int> FillingScheme(TFile* ff, const char* path, const float thr) {
TH1F* bx = nullptr;
std::vector<int> filledbx;
if (ff) {
if (ff->cd(path)) {
bx = (TH1F*)gDirectory->Get("bx");
if (bx) {
// bx->Draw();
std::cout << "Number of entries " << bx->GetEntries() << " threshold " << thr / 3564. * bx->GetEntries()
<< std::endl;
for (int i = 1; i < bx->GetNbinsX() + 1; ++i) {
if (bx->GetBinContent(i) > thr / 3564. * bx->GetEntries()) {
if (!filledbx.empty() && i == filledbx[filledbx.size() - 1] + 1) {
std::cout << "This is not a 50ns run ! " << std::endl;
filledbx.clear();
return filledbx;
}
filledbx.push_back(i);
}
}
} else {
std::cout << "Histogram not found" << std::endl;
}
} else {
std::cout << "module path is not ok" << std::endl;
}
} else {
std::cout << "Input file pointer is not ok" << std::endl;
}
// std::cout << filledbx.size() << " filled bunch crossings" << std::endl;
// for(std::vector<int>::const_iterator fbx=filledbx.begin();fbx!=filledbx.end();++fbx) { std::cout << *fbx << std::endl;}
return filledbx;
}
std::vector<int> FillingSchemeFromProfile(TFile* ff, const char* path, const char* hname, const float thr) {
TProfile* bx = nullptr;
std::vector<int> filledbx;
if (ff) {
if (ff->cd(path)) {
bx = (TProfile*)gDirectory->Get(hname);
if (bx) {
// bx->Draw();
std::cout << "Number of entries " << bx->GetEntries() << " threshold " << thr / 3564. * bx->GetEntries()
<< std::endl;
for (int i = 1; i < bx->GetNbinsX() + 1; ++i) {
if (bx->GetBinEntries(i) > thr / 3564. * bx->GetEntries()) {
if (!filledbx.empty() && i == filledbx[filledbx.size() - 1] + 1) {
std::cout << "This is not a 50ns run ! " << std::endl;
filledbx.clear();
return filledbx;
}
filledbx.push_back(i);
}
}
} else {
std::cout << "Histogram not found" << std::endl;
}
} else {
std::cout << "module path is not ok" << std::endl;
}
} else {
std::cout << "Input file pointer is not ok" << std::endl;
}
// std::cout << filledbx.size() << " filled bunch crossings" << std::endl;
// for(std::vector<int>::const_iterator fbx=filledbx.begin();fbx!=filledbx.end();++fbx) { std::cout << *fbx << std::endl;}
return filledbx;
}
|