-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfastDQM_CeF3_BTF.C
706 lines (578 loc) · 32 KB
/
fastDQM_CeF3_BTF.C
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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
#define fastDQM_CeF3_BTF_cxx
#include "fastDQM_CeF3_BTF.h"
#include <TH2.h>
#include <TF1.h>
#include <TStyle.h>
#include <TCanvas.h>
#include <TMath.h>
#include <iostream>
float bgoIntercalibration[BGO_CHANNELS] = { 1., 1., 1., 1., 1., 1., 1., 1.};
float cef3Intercalibration[BGO_CHANNELS] = { 1., 1., 1., 1.};
float hodoXIntercalibration[HODOX_CHANNELS] = { 1., 1., 1., 1., 1., 1., 1., 1.};
float hodoYIntercalibration[HODOY_CHANNELS] = { 1., 1., 1., 1., 1., 1., 1., 1.};
float centerXTaggerIntercalibration[CENTERX_TAGGER_CHANNELS] = { 1., 1.};
float centerYTaggerIntercalibration[CENTERY_TAGGER_CHANNELS] = { 1.};
// pedestals from Run 91
float bgoPedMean[BGO_CHANNELS] = { 157.735, 148.432, 185.424, 171.484, 167.857, 164.303, 169.315, 151.413};
//float bgoPedRMS[BGO_CHANNELS] = { 3.86671, 2.32314, 3.12291, 2.36773, 3.72065, 2.02948, 4.02517, 2.53844};
float cef3PedMean[CEF3_CHANNELS] = { 124.872, 106.911, 114.198, 121.555 };
//float cef3PedRMS[CEF3_CHANNELS] = { 1.07245, 1.85074, 2.34754, 4.08115 };
float hodoXPedMean[BGO_CHANNELS] = { 113.263, 96.3056, 129.509, 119.84, 95.1994, 136.194, 135.549, 162.077};
//float hodoXPedRMS[BGO_CHANNELS] = { };
float hodoYPedMean[BGO_CHANNELS] = { 108.752, 101.68, 118.983, 137.645, 94.2584, 99.2072, 89.6646, 99.2206};
//float hodoYPedRMS[BGO_CHANNELS] = { };
// These channel numbers HAVE TO BE CHECKED! Left is defined looking at the matrix from the beam side
bool isInBGOUpRow(int bgoChannel)
{
return (bgoChannel==0 || bgoChannel==1 ||bgoChannel==2);
}
bool isInBGODownRow(int bgoChannel)
{
return (bgoChannel==6 || bgoChannel==7 ||bgoChannel==8);
}
bool isInBGORightRow(int bgoChannel)
{
return (bgoChannel==2 || bgoChannel==4 ||bgoChannel==7);
}
bool isInBGOLeftRow(int bgoChannel)
{
return (bgoChannel==0 || bgoChannel==3 ||bgoChannel==5);
}
// 24h hours 5min intervals
#define TIME_MAX_INTERVALS 248
#define TIME_INTERVAL_SIZE 5*60*1000 //interval size is 5min expressed in msec
// A simple struct to simplify time average code
struct timeAverage
{
double timeAverage_array[TIME_MAX_INTERVALS];
double timeRms_array[TIME_MAX_INTERVALS];
unsigned int nMeasures_per_interval[TIME_MAX_INTERVALS];
timeAverage()
{
for (unsigned int i(0);i<TIME_MAX_INTERVALS;++i)
{
timeAverage_array[i]=0;
timeRms_array[i]=0;
nMeasures_per_interval[i]=0;
}
}
void addMeasure(unsigned int interval, float value)
{
if (interval<TIME_MAX_INTERVALS)
{
timeAverage_array[interval]+=value;
timeRms_array[interval]+=value*value;
nMeasures_per_interval[interval]++;
}
else
{
std::cout << "ERROR! Adding measurement at time " << interval << " which is outside the TIME_MAX_INTERVALS" << std::endl;
}
}
void calculateAverages()
{
for(unsigned int i(0);i<TIME_MAX_INTERVALS;++i)
{
if (nMeasures_per_interval[i]>0)
{
timeAverage_array[i]=timeAverage_array[i]/(float)nMeasures_per_interval[i];
timeRms_array[i]=TMath::Sqrt((timeRms_array[i]/(float)nMeasures_per_interval[i])-timeAverage_array[i]*timeAverage_array[i]);
}
}
}
};
void fillTimeProfile(const timeAverage& timeAvg, TH1F* timeProfile)
{
for (unsigned int i(0);i<TIME_MAX_INTERVALS;++i)
{
if (timeAvg.nMeasures_per_interval[i]==0)
continue;
timeProfile->SetBinContent(i+1,timeAvg.timeAverage_array[i]);
timeProfile->SetBinError(i+1,timeAvg.timeRms_array[i]);
}
}
void fastDQM_CeF3_BTF::Loop()
{
// In a ROOT session, you can do:
// Root > .L fastDQM_CeF3_BTF.C
// Root > fastDQM_CeF3_BTF t
// Root > t.GetEntry(12); // Fill t data members with entry number 12
// Root > t.Show(); // Show values of entry 12
// Root > t.Show(16); // Read and show values of entry 16
// Root > t.Loop(); // Loop on all entries
//
// This is the loop skeleton where:
// jentry is the global entry number in the chain
// ientry is the entry number in the current Tree
// Note that the argument to GetEntry must be:
// jentry for TChain::GetEntry
// ientry for TTree::GetEntry and TBranch::GetEntry
//
// To read only selected branches, Insert statements like:
// METHOD1:
// fChain->SetBranchStatus("*",0); // disable all branches
// fChain->SetBranchStatus("branchname",1); // activate branchname
// METHOD2: replace line
// fChain->GetEntry(jentry); //read all branches
//by b_branchname->GetEntry(ientry); //read only this branch
float nTriggers[TIME_MAX_INTERVALS];
for (unsigned int i(0);i<TIME_MAX_INTERVALS;++i)
nTriggers[i]=0;
timeAverage rate_TimeAverage;
//BGO histograms
TH1F* h_bgoRawSpectrum[BGO_CHANNELS];
TH1F* h_bgoCorSpectrum[BGO_CHANNELS];
for (int i=0;i<BGO_CHANNELS;++i)
{
h_bgoRawSpectrum[i]=new TH1F(Form("bgoRawSpectrum_%d",i),Form("bgoRawSpectrum_%d",i),4096,-0.5,4095.5);
outObjects[TString("BGORAW_")+TString(h_bgoRawSpectrum[i]->GetName())]=(TObject*)h_bgoRawSpectrum[i];
h_bgoCorSpectrum[i]=new TH1F(Form("bgoCorSpectrum_%d",i),Form("bgoCorSpectrum_%d",i),4096,-0.5,4095.5);
outObjects[TString("BGOCOR_")+TString(h_bgoCorSpectrum[i]->GetName())]=(TObject*)h_bgoCorSpectrum[i];
}
TH1F* h_bgoEnergy;
h_bgoEnergy=new TH1F("bgoEnergy","bgoEnergy",4096,-0.5,4095.5);
outObjects[TString("BGO_")+TString(h_bgoEnergy->GetName())]=(TObject*)h_bgoEnergy;
timeAverage bgoEnergy_TimeAverage;
TH1F* h_bgoEnergyProfile;
h_bgoEnergyProfile=new TH1F("bgoEnergyProfile","bgoEnergyProfile",BGO_CHANNELS,-0.5,BGO_CHANNELS-0.5);
outObjects[TString("BGO_")+TString(h_bgoEnergyProfile->GetName())]=(TObject*)h_bgoEnergyProfile;
TH1F* h_bgoEnergyUp;
h_bgoEnergyUp=new TH1F("bgoEnergyUp","bgoEnergyUp",4096,-0.5,4095.5);
outObjects[TString("BGO_")+TString(h_bgoEnergyUp->GetName())]=(TObject*)h_bgoEnergyUp;
TH1F* h_bgoEnergyDown;
h_bgoEnergyDown=new TH1F("bgoEnergyDown","bgoEnergyDown",4096,-0.5,4095.5);
outObjects[TString("BGO_")+TString(h_bgoEnergyDown->GetName())]=(TObject*)h_bgoEnergyDown;
TH1F* h_bgoEnergyLeft;
h_bgoEnergyLeft=new TH1F("bgoEnergyLeft","bgoEnergyLeft",4096,-0.5,4095.5);
outObjects[TString("BGO_")+TString(h_bgoEnergyLeft->GetName())]=(TObject*)h_bgoEnergyLeft;
TH1F* h_bgoEnergyRight;
h_bgoEnergyRight=new TH1F("bgoEnergyRight","bgoEnergyRight",4096,-0.5,4095.5);
outObjects[TString("BGO_")+TString(h_bgoEnergyRight->GetName())]=(TObject*)h_bgoEnergyRight;
//CeF3 histograms
TH1F* h_cef3RawSpectrum[CEF3_CHANNELS];
TH1F* h_cef3CorSpectrum[CEF3_CHANNELS];
for (int i=0;i<CEF3_CHANNELS;++i)
{
h_cef3RawSpectrum[i]=new TH1F(Form("cef3RawSpectrum_%d",i),Form("cef3RawSpectrum_%d",i),4096,-0.5,4095.5);
outObjects[TString("CEF3RAW_")+TString(h_cef3RawSpectrum[i]->GetName())]=(TObject*)h_cef3RawSpectrum[i];
h_cef3CorSpectrum[i]=new TH1F(Form("cef3CorSpectrum_%d",i),Form("cef3CorSpectrum_%d",i),4096,-0.5,4095.5);
outObjects[TString("CEF3COR_")+TString(h_cef3CorSpectrum[i]->GetName())]=(TObject*)h_cef3CorSpectrum[i];
}
timeAverage cef3Energy_TimeAverage;
TH1F* h_cef3Energy;
h_cef3Energy=new TH1F("cef3Energy","cef3Energy",4096,-0.5,4095.5);
outObjects[TString("CEF3_")+TString(h_cef3Energy->GetName())]=(TObject*)h_cef3Energy;
TH1F* h_cef3EnergyProfile;
h_cef3EnergyProfile=new TH1F("cef3EnergyProfile","cef3EnergyProfile",CEF3_CHANNELS,-0.5,CEF3_CHANNELS-0.5);
outObjects[TString("CEF3_")+TString(h_cef3EnergyProfile->GetName())]=(TObject*)h_cef3EnergyProfile;
//Full calo energy
TH1F* h_caloEnergy;
h_caloEnergy=new TH1F("caloEnergy","caloEnergy",4096,-0.5,4095.5);
outObjects[TString("CALO_")+TString(h_caloEnergy->GetName())]=(TObject*)h_caloEnergy;
timeAverage caloEnergy_TimeAverage;
//HodoX histograms
TH1F* h_hodoXRawSpectrum[HODOX_CHANNELS];
TH1F* h_hodoXCorSpectrum[HODOX_CHANNELS];
for (int i=0;i<HODOX_CHANNELS;++i)
{
h_hodoXRawSpectrum[i]=new TH1F(Form("hodoXRawSpectrum_%d",i),Form("hodoXRawSpectrum_%d",i),4096,-0.5,4095.5);
outObjects[TString("HODOXRAW_")+TString(h_hodoXRawSpectrum[i]->GetName())]=(TObject*)h_hodoXRawSpectrum[i];
h_hodoXCorSpectrum[i]=new TH1F(Form("hodoXCorSpectrum_%d",i),Form("hodoXCorSpectrum_%d",i),4096,-0.5,4095.5);
outObjects[TString("HODOXCOR_")+TString(h_hodoXCorSpectrum[i]->GetName())]=(TObject*)h_hodoXCorSpectrum[i];
}
TH1F* h_hodoXEnergy;
h_hodoXEnergy=new TH1F("hodoXEnergy","hodoXEnergy",4096,-0.5,4095.5);
outObjects[TString("HODO_")+TString(h_hodoXEnergy->GetName())]=(TObject*)h_hodoXEnergy;
TH1F* h_hodoXPos;
h_hodoXPos=new TH1F("hodoXPos","hodoXPos",200,0,HODOX_CHANNELS);
outObjects[TString("HODO_")+TString(h_hodoXPos->GetName())]=(TObject*)h_hodoXPos;
timeAverage hodoXEnergy_TimeAverage;
timeAverage hodoXPos_TimeAverage;
TH1F* h_hodoXEnergyProfile;
h_hodoXEnergyProfile=new TH1F("hodoXEnergyProfile","hodoXEnergyProfile",HODOX_CHANNELS,-0.5,HODOX_CHANNELS-0.5);
outObjects[TString("HODO_")+TString(h_hodoXEnergyProfile->GetName())]=(TObject*)h_hodoXEnergyProfile;
//HodoY histograms
TH1F* h_hodoYRawSpectrum[HODOY_CHANNELS];
TH1F* h_hodoYCorSpectrum[HODOY_CHANNELS];
for (int i=0;i<HODOY_CHANNELS;++i)
{
h_hodoYRawSpectrum[i]=new TH1F(Form("hodoYRawSpectrum_%d",i),Form("hodoYRawSpectrum_%d",i),4096,-0.5,4095.5);
outObjects[TString("HODOYRAW_")+TString(h_hodoYRawSpectrum[i]->GetName())]=(TObject*)h_hodoYRawSpectrum[i];
h_hodoYCorSpectrum[i]=new TH1F(Form("hodoYCorSpectrum_%d",i),Form("hodoYCorSpectrum_%d",i),4096,-0.5,4095.5);
outObjects[TString("HODOYCOR_")+TString(h_hodoYCorSpectrum[i]->GetName())]=(TObject*)h_hodoYCorSpectrum[i];
}
TH1F* h_hodoYEnergy;
h_hodoYEnergy=new TH1F("hodoYEnergy","hodoYEnergy",4096,-0.5,4095.5);
outObjects[TString("HODO_")+TString(h_hodoYEnergy->GetName())]=(TObject*)h_hodoYEnergy;
TH1F* h_hodoYPos;
h_hodoYPos=new TH1F("hodoYPos","hodoYPos",200,0,HODOY_CHANNELS);
outObjects[TString("HODO_")+TString(h_hodoYPos->GetName())]=(TObject*)h_hodoYPos;
timeAverage hodoYEnergy_TimeAverage;
timeAverage hodoYPos_TimeAverage;
TH1F* h_hodoYEnergyProfile;
h_hodoYEnergyProfile=new TH1F("hodoYEnergyProfile","hodoYEnergyProfile",HODOY_CHANNELS,-0.5,HODOY_CHANNELS-0.5);
outObjects[TString("HODO_")+TString(h_hodoYEnergyProfile->GetName())]=(TObject*)h_hodoYEnergyProfile;
//CenterX tagger histograms
TH1F* h_centerXTaggerRawSpectrum[CENTERX_TAGGER_CHANNELS];
for (int i=0;i<CENTERX_TAGGER_CHANNELS;++i)
{
h_centerXTaggerRawSpectrum[i]=new TH1F(Form("centerXTaggerRawSpectrum_%d",i),Form("centerXTaggerRawSpectrum_%d",i),4096,-0.5,4095.5);
outObjects[TString("CENTERTAGGER_")+TString(h_centerXTaggerRawSpectrum[i]->GetName())]=(TObject*)h_centerXTaggerRawSpectrum[i];
}
TH1F* h_centerXTaggerEnergy;
h_centerXTaggerEnergy=new TH1F("centerXTaggerEnergy","centerXTaggerEnergy",4096,-0.5,4095.5);
outObjects[TString("CENTERTAGGER_")+TString(h_centerXTaggerEnergy->GetName())]=(TObject*)h_centerXTaggerEnergy;
timeAverage centerXTaggerEnergy_TimeAverage;
TH1F* h_centerXTaggerEnergyProfile;
h_centerXTaggerEnergyProfile=new TH1F("centerXTaggerEnergyProfile","centerXTaggerEnergyProfile",CENTERX_TAGGER_CHANNELS,-0.5,CENTERX_TAGGER_CHANNELS-0.5);
outObjects[TString("CENTERTAGGER_")+TString(h_centerXTaggerEnergyProfile->GetName())]=(TObject*)h_centerXTaggerEnergyProfile;
//CenterY tagger histograms
TH1F* h_centerYTaggerRawSpectrum[CENTERY_TAGGER_CHANNELS];
for (int i=0;i<CENTERY_TAGGER_CHANNELS;++i)
{
h_centerYTaggerRawSpectrum[i]=new TH1F(Form("centerYTaggerRawSpectrum_%d",i),Form("centerYTaggerRawSpectrum_%d",i),4096,-0.5,4095.5);
outObjects[TString("CENTERTAGGER_")+TString(h_centerYTaggerRawSpectrum[i]->GetName())]=(TObject*)h_centerYTaggerRawSpectrum[i];
}
TH1F* h_centerYTaggerEnergy;
h_centerYTaggerEnergy=new TH1F("centerYTaggerEnergy","centerYTaggerEnergy",4096,-0.5,4095.5);
outObjects[TString("CENTERTAGGER_")+TString(h_centerYTaggerEnergy->GetName())]=(TObject*)h_centerYTaggerEnergy;
timeAverage centerYTaggerEnergy_TimeAverage;
TH1F* h_centerYTaggerEnergyProfile;
h_centerYTaggerEnergyProfile=new TH1F("centerYTaggerEnergyProfile","centerYTaggerEnergyProfile",CENTERY_TAGGER_CHANNELS,-0.5,CENTERY_TAGGER_CHANNELS-0.5);
outObjects[TString("CENTERTAGGER_")+TString(h_centerYTaggerEnergyProfile->GetName())]=(TObject*)h_centerYTaggerEnergyProfile;
//Scintillator histograms
TH1F* h_scintFrontRawSpectrum;
h_scintFrontRawSpectrum=new TH1F("scintFrontRawSpectrum","scintFrontRawSpectrum",4096,-0.5,4095.5);
outObjects[TString("SCINT_")+TString(h_scintFrontRawSpectrum->GetName())]=(TObject*)h_scintFrontRawSpectrum;
timeAverage scintFrontEnergy_TimeAverage;
TH1F* h_scintBackRawSpectrum;
h_scintBackRawSpectrum=new TH1F("scintBackRawSpectrum","scintBackRawSpectrum",4096,-0.5,4095.5);
outObjects[TString("SCINT_")+TString(h_scintBackRawSpectrum->GetName())]=(TObject*)h_scintBackRawSpectrum;
timeAverage scintBackEnergy_TimeAverage;
//Correlation plots
TH2F* h_bgo_vs_cef3;
h_bgo_vs_cef3=new TH2F("bgo_vs_cef3","bgo_vs_cef3",4096,-0.5,4095.5,4096,-0.5,4095.5);
outObjects[TString("CORRCALO_")+TString(h_bgo_vs_cef3->GetName())]=(TObject*)h_bgo_vs_cef3;
TH2F* h_hodoX_vs_calo;
h_hodoX_vs_calo=new TH2F("hodoX_vs_calo","hodoX_vs_calo",4096,-0.5,4095.5,4096,-0.5,4095.5);
outObjects[TString("CORRCALOHODO_")+TString(h_hodoX_vs_calo->GetName())]=(TObject*)h_hodoX_vs_calo;
TH2F* h_hodoXPos_vs_bgoLRAsymm;
h_hodoXPos_vs_bgoLRAsymm=new TH2F("hodoX_vs_bgoLRAsymm","hodoXPos_vs_bgoLRAsymm",200,-1.,1.,200,0.,HODOX_CHANNELS);
outObjects[TString("HODO_")+TString(h_hodoXPos_vs_bgoLRAsymm->GetName())]=(TObject*)h_hodoXPos_vs_bgoLRAsymm;
TH2F* h_hodoY_vs_calo;
h_hodoY_vs_calo=new TH2F("hodoY_vs_calo","hodoY_vs_calo",4096,-0.5,4095.5,4096,-0.5,4095.5);
outObjects[TString("CORRCALOHODO_")+TString(h_hodoY_vs_calo->GetName())]=(TObject*)h_hodoY_vs_calo;
TH2F* h_hodoYPos_vs_bgoUDAsymm;
h_hodoYPos_vs_bgoUDAsymm=new TH2F("hodoY_vs_bgoUDAsymm","hodoYPos_vs_bgoUDAsymm",200,-1.,1.,200,0.,HODOY_CHANNELS);
outObjects[TString("HODO_")+TString(h_hodoYPos_vs_bgoUDAsymm->GetName())]=(TObject*)h_hodoYPos_vs_bgoUDAsymm;
TH2F* h_centerXTagger_vs_calo;
h_centerXTagger_vs_calo=new TH2F("centerXTagger_vs_calo","centerXTagger_vs_calo",4096,-0.5,4095.5,4096,-0.5,4095.5);
outObjects[TString("CORRCALOCENTERTAGGER_")+TString(h_centerXTagger_vs_calo->GetName())]=(TObject*)h_centerXTagger_vs_calo;
TH2F* h_centerYTagger_vs_calo;
h_centerYTagger_vs_calo=new TH2F("centerYTagger_vs_calo","centerYTagger_vs_calo",4096,-0.5,4095.5,4096,-0.5,4095.5);
outObjects[TString("CORRCALOCENTERTAGGER_")+TString(h_centerYTagger_vs_calo->GetName())]=(TObject*)h_centerYTagger_vs_calo;
TH2F* h_scintFront_vs_calo;
h_scintFront_vs_calo=new TH2F("scintFront_vs_calo","scintFront_vs_calo",4096,-0.5,4095.5,4096,-0.5,4095.5);
outObjects[TString("CORRSCINTCALO_")+TString(h_scintFront_vs_calo->GetName())]=(TObject*)h_scintFront_vs_calo;
TH2F* h_scintBack_vs_calo;
h_scintBack_vs_calo=new TH2F("scintBack_vs_calo","scintBack_vs_calo",4096,-0.5,4095.5,4096,-0.5,4095.5);
outObjects[TString("CORRSCINTCALO_")+TString(h_scintBack_vs_calo->GetName())]=(TObject*)h_scintBack_vs_calo;
//Stability plots (1 point every 5 minutes)
TH1F* h_nTriggersTimeProfile;
h_nTriggersTimeProfile=new TH1F("nTriggersTimeProfile","nTriggersTimeProfile",TIME_MAX_INTERVALS,-0.5,TIME_MAX_INTERVALS-0.5);
outObjects[TString("TIMEPROFILETRIG_")+TString(h_nTriggersTimeProfile->GetName())]=(TObject*)h_nTriggersTimeProfile;
TH1F* h_rateTimeProfile;
h_rateTimeProfile=new TH1F("rateTimeProfile","rateTimeProfile",TIME_MAX_INTERVALS,-0.5,TIME_MAX_INTERVALS-0.5);
outObjects[TString("TIMEPROFILETRIG_")+TString(h_rateTimeProfile->GetName())]=(TObject*)h_rateTimeProfile;
TH1F* h_bgoEnergyTimeProfile;
h_bgoEnergyTimeProfile=new TH1F("bgoEnergyTimeProfile","bgoEnergyTimeProfile",TIME_MAX_INTERVALS,-0.5,TIME_MAX_INTERVALS-0.5);
outObjects[TString("TIMEPROFILECALO_")+TString(h_bgoEnergyTimeProfile->GetName())]=(TObject*)h_bgoEnergyTimeProfile;
TH1F* h_cef3EnergyTimeProfile;
h_cef3EnergyTimeProfile=new TH1F("cef3EnergyTimeProfile","cef3EnergyTimeProfile",TIME_MAX_INTERVALS,-0.5,TIME_MAX_INTERVALS-0.5);
outObjects[TString("TIMEPROFILECALO_")+TString(h_cef3EnergyTimeProfile->GetName())]=(TObject*)h_cef3EnergyTimeProfile;
TH1F* h_caloEnergyTimeProfile;
h_caloEnergyTimeProfile=new TH1F("caloEnergyTimeProfile","caloEnergyTimeProfile",TIME_MAX_INTERVALS,-0.5,TIME_MAX_INTERVALS-0.5);
outObjects[TString("TIMEPROFILECALO_")+TString(h_caloEnergyTimeProfile->GetName())]=(TObject*)h_caloEnergyTimeProfile;
TH1F* h_hodoXEnergyTimeProfile;
h_hodoXEnergyTimeProfile=new TH1F("hodoXEnergyTimeProfile","hodoXEnergyTimeProfile",TIME_MAX_INTERVALS,-0.5,TIME_MAX_INTERVALS-0.5);
outObjects[TString("TIMEPROFILEHODO_")+TString(h_hodoXEnergyTimeProfile->GetName())]=(TObject*)h_hodoXEnergyTimeProfile;
TH1F* h_hodoXPosTimeProfile;
h_hodoXPosTimeProfile=new TH1F("hodoXPosTimeProfile","hodoXPosTimeProfile",TIME_MAX_INTERVALS,-0.5,TIME_MAX_INTERVALS-0.5);
outObjects[TString("TIMEPROFILEHODO_")+TString(h_hodoXPosTimeProfile->GetName())]=(TObject*)h_hodoXPosTimeProfile;
TH1F* h_hodoYEnergyTimeProfile;
h_hodoYEnergyTimeProfile=new TH1F("hodoYEnergyTimeProfile","hodoYEnergyTimeProfile",TIME_MAX_INTERVALS,-0.5,TIME_MAX_INTERVALS-0.5);
outObjects[TString("TIMEPROFILEHODO_")+TString(h_hodoYEnergyTimeProfile->GetName())]=(TObject*)h_hodoYEnergyTimeProfile;
TH1F* h_hodoYPosTimeProfile;
h_hodoYPosTimeProfile=new TH1F("hodoYPosTimeProfile","hodoYPosTimeProfile",TIME_MAX_INTERVALS,-0.5,TIME_MAX_INTERVALS-0.5);
outObjects[TString("TIMEPROFILEHODO_")+TString(h_hodoYPosTimeProfile->GetName())]=(TObject*)h_hodoYPosTimeProfile;
TH1F* h_centerXTaggerEnergyTimeProfile;
h_centerXTaggerEnergyTimeProfile=new TH1F("centerXTaggerEnergyTimeProfile","centerXTaggerEnergyTimeProfile",TIME_MAX_INTERVALS,-0.5,TIME_MAX_INTERVALS-0.5);
outObjects[TString("TIMEPROFILECENTERTAGGER_")+TString(h_centerXTaggerEnergyTimeProfile->GetName())]=(TObject*)h_centerXTaggerEnergyTimeProfile;
TH1F* h_centerYTaggerEnergyTimeProfile;
h_centerYTaggerEnergyTimeProfile=new TH1F("centerYTaggerEnergyTimeProfile","centerYTaggerEnergyTimeProfile",TIME_MAX_INTERVALS,-0.5,TIME_MAX_INTERVALS-0.5);
outObjects[TString("TIMEPROFILECENTERTAGGER_")+TString(h_centerYTaggerEnergyTimeProfile->GetName())]=(TObject*)h_centerYTaggerEnergyTimeProfile;
TH1F* h_scintFrontEnergyTimeProfile;
h_scintFrontEnergyTimeProfile=new TH1F("scintFrontEnergyTimeProfile","scintFrontEnergyTimeProfile",TIME_MAX_INTERVALS,-0.5,TIME_MAX_INTERVALS-0.5);
outObjects[TString("TIMEPROFILESCINT_")+TString(h_scintFrontEnergyTimeProfile->GetName())]=(TObject*)h_scintFrontEnergyTimeProfile;
TH1F* h_scintBackEnergyTimeProfile;
h_scintBackEnergyTimeProfile=new TH1F("scintBackEnergyTimeProfile","scintBackEnergyTimeProfile",TIME_MAX_INTERVALS,-0.5,TIME_MAX_INTERVALS-0.5);
outObjects[TString("TIMEPROFILESCINT_")+TString(h_scintBackEnergyTimeProfile->GetName())]=(TObject*)h_scintBackEnergyTimeProfile;
std::cout << "==================== Booked histograms =======================" << std::endl;
for (std::map<TString,TObject*>::const_iterator out=outObjects.begin();out!=outObjects.end();++out)
std::cout << out->second->GetName() << std::endl;
std::cout << "==================== Loop over events =======================" << std::endl;
if (fChain == 0) return;
Long64_t nentries = fChain->GetEntriesFast();
Long64_t nbytes = 0, nb = 0;
unsigned int startTimeStamp=0;
unsigned int oldTime=0;
for (Long64_t jentry=0; jentry<nentries;jentry++) {
Long64_t ientry = LoadTree(jentry);
if (jentry%1000==0)
std::cout << "Analysing event " << jentry << std::endl;
if (ientry < 0) break;
nb = fChain->GetEntry(jentry); nbytes += nb;
unsigned int itime=0;
if (jentry==0)
{
startTimeStamp=evtTime;
std::cout << "First event taken @ timestamp (days from 01/04/2014) " << ((float)startTimeStamp/1000.)/86400. << std::endl;
}
if (startTimeStamp>0 && evtTime>0)
itime=(evtTime-startTimeStamp)/(TIME_INTERVAL_SIZE); //binning time 5minutes interval (expect of the order od 25Hz*60*5 triggers in this range)
if (jentry%100==0 && jentry>0)
{
rate_TimeAverage.addMeasure(itime,1.e2*1.e3/(double)(evtTime-oldTime));
oldTime=evtTime;
}
nTriggers[itime]++;
float bgoEnergy=0,bgoLeftEnergy=0,bgoRightEnergy=0,bgoUpEnergy=0,bgoDownEnergy=0,
cef3Energy=0,caloEnergy=0,
hodoXEnergy=0,hodoYEnergy=0,centerXTaggerEnergy=0,centerYTaggerEnergy=0,scintFrontEnergy=0,scintBackEnergy=0;
float hodoXPos=0,hodoYPos=0;
//Loop over adc channels
for (int i=0;i<NUM_ADC_CHANNELS;++i)
{
//Checking that everything makes sense
if (adcData[i]<0 || adcData[i]>4095)
std::cout << "WARNING ADC value outside ADC 12bit range!" << std::endl;
if (adcBoard[i]>1 && adcBoard[i]<0)
std::cout << "WARNING ADC board is unknown!" << std::endl;
if (adcChannel[i]<0)
std::cout << "WARNING ADC channel is unknown!" << std::endl;
if ( (adcBoard[i]==0 && adcChannel[i]>7) || (adcBoard[i]==1 && adcChannel[i]>31))
std::cout << "WARNING ADC channel is unknown!" << std::endl;
// BGO plots
if (adcBoard[i]==BGO_ADC_BOARD && (adcChannel[i]>=BGO_ADC_START_CHANNEL && adcChannel[i]<=BGO_ADC_END_CHANNEL) )
{
float thisBGO = (adcData[i]-bgoPedMean[adcChannel[i]-BGO_ADC_START_CHANNEL])
* bgoIntercalibration[adcChannel[i]-BGO_ADC_START_CHANNEL];
bgoEnergy+= thisBGO;
if (isInBGOUpRow(adcChannel[i]-BGO_ADC_START_CHANNEL))
bgoUpEnergy+=thisBGO;
if (isInBGODownRow(adcChannel[i]-BGO_ADC_START_CHANNEL))
bgoDownEnergy+=thisBGO;
if (isInBGORightRow(adcChannel[i]-BGO_ADC_START_CHANNEL))
bgoRightEnergy+=thisBGO;
if (isInBGOLeftRow(adcChannel[i]-BGO_ADC_START_CHANNEL))
bgoLeftEnergy+=thisBGO;
// single channel spectrum
h_bgoRawSpectrum[adcChannel[i]-BGO_ADC_START_CHANNEL]->Fill(adcData[i]);
h_bgoCorSpectrum[adcChannel[i]-BGO_ADC_START_CHANNEL]->Fill(adcData[i]-bgoPedMean[adcChannel[i]-BGO_ADC_START_CHANNEL]);
}
else if (adcBoard[i]==CEF3_ADC_BOARD && (adcChannel[i]>=CEF3_ADC_START_CHANNEL && adcChannel[i]<=CEF3_ADC_END_CHANNEL) )
{
cef3Energy+=(adcData[i]-cef3PedMean[adcChannel[i]-CEF3_ADC_START_CHANNEL])
*cef3Intercalibration[adcChannel[i]-CEF3_ADC_START_CHANNEL];
h_cef3RawSpectrum[adcChannel[i]-CEF3_ADC_START_CHANNEL]->Fill(adcData[i]);
h_cef3CorSpectrum[adcChannel[i]-CEF3_ADC_START_CHANNEL]->Fill(adcData[i]-cef3PedMean[adcChannel[i]-CEF3_ADC_START_CHANNEL]);
}
else if (adcBoard[i]==HODOX_ADC_BOARD && (adcChannel[i]>=HODOX_ADC_START_CHANNEL && adcChannel[i]<=HODOX_ADC_END_CHANNEL) )
{
hodoXEnergy+=(adcData[i]-hodoXPedMean[adcChannel[i]-HODOX_ADC_START_CHANNEL])
*hodoXIntercalibration[adcChannel[i]-HODOX_ADC_START_CHANNEL];
hodoXPos+=(adcChannel[i]-HODOX_ADC_START_CHANNEL)*adcData[i]*hodoXIntercalibration[adcChannel[i]-HODOX_ADC_START_CHANNEL];
h_hodoXRawSpectrum[adcChannel[i]-HODOX_ADC_START_CHANNEL]->Fill(adcData[i]);
h_hodoXCorSpectrum[adcChannel[i]-HODOX_ADC_START_CHANNEL]->Fill(adcData[i]-hodoXPedMean[adcChannel[i]-HODOX_ADC_START_CHANNEL]);
}
else if (adcBoard[i]==HODOY_ADC_BOARD && (adcChannel[i]>=HODOY_ADC_START_CHANNEL && adcChannel[i]<=HODOY_ADC_END_CHANNEL) )
{
hodoYEnergy+=(adcData[i]-hodoYPedMean[adcChannel[i]-HODOY_ADC_START_CHANNEL])
*hodoYIntercalibration[adcChannel[i]-HODOY_ADC_START_CHANNEL];
hodoYPos+=(adcChannel[i]-HODOY_ADC_START_CHANNEL)*adcData[i]*hodoYIntercalibration[adcChannel[i]-HODOY_ADC_START_CHANNEL];
h_hodoYRawSpectrum[adcChannel[i]-HODOY_ADC_START_CHANNEL]->Fill(adcData[i]);
h_hodoYCorSpectrum[adcChannel[i]-HODOY_ADC_START_CHANNEL]->Fill(adcData[i]-hodoYPedMean[adcChannel[i]-HODOY_ADC_START_CHANNEL]);
}
else if (adcBoard[i]==CENTERX_TAGGER_ADC_BOARD && (adcChannel[i]>=CENTERX_TAGGER_ADC_START_CHANNEL && adcChannel[i]<=CENTERX_TAGGER_ADC_END_CHANNEL) )
{
centerXTaggerEnergy+=adcData[i]*centerXTaggerIntercalibration[adcChannel[i]-CENTERX_TAGGER_ADC_START_CHANNEL];
h_centerXTaggerRawSpectrum[adcChannel[i]-CENTERX_TAGGER_ADC_START_CHANNEL]->Fill(adcData[i]);
}
else if (adcBoard[i]==CENTERY_TAGGER_ADC_BOARD && (adcChannel[i]>=CENTERY_TAGGER_ADC_START_CHANNEL && adcChannel[i]<=CENTERY_TAGGER_ADC_END_CHANNEL) )
{
centerYTaggerEnergy+=adcData[i]*centerYTaggerIntercalibration[adcChannel[i]-CENTERY_TAGGER_ADC_START_CHANNEL];
h_centerYTaggerRawSpectrum[adcChannel[i]-CENTERY_TAGGER_ADC_START_CHANNEL]->Fill(adcData[i]);
}
else if (adcBoard[i]==SCINT_FRONT_ADC_BOARD && adcChannel[i]==SCINT_FRONT_ADC_CHANNEL )
{
scintFrontEnergy=adcData[i];
h_scintFrontRawSpectrum->Fill(adcData[i]);
}
else if (adcBoard[i]==SCINT_BACK_ADC_BOARD && adcChannel[i]==SCINT_BACK_ADC_CHANNEL )
{
scintBackEnergy=adcData[i];
h_scintBackRawSpectrum->Fill(adcData[i]);
}
else
{
//unused channel
}
}
caloEnergy=bgoEnergy+cef3Energy;
hodoXPos=hodoXPos/hodoXEnergy;
hodoYPos=hodoYPos/hodoYEnergy;
//Fill energy plots
h_bgoEnergy->Fill(bgoEnergy);
h_bgoEnergyUp->Fill(bgoUpEnergy);
h_bgoEnergyDown->Fill(bgoDownEnergy);
h_bgoEnergyLeft->Fill(bgoLeftEnergy);
h_bgoEnergyRight->Fill(bgoRightEnergy);
h_cef3Energy->Fill(cef3Energy);
h_caloEnergy->Fill(caloEnergy);
h_hodoXEnergy->Fill(hodoXEnergy);
h_hodoYEnergy->Fill(hodoYEnergy);
h_centerXTaggerEnergy->Fill(centerXTaggerEnergy);
h_centerYTaggerEnergy->Fill(centerYTaggerEnergy);
//Fill position plots
h_hodoXPos->Fill(hodoXPos);
h_hodoYPos->Fill(hodoYPos);
//Fill time averages
bgoEnergy_TimeAverage.addMeasure(itime,bgoEnergy);
cef3Energy_TimeAverage.addMeasure(itime,cef3Energy);
caloEnergy_TimeAverage.addMeasure(itime,caloEnergy);
hodoXEnergy_TimeAverage.addMeasure(itime,hodoXEnergy);
hodoYEnergy_TimeAverage.addMeasure(itime,hodoYEnergy);
hodoXPos_TimeAverage.addMeasure(itime,hodoXPos);
hodoYPos_TimeAverage.addMeasure(itime,hodoYPos);
centerXTaggerEnergy_TimeAverage.addMeasure(itime,centerXTaggerEnergy);
centerYTaggerEnergy_TimeAverage.addMeasure(itime,centerYTaggerEnergy);
scintFrontEnergy_TimeAverage.addMeasure(itime,scintFrontEnergy);
scintBackEnergy_TimeAverage.addMeasure(itime,scintBackEnergy);
//Fill correlation plots
h_bgo_vs_cef3->Fill(cef3Energy,bgoEnergy);
h_hodoX_vs_calo->Fill(caloEnergy,hodoXEnergy);
h_hodoXPos_vs_bgoLRAsymm->Fill((bgoLeftEnergy-bgoRightEnergy)/(bgoLeftEnergy+bgoRightEnergy),hodoXPos);
h_hodoYPos_vs_bgoUDAsymm->Fill((bgoUpEnergy-bgoDownEnergy)/(bgoUpEnergy+bgoDownEnergy),hodoYPos);
h_hodoY_vs_calo->Fill(caloEnergy,hodoYEnergy);
h_centerXTagger_vs_calo->Fill(caloEnergy,centerXTaggerEnergy);
h_centerYTagger_vs_calo->Fill(caloEnergy,centerYTaggerEnergy);
h_scintFront_vs_calo->Fill(caloEnergy,scintFrontEnergy);
h_scintBack_vs_calo->Fill(caloEnergy,scintBackEnergy);
}
//Fill profile histograms
for (unsigned int i(0); i<BGO_CHANNELS;++i)
{
float mean=h_bgoRawSpectrum[i]->GetMean();
float rms=h_bgoRawSpectrum[i]->GetRMS();
h_bgoEnergyProfile->SetBinContent(i+1,mean);
h_bgoEnergyProfile->SetBinError(i+1,rms);
}
for (unsigned int i(0); i<CEF3_CHANNELS;++i)
{
float mean=h_cef3RawSpectrum[i]->GetMean();
float rms=h_cef3RawSpectrum[i]->GetRMS();
h_cef3EnergyProfile->SetBinContent(i+1,mean);
h_cef3EnergyProfile->SetBinError(i+1,rms);
}
for (unsigned int i(0); i<HODOX_CHANNELS;++i)
{
float eventsAbobePedestal=h_hodoXCorSpectrum[i]->Integral(10,50);
// float rms=h_hodoXRawSpectrum[i]->GetRMS();
h_hodoXEnergyProfile->SetBinContent(i+1,eventsAbobePedestal);
h_hodoXEnergyProfile->SetBinError(i+1,sqrt(eventsAbobePedestal));
}
TF1* fitFuncHodo=new TF1("fitFuncHodo","pol0+gaus(1)",0.,8.);
float avgY = 0.;
for(unsigned int i(0); i<HODOX_CHANNELS; i++)
avgY+= h_hodoXEnergyProfile->GetBinContent(i+1);
avgY /= HODOX_CHANNELS;
fitFuncHodo->SetParameter(1,avgY);
fitFuncHodo->SetParameter(2,h_hodoXEnergyProfile->GetMean());
fitFuncHodo->SetParameter(3,h_hodoXEnergyProfile->GetRMS());
std::cout << " Fitting h_hodoXEnergyProfile" << std::endl;
h_hodoXEnergyProfile->Fit(fitFuncHodo,"RL+","",0.,8.);
for (unsigned int i(0); i<HODOY_CHANNELS;++i)
{
float eventsAbobePedestal=h_hodoYCorSpectrum[i]->Integral(10,50);
// float rms=h_hodoYRawSpectrum[i]->GetRMS();
h_hodoYEnergyProfile->SetBinContent(i+1,eventsAbobePedestal);
h_hodoYEnergyProfile->SetBinError(i+1,sqrt(eventsAbobePedestal));
}
avgY = 0.;
for(unsigned int i(0); i<HODOY_CHANNELS; i++)
avgY+= h_hodoYEnergyProfile->GetBinContent(i+1);
avgY /= HODOY_CHANNELS;
fitFuncHodo->SetParameter(1,avgY);
fitFuncHodo->SetParameter(2,h_hodoYEnergyProfile->GetMean());
fitFuncHodo->SetParameter(3,h_hodoYEnergyProfile->GetRMS());
std::cout << " Fitting h_hodoYEnergyProfile" << std::endl;
h_hodoYEnergyProfile->Fit(fitFuncHodo,"RL+","",0.,8.);
for (unsigned int i(0); i<CENTERX_TAGGER_CHANNELS;++i)
{
float mean=h_centerXTaggerRawSpectrum[i]->GetMean();
float rms=h_centerXTaggerRawSpectrum[i]->GetRMS();
h_centerXTaggerEnergyProfile->SetBinContent(i+1,mean);
h_centerXTaggerEnergyProfile->SetBinError(i+1,rms);
}
for (unsigned int i(0); i<CENTERY_TAGGER_CHANNELS;++i)
{
float mean=h_centerYTaggerRawSpectrum[i]->GetMean();
float rms=h_centerYTaggerRawSpectrum[i]->GetRMS();
h_centerYTaggerEnergyProfile->SetBinContent(i+1,mean);
h_centerYTaggerEnergyProfile->SetBinError(i+1,rms);
}
//Calculate & fill time profile histograms
for (unsigned int i(0);i<TIME_MAX_INTERVALS;++i)
if (nTriggers[i]>0)
{
h_nTriggersTimeProfile->SetBinContent(i+1,nTriggers[i]);
h_nTriggersTimeProfile->SetBinError(i+1,TMath::Sqrt(nTriggers[i]));
}
rate_TimeAverage.calculateAverages();
fillTimeProfile(rate_TimeAverage,h_rateTimeProfile);
bgoEnergy_TimeAverage.calculateAverages();
fillTimeProfile(bgoEnergy_TimeAverage,h_bgoEnergyTimeProfile);
cef3Energy_TimeAverage.calculateAverages();
fillTimeProfile(cef3Energy_TimeAverage,h_cef3EnergyTimeProfile);
caloEnergy_TimeAverage.calculateAverages();
fillTimeProfile(caloEnergy_TimeAverage,h_caloEnergyTimeProfile);
hodoXEnergy_TimeAverage.calculateAverages();
fillTimeProfile(hodoXEnergy_TimeAverage,h_hodoXEnergyTimeProfile);
hodoXPos_TimeAverage.calculateAverages();
fillTimeProfile(hodoXPos_TimeAverage,h_hodoXPosTimeProfile);
hodoYEnergy_TimeAverage.calculateAverages();
fillTimeProfile(hodoYEnergy_TimeAverage,h_hodoYEnergyTimeProfile);
hodoYPos_TimeAverage.calculateAverages();
fillTimeProfile(hodoYPos_TimeAverage,h_hodoYPosTimeProfile);
centerXTaggerEnergy_TimeAverage.calculateAverages();
fillTimeProfile(centerXTaggerEnergy_TimeAverage,h_centerXTaggerEnergyTimeProfile);
centerYTaggerEnergy_TimeAverage.calculateAverages();
fillTimeProfile(centerYTaggerEnergy_TimeAverage,h_centerYTaggerEnergyTimeProfile);
scintFrontEnergy_TimeAverage.calculateAverages();
fillTimeProfile(scintFrontEnergy_TimeAverage,h_scintFrontEnergyTimeProfile);
scintBackEnergy_TimeAverage.calculateAverages();
fillTimeProfile(scintBackEnergy_TimeAverage,h_scintBackEnergyTimeProfile);
TFile *fOut=new TFile(outFile.c_str(),"RECREATE");
if (!fOut || !fOut->IsOpen()) {
std::cout << "outFile " << outFile << " cannot be opened. Giving up" << std::endl;
return;
}
std::cout << "==================== Saving histograms =======================" << std::endl;
std::cout << "outFile " << outFile << " opened" << std::endl;
fOut->cd();
for (std::map<TString,TObject*>::const_iterator out=outObjects.begin();out!=outObjects.end();++out)
out->second->Write(out->first);
fOut->Close();
std::cout << "outFile " << outFile << " closed" << std::endl;
std::cout << "==================== DQM analysis is done =======================" << std::endl;
}