1
|
#include "processData.h"
|
2
|
|
3
|
void processData() {
|
4
|
|
5
|
Double_t amplification = 0.5;
|
6
|
|
7
|
TChain *chCal = new TChain("tree");
|
8
|
chCal->Add("/mnt/data/exp2001/data/analysed/reco/crun09_0001.lmd.reco.root");
|
9
|
|
10
|
TChain *ch = new TChain("tree");
|
11
|
ch->Add("/mnt/data/exp2001/data/analysed/reco/run*.root");
|
12
|
|
13
|
|
14
|
TCanvas *c_raw = new TCanvas("c_raw","raw Data",1800,1000);
|
15
|
c_raw->Divide(2,3);
|
16
|
|
17
|
c_raw->cd(1);
|
18
|
|
19
|
chCal->Draw("tF5-tF3+68.475 >> h1(500,160,170)","","");
|
20
|
c_raw->Update();
|
21
|
|
22
|
hCal = (TH1F*)gPad->GetPrimitive("h1");
|
23
|
|
24
|
c_raw->cd(2);
|
25
|
|
26
|
ch->Draw("tF5-tF3+68.475 >> h2(200,160,170)","","");
|
27
|
|
28
|
c_raw->Update();
|
29
|
|
30
|
hExp = (TH1F*)gPad->GetPrimitive("h2");
|
31
|
|
32
|
c_raw->cd(3);
|
33
|
gCal = SetGraphs(hCal);
|
34
|
gCal->Draw("AL*");
|
35
|
c_raw->Update();
|
36
|
|
37
|
c_raw->cd(4);
|
38
|
gExp = SetGraphs(hExp);
|
39
|
gExp->Draw("AL*");
|
40
|
c_raw->Update();
|
41
|
|
42
|
c_raw->cd(5);
|
43
|
chCal->Draw("(he8.E()-he8.Mag())*1000","","");
|
44
|
c_raw->Update();
|
45
|
|
46
|
c_raw->cd(6);
|
47
|
ch->Draw("(he8.E()-he8.Mag())*1000","","");
|
48
|
c_raw->Update();
|
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
|
TCanvas *c_smooth = new TCanvas("c_smooth","smooth Data",1800,1000);
|
74
|
c_smooth->Divide(3,4);
|
75
|
|
76
|
c_smooth->cd(1);
|
77
|
hCal_smooth = (TH1F*)hCal->Clone();
|
78
|
hCal_smooth->Smooth(2);
|
79
|
hCal_smooth->Draw();
|
80
|
c_smooth->Update();
|
81
|
|
82
|
c_smooth->cd(2);
|
83
|
hExp_smooth = (TH1F*)hExp->Clone();
|
84
|
hExp_smooth->Smooth(2);
|
85
|
hExp_smooth->Draw();
|
86
|
c_smooth->Update();
|
87
|
|
88
|
c_smooth->cd(3);
|
89
|
hExp_smooth->Draw();
|
90
|
|
91
|
TH1F *hCal_smooth_shift = shiftHisto(hCal_smooth,hExp_smooth, 0);
|
92
|
hCal_smooth_shift->SetLineColor(kRed);
|
93
|
hCal_smooth_shift->Draw("same");
|
94
|
c_smooth->Update();
|
95
|
|
96
|
|
97
|
c_smooth->cd(4);
|
98
|
gCal_smooth = SetGraphs(hCal_smooth);
|
99
|
gCal_smooth->Draw("AL");
|
100
|
c_smooth->Update();
|
101
|
|
102
|
c_smooth->cd(5);
|
103
|
gExp_smooth = SetGraphs(hExp_smooth);
|
104
|
gExp_smooth->Draw("AL");
|
105
|
c_smooth->Update();
|
106
|
|
107
|
|
108
|
|
109
|
c_smooth->cd(7);
|
110
|
Double_t timeCal;
|
111
|
TGraph *gCal_smooth_CFD = SetCFDGraph(gCal_smooth, amplification, 1.5 ,&timeCal);
|
112
|
cout << "CFDtime on lvl " << amplification << " for Calibration data: " << timeCal << endl;
|
113
|
gCal_smooth_CFD->Draw("AL*");
|
114
|
|
115
|
TMarker *mCal_cfd = new TMarker(timeCal, gCal_smooth_CFD->Eval(timeCal), 3);
|
116
|
mCal_cfd->SetMarkerColor(kRed);
|
117
|
mCal_cfd->Draw("same");
|
118
|
|
119
|
TLine *l_zero = new TLine(*(gCal_smooth_CFD->GetX()), 0, *(gCal_smooth_CFD->GetX()+gCal_smooth_CFD->GetN()-1),0);
|
120
|
l_zero->SetLineColor(kRed);
|
121
|
l_zero->Draw("same");
|
122
|
|
123
|
c_smooth->Update();
|
124
|
|
125
|
c_smooth->cd(8);
|
126
|
Double_t timeExp;
|
127
|
TGraph *gExp_smooth_CFD = SetCFDGraph(gExp_smooth, amplification, 1.5 ,&timeExp);
|
128
|
cout << "CFDtime on lvl " << amplification << " for Experimental data: " << timeExp << endl;
|
129
|
gExp_smooth_CFD->Draw("AL*");
|
130
|
|
131
|
TMarker *mExp_cfd = new TMarker(timeExp, gExp_smooth_CFD->Eval(timeExp), 3);
|
132
|
mExp_cfd->SetMarkerColor(kRed);
|
133
|
mExp_cfd->Draw("same");
|
134
|
|
135
|
l_zero->Draw("same");
|
136
|
|
137
|
c_smooth->Update();
|
138
|
|
139
|
|
140
|
|
141
|
c_smooth->cd(10);
|
142
|
Double_t timeCal_low;
|
143
|
TGraph *gCal_back_CFD = SetCFDGraph_back(gCal_smooth, amplification, 0.5 ,&timeCal_low);
|
144
|
cout << "Low Energy CFDtime on lvl " << amplification << " for Calibration data: " << timeCal_low << endl;
|
145
|
gCal_back_CFD->Draw("AL*");
|
146
|
|
147
|
TMarker *mCal_cfd_back = new TMarker(timeCal_low, gCal_back_CFD->Eval(timeCal_low), 3);
|
148
|
mCal_cfd_back->SetMarkerColor(kRed);
|
149
|
mCal_cfd_back->Draw("same");
|
150
|
|
151
|
l_zero->Draw("same");
|
152
|
|
153
|
c_smooth->Update();
|
154
|
|
155
|
c_smooth->cd(11);
|
156
|
Double_t timeExp_low;
|
157
|
TGraph *gExp_back_CFD = SetCFDGraph_back(gExp_smooth, amplification, 0.5 ,&timeExp_low);
|
158
|
cout << "Low Energy CFDtime on lvl " << amplification << " for Experimental data: " << timeExp_low << endl;
|
159
|
gExp_back_CFD->Draw("AL*");
|
160
|
|
161
|
TMarker *mExp_cfd_back = new TMarker(timeExp_low, gExp_back_CFD->Eval(timeExp_low), 3);
|
162
|
mExp_cfd_back->SetMarkerColor(kRed);
|
163
|
mExp_cfd_back->Draw("same");
|
164
|
|
165
|
l_zero->Draw("same");
|
166
|
|
167
|
c_smooth->Update();
|
168
|
|
169
|
|
170
|
Double_t yDev_cal,xDev_cal;
|
171
|
getPeregib(gCal_smooth,timeCal_low ,0.1,&yDev_cal,&xDev_cal);
|
172
|
|
173
|
Double_t yDev_exp,xDev_exp;
|
174
|
getPeregib(gExp_smooth,timeExp_low ,0.1,&yDev_exp,&xDev_exp);
|
175
|
|
176
|
|
177
|
c_smooth->cd(4);
|
178
|
|
179
|
TMarker *mCal = new TMarker(timeCal, gCal_smooth->Eval(timeCal), 3);
|
180
|
mCal->SetMarkerColor(kRed);
|
181
|
mCal->Draw("same");
|
182
|
|
183
|
TMarker *mCal_back = new TMarker(timeCal_low, gCal_smooth->Eval(timeCal_low), 3);
|
184
|
mCal_back->SetMarkerColor(kGreen);
|
185
|
mCal_back->Draw("same");
|
186
|
|
187
|
TMarker *mCal_dev = new TMarker(xDev_cal, gCal_smooth->Eval(xDev_cal), 3);
|
188
|
mCal_dev->SetMarkerColor(kMagenta);
|
189
|
mCal_dev->Draw("same");
|
190
|
|
191
|
TLine *lCal = new TLine(*(gCal_smooth->GetX()), hCal_smooth->GetMaximum()/2, *(gCal_smooth->GetX()+gCal_smooth->GetN()-1), hCal_smooth->GetMaximum()/2);
|
192
|
lCal->SetLineColor(kRed);
|
193
|
lCal->Draw("same");
|
194
|
|
195
|
c_smooth->Update();
|
196
|
|
197
|
c_smooth->cd(5);
|
198
|
|
199
|
TMarker *mExp = new TMarker(timeExp, gExp_smooth->Eval(timeExp), 3);
|
200
|
mExp->SetMarkerColor(kRed);
|
201
|
mExp->Draw("same");
|
202
|
|
203
|
TMarker *mExp_back = new TMarker(timeExp_low, gExp_smooth->Eval(timeExp_low), 3);
|
204
|
mExp_back->SetMarkerColor(kGreen);
|
205
|
mExp_back->Draw("same");
|
206
|
|
207
|
TMarker *mExp_dev = new TMarker(xDev_exp, gExp_smooth->Eval(xDev_exp), 3);
|
208
|
mExp_dev->SetMarkerColor(kMagenta);
|
209
|
mExp_dev->Draw("same");
|
210
|
|
211
|
TLine *lExp = new TLine(*(gExp_smooth->GetX()), hExp_smooth->GetMaximum()/2, *(gExp_smooth->GetX()+gExp_smooth->GetN()-1), hExp_smooth->GetMaximum()/2);
|
212
|
lExp->SetLineColor(kRed);
|
213
|
lExp->Draw("same");
|
214
|
|
215
|
c_smooth->Update();
|
216
|
|
217
|
cout << "Peregib points: " << xDev_exp << " " << xDev_cal << endl;
|
218
|
|
219
|
cout << " Bin width: " << hExp_smooth->GetBinWidth(1) << endl;
|
220
|
|
221
|
|
222
|
|
223
|
|
224
|
TGraph *g_temp_exp = (TGraph*)gExp_smooth->Clone();
|
225
|
TGraph *g_temp_exp1 = (TGraph*)gExp_smooth->Clone();
|
226
|
|
227
|
TF1 *fitf = new TF1("fitf","[0]*x + [1]");
|
228
|
fitf->SetLineColor(kRed);
|
229
|
|
230
|
TCanvas *c_temp = new TCanvas("c_temp","title",1800,1000);
|
231
|
|
232
|
|
233
|
|
234
|
|
235
|
|
236
|
|
237
|
|
238
|
|
239
|
|
240
|
|
241
|
|
242
|
|
243
|
|
244
|
|
245
|
|
246
|
|
247
|
c_temp->cd();
|
248
|
|
249
|
Double_t lin_c, sh_c;
|
250
|
lin_c = 0.93;
|
251
|
sh_c = 0.54;
|
252
|
for (Int_t i=0;i<g_temp_exp1->GetN();i++) {
|
253
|
g_temp_exp1->SetPoint(i,*(g_temp_exp1->GetX()+i)+sh_c, *(g_temp_exp1->GetY()+i)*lin_c );
|
254
|
}
|
255
|
g_temp_exp1->Draw();
|
256
|
|
257
|
|
258
|
|
259
|
TGraph *g_temp = shiftGraph(gCal_smooth,gExp_smooth, 0.);
|
260
|
g_temp->SetLineColor(kRed);
|
261
|
g_temp->Draw("same");
|
262
|
c_temp->Update();
|
263
|
|
264
|
|
265
|
return;
|
266
|
|
267
|
cout << "Calibration data. Bin width: " << hCal->GetBinWidth(1) << endl;
|
268
|
cout << getLed_low(hCal,10) << " ";
|
269
|
cout << getLed_low(hCal,100) << " ";
|
270
|
cout << getLed_low(hCal,300) << " ";
|
271
|
cout << getLed_low(hCal,500) << endl << endl;
|
272
|
|
273
|
|
274
|
cout << "EXP data. Bin width: " << hExp->GetBinWidth(1) << endl;
|
275
|
cout << getLed_low(hExp,10) << " ";
|
276
|
cout << getLed_low(hExp,100) << " ";
|
277
|
cout << getLed_low(hExp,300) << " ";
|
278
|
cout << getLed_low(hExp,500) << endl;
|
279
|
|
280
|
}
|
281
|
|
282
|
Double_t getLed_low(TH1F *hist, Double_t thresh) {
|
283
|
|
284
|
for (Int_t i=1;i<hist->GetNbinsX()+1;i++){
|
285
|
if (hist->GetBinContent(i)>thresh) {
|
286
|
return hist->GetBinCenter(i);
|
287
|
}
|
288
|
}
|
289
|
|
290
|
return -1;
|
291
|
}
|
292
|
|
293
|
Double_t getLed_up(TH1F *hist, Double_t thresh) {
|
294
|
|
295
|
for (Int_t i=hist->GetNbinsX();i>0;i--){
|
296
|
if (hist->GetBinContent(i)>thresh) {
|
297
|
return hist->GetBinCenter(i);
|
298
|
}
|
299
|
}
|
300
|
|
301
|
return -1;
|
302
|
}
|
303
|
|
304
|
TGraph* SetGraphs(TH1F* hist) {
|
305
|
|
306
|
TGraph *g = new TGraph();
|
307
|
|
308
|
for (Int_t i=0; i<hist->GetNbinsX(); i++) {
|
309
|
g->SetPoint(i, hist->GetBinCenter(i+1), hist->GetBinContent(i+1));
|
310
|
}
|
311
|
|
312
|
return g;
|
313
|
}
|
314
|
|
315
|
|
316
|
TGraph* SetCFDGraph_static(TGraph *g, Double_t amp, Int_t delay) {
|
317
|
|
318
|
Double_t stepX = *(g->GetX()+1) - *(g->GetX());
|
319
|
|
320
|
TGraph *gCFD = new TGraph();
|
321
|
gCFD->Set(g->GetN() + delay);
|
322
|
|
323
|
for (Int_t i=0;i<gCFD->GetN();i++) {
|
324
|
static Double_t yVal;
|
325
|
static Double_t xVal;
|
326
|
|
327
|
if (i<delay) {
|
328
|
yVal = *(g->GetY()+i)*amp*(-1);
|
329
|
xVal = *(g->GetX()+i)-delay*stepX;
|
330
|
}
|
331
|
|
332
|
if (i>=delay && i<g->GetN()) {
|
333
|
yVal = *(g->GetY()+i)*amp*(-1) + *(g->GetY()+i-delay);
|
334
|
xVal = *(g->GetX()+i-delay);
|
335
|
}
|
336
|
|
337
|
if (i>=g->GetN()) {
|
338
|
yVal = *(g->GetY()+i-delay-1);
|
339
|
xVal = *(g->GetX()+i-delay-1);
|
340
|
}
|
341
|
|
342
|
gCFD->SetPoint(i, xVal, yVal);
|
343
|
|
344
|
}
|
345
|
|
346
|
return gCFD;
|
347
|
}
|
348
|
|
349
|
TGraph* shiftGraph(TGraph *g1, TGraph *g2, Double_t shift) {
|
350
|
|
351
|
Double_t max1,max2;
|
352
|
|
353
|
max1 = *(g1->GetY());
|
354
|
for (Int_t i=0;i<g1->GetN();i++) {
|
355
|
if (max1<*(g1->GetY()+i)) max1 = *(g1->GetY()+i);
|
356
|
}
|
357
|
|
358
|
max2 = *(g2->GetY());
|
359
|
for (Int_t i=0;i<g2->GetN();i++) {
|
360
|
if (max2<*(g2->GetY()+i)) max2 = *(g2->GetY()+i);
|
361
|
}
|
362
|
|
363
|
Double_t amp = max2/max1;
|
364
|
|
365
|
TGraph *gTemp = new TGraph();
|
366
|
gTemp->Set(g1->GetN());
|
367
|
|
368
|
for (Int_t i=0;i<gTemp->GetN();i++) {
|
369
|
gTemp->SetPoint(i,*(g1->GetX()+i)+shift, *(g1->GetY()+i)*amp );
|
370
|
}
|
371
|
|
372
|
return gTemp;
|
373
|
|
374
|
}
|
375
|
|
376
|
TH1F* shiftHisto(TH1F *h1, TH1F *h2, Double_t shift) {
|
377
|
|
378
|
Int_t binShift = shift/h1->GetBinWidth(1);
|
379
|
Double_t amp = h2->GetMaximum()/h1->GetMaximum();
|
380
|
|
381
|
TH1F *htemp = (TH1F*)h1->Clone();
|
382
|
|
383
|
for(Int_t i=1;i<htemp->GetNbinsX()+1;i++) {
|
384
|
|
385
|
if(i+binShift<=htemp->GetNbinsX()) htemp->SetBinContent(i,h1->GetBinContent(i-binShift)*amp);
|
386
|
else {
|
387
|
htemp->SetBinContent(i,0);
|
388
|
}
|
389
|
|
390
|
}
|
391
|
|
392
|
return htemp;
|
393
|
|
394
|
}
|
395
|
|
396
|
|
397
|
TGraph* SetCFDGraph_back(TGraph *g, Double_t amp, Double_t delay,Double_t* CFDtime) {
|
398
|
|
399
|
const Double_t timeStep = 0.05;
|
400
|
Double_t mytime = *(g->GetX());
|
401
|
|
402
|
Double_t timeMin = mytime;
|
403
|
Double_t timeMax = mytime;
|
404
|
Double_t valMin = *(g->GetY());
|
405
|
Double_t valMax = *(g->GetY());
|
406
|
|
407
|
Int_t nBins = ( *(g->GetX()+g->GetN()-1) - *(g->GetX()) + delay)/timeStep;
|
408
|
|
409
|
TGraph *gCFD = new TGraph();
|
410
|
gCFD->Set(nBins);
|
411
|
|
412
|
for (Int_t i=0;i<gCFD->GetN();i++) {
|
413
|
static Double_t yVal;
|
414
|
|
415
|
if ( mytime<delay+*(g->GetX()) ) {
|
416
|
yVal = g->Eval(mytime);
|
417
|
}
|
418
|
|
419
|
|
420
|
if ( mytime>=delay+*(g->GetX()) && mytime< *(g->GetX()+g->GetN()-1) ) {
|
421
|
yVal = g->Eval(mytime-delay)*amp*(-1) + g->Eval(mytime);
|
422
|
}
|
423
|
|
424
|
if ( mytime>= *(g->GetX()+g->GetN()-1) ) {
|
425
|
yVal = g->Eval(mytime-delay)*amp*(-1);
|
426
|
}
|
427
|
|
428
|
if (yVal>valMax) {
|
429
|
valMax = yVal;
|
430
|
timeMax = mytime;
|
431
|
}
|
432
|
|
433
|
if (yVal<valMin) {
|
434
|
valMin = yVal;
|
435
|
timeMin = mytime;
|
436
|
}
|
437
|
|
438
|
gCFD->SetPoint(i, mytime, yVal);
|
439
|
|
440
|
mytime += timeStep;
|
441
|
}
|
442
|
|
443
|
mytime = timeMin;
|
444
|
while( (gCFD->Eval(mytime) <= 0) && (mytime >= timeMax) ) {
|
445
|
*CFDtime = mytime;
|
446
|
mytime -= timeStep;
|
447
|
}
|
448
|
|
449
|
return gCFD;
|
450
|
}
|
451
|
|
452
|
TGraph* SetCFDGraph(TGraph *g, Double_t amp, Double_t delay,Double_t* CFDtime) {
|
453
|
|
454
|
const Double_t timeStep = 0.05;
|
455
|
Double_t mytime = *(g->GetX()) - delay;
|
456
|
|
457
|
Double_t timeMin = mytime;
|
458
|
Double_t timeMax = mytime;
|
459
|
Double_t valMin = *(g->GetY());
|
460
|
Double_t valMax = *(g->GetY());
|
461
|
|
462
|
Int_t nBins = ( *(g->GetX()+g->GetN()-1) - *(g->GetX()) + delay)/timeStep;
|
463
|
|
464
|
TGraph *gCFD = new TGraph();
|
465
|
gCFD->Set(nBins);
|
466
|
|
467
|
for (Int_t i=0;i<gCFD->GetN();i++) {
|
468
|
static Double_t yVal;
|
469
|
|
470
|
if ( mytime<*(g->GetX()) ) {
|
471
|
yVal = g->Eval(mytime+delay)*amp*(-1);
|
472
|
}
|
473
|
|
474
|
if ( mytime>=*(g->GetX()) && mytime< *(g->GetX()+g->GetN()-1)-delay ) {
|
475
|
yVal = g->Eval(mytime+delay)*amp*(-1) + g->Eval(mytime);
|
476
|
}
|
477
|
|
478
|
if ( mytime>= *(g->GetX()+g->GetN()-1)-delay ) {
|
479
|
yVal = g->Eval(mytime);
|
480
|
}
|
481
|
|
482
|
if (yVal>valMax) {
|
483
|
valMax = yVal;
|
484
|
timeMax = mytime;
|
485
|
}
|
486
|
|
487
|
if (yVal<valMin) {
|
488
|
valMin = yVal;
|
489
|
timeMin = mytime;
|
490
|
}
|
491
|
|
492
|
gCFD->SetPoint(i, mytime, yVal);
|
493
|
|
494
|
mytime += timeStep;
|
495
|
}
|
496
|
|
497
|
mytime = timeMin;
|
498
|
while( (gCFD->Eval(mytime) <= 0) && (mytime <= timeMax) ) {
|
499
|
*CFDtime = mytime;
|
500
|
mytime += timeStep;
|
501
|
}
|
502
|
|
503
|
return gCFD;
|
504
|
}
|
505
|
|
506
|
void getPeregib(TGraph *g, Double_t x, Double_t range,Double_t *maxDev,Double_t *XmaxDev) {
|
507
|
|
508
|
const Double_t timeStep = 0.05;
|
509
|
|
510
|
Double_t mytime = x - range;
|
511
|
Double_t preValue = g->Eval(mytime-timeStep);
|
512
|
|
513
|
*maxDev = fabs( (g->Eval(mytime)-g->Eval(mytime-timeStep))/timeStep );
|
514
|
*XmaxDev = mytime;
|
515
|
|
516
|
while (mytime<x+range) {
|
517
|
|
518
|
static Double_t value;
|
519
|
value = g->Eval(mytime);
|
520
|
|
521
|
static Double_t dev;
|
522
|
dev = (value - preValue)/timeStep;
|
523
|
|
524
|
if (dev>*maxDev) {
|
525
|
*maxDev = dev;
|
526
|
*XmaxDev = mytime;
|
527
|
}
|
528
|
|
529
|
mytime += timeStep;
|
530
|
preValue = value;
|
531
|
}
|
532
|
|
533
|
return 0;
|
534
|
|
535
|
}
|