forked from alisw/AliRoot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTOFcalibAPI.C
1547 lines (1314 loc) · 50.7 KB
/
TOFcalibAPI.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
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* calibapi.cxx
* set of functions to read TOFcompactCalib data and
* deal with TOF calibration in a centralized way
*/
#include <stdio.h>
#include <signal.h>
#define MAXHITS 100000
#define MAXPOINTS 100000
/* input data */
TFile *datafile = NULL;
TTree *datatree = NULL;
Int_t nevents = 0;
Int_t curev = 0;
Int_t runNb = 0;
UInt_t timestamp = 0;
Float_t vertex = 0.;
Float_t timezero = 0.;
Int_t nhits = 0;
Float_t momentum[MAXHITS];
Float_t length[MAXHITS];
Int_t index[MAXHITS];
Float_t time[MAXHITS];
Float_t tot[MAXHITS];
Float_t texp[MAXHITS];
/* calib histos */
enum EParam_t {
kTRM,
kFEA,
kChannel,
kNParams
};
const Char_t *paramName[kNParams] = {"trm", "fea", "channel"};
Int_t paramBins[kNParams] = {720, 6552, 157248};
Float_t paramMin[kNParams] = {0., 0., 0.};
Float_t paramMax[kNParams] = {720., 6552., 157248.};
Int_t deltatBins = 201;
Float_t deltatMin = -2440. - 12.2;
Float_t deltatMax = 2440. + 12.2;
Int_t totBins = 400;
Float_t totMin = 4.88;
Float_t totMax = 24.4;
UInt_t timeZeroSampling = 600; /* seconds */
UInt_t timeMin = 0;
UInt_t timeMax = 0;
UInt_t timeBins = 0;
TH2F *hFEAHitMap = NULL;
TH2F *hChannelHitMap = NULL;
TH2F *hTimeZeroFillHisto = NULL;
TH1F *hTimeZeroFill_mean = NULL;
TH1F *hTimeZeroFill_sigma = NULL;
TProfile *hTimePressureHisto = NULL;
TH2F *hCalibHisto[kNParams] = {NULL, NULL, NULL};
TH1F *hCalibParam_mean[kNParams] = {NULL, NULL, NULL};
TH1F *hCalibParam_sigma[kNParams] = {NULL, NULL, NULL};
TH1F *hChannelParam_mean = NULL;
TH1F *hChannelParam_sigma = NULL;
TH2F *hPerfHistoDeltaT = NULL;
TH2F *hPerfHistoBeta = NULL;
AliTOFcalibHisto *calibHisto = NULL;
/* other */
#define MAXRUNS 1000000
AliLHCClockPhase *lhcClockPhase[MAXRUNS];
AliDCSSensor *cavernPressure[MAXRUNS];
/* monitoring */
TStopwatch stopwatch;
//_____________________________________________________________
Bool_t init()
{
AliCDBManager *cdb = AliCDBManager::Instance();
cdb->SetDefaultStorage("raw://");
/* loop over events */
printf("init: loop over events\n");
for (curev = 0; curev < nevents; curev++) {
/* get and check event */
datatree->GetEvent(curev);
if (cdb->GetRun() == runNb) continue;
/* set run and read GRP */
cdb->SetRun(runNb);
/* get LHC clock-phase */
AliCDBEntry *cdbe = (AliCDBEntry *)cdb->Get("GRP/Calib/LHCClockPhase");
lhcClockPhase[runNb] = (AliLHCClockPhase *)cdbe->GetObject();
}
return kFALSE;
}
//_____________________________________________________________
Bool_t
runCalib(const Char_t *filename, const Char_t *paramfilename = NULL, Bool_t useTimeZeroTOF = kFALSE, Bool_t useLHCClockPhase = kFALSE, Bool_t runFix = kTRUE, Int_t nSteps = 2, Int_t evMax = kMaxInt)
{
/* open data */
if (openData(filename, evMax))
return kTRUE;
/* open calib params */
if (paramfilename)
if (openCalibParams(paramfilename))
return kTRUE;
/* init if needed */
if (useLHCClockPhase)
init();
/* fill and fit time-zero fill */
deltatMin = -24400. - 122.;
deltatMax = +24400. + 122.;
fillTimeZeroFillHisto(useTimeZeroTOF, useLHCClockPhase);
fitTimeZeroFillHisto();
deltatMin = -2440. - 12.2;
deltatMax = +2440. + 12.2;
fillTimeZeroFillHisto(useTimeZeroTOF, useLHCClockPhase);
fitTimeZeroFillHisto();
writeCalibHistos("calibhistos.step-timezero.root");
writeCalibParams("calibparams.step-timezero.root");
/* fill with extended range and fix what is far away */
if (runFix) {
/* fix up to 250 ns shift */
deltatMin = -244000. - 1220.;
deltatMax = +244000. + 1220.;
fillCalibHistos(useTimeZeroTOF, useLHCClockPhase);
writeCalibHistos("calibhistos.step-fix-250ns.root");
fitCalibHistos(10., 10., 100, kTRUE);
writeCalibParams("calibparams.step-fix-250ns.root");
/* fix up to 25 ns shift */
deltatMin = -24400. - 122.;
deltatMax = +24400. + 122.;
fillCalibHistos(useTimeZeroTOF, useLHCClockPhase);
writeCalibHistos("calibhistos.step-fix-25ns.root");
fitCalibHistos(10., 10., 100, kTRUE);
writeCalibParams("calibparams.step-fix-25ns.root");
}
/* fill and fit with limited range */
deltatMin = -2440. - 12.2;
deltatMax = +2440. + 12.2;
for (Int_t istep = 0; istep < nSteps; istep++) {
fillCalibHistos(useTimeZeroTOF, useLHCClockPhase);
writeCalibHistos(Form("calibhistos.step-%d.root", istep));
fitCalibHistos(3., 2., 100, kFALSE);
writeCalibParams(Form("calibparams.step-%d.root", istep));
}
/* fill and fit common shift */
// fillCalibHistos(kFALSE, useLHCClockPhase);
// writeCalibHistos("calibhistos.step-common.root");
// fitCommonShift();
// writeCalibParams("calibparams.step-common.root");
/* final resuls */
fillCalibHistos(useTimeZeroTOF, useLHCClockPhase);
writeCalibHistos("calibhistos.root");
writeCalibParams("calibparams.root");
return kFALSE;
}
//_____________________________________________________________
Bool_t
checkCalib(const Char_t *filename, const Char_t *paramfilename = NULL, Bool_t useTimeZeroTOF = kFALSE, Bool_t useLHCClockPhase = kFALSE, Bool_t runExtended = kTRUE, Int_t evMax = kMaxInt)
{
/* open data */
if (openData(filename, evMax))
return kTRUE;
/* open calib params */
if (paramfilename)
if (openCalibParams(paramfilename))
return kTRUE;
/* fill and fit time-zero fill */
deltatMin = -24400.;
deltatMax = +24400.;
fillTimeZeroFillHisto(useTimeZeroTOF, useLHCClockPhase);
fitTimeZeroFillHisto();
deltatMin = -2440.;
deltatMax = +2440.;
fillTimeZeroFillHisto(useTimeZeroTOF, useLHCClockPhase);
fitTimeZeroFillHisto();
/* fill with extended range */
if (runExtended) {
deltatMin = -244000.;
deltatMax = +244000.;
fillCalibHistos(useTimeZeroTOF, useLHCClockPhase);
writeCalibHistos("checkcalib.extended-250ns.root");
deltatMin = -24400.;
deltatMax = +24400.;
fillCalibHistos(useTimeZeroTOF, useLHCClockPhase);
writeCalibHistos("checkcalib.extended-25ns.root");
}
/* fill with limited range */
deltatMin = -2440.;
deltatMax = +2440.;
fillCalibHistos(useTimeZeroTOF, useLHCClockPhase);
writeCalibHistos("checkcalib.root");
writeCalibParams("checkcalib.calibparams.root");
return kFALSE;
}
//_____________________________________________________________
Bool_t
checkPerf(const Char_t *filename, const Char_t *paramfilename = NULL, Bool_t useTimeZeroTOF = kFALSE, Bool_t useLHCClockPhase = kFALSE, Int_t evMax = kMaxInt)
{
/* open data */
if (openData(filename, evMax))
return kTRUE;
/* open calib params */
if (paramfilename)
if (openCalibParams(paramfilename))
return kTRUE;
fillTimeZeroFillHisto(useTimeZeroTOF, useLHCClockPhase);
fitTimeZeroFillHisto();
fillPerfHistos(useTimeZeroTOF, useLHCClockPhase);
writePerfHistos("checkperf.root");
return kFALSE;
}
//_____________________________________________________________
Bool_t
openData(const Char_t *filename, Int_t evMax = kMaxInt)
{
/*
* open data
*/
/* open file */
printf("openData: opening file: %s\n", filename);
datafile = TFile::Open(filename);
if (!datafile || !datafile->IsOpen()) {
printf("openData: cannot open file %s\n", filename)
return kTRUE;
}
/* get tree */
datatree = (TTree *)datafile->Get("aodTree");
if (!datatree) {
printf("openData: cannot find \'aodTree\' tree in %s\n", filename);
return kTRUE;
}
nevents = datatree->GetEntries();
printf("openData: got \'aodTree\' tree: %d entries\n", nevents);
if (nevents > evMax) {
printf("openData: setting max event to %d as requested\n", evMax);
nevents = evMax;
}
/* connect inputs */
datatree->SetBranchAddress("run", &runNb);
datatree->SetBranchAddress("timestamp", ×tamp);
datatree->SetBranchAddress("vertex", &vertex);
datatree->SetBranchAddress("timezero", &timezero);
datatree->SetBranchAddress("nhits", &nhits);
datatree->SetBranchAddress("momentum", &momentum);
datatree->SetBranchAddress("length", &length);
datatree->SetBranchAddress("index", &index);
datatree->SetBranchAddress("time", &time);
datatree->SetBranchAddress("tot", &tot);
datatree->SetBranchAddress("texp", &texp);
/* get first event, and retrieve the year */
datatree->GetEvent(0);
TTimeStamp ts(timestamp);
UInt_t year;
ts.GetDate(kTRUE, 0, &year);
TTimeStamp firstTimestamp(year, 1, 1, 0, 0, 0, 0, kTRUE);
TTimeStamp lastTimestamp(year + 1, 1, 1, 0, 0, 0, 0, kTRUE);
timeMin = firstTimestamp.GetTimeSpec().tv_sec;
timeMax = lastTimestamp.GetTimeSpec().tv_sec;
timeBins = (timeMax - timeMin) / timeZeroSampling;
printf("openData: calibration running on %d data\n", year);
return kFALSE;
}
//_____________________________________________________________
Bool_t
acceptEvent(Bool_t useTimeZeroTOF = kFALSE)
{
/*
* acceptEvent
*/
if (useTimeZeroTOF && timezero == 999999.) return kFALSE;
return kTRUE;
}
//_____________________________________________________________
Float_t
getTimeZeroFill(UInt_t ts)
{
/*
* getTimeZeroFill
*/
if (!hTimeZeroFill_mean) return 0.;
Int_t tsbin = hTimeZeroFill_mean->FindBin(ts);
return hTimeZeroFill_mean->GetBinContent(tsbin);
}
//_____________________________________________________________
Float_t
getLHCClockPhase(UInt_t ts)
{
/*
* getLHCClockPhase
*/
return lhcClockPhase[runNb] ? 1.e3 * lhcClockPhase[runNb]->GetPhase(ts) : 0.;
}
//_____________________________________________________________
Float_t
getCalib(Int_t idx)
{
/*
* getCalib
*/
if (!hChannelParam_mean) return 0.;
return hChannelParam_mean->GetBinContent(idx + 1);
}
//_____________________________________________________________
Float_t
getDeltaT(Int_t ihit, Bool_t useTimeZeroTOF = kFALSE, Bool_t useLHCClockPhase = kFALSE)
{
/*
* getDeltaT
*/
Float_t val = time[ihit] - getCalib(index[ihit]) - getTimeZeroFill(timestamp) - texp[ihit];
if (useTimeZeroTOF) val -= timezero ;
if (useLHCClockPhase) val += getLHCClockPhase(timestamp);
return val;
}
//_____________________________________________________________
Float_t
getBeta(Int_t ihit, Bool_t useTimeZeroTOF = kFALSE, Bool_t useLHCClockPhase = kFALSE)
{
/*
* getBeta
*/
Float_t tof = time[ihit] - getCalib(index[ihit]) - getTimeZeroFill(timestamp);
if (useTimeZeroTOF) tof -= timezero ;
if (useLHCClockPhase) tof += getLHCClockPhase(timestamp);
Float_t beta = length[ihit] / tof / 2.99792458000000000e-2;
return beta;
}
//_____________________________________________________________
Float_t
getMass(Int_t ihit, Bool_t useTimeZeroTOF = kFALSE, Bool_t useLHCClockPhase = kFALSE)
{
/*
* getMass
*/
Float_t tof = time[ihit] - getCalib(index[ihit]) - getTimeZeroFill(timestamp);
if (useTimeZeroTOF) tof -= timezero ;
if (useLHCClockPhase) tof += getLHCClockPhase(timestamp);
Float_t beta = length[ihit] / tof / 2.99792458000000000e-2;
if (beta > 1.) beta *= -1.
Float_t mass = momentum[ihit] * TMath::Sqrt(1. / (beta * beta) - 1.)
return mass;
}
//_____________________________________________________________
Int_t
getIndex(Int_t param, Int_t idx)
{
/*
* getIndex
*/
if (!calibHisto) {
calibHisto = new AliTOFcalibHisto();
calibHisto->LoadCalibHisto();
}
/* switch param */
Int_t sector, ddl, trm, strip, padx, paramIndex;
switch (param) {
case kTRM:
ddl = calibHisto->GetCalibMap(AliTOFcalibHisto::kDDL, idx);
trm = calibHisto->GetCalibMap(AliTOFcalibHisto::kTRM, idx);
paramIndex = trm + 10 * ddl;
break;
case kFEA:
sector = calibHisto->GetCalibMap(AliTOFcalibHisto::kSector, idx);
strip = calibHisto->GetCalibMap(AliTOFcalibHisto::kSectorStrip, idx);
padx = calibHisto->GetCalibMap(AliTOFcalibHisto::kPadX, idx);
paramIndex = padx / 12 + 4 * strip + 364 * sector;
break;
case kChannel:
paramIndex = idx;
break;
}
return paramIndex;
}
//_____________________________________________________________
Int_t
getHitMapXY(Int_t param, Int_t idx, Float_t *hitmap)
{
/*
* getHitMapXY
*/
if (!calibHisto) {
calibHisto = new AliTOFcalibHisto();
calibHisto->LoadCalibHisto();
}
/* get from calib histo */
Int_t sector, strip, padx, padz, fea;
sector = calibHisto->GetCalibMap(AliTOFcalibHisto::kSector, idx);
strip = calibHisto->GetCalibMap(AliTOFcalibHisto::kSectorStrip, idx);
padx = calibHisto->GetCalibMap(AliTOFcalibHisto::kPadX, idx);
padz = calibHisto->GetCalibMap(AliTOFcalibHisto::kPadZ, idx);
fea = padx / 12;
/* switch param */
switch (param) {
case kFEA:
hitmap[0] = sector + ((Double_t)(3 - fea) + 0.5) / 4.;
hitmap[1] = strip;
break;
case kChannel:
hitmap[0] = sector + ((Double_t)(47 - padx) + 0.5) / 48.;
hitmap[1] = strip + ((Double_t)(padz) + 0.5) / 2.;
break;
default:
hitmap[0] = 0.;
hitmap[1] = 0.;
break;
}
}
//_____________________________________________________________
void
fillTimeZeroFillHisto(Bool_t useTimeZeroTOF = kFALSE, Bool_t useLHCClockPhase = kFALSE)
{
/*
* fillTimeZeroFillHisto
*/
/* create/reset histos */
if (hTimeZeroFillHisto) delete hTimeZeroFillHisto;
hTimeZeroFillHisto = new TH2F("hTimeZeroFillHisto", "", timeBins, timeMin, timeMax, deltatBins, deltatMin, deltatMax);
if (hTimePressureHisto) delete hTimePressureHisto;
hTimePressureHisto = new TProfile("hTimePressureHisto", "", timeBins, timeMin, timeMax);
/* reset and start stopwatch */
stopwatch.Reset();
stopwatch.Start();
/* loop over events */
printf("fillTimeZeroFillHisto: loop over events\n");
if (useTimeZeroTOF)
printf("fillTimeZeroFillHisto: time-zero TOF requested\n");
else
printf("fillTimeZeroFillHisto: not using time-zero TOF\n");
if (useLHCClockPhase)
printf("fillTimeZeroFillHisto: BPTX clock-phase requested\n");
else
printf("fillTimeZeroFillHisto: not using BPTX clock-phase\n");
Float_t hitmap[2], deltat;
for (curev = 0; curev < nevents; curev++) {
/* get and check event */
datatree->GetEvent(curev);
if (!acceptEvent(useTimeZeroTOF)) continue;
/* loop over hits */
for (Int_t ihit = 0; ihit < nhits; ihit++) {
deltat = getDeltaT(ihit, useTimeZeroTOF, useLHCClockPhase);
/* fill histos */
hTimeZeroFillHisto->Fill(timestamp, deltat);
} /* end of loop over hits */
} /* end of loop over events */
/* print monitor */
monitor();
}
//_____________________________________________________________
void
fillCalibHistos(Bool_t useTimeZeroTOF = kFALSE, Bool_t useLHCClockPhase = kFALSE)
{
/*
* fillCalibHistos
*/
/* create/reset histos */
if (!hFEAHitMap)
hFEAHitMap = new TH2F("hFEAHitMap", "", 72, 0., 18., 91, 0., 91.);
else
hFEAHitMap->Reset();
if (!hChannelHitMap)
hChannelHitMap = new TH2F("hChannelHitMap", "", 864, 0., 18., 91, 0., 91.);
else
hChannelHitMap->Reset();
for (Int_t iparam = 0; iparam < kNParams; iparam++) {
if (hCalibHisto[iparam]) delete hCalibHisto[iparam];
hCalibHisto[iparam] = new TH2F(Form("hCalibHisto_%s", paramName[iparam]), "", paramBins[iparam], paramMin[iparam], paramMax[iparam], deltatBins, deltatMin, deltatMax);
}
/* reset and start stopwatch */
stopwatch.Reset();
stopwatch.Start();
/* loop over events */
printf("fillCalibHistos: loop over events\n");
if (useTimeZeroTOF)
printf("fillCalibHistos: time-zero TOF requested\n");
else
printf("fillCalibHistos: not using time-zero TOF\n");
if (useLHCClockPhase)
printf("fillCalibHistos: BPTX clock-phase requested\n");
else
printf("fillCalibHistos: not using BPTX clock-phase\n");
Float_t hitmap[2], deltat;
for (curev = 0; curev < nevents; curev++) {
/* get and check event */
datatree->GetEvent(curev);
if (!acceptEvent(useTimeZeroTOF)) continue;
/* loop over hits */
for (Int_t ihit = 0; ihit < nhits; ihit++) {
deltat = getDeltaT(ihit, useTimeZeroTOF, useLHCClockPhase);
/* fill histos */
getHitMapXY(kFEA, index[ihit], hitmap);
hFEAHitMap->Fill(hitmap[0], hitmap[1]);
getHitMapXY(kChannel, index[ihit], hitmap);
hChannelHitMap->Fill(hitmap[0], hitmap[1]);
for (Int_t iparam = 0; iparam < kNParams; iparam++) {
hCalibHisto[iparam]->Fill(getIndex(iparam, index[ihit]), deltat);
}
} /* end of loop over hits */
} /* end of loop over events */
/* print monitor */
monitor();
}
//_____________________________________________________________
void
fillPerfHistos(Bool_t useTimeZeroTOF = kFALSE, Bool_t useLHCClockPhase = kFALSE)
{
/*
* fillPerfHistos
*/
/* create/reset histos */
if (!hFEAHitMap)
hFEAHitMap = new TH2F("hFEAHitMap", "", 72, 0., 18., 91, 0., 91.);
else
hFEAHitMap->Reset();
if (!hChannelHitMap)
hChannelHitMap = new TH2F("hChannelHitMap", "", 864, 0., 18., 91, 0., 91.);
else
hChannelHitMap->Reset();
if (!hPerfHistoDeltaT)
hPerfHistoDeltaT = new TH2F("hPerfHistoDeltaT", "", 250, 0., 5., 20000, -244000., 244000.);
else
hPerfHistoDeltaT->Reset();
if (!hPerfHistoBeta)
hPerfHistoBeta = new TH2F("hPerfHistoBeta", "", 1000, 0., 10., 2200, 0., 1.1);
else
hPerfHistoBeta->Reset();
/* reset and start stopwatch */
stopwatch.Reset();
stopwatch.Start();
/* loop over events */
printf("fillPerfHistos: loop over events\n");
if (useTimeZeroTOF)
printf("fillPerfHistos: time-zero TOF requested\n");
else
printf("fillPerfHistos: not using time-zero TOF\n");
if (useLHCClockPhase)
printf("fillPerfHisto: BPTX clock-phase requested\n");
else
printf("fillPerfHisto: not using BPTX clock-phase\n");
Float_t hitmap[2], deltat, beta, mass;
for (curev = 0; curev < nevents; curev++) {
/* get and check event */
datatree->GetEvent(curev);
if (!acceptEvent(useTimeZeroTOF)) continue;
/* loop over hits */
for (Int_t ihit = 0; ihit < nhits; ihit++) {
deltat = getDeltaT(ihit, useTimeZeroTOF, useLHCClockPhase);
beta = getBeta(ihit, useTimeZeroTOF, useLHCClockPhase);
// mass = getMass(ihit, useTimeZeroTOF, useLHCClockPhase);
/* fill histos */
getHitMapXY(kFEA, index[ihit], hitmap);
hFEAHitMap->Fill(hitmap[0], hitmap[1]);
getHitMapXY(kChannel, index[ihit], hitmap);
hChannelHitMap->Fill(hitmap[0], hitmap[1]);
hPerfHistoDeltaT->Fill(momentum[ihit], deltat);
hPerfHistoBeta->Fill(momentum[ihit], beta);
// hPerfHistoMass->Fill(p, mass);
} /* end of loop over hits */
} /* end of loop over events */
/* print monitor */
monitor();
}
//_____________________________________________________________
Bool_t
writeCalibHistos(const Char_t *filename)
{
/*
* writeCalibHistos
*/
/* open output file and write */
TFile *fileout = TFile::Open(filename, "RECREATE");
if (!fileout || !fileout->IsOpen()) {
printf("writeCalibHistos: error while opening output file %s\n", filename);
return kTRUE;
}
if (hFEAHitMap) hFEAHitMap->Write();
if (hChannelHitMap) hChannelHitMap->Write();
if (hTimeZeroFillHisto) hTimeZeroFillHisto->Write();
if (hTimePressureHisto) hTimePressureHisto->Write();
for (Int_t iparam = 0; iparam < kNParams; iparam++) {
if (hCalibHisto[iparam]) hCalibHisto[iparam]->Write();
}
fileout->Close();
printf("writeCalibHistos: output written on %s\n", filename);
return kFALSE;
}
//_____________________________________________________________
Bool_t
writePerfHistos(const Char_t *filename)
{
/*
* writePerfHistos
*/
/* open output file and write */
TFile *fileout = TFile::Open(filename, "RECREATE");
if (!fileout || !fileout->IsOpen()) {
printf("writePerfHistos: error while opening output file %s\n", filename);
return kTRUE;
}
if (hFEAHitMap) hFEAHitMap->Write();
if (hChannelHitMap) hChannelHitMap->Write();
if (hPerfHistoDeltaT) hPerfHistoDeltaT->Write();
if (hPerfHistoBeta) hPerfHistoBeta->Write();
fileout->Close();
printf("writePerfHistos: output written on %s\n", filename);
return kFALSE;
}
//_____________________________________________________________
Bool_t
writeCalibParams(const Char_t *filename)
{
/*
* writeCalibParams
*/
/* open output file and write */
TFile *fileout = TFile::Open(filename, "RECREATE");
if (!fileout || !fileout->IsOpen()) {
printf("writeCalibParams: error while opening output file %s\n", filename);
return kTRUE;
}
if (hTimeZeroFill_mean) hTimeZeroFill_mean->Write();
if (hTimeZeroFill_sigma) hTimeZeroFill_sigma->Write();
for (Int_t iparam = 0; iparam < kNParams; iparam++) {
if (hCalibParam_mean[iparam]) hCalibParam_mean[iparam]->Write();
if (hCalibParam_sigma[iparam]) hCalibParam_sigma[iparam]->Write();
}
if (hChannelParam_mean) hChannelParam_mean->Write();
if (hChannelParam_sigma) hChannelParam_sigma->Write();
fileout->Close();
printf("writeCalibParams: output written on %s\n", filename);
return kFALSE;
}
//_____________________________________________________________
Bool_t
openCalibHistos(const Char_t *filename)
{
/*
* openCalibHistos
*/
/* open file and write */
printf("openCalibHistos: opening file: %s\n", filename);
TFile *filein = TFile::Open(filename);
if (!filein || !filein->IsOpen()) {
printf("openCalibHistos: cannot open file %s\n", filename);
return kTRUE;
}
/* time-zero fill */
if (hTimeZeroFillHisto) {
printf("openCalibHistos: histo \'hTimeZeroFillHisto\' will be replaced\n");
delete hTimeZeroFillHisto;
}
hTimeZeroFillHisto = (TH2F *)filein->Get("hTimeZeroFillHisto");
if (!hTimeZeroFillHisto) {
printf("openCalibHistos: cannot get \'hTimeZeroFillHisto\' from file %s\n", filename);
return kTRUE;
}
printf("openCalibHistos: got \'hTimeZeroFillHisto\' from file\n");
for (Int_t iparam = 0; iparam < kNParams; iparam++) {
/* calib */
if (hCalibHisto[iparam]) {
printf("openCalibHistos: histo \'hCalibHisto_%s\' will be replaced\n", paramName[iparam]);
delete hCalibHisto[iparam];
}
hCalibHisto[iparam] = (TH2F *)filein->Get(Form("hCalibHisto_%s", paramName[iparam]));
if (!hCalibHisto[iparam]) {
printf("openCalibHistos: cannot get \'hCalibHisto_%s\' from file %s\n", paramName[iparam], filename);
return kTRUE;
}
printf("openCalibHistos: got \'hCalibHisto_%s\' from file\n", paramName[iparam]);
}
return kFALSE;
}
//_____________________________________________________________
Bool_t
openCalibParams(const Char_t *filename)
{
/*
* openCalibParams
*/
/* open file */
printf("openCalibParams: opening file: %s\n", filename);
TFile *filein = TFile::Open(filename);
if (!filein || !filein->IsOpen()) {
printf("openCalibParams: cannot open file %s\n", filename);
return kTRUE;
}
/* mean */
if (hChannelParam_mean) {
printf("openCalibParams: histo \'hChannelParam_mean\' will be replaced\n");
delete hChannelParam_mean;
}
hChannelParam_mean = (TH1F *)filein->Get("hChannelParam_mean");
if (!hChannelParam_mean) {
printf("openCalibParams: cannot get \'hChannelParam_mean\' from file %s\n", filename);
return kTRUE;
}
printf("openCalibParams: got \'hChannelParam_mean\' from file\n");
/* sigma */
if (hChannelParam_sigma) {
printf("openCalibParams: histo \'hChannelParam_sigma\' will be replaced\n");
delete hChannelParam_sigma;
}
hChannelParam_sigma = (TH1F *)filein->Get("hChannelParam_sigma");
if (!hChannelParam_sigma) {
printf("openCalibParams: cannot get \'hChannelParam_sigma\' from file %s\n", filename);
return kTRUE;
}
printf("openCalibParams: got \'hChannelParam_sigma\' from file\n");
return kFALSE;
}
//_____________________________________________________________
Bool_t
fitTimeZeroFillHisto(Float_t nSigmaMin = 2., Float_t nSigmaMax = 1., Int_t minIntegral = 1000, Bool_t useMaxBin = kFALSE)
{
/*
* fitTimeZeroFillHisto
*/
// if (!hChannelParam_mean || !hCalibHisto[kChannel]) return kTRUE;
if (!hTimeZeroFill_mean) hTimeZeroFill_mean = new TH1F("hTimeZeroFill_mean", "", timeBins, timeMin, timeMax);
if (!hTimeZeroFill_sigma) hTimeZeroFill_sigma = new TH1F("hTimeZeroFill_sigma", "", timeBins, timeMin, timeMax);
if (useMaxBin)
printf("fitTimeZeroFill: fitting time-zero fill (using max bin, intMin=%d)\n", minIntegral);
else
printf("fitTimeZeroFill: fitting time-zero fill (sigmaMin=%.1f, sigmaMax=%.1f, intMin=%d)\n", nSigmaMin, nSigmaMax, minIntegral);
TF1 *fitFunc = (TF1 *)gROOT->GetFunction("gaus");
for (Int_t ibin = 0; ibin < hTimeZeroFillHisto->GetNbinsX(); ibin++) {
TH1D *hpy = hTimeZeroFillHisto->ProjectionY("hpy", ibin + 1, ibin +1);
if (hpy->GetEntries() <= minIntegral) {
delete hpy;
continue;
}
if (fitPeak(fitFunc, hpy, nSigmaMin, nSigmaMax) != 0) {
delete hpy;
continue;
}
hTimeZeroFill_mean->AddBinContent(ibin + 1, fitFunc->GetParameter(1));
hTimeZeroFill_mean->SetBinError(ibin + 1, fitFunc->GetParError(1));
hTimeZeroFill_sigma->SetBinContent(ibin + 1, fitFunc->GetParameter(2));
hTimeZeroFill_sigma->SetBinError(ibin + 1, fitFunc->GetParError(2));
delete hpy;
}
return kFALSE;
}
//_____________________________________________________________
Bool_t
fitCommonShift(Float_t nSigmaMin = 2., Float_t nSigmaMax = 1., Int_t minIntegral = 1000, Bool_t useMaxBin = kFALSE)
{
/*
* fitCommonShift
*/
if (!hChannelParam_mean || !hCalibHisto[kChannel]) return kTRUE;
if (useMaxBin)
printf("fitCommonShift: fitting common shift (using max bin, intMin=%d)\n", minIntegral);
else
printf("fitCommonShift: fitting common shift (sigmaMin=%.1f, sigmaMax=%.1f, intMin=%d)\n", nSigmaMin, nSigmaMax, minIntegral);
TF1 *fitFunc = (TF1 *)gROOT->GetFunction("gaus");
TH1D *hpy = hCalibHisto[kChannel]->ProjectionY("hpy");
if (hpy->GetEntries() <= minIntegral) {
delete hpy;
continue;
}
if (useMaxBin) {
for (Int_t idx = 0; idx < 157248; idx++)
hChannelParam_mean->AddBinContent(idx + 1, hpy->GetBinCenter(hpy->GetMaximumBin()));
delete hpy;
return kFALSE;
}
if (fitPeak(fitFunc, hpy, nSigmaMin, nSigmaMax) != 0) {
delete hpy;
return kTRUE;
}
for (Int_t idx = 0; idx < 157248; idx++)
hChannelParam_mean->AddBinContent(idx + 1, fitFunc->GetParameter(1));
delete hpy;
return kFALSE;
}
//_____________________________________________________________
Bool_t
fitCalibHistos(Float_t nSigmaMin, Float_t nSigmaMax, Int_t minIntegral, Bool_t useMaxBin)
{
/*
* fitCalibHistos
*/
for (Int_t iparam = 0; iparam < kNParams; iparam++)
fitCalibHisto(iparam, nSigmaMin, nSigmaMax, minIntegral, useMaxBin);
updateChannelParams();
}
//_____________________________________________________________
Bool_t
updateChannelParams()
{
if (!hChannelParam_mean) hChannelParam_mean = new TH1F("hChannelParam_mean", "", paramBins[kChannel], paramMin[kChannel], paramMax[kChannel]);
if (!hChannelParam_sigma) hChannelParam_sigma = new TH1F("hChannelParam_sigma", "", paramBins[kChannel], paramMin[kChannel], paramMax[kChannel]);
Double_t mean, meanerr, sigma, sigmaerr;
for (Int_t idx = 0; idx < 157248; idx++) {
for (Int_t iparam = kNParams - 1; iparam >= 0; iparam--) {
if (!hCalibParam_mean[iparam]) continue;
if (hCalibParam_mean[iparam]->GetBinError(getIndex(iparam, idx) + 1) == 0.) continue;
mean = hCalibParam_mean[iparam]->GetBinContent(getIndex(iparam, idx) + 1);
meanerr = hCalibParam_mean[iparam]->GetBinError(getIndex(iparam, idx) + 1);
sigma = hCalibParam_sigma[iparam]->GetBinContent(getIndex(iparam, idx) + 1);
sigmaerr = hCalibParam_sigma[iparam]->GetBinError(getIndex(iparam, idx) + 1);
hChannelParam_mean->AddBinContent(idx + 1, mean);
hChannelParam_mean->SetBinError(idx + 1, meanerr);
hChannelParam_sigma->SetBinContent(idx + 1, sigma);
hChannelParam_sigma->SetBinError(idx + 1, sigmaerr);
break;
}
}
}
//_____________________________________________________________
Bool_t
fitCalibHisto(Int_t param, Float_t nSigmaMin, Float_t nSigmaMax, Int_t minIntegral, Bool_t useMaxBin)
{
/*
* fitCalibHisto
*/
/* check data histo */
if (!hCalibHisto[param]) {
printf("fitCalibHisto: cannot get \'hCalibHisto_%s\'\n", paramName[param]);
return kTRUE;
}
/* check mean histo */
if (!hCalibParam_mean[param]) hCalibParam_mean[param] = new TH1F(Form("hCalibParam_%s_mean", paramName[param]), "", paramBins[param], paramMin[param], paramMax[param]);
else hCalibParam_mean[param]->Reset();
/* check sigma histo */
if (!hCalibParam_sigma[param]) hCalibParam_sigma[param] = new TH1F(Form("hCalibParam_%s_sigma", paramName[param]), "", paramBins[param], paramMin[param], paramMax[param]);
else hCalibParam_sigma[param]->Reset();
/* fit */
return fitCalibHisto(hCalibHisto[param], hCalibParam_mean[param], hCalibParam_sigma[param], nSigmaMin, nSigmaMax, minIntegral, useMaxBin);
}
//_____________________________________________________________
Bool_t
fitCalibHisto(TH2F *hdata, TH1F *hmean, TH1F *hsigma, Float_t nSigmaMin, Float_t nSigmaMax, Int_t minIntegral, Bool_t useMaxBin)
{
/*
* fitCalibHisto
*/
if (!hdata || !hmean || !hsigma) return kTRUE;
if (useMaxBin)
printf("fitCalibHisto: fitting \'%s\' (using max bin, intMin=%d)\n", hdata->GetName(), minIntegral);
else
printf("fitCalibHisto: fitting \'%s\' (sigmaMin=%.1f, sigmaMax=%.1f, intMin=%d)\n", hdata->GetName(), nSigmaMin, nSigmaMax, minIntegral);
TF1 *fitFunc = (TF1 *)gROOT->GetFunction("gaus");
Int_t nDone = 0;
for (Int_t ibin = 0; ibin < hdata->GetNbinsX(); ibin++) {
TH1D *hpy = hdata->ProjectionY("hpy", ibin + 1, ibin + 1);
if (hpy->GetEntries() <= minIntegral) {
delete hpy;
continue;
}
if (useMaxBin) {
hmean->SetBinContent(ibin + 1, hpy->GetBinCenter(hpy->GetMaximumBin()));
hmean->SetBinError(ibin + 1, hpy->GetBinWidth(hpy->GetMaximumBin()));
hsigma->SetBinContent(ibin + 1, hpy->GetBinWidth(hpy->GetMaximumBin()));
hsigma->SetBinError(ibin + 1, hpy->GetBinWidth(hpy->GetMaximumBin()));
// hmean->SetBinContent(ibin + 1, hpy->GetMean());
// hmean->SetBinError(ibin + 1, hpy->GetMeanError());
// hsigma->SetBinContent(ibin + 1, hpy->GetRMS());
// hsigma->SetBinError(ibin + 1, hpy->GetRMSError());
nDone++;
delete hpy;