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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
|
#include "StatisticsPlots.h"
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <iostream>
#include "TPad.h"
#include "TH1D.h"
#include "TFile.h"
#include "TH2F.h"
#include "TH1F.h"
#include "TText.h"
#include "DPGAnalysis/SiStripTools/interface/CommonAnalyzer.h"
#include "TCanvas.h"
#include "TGraphAsymmErrors.h"
void DeadTimeAPVCycle(TH1F* hist, const std::vector<int>& bins) {
float ntotodd = 0;
float ntoteven = 0;
float nspecialodd = 0;
float nspecialeven = 0;
unsigned int nbintotodd = 0;
unsigned int nbintoteven = 0;
unsigned int nbinspecialodd = 0;
unsigned int nbinspecialeven = 0;
for (int i = 1; i < hist->GetNbinsX() + 1; ++i) {
bool isSpecial = false;
for (unsigned int special = 0; special < bins.size(); ++special) {
if (i == bins[special]) {
isSpecial = true;
break;
}
}
if (i % 2 == 0) {
if (isSpecial) {
++nbinspecialeven;
nspecialeven += hist->GetBinContent(i);
} else {
++nbintoteven;
ntoteven += hist->GetBinContent(i);
}
} else {
if (isSpecial) {
++nbinspecialodd;
nspecialodd += hist->GetBinContent(i);
} else {
++nbintotodd;
ntotodd += hist->GetBinContent(i);
}
}
}
std::cout << "Summary" << std::endl;
std::cout << "Odd events " << ntotodd << " special " << nspecialodd << std::endl;
std::cout << "Odd bins " << nbintotodd << " special " << nbinspecialodd << std::endl;
std::cout << "Odd bins populations" << float(ntotodd) / nbintotodd << " special "
<< float(nspecialodd) / nbinspecialodd << std::endl;
std::cout << "Even events " << ntoteven << " special " << nspecialeven << std::endl;
std::cout << "Even bins " << nbintoteven << " special " << nbinspecialeven << std::endl;
std::cout << "Even bins populations" << float(ntoteven) / nbintoteven << " special "
<< float(nspecialeven) / nbinspecialeven << std::endl;
float oddloss = nspecialodd - nbinspecialodd * ntotodd / nbintotodd;
float evenloss = nspecialeven - nbinspecialeven * ntoteven / nbintoteven;
float fracloss = (oddloss + evenloss) / (ntotodd + ntoteven + nspecialodd + nspecialeven);
std::cout << "Loss " << oddloss << " " << evenloss << " " << fracloss << std::endl;
}
TH1F* CombinedHisto(TFile& ff, const char* module, const char* histname) {
CommonAnalyzer castat(&ff, "", module);
TH1F* result = nullptr;
std::vector<unsigned int> runs = castat.getRunList();
std::sort(runs.begin(), runs.end());
{
for (unsigned int i = 0; i < runs.size(); ++i) {
char runlabel[100];
sprintf(runlabel, "%d", runs[i]);
char runpath[100];
sprintf(runpath, "run_%d", runs[i]);
castat.setPath(runpath);
TH1F* hist = (TH1F*)castat.getObject(histname);
if (hist) {
if (result == nullptr) {
result = new TH1F(*hist);
result->Reset();
}
result->Add(hist);
std::cout << hist->GetTitle() << " added: " << hist->GetEntries() << " " << result->GetEntries() << std::endl;
}
}
}
return result;
}
TH1F* TimeRatio(TFile& ff, const char* modulen, const char* moduled, const int irun, const int rebin) {
CommonAnalyzer castatn(&ff, "", modulen);
CommonAnalyzer castatd(&ff, "", moduled);
char runlabel[100];
sprintf(runlabel, "%d", irun);
char runpath[100];
sprintf(runpath, "run_%d", irun);
castatn.setPath(runpath);
castatd.setPath(runpath);
TH1F* ratio = nullptr;
TH1F* orbitn = nullptr;
if (orbitn == nullptr)
orbitn = (TH1F*)castatn.getObject("orbit");
TH1F* orbitd = nullptr;
if (orbitd == nullptr)
orbitd = (TH1F*)castatd.getObject("orbit");
if (orbitn != nullptr && orbitd != nullptr) {
orbitn->Rebin(rebin);
orbitd->Rebin(rebin);
ratio = new TH1F(*orbitd);
ratio->Reset();
ratio->Divide(orbitn, orbitd);
}
return ratio;
}
TH1D* SummaryHisto(TFile& ff, const char* module) {
CommonAnalyzer castat(&ff, "", module);
TH1D* nevents = new TH1D("nevents", "Number of events vs run", 10, 0., 10.);
nevents->SetCanExtend(TH1::kXaxis);
std::vector<unsigned int> runs = castat.getRunList();
std::sort(runs.begin(), runs.end());
{
for (unsigned int i = 0; i < runs.size(); ++i) {
char runlabel[100];
sprintf(runlabel, "%d", runs[i]);
char runpath[100];
sprintf(runpath, "run_%d", runs[i]);
castat.setPath(runpath);
TH1F* orbit = nullptr;
if (orbit == nullptr)
orbit = (TH1F*)castat.getObject("orbit");
if (orbit) {
// fill the summary
nevents->Fill(runlabel, orbit->GetEntries());
}
}
}
return nevents;
}
TH1D* SummaryHistoRatio(TFile& f1, const char* mod1, TFile& f2, const char* mod2, const char* hname) {
TH1D* denom = SummaryHisto(f1, mod1);
TH1D* numer = SummaryHisto(f2, mod2);
TH1D* ratio = (TH1D*)denom->Clone(hname);
ratio->SetTitle("Fraction of events vs run");
ratio->Sumw2();
ratio->Reset();
ratio->SetDirectory(nullptr);
ratio->Divide(numer, denom, 1, 1, "b");
return ratio;
}
TGraphAsymmErrors* SummaryHistoRatioGraph(
TFile& f1, const char* mod1, TFile& f2, const char* mod2, const char* /* hname */) {
TH1D* denom = SummaryHisto(f1, mod1);
TH1D* numer = SummaryHisto(f2, mod2);
TGraphAsymmErrors* ratio = new TGraphAsymmErrors;
;
ratio->BayesDivide(numer, denom);
return ratio;
}
TH2F* Combined2DHisto(TFile& ff, const char* module, const char* histname) {
CommonAnalyzer castat(&ff, "", module);
TH2F* result = nullptr;
std::vector<unsigned int> runs = castat.getRunList();
std::sort(runs.begin(), runs.end());
{
for (unsigned int i = 0; i < runs.size(); ++i) {
char runlabel[100];
sprintf(runlabel, "%d", runs[i]);
char runpath[100];
sprintf(runpath, "run_%d", runs[i]);
castat.setPath(runpath);
TH2F* hist = (TH2F*)castat.getObject(histname);
if (hist) {
if (result == nullptr) {
result = new TH2F(*hist);
result->Reset();
}
result->Add(hist);
std::cout << hist->GetTitle() << " added: " << hist->GetEntries() << " " << result->GetEntries() << std::endl;
}
}
}
return result;
}
void StatisticsPlots(const char* fullname,
const char* module,
const char* label,
const char* postfix,
const char* shortname,
const char* outtrunk) {
char modfull[300];
sprintf(modfull, "%s%s", module, postfix);
char labfull[300];
sprintf(labfull, "%s%s", label, postfix);
char dirname[400];
sprintf(dirname, "%s", shortname);
// char fullname[300];
// if(strlen(family)==0) { sprintf(fullname,"rootfiles/Tracking_PFG_%s.root",filename);}
// else { sprintf(fullname,"rootfiles/%s.root",dirname); }
TFile ff(fullname);
// Colliding events
/*
char modname[300];
sprintf(modname,"trackcount%s",postfix);
CommonAnalyzer castatall(&ff,"",modname);
TH1F* ntrk = (TH1F*)castatall.getObject("ntrk");
if (ntrk) {
std::cout << " All runs " << ntrk->GetEntries() << std::endl;
delete ntrk;
}
*/
// sprintf(modname,"eventtimedistribution%s",postfix);
CommonAnalyzer castat(&ff, "", modfull);
// Summary histograms
TH1D* nevents = new TH1D("nevents", "Number of events vs run", 10, 0., 10.);
nevents->SetCanExtend(TH1::kXaxis);
std::vector<unsigned int> runs = castat.getRunList();
std::sort(runs.begin(), runs.end());
{
std::cout << "Collision Events" << std::endl;
for (unsigned int i = 0; i < runs.size(); ++i) {
char runlabel[100];
sprintf(runlabel, "%d", runs[i]);
char runpath[100];
sprintf(runpath, "run_%d", runs[i]);
castat.setPath(runpath);
TH1* orbit = nullptr;
TH2F* orbitvsbx = (TH2F*)castat.getObject("orbitvsbxincycle");
if (orbitvsbx == nullptr)
orbitvsbx = (TH2F*)castat.getObject("orbitvsbx");
if (orbitvsbx) {
std::cout << runpath << " " << orbitvsbx->GetEntries() << std::endl;
// prepare plot
new TCanvas;
if (orbitvsbx->GetEntries() > 0) {
orbit = orbitvsbx->ProjectionY();
}
delete orbitvsbx;
}
if (orbit == nullptr)
orbit = (TH1F*)castat.getObject("orbit");
if (orbit) {
orbit->GetXaxis()->SetTitle("orbit");
orbit->SetTitle(runpath);
//normalize to get the rate
orbit->Scale(11223, "width");
orbit->GetYaxis()->SetTitle("Rate (Hz)");
// fill the summary
nevents->Fill(runlabel, orbit->GetEntries());
//
orbit->Draw();
std::string plotfilename;
plotfilename += outtrunk;
plotfilename += dirname;
plotfilename += "/orbit_";
plotfilename += labfull;
plotfilename += "_";
plotfilename += dirname;
plotfilename += "_";
plotfilename += runpath;
plotfilename += ".gif";
gPad->Print(plotfilename.c_str());
delete orbit;
}
TH1F* dbx = (TH1F*)castat.getObject("dbx");
if (dbx) {
// prepare plot
if (dbx->GetEntries() > 0) {
dbx->Draw();
gPad->SetLogy(1);
std::string plotfilename;
plotfilename += outtrunk;
plotfilename += dirname;
plotfilename += "/dbx_";
plotfilename += labfull;
plotfilename += "_";
plotfilename += dirname;
plotfilename += "_";
plotfilename += runpath;
plotfilename += ".gif";
gPad->Print(plotfilename.c_str());
delete dbx;
}
gPad->SetLogy(0);
}
TH1F* bx = (TH1F*)castat.getObject("bx");
if (bx) {
// prepare plot
if (bx->GetEntries() > 0) {
bx->SetLineColor(kRed);
bx->Draw();
gPad->SetLogy(1);
std::string plotfilename;
plotfilename += outtrunk;
plotfilename += dirname;
plotfilename += "/bx_";
plotfilename += labfull;
plotfilename += "_";
plotfilename += dirname;
plotfilename += "_";
plotfilename += runpath;
plotfilename += ".gif";
gPad->Print(plotfilename.c_str());
delete bx;
}
gPad->SetLogy(0);
}
}
}
if (!runs.empty()) {
std::string plotfilename;
plotfilename = outtrunk;
plotfilename += dirname;
plotfilename += "/nevents_";
plotfilename += labfull;
plotfilename += "_";
plotfilename += dirname;
plotfilename += ".gif";
TCanvas* cwide = new TCanvas(plotfilename.c_str(), plotfilename.c_str(), 1500, 500);
nevents->Draw();
char nentries[100];
sprintf(nentries, "%.0f", nevents->GetSumOfWeights());
TText ttlabel;
ttlabel.DrawTextNDC(.8, .7, nentries);
std::cout << nentries << std::endl;
gPad->Print(plotfilename.c_str());
delete cwide;
}
delete nevents;
ff.Close();
}
|