forked from rdom/fastpid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprttools.C
1399 lines (1225 loc) · 40.1 KB
/
prttools.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
// prttools - useful functions for hld*, prt*
// original author: Roman Dzhygadlo - GSI Darmstadt
#ifndef prttools_h
#define prttools_h 1
#include "TROOT.h"
#include "TSystem.h"
#include "TStyle.h"
#include "TCanvas.h"
#include "TPad.h"
#include "TH1.h"
#include "TH2.h"
#include "TGraph.h"
#include "TMultiGraph.h"
#include "TSpline.h"
#include "TF1.h"
#include "TFile.h"
#include "TTree.h"
#include "TClonesArray.h"
#include "TVector3.h"
#include "TMath.h"
#include "TChain.h"
#include "TGaxis.h"
#include "TColor.h"
#include "TString.h"
#include "TArrayD.h"
#include "TSpectrum.h"
#include "TSpectrum2.h"
#include "Math/Minimizer.h"
#include "Math/Factory.h"
#include "Math/Functor.h"
#include "TRandom2.h"
#include "TError.h"
#include "TPaveStats.h"
#include "TObjString.h"
#include "TApplication.h"
#include <TLegend.h>
#include <TAxis.h>
#include <TPaletteAxis.h>
#include <TRandom.h>
#include <TCutG.h>
#include <TKey.h>
#include "TPRegexp.h"
#include "TFitResult.h"
#include <iostream>
#include <fstream>
#include <sstream>
#if defined(prt__sim) || defined(prt__beam) || defined(eic__sim)
class PrtRun;
class PrtEvent;
class PrtHit;
PrtEvent* prt_event = 0;
#endif
#if defined(prt__sim) || defined(prt__beam)
#include "datainfo.C"
DataInfo prt_data_info;
#endif
#if defined(eic__sim)
const int prt_nmcp = 4 * 7;
const int prt_npix = 16 * 16;
#else
const int prt_nmcp = 24;// 12; // 12;
const int prt_npix = 16 * 16; // 64
#endif
// const int prt_ntdc=16;
// TString prt_tdcsid[prt_ntdc] ={"10","11","12","13",
// "20","21","22","23",
// "780","781","782","783",
// "840","841","842","843"
// };
//may2015
const int prt_ntdc_may2015=41;
TString prt_tdcsid_may2015[] ={"2000","2001","2002","2003","2004","2005","2006","2007","2008","2009",
"200a","200b","200c","200d","200e","200f","2010","2011","2012","2013",
"2014","2015","2016","2018","2019","201a","201c","2020","2023","2024",
"2025","2026","2027","2028","2029","202a","202b","202c","202d","202e","202f"
};
//jun2015
const int prt_ntdc_jun2015=30;
TString prt_tdcsid_jun2015[] ={"2000","2001","2002","2003","2004","2005","2006","2007","2008","2009",
"200a","200b","200c","200d","200e","200f","2010","2011","2012","2013",
"2014","2015","2016","2018","2019","201a","201c","201d","202c","202d"
};
//oct2016
const int prt_ntdc_oct2016=20;
TString prt_tdcsid_oct2016[] ={"2000","2001","2002","2003","2004","2005","2006","2007","2008","2009",
"200a","200b","200c",
"2018","201b","201c","201f","202c","202d","202d"
};
//aug2017 jul2018
const int prt_ntdc_jul2018 = 32;
TString prt_tdcsid_jul2018 [] ={"2000","2001","2002","2003","2004","2005","2006","2007","2008","2009","200a","200b","200c","200d","200e","200f","2010","2011","2012","2013",
"2014","2015","2016","2017","2018","2019","201a","201b",
"201c","201d","201e","201f"
};
//jul2019
const int prt_ntdc_jul2019 = 21;
TString prt_tdcsid_jul2019[] ={"2014","2015","2016","2017","2000","2001","2002","2003","2004","2005",
"2006","2007","2008","2009","200a","200b","200c","200d","200e","200f",
"2010"};
const int prt_maxdircch = prt_nmcp*prt_npix;
const int prt_maxnametdc=10000;
TRandom prt_rand;
TChain* prt_ch = 0;
int prt_entries(0),prt_particle(0),prt_geometry(2023),prt_beamx(0),prt_beamz(0);
int prt_last_layoutId,prt_last_max,prt_last_maxz,prt_last_minz;
double prt_theta(0), prt_test1(0),prt_test2(0),prt_mom(0),prt_phi(0);
TString prt_savepath(""),prt_info("");
TH2F* prt_hdigi[prt_nmcp];
TSpectrum *prt_spect = new TSpectrum(2);
const int prt_ntdcm = 80; //41
int prt_ntdc = prt_ntdcm;
int prt_maxch = prt_ntdc*48;
TString prt_tdcsid[prt_ntdcm];
const int prt_maxchm = prt_ntdcm*48;
int map_tdc[prt_maxnametdc];
int map_mpc[prt_maxchm/prt_npix][prt_npix];
int map_mcp[prt_maxchm];
int map_pix[prt_maxchm];
int map_row[prt_maxchm];
int map_col[prt_maxchm];
int prt_pid(0), prt_pdg[]={11,13,211,321,2212};
double prt_mass[]={0.000511,0.1056584,0.139570,0.49368,0.9382723};
TString prt_name[]={"e","muon","pion","kaon","proton"};
TString prt_lname[]={"e","#mu","#pi","K","p"};
int prt_color[]={kOrange+6,kCyan+1,kBlue+1,kRed+1,kRed+1};
double prt_particleArray[3000];
TF1 *prt_gaust;
TVector3 prt_fit(TH1 *h, double range = 3, double threshold=20, double limit=2, int peakSearch=1,int bkg = 0, TString opt="MQ"){
int binmax = h->GetMaximumBin();
double xmax = h->GetXaxis()->GetBinCenter(binmax);
if(bkg==0) prt_gaust = new TF1("prt_gaust","[0]*exp(-0.5*((x-[1])/[2])^2)",xmax-range,xmax+range);
else if(bkg==1) prt_gaust = new TF1("prt_gaust","[0]*exp(-0.5*((x-[1])/[2])^2)+[3]+x*[4]",xmax-range,xmax+range);
prt_gaust->SetNpx(500);
prt_gaust->SetParNames("const","mean","sigma");
prt_gaust->SetLineColor(2);
double integral = h->Integral(h->GetXaxis()->FindBin(xmax-range),h->GetXaxis()->FindBin(xmax+range));
double xxmin, xxmax, sigma1(0), mean1(0), mean2(0);
xxmax = xmax;
xxmin = xxmax;
int nfound(1);
if(integral>threshold){
if(peakSearch == 1){
prt_gaust->SetParameter(1,xmax);
prt_gaust->SetParameter(2,0.005);
prt_gaust->SetParLimits(2,0.003,limit);
h->Fit("prt_gaust",opt,"",xxmin-range, xxmax+range);
}
if(peakSearch>1){
nfound = prt_spect->Search(h,4,"goff",0.1);
std::cout<<"nfound "<<nfound <<std::endl;
if(nfound==1){
prt_gaust =new TF1("prt_gaust","gaus(0)",xmax-range,xmax+range);
prt_gaust->SetNpx(500);
prt_gaust->SetParameter(1,prt_spect->GetPositionX()[0]);
}else if(nfound>=2){
double p1 = prt_spect->GetPositionX()[0];
double p2 = prt_spect->GetPositionX()[1];
if(p1>p2) {
xxmax = p1;
xxmin = p2;
}else {
xxmax = p2;
xxmin = p1;
}
if(peakSearch==20){
xxmax=xxmin;
prt_gaust =new TF1("prt_gaust","gaus(0)",xxmin-range,xxmin+range);
prt_gaust->SetNpx(500);
prt_gaust->SetParameter(1,prt_spect->GetPositionX()[0]);
}else{
prt_gaust =new TF1("prt_gaust","gaus(0)+gaus(3)",xmax-range,xmax+range);
prt_gaust->SetNpx(500);
prt_gaust->SetParameter(0,1000);
prt_gaust->SetParameter(3,1000);
prt_gaust->FixParameter(1,xxmin);
prt_gaust->FixParameter(4,xxmax);
prt_gaust->SetParameter(2,0.1);
prt_gaust->SetParameter(5,0.1);
h->Fit("prt_gaust",opt,"",xxmin-range, xxmax+range);
prt_gaust->ReleaseParameter(1);
prt_gaust->ReleaseParameter(4);
}
}
prt_gaust->SetParameter(2,0.2);
prt_gaust->SetParameter(5,0.2);
}
h->Fit("prt_gaust",opt,"",xxmin-range, xxmax+range);
mean1 = prt_gaust->GetParameter(1);
sigma1 = prt_gaust->GetParameter(2);
if(sigma1>10) sigma1=10;
if(peakSearch == 2){
mean2 = (nfound==1) ? prt_gaust->GetParameter(1) : prt_gaust->GetParameter(4);
// sigma2 = (nfound==1) ? prt_gaust->GetParameter(2) : prt_gaust->GetParameter(5);
}
}
delete prt_gaust;
return TVector3(mean1,sigma1,mean2);
}
TGraph *prt_fitslices(TH2F *hh,double minrange=0, double maxrange=0, double fitrange=1,int rebin=1,int ret=0){
TH2F *h =(TH2F*) hh->Clone("h");
h->RebinY(rebin);
int point(0);
TGraph *gres = new TGraph();
for (int i=1;i<h->GetNbinsY();i++){
double x = h->GetYaxis()->GetBinCenter(i);
TH1D* hp;
if(minrange!=maxrange){
TCutG *cut = new TCutG("prt_onepeakcut",5);
cut->SetVarX("y");
cut->SetVarY("x");
cut->SetPoint(0,minrange,-1E6);
cut->SetPoint(1,minrange, 1E6);
cut->SetPoint(2,maxrange, 1E6);
cut->SetPoint(3,maxrange,-1E6);
cut->SetPoint(4,minrange,-1E6);
hp = h->ProjectionX(Form("bin%d",i),i,i,"[prt_onepeakcut]");
}else{
hp = h->ProjectionX(Form("bin%d",i),i,i);
}
TVector3 res = prt_fit((TH1F*)hp,fitrange,100,2,1,1);
double y=0;
if(ret==0) y = res.X();
if(ret==1) y = res.Y();
if(ret==2) y = res.X() + 0.5*res.Y();
if(ret==3) y = res.X() - 0.5*res.Y();
if(y==0 || y<minrange || y>maxrange) continue;
gres->SetPoint(point,y,x);
gres->SetLineWidth(2);
gres->SetLineColor(kRed);
point++;
}
return gres;
}
void prt_createMap(int setupid = 2019){
prt_geometry = setupid;
if(prt_geometry==2015) prt_ntdc = prt_ntdc_jun2015;
if(prt_geometry==2016) prt_ntdc = prt_ntdc_oct2016;
if(prt_geometry==2017) prt_ntdc = prt_ntdc_jul2018;
if(prt_geometry==2018) prt_ntdc = prt_ntdc_jul2018;
if(prt_geometry==2019) prt_ntdc = prt_ntdc_jul2019;
for(int i=0; i<prt_ntdc; i++){
if(prt_geometry==2015) prt_tdcsid[i] = prt_tdcsid_jun2015[i];
if(prt_geometry==2016) prt_tdcsid[i] = prt_tdcsid_oct2016[i];
if(prt_geometry==2017) prt_tdcsid[i] = prt_tdcsid_jul2018[i];
if(prt_geometry==2018) prt_tdcsid[i] = prt_tdcsid_jul2018[i];
if(prt_geometry==2019) prt_tdcsid[i] = prt_tdcsid_jul2019[i];
}
TGaxis::SetMaxDigits(4);
for(int i=0; i<prt_maxnametdc; i++) map_tdc[i]=-1;
for(int i=0; i<prt_ntdc; i++){
int dec = TString::BaseConvert(prt_tdcsid[i],16,10).Atoi();
map_tdc[dec]=i;
}
// for(int ch=0; ch<prt_maxdircch; ch++){
for(int ch=0; ch<prt_maxch; ch++){
int mcp = ch/prt_npix;
int pix = ch%prt_npix;
int col = pix/2 - 8*(pix/16);
int row = pix%2 + 2*(pix/16);
// pix = col+sqrt(prt_npix)*row;
map_mpc[mcp][pix]=ch;
map_mcp[ch] = mcp;
map_pix[ch] = pix;
map_row[ch] = row;
map_col[ch] = col;
}
for(int i=0; i<5; i++){
prt_particleArray[prt_pdg[i]]=i;
}
prt_particleArray[212]=2;
}
int prt_getChannelNumber(int tdc, int tdcChannel){
int ch = -1;
if(prt_geometry==2018){
ch=0;
for(int i=0; i<=tdc; i++){
if(i==tdc && (i==2 || i==6 || i==10 || i==14)) ch += tdcChannel-32;
else if(i==tdc) ch += tdcChannel;
else if(i==1 || i==2 || i==5 || i==6 || i==9 || i==10 || i==13 || i==14) ch += 16;
else ch += 48;
}
}else if(prt_geometry==2023){
ch = 32*tdc+tdcChannel;
}else{
ch = 48*tdc+tdcChannel;
}
return ch;
}
int prt_getTdcId(int ch){
int tch=0, tdcid=0;
if(prt_geometry==2018){
for(int i=0; i<=prt_ntdc; i++){
tdcid=i;
if(i==2 || i==6 || i==10 || i==14) tch += 16;
else if(i==1 || i==2 || i==5 || i==6 || i==9 || i==10 || i==13 || i==14) tch += 16;
else tch += 48;
if(tch>ch) break;
}
}else if(prt_geometry==2023){
tdcid=ch/32;
}else{
tdcid=ch/48;
}
return tdcid;
}
TString prt_getTdcName(int ch){
return prt_tdcsid[prt_getTdcId(ch)];
}
int prt_getTdcChannel(int ch){
int tch=0,tdcc=0;
if(prt_geometry==2018){
for(int i=0; i<=prt_ntdc; i++){
tdcc=ch-tch+1;
if(i==2 || i==6 || i==10 || i==14 || i==1 || i==2 || i==5 || i==6 || i==9 || i==10 || i==13 || i==14) tch += 16;
else tch += 48;
if(tch>ch){
break;
};
}
}else if(prt_geometry==2023){
tdcc=ch%32+1;
}else{
tdcc=ch%48+1;
}
return tdcc;
}
int prt_removeRefChannels(int ch, int tdcSeqId){
return ch - tdcSeqId;
}
int prt_addRefChannels(int ch,int tdcSeqId){
return ch + tdcSeqId;
}
Bool_t prt_isBadChannel(int ch){
if(ch<0 || ch>=prt_maxdircch) return true;
// // bad pixels july15
// if(ch==202) return true;
// if(ch==204) return true;
// if(ch==206) return true;
// if(ch==830) return true;
// if(ch==831) return true;
// if(ch==828) return true;
// if(ch==815) return true;
// if(ch>383 && ch<400) return true; //dead chain
return false;
}
TString prt_randstr(int len = 10){
TString str = "";
static const char alphanum[] =
"0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
for (int i = 0; i < len; ++i) {
str += alphanum[rand() % (sizeof(alphanum) - 1)];
}
return str;
}
// layoutId == 5 - 5 row's design for the PANDA Barrel DIRC
// layoutId == 2015 - cern 2015
// layoutId == 2016 - cern 2016
// layoutId == 2017 - cern 2017
// layoutId == 2018 - cern 2018
// layoutId == 2021 - new 3.6 row's design for the PANDA Barrel DIRC
// layoutId == 2023 - new 2x4 layout for the PANDA Barrel DIRC
// layoutId == 2031 - EIC DIRC beam test
// layoutId == 2030 - EIC DIRC prism
// layoutId == 2032 - EIC DIRC focusing prism
TH1 * prt_cdigi_th;
TCanvas *prt_drawDigi(int layoutId = 0, double maxz = 0, double minz = 0, TCanvas *cdigi = NULL){
prt_last_layoutId=layoutId;
prt_last_maxz=maxz;
prt_last_minz=minz;
if(prt_geometry==2021) layoutId=2021;
// if(prt_geometry==2019) layoutId=2018;
TString sid = prt_randstr(3);
if(cdigi) cdigi->cd();
else cdigi = new TCanvas("hp="+sid,"hp_"+sid,800,400);
TPad* prt_hpads[prt_nmcp];
TPad* prt_hpglobal;
if(layoutId==2015 || layoutId==5) prt_hpglobal = new TPad(sid,"T",0.04,0.04,0.88,0.96);
else if(layoutId==2021) prt_hpglobal = new TPad(sid,"T",0.12,0.02,0.78,0.98);
else if(layoutId==2016) prt_hpglobal = new TPad(sid,"T",0.2,0.02,0.75,0.98);
else if(layoutId==2017) prt_hpglobal = new TPad(sid,"T",0.15,0.02,0.80,0.98);
else if(layoutId==2018) prt_hpglobal = new TPad(sid,"T",0.05,0.07,0.9,0.93);
else if(layoutId==2023) prt_hpglobal = new TPad(sid,"T",0.073,0.02,0.877,0.98);
else if(layoutId==2030) prt_hpglobal = new TPad(sid,"T",0.10,0.025,0.82,0.975);
else if(layoutId==2032) prt_hpglobal = new TPad(sid,"T",0.04,0.025,0.91,0.975);
else if(layoutId==2031) prt_hpglobal = new TPad(sid,"T",0.12,0.01,0.80,0.99);
else prt_hpglobal = new TPad(sid,"T",0.04,0.04,0.96,0.96);
prt_hpglobal->SetFillStyle(0);
prt_hpglobal->Draw();
prt_hpglobal->cd();
int nrow = 3, ncol = 5;
if(layoutId ==2016) ncol=3;
if(layoutId ==2017) ncol=4;
if(layoutId ==2018 || layoutId ==2023) {nrow=2; ncol=4;}
if(layoutId ==2021) ncol=4;
if(layoutId ==2030) {nrow=4; ncol=6;}
if(layoutId ==2032) {nrow=4; ncol=7;}
if(layoutId ==2031) {nrow=3; ncol=4;}
if(layoutId > 1){
float tbw(0.02), tbh(0.01), shift(0),shiftw(0.02),shifth(0),margin(0.01);
int padi(0);
for(int i=0; i<ncol; i++){
for(int j=0; j<nrow; j++){
if(j==1) shift = -0.028;
else shift = 0;
shifth=0;
if(layoutId == 5) {shift =0; shiftw=0.001; tbw=0.001; tbh=0.001;}
if(layoutId == 2021) {
if(i==0 && j == nrow-1) continue;
shift =0; shiftw=0.001; tbw=0.001; tbh=0.001;
if(i==0) shifth=0.167;
}
if(layoutId == 2016) {
shift = -0.01; shiftw=0.01; tbw=0.03; tbh=0.006;
if(j==1) shift += 0.015;
}
if(layoutId == 2017) {
margin= 0.1;
shift = 0; shiftw=0.01; tbw=0.005; tbh=0.006;
//if(j==1) shift += 0.015;
}
if(layoutId == 2018) {
margin= 0.1;
shift = 0; shiftw=0.01; tbw=0.005; tbh=0.006;
}
if(layoutId == 2023) {
margin= 0.1;
shift = 0; shiftw=0.01; tbw=0.0015; tbh=0.042;
}
if(layoutId == 2030) {
margin= 0.1;
shift = 0; shiftw=0.01; tbw=0.001; tbh=0.001;
padi=j*ncol+i;
}
if(layoutId == 2032) {
margin= 0.1;
shift = 0; shiftw=0.01; tbw=0.001; tbh=0.001;
padi=j*ncol+i;
}
if(layoutId == 2031) {
margin= 0.1;
shift = 0; shiftw=0.01; tbw=0.001; tbh=0.001;
padi=i*nrow+j;
}
prt_hpads[padi] = new TPad(sid+Form("P%d",i*10+j),"T",
i/(ncol+2*margin)+tbw+shift+shiftw,
j/(double)nrow+tbh+shifth,
(i+1)/(ncol+2*margin)-tbw+shift+shiftw,
(1+j)/(double)nrow-tbh+shifth, 21);
prt_hpads[padi]->SetFillColor(kCyan-8);
prt_hpads[padi]->SetMargin(0.055,0.055,0.055,0.055);
prt_hpads[padi]->Draw();
padi++;
}
}
}else{
float tbw(0.02), tbh(0.01), shift(0),shiftw(-0.02);
int padi(0);
for(int ii=0; ii<ncol; ii++){
for(int j=0; j<nrow; j++){
if(j==1) shift = 0.04;
else shift = 0;
prt_hpads[padi] = new TPad(Form("P%d",ii*10+j),"T", ii/(double)ncol+tbw+shift+shiftw , j/(double)nrow+tbh, (ii+1)/(double)ncol-tbw+shift+shiftw, (1+j)/(double)nrow-tbh, 21);
prt_hpads[padi]->SetFillColor(kCyan-8);
prt_hpads[padi]->SetMargin(0.04,0.04,0.04,0.04);
prt_hpads[padi]->Draw();
padi++;
}
}
}
int np;
double max=0;
{
double tmax;
if(maxz==0){
for(int p=0; p<nrow*ncol;p++){
tmax = prt_hdigi[p]->GetBinContent(prt_hdigi[p]->GetMaximumBin());
if(max<tmax) max = tmax;
}
}else{
max = maxz;
}
if(maxz==-2 || minz==-2){ // optimize range
for(int p=0; p<nrow*ncol;p++){
tmax = prt_hdigi[p]->GetMaximum();
if(max<tmax) max = tmax;
}
int tbins = 2000;
TH1F *h = new TH1F("","",tbins,0,max);
for(int p=0; p<nrow*ncol;p++){
for(int i=0; i<8; i++){
for(int j=0; j<8; j++){
double val = prt_hdigi[p]->GetBinContent(i+1,j+1);
if(val!=0) h->Fill(val);
}
}
}
double integral;
for(int i=0; i<tbins; i++){
integral = h->Integral(0,i);
if(integral>0) {
if(minz==-2) minz = h->GetBinCenter(i);
break;
}
}
for(int i=tbins; i>0; i--){
integral = h->Integral(i,tbins);
if(integral>10) {
if(maxz==-2) max = h->GetBinCenter(i);
break;
}
}
}
}
prt_last_max = max;
int nnmax(0);
for(int p=0; p<nrow*ncol;p++){
if(layoutId == 1 || layoutId == 4) np =p%nrow*ncol + p/3;
else np = p;
if(layoutId == 6 && p>10) continue;
prt_hpads[p]->cd();
prt_hdigi[np]->Draw("col");//"col+text"
if(maxz==-1) max = prt_hdigi[np]->GetBinContent(prt_hdigi[np]->GetMaximumBin());
if(nnmax<prt_hdigi[np]->GetEntries()) nnmax=np;
prt_hdigi[np]->SetMaximum(max);
prt_hdigi[np]->SetMinimum(minz);
}
// prt_cdigi_palette = (TPaletteAxis*)prt_hdigi[nnmax]->GetListOfFunctions()->FindObject("palette");
// prt_cdigi_palette->SetX1NDC(0.89);
// prt_cdigi_palette->SetY1NDC(0.1);
// prt_cdigi_palette->SetX2NDC(0.93);
// prt_cdigi_palette->SetY2NDC(0.90);
cdigi->cd();
TPaletteAxis* prt_cdigi_palette;
if(layoutId==2018 || layoutId==2023) prt_cdigi_palette = new TPaletteAxis(0.89,0.1,0.93,0.90,(TH1 *) prt_hdigi[nnmax]);
else if(layoutId==2032) prt_cdigi_palette = new TPaletteAxis(0.91,0.1,0.94,0.90,(TH1 *) prt_hdigi[nnmax]);
else prt_cdigi_palette = new TPaletteAxis(0.82,0.1,0.86,0.90,(TH1 *) prt_hdigi[nnmax]);
prt_cdigi_palette->SetName("prt_palette");
prt_cdigi_palette->Draw();
cdigi->Modified();
cdigi->Update();
return cdigi;
}
TString prt_getPixData(TString s="m,p,v\n", int layoutId=1){
int nrow = 3, ncol = 5, np, nmax=0, npix=8;
if(layoutId ==2016) ncol=3;
if(layoutId ==2017) ncol=4;
if(layoutId ==2018 || layoutId ==2023) {nrow=2; ncol=4;}
if(layoutId ==2021) ncol=4;
if(layoutId ==2030) {nrow=4; ncol=6; npix=16;}
if(layoutId ==2032) {nrow=4; ncol=7; npix=16;}
if(layoutId ==2031) {nrow=3; ncol=4; npix=16;}
int nnmax(0);
for(int p=0; p<nrow*ncol;p++){
if(layoutId == 1 || layoutId == 4) np =p%nrow*ncol + p/3;
else if(layoutId == 2030) np =p%ncol*nrow + p/ncol;
else np = p;
if(prt_last_maxz==-1) prt_last_max = prt_hdigi[p]->GetBinContent(prt_hdigi[p]->GetMaximumBin());
if(nnmax<prt_hdigi[p]->GetEntries()) nnmax=p;
prt_hdigi[p]->SetMaximum(prt_last_max);
prt_hdigi[p]->SetMinimum(prt_last_minz);
for(int i=1; i<=npix; i++){
for(int j=1; j<=npix; j++){
double weight = (double)(prt_hdigi[p]->GetBinContent(i,j))/(double)prt_last_max*255;
if(weight>255) weight=255;
if(weight > 0) s += Form("%d,%d,%d\n", np, (i-1)*npix+j-1, (int)weight);
}
}
}
return s;
}
void prt_initDigi(int type=1){
if(type == 1){
for(int m=0; m<prt_nmcp;m++){
if(prt_hdigi[m]) prt_hdigi[m]->Reset("M");
else{
prt_hdigi[m] = new TH2F( Form("mcp%d", m),Form("mcp%d", m),8,0.,8.,8,0.,8.);
prt_hdigi[m]->SetStats(0);
prt_hdigi[m]->SetTitle(0);
prt_hdigi[m]->GetXaxis()->SetNdivisions(10);
prt_hdigi[m]->GetYaxis()->SetNdivisions(10);
prt_hdigi[m]->GetXaxis()->SetLabelOffset(100);
prt_hdigi[m]->GetYaxis()->SetLabelOffset(100);
prt_hdigi[m]->GetXaxis()->SetTickLength(1);
prt_hdigi[m]->GetYaxis()->SetTickLength(1);
prt_hdigi[m]->GetXaxis()->SetAxisColor(15);
prt_hdigi[m]->GetYaxis()->SetAxisColor(15);
}
}
}
if(type == 2){ //eic
for(int m=0; m<prt_nmcp;m++){
if(prt_hdigi[m]) prt_hdigi[m]->Reset("M");
else{
prt_hdigi[m] = new TH2F( Form("mcp%d", m),Form("mcp%d", m),16,0,16,16,0,16);
prt_hdigi[m]->SetStats(0);
prt_hdigi[m]->SetTitle(0);
prt_hdigi[m]->GetXaxis()->SetNdivisions(20);
prt_hdigi[m]->GetYaxis()->SetNdivisions(20);
prt_hdigi[m]->GetXaxis()->SetLabelOffset(100);
prt_hdigi[m]->GetYaxis()->SetLabelOffset(100);
prt_hdigi[m]->GetXaxis()->SetTickLength(1);
prt_hdigi[m]->GetYaxis()->SetTickLength(1);
prt_hdigi[m]->GetXaxis()->SetAxisColor(15);
prt_hdigi[m]->GetYaxis()->SetAxisColor(15);
}
}
}
}
void prt_resetDigi(){
for(int m=0; m<prt_nmcp;m++){
prt_hdigi[m]->Reset("M");
}
}
void prt_axisHits800x500(TH2 * hist){
hist->SetStats(0);
hist->SetTitle(Form("%d hits",(int)hist->GetEntries()));
hist->GetXaxis()->SetTitle("z, [cm]");
hist->GetXaxis()->SetTitleSize(0.05);
hist->GetXaxis()->SetTitleOffset(0.8);
hist->GetYaxis()->SetTitle("y, [cm]");
hist->GetYaxis()->SetTitleSize(0.05);
hist->GetYaxis()->SetTitleOffset(0.7);
}
void prt_axisAngle800x500(TH2 * hist){
hist->SetStats(0);
hist->SetTitle(Form("%d hits",(int)hist->GetEntries()));
hist->GetXaxis()->SetTitle("#theta, [degree]");
hist->GetXaxis()->SetTitleSize(0.05);
hist->GetXaxis()->SetTitleOffset(0.8);
hist->GetYaxis()->SetTitle("photons per track, [#]");
hist->GetYaxis()->SetTitleSize(0.05);
hist->GetYaxis()->SetTitleOffset(0.7);
}
void prt_axisAngle800x500(TH1 * hist){
hist->SetStats(0);
hist->SetTitle(Form("%d hits",(int)hist->GetEntries()));
hist->GetXaxis()->SetTitle("#theta, [degree]");
hist->GetXaxis()->SetTitleSize(0.05);
hist->GetXaxis()->SetTitleOffset(0.8);
hist->GetYaxis()->SetTitle("photons per track, [#]");
hist->GetYaxis()->SetTitleSize(0.05);
hist->GetYaxis()->SetTitleOffset(0.7);
}
void prt_axisTime800x500(TH2 * hist){
hist->GetXaxis()->SetTitle("time, [ns]");
hist->GetXaxis()->SetTitleSize(0.05);
hist->GetXaxis()->SetTitleOffset(0.8);
hist->GetYaxis()->SetTitle("entries, #");
hist->GetYaxis()->SetTitleSize(0.05);
hist->GetYaxis()->SetTitleOffset(0.7);
hist->SetLineColor(1);
}
void prt_axisTime800x500(TH1 * hist, TString xtitle = "time [ns]"){
TGaxis::SetMaxDigits(3);
hist->GetXaxis()->SetTitle(xtitle);
hist->GetXaxis()->SetTitleSize(0.06);
hist->GetXaxis()->SetTitleOffset(0.8);
hist->GetXaxis()->SetLabelSize(0.05);
hist->GetYaxis()->SetTitle("entries [#]");
hist->GetYaxis()->SetTitleSize(0.06);
hist->GetYaxis()->SetTitleOffset(0.7);
hist->GetYaxis()->SetLabelSize(0.05);
hist->SetLineColor(1);
}
void prt_setPrettyStyle(){
// Canvas printing details: white bg, no borders.
gStyle->SetCanvasColor(0);
gStyle->SetCanvasBorderMode(0);
gStyle->SetCanvasBorderSize(0);
// Canvas frame printing details: white bg, no borders.
gStyle->SetFrameFillColor(0);
gStyle->SetFrameBorderMode(0);
gStyle->SetFrameBorderSize(0);
// Plot title details: centered, no bg, no border, nice font.
gStyle->SetTitleX(0.1);
gStyle->SetTitleW(0.8);
gStyle->SetTitleBorderSize(0);
gStyle->SetTitleFillColor(0);
// Font details for titles and labels.
gStyle->SetTitleFont(42, "xyz");
gStyle->SetTitleFont(42, "pad");
gStyle->SetLabelFont(42, "xyz");
gStyle->SetLabelFont(42, "pad");
// Details for stat box.
gStyle->SetStatColor(0);
gStyle->SetStatFont(42);
gStyle->SetStatBorderSize(1);
gStyle->SetStatX(0.975);
gStyle->SetStatY(0.9);
// gStyle->SetOptStat(0);
}
void prt_setGStyle(TGraph *g, int id){
int prt_coll[]={kBlack,kRed+1,kGreen, kBlue, 4,kCyan-6,kOrange, 7,8,9,10,1,1,1};
int prt_colm[]={kBlack,kRed+1,kGreen+2,kBlue+1,4,kCyan-6,kOrange+1,7,8,9,10,1,1,1};
int cl=(id<10)? prt_coll[id]:id;
int cm=(id<10)? prt_colm[id]:id;
g->SetLineColor(cl);
g->SetMarkerColor(cm);
g->SetMarkerStyle(20);
g->SetMarkerSize(0.8);
g->SetName(Form("gr_%d",id));
}
void prt_setRootPalette(int pal = 0){
// pal = 1: rainbow\n"
// pal = 2: reverse-rainbow\n"
// pal = 3: amber\n"
// pal = 4: reverse-amber\n"
// pal = 5: blue/white\n"
// pal = 6: white/blue\n"
// pal = 7: red temperature\n"
// pal = 8: reverse-red temperature\n"
// pal = 9: green/white\n"
// pal = 10: white/green\n"
// pal = 11: orange/blue\n"
// pal = 12: blue/orange\n"
// pal = 13: white/black\n"
// pal = 14: black/white\n"
const int NRGBs = 5;
const int NCont = 255;
gStyle->SetNumberContours(NCont);
if (pal < 1 && pal> 15) return;
else pal--;
double stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
double red[15][NRGBs] = {{ 0.00, 0.00, 0.87, 1.00, 0.51 },
{ 0.51, 1.00, 0.87, 0.00, 0.00 },
{ 0.17, 0.39, 0.62, 0.79, 1.00 },
{ 1.00, 0.79, 0.62, 0.39, 0.17 },
{ 0.00, 0.00, 0.00, 0.38, 1.00 },
{ 1.00, 0.38, 0.00, 0.00, 0.00 },
{ 0.00, 0.50, 0.89, 0.95, 1.00 },
{ 1.00, 0.95, 0.89, 0.50, 0.00 },
{ 0.00, 0.00, 0.38, 0.75, 1.00 },
{ 0.00, 0.34, 0.61, 0.84, 1.00 },
{ 0.75, 1.00, 0.24, 0.00, 0.00 },
{ 0.00, 0.00, 0.24, 1.00, 0.75 },
{ 0.00, 0.34, 0.61, 0.84, 1.00 },
{ 1.00, 0.84, 0.61, 0.34, 0.00 },
{ 0.00, 0.00, 0.80, 1.00, 0.80 }
};
double green[15][NRGBs] = {{ 0.00, 0.81, 1.00, 0.20, 0.00 },
{ 0.00, 0.20, 1.00, 0.81, 0.00 },
{ 0.01, 0.02, 0.39, 0.68, 1.00 },
{ 1.00, 0.68, 0.39, 0.02, 0.01 },
{ 0.00, 0.00, 0.38, 0.76, 1.00 },
{ 1.00, 0.76, 0.38, 0.00, 0.00 },
{ 0.00, 0.00, 0.27, 0.71, 1.00 },
{ 1.00, 0.71, 0.27, 0.00, 0.00 },
{ 0.00, 0.35, 0.62, 0.85, 1.00 },
{ 1.00, 0.75, 0.38, 0.00, 0.00 },
{ 0.24, 1.00, 0.75, 0.18, 0.00 },
{ 0.00, 0.18, 0.75, 1.00, 0.24 },
{ 0.00, 0.34, 0.61, 0.84, 1.00 },
{ 1.00, 0.84, 0.61, 0.34, 0.00 },
{ 0.00, 0.85, 1.00, 0.30, 0.00 }
};
double blue[15][NRGBs] = {{ 0.51, 1.00, 0.12, 0.00, 0.00 },
{ 0.00, 0.00, 0.12, 1.00, 0.51 },
{ 0.00, 0.09, 0.18, 0.09, 0.00 },
{ 0.00, 0.09, 0.18, 0.09, 0.00 },
{ 0.00, 0.47, 0.83, 1.00, 1.00 },
{ 1.00, 1.00, 0.83, 0.47, 0.00 },
{ 0.00, 0.00, 0.00, 0.40, 1.00 },
{ 1.00, 0.40, 0.00, 0.00, 0.00 },
{ 0.00, 0.00, 0.00, 0.47, 1.00 },
{ 1.00, 0.47, 0.00, 0.00, 0.00 },
{ 0.00, 0.62, 1.00, 0.68, 0.12 },
{ 0.12, 0.68, 1.00, 0.62, 0.00 },
{ 0.00, 0.34, 0.61, 0.84, 1.00 },
{ 1.00, 0.84, 0.61, 0.34, 0.00 },
{ 0.60, 1.00, 0.10, 0.00, 0.00 }
};
TColor::CreateGradientColorTable(NRGBs, stops, red[pal], green[pal], blue[pal], NCont);
}
#if defined(prt__sim) || defined(eic__sim)
bool prt_init(TString inFile="../build/hits.root", int bdigi=0, TString savepath="", int setupid = 2019){
if(inFile=="" || gSystem->AccessPathName(inFile)) return false;
if(savepath!="") prt_savepath=savepath;
prt_setRootPalette(1);
prt_createMap(setupid);
delete prt_ch;
prt_ch = new TChain("data");
prt_ch->Add(inFile);
prt_ch->SetBranchAddress("PrtEvent", &prt_event);
prt_entries = prt_ch->GetEntries();
std::cout<<"Entries in chain: "<<prt_entries <<std::endl;
if(bdigi) prt_initDigi(bdigi);
return true;
}
void prt_nextEvent(int ievent, int printstep){
prt_ch->GetEntry(ievent);
if(ievent%printstep==0 && ievent!=0) std::cout<<"Event # "<<ievent<< " # hits "<<prt_event->GetHitSize()<<std::endl;
if(ievent == 0){
if(gROOT->GetApplication()){
TIter next(gROOT->GetApplication()->InputFiles());
TObjString *os=0;
while((os = (TObjString*)next())){
prt_info += os->GetString()+" ";
}
prt_info += "\n";
}
prt_info += prt_event->PrintInfo();
prt_mom = prt_event->GetMomentum().Mag() +0.01;
prt_theta = prt_event->GetAngle();
prt_phi = prt_event->GetPhi();
prt_geometry= prt_event->GetGeometry();
prt_beamx= prt_event->GetBeamX();
prt_beamz= prt_event->GetBeamZ();
prt_test1 = prt_event->GetTest1();
prt_test2 = prt_event->GetTest2();
}
prt_particle = prt_event->GetParticle();
if(prt_event->GetParticle()<3000 && prt_event->GetParticle()>0){
prt_pid=prt_particleArray[prt_event->GetParticle()];
}
}
#endif
#ifdef prt__beam
bool prt_init(TString inFile="../build/hits.root", int bdigi=0, TString savepath="", int setupid=2019){
if(inFile=="") return false;
if(savepath!="") prt_savepath=savepath;
prt_createMap(setupid);
prt_setRootPalette(1);
delete prt_ch;
prt_ch = new TChain("data");
prt_ch->Add(inFile);
prt_ch->SetBranchAddress("PrtEvent", &prt_event);
// prt_ch->SetBranchStatus("fHitArray.fLocalPos", 0);
// prt_ch->SetBranchStatus("fHitArray.fGlobalPos", 0);
// prt_ch->SetBranchStatus("fHitArray.fDigiPos", 0);
// prt_ch->SetBranchStatus("fHitArray.fMomentum", 0);
// prt_ch->SetBranchStatus("fHitArray.fPosition", 0);
prt_ch->SetBranchStatus("fHitArray.fParentParticleId", 0);
prt_ch->SetBranchStatus("fHitArray.fNreflectionsInPrizm", 0);
prt_ch->SetBranchStatus("fHitArray.fPathInPrizm", 0);
prt_ch->SetBranchStatus("fHitArray.fCherenkovMC", 0);
prt_ch->SetBranchStatus("fPosition", 0);
prt_entries = prt_ch->GetEntries();
std::cout<<"Entries in chain: "<<prt_entries <<std::endl;
if(bdigi) prt_initDigi(bdigi);
return true;
}
void prt_nextEvent(int ievent, int printstep){
prt_ch->GetEntry(ievent);
if(ievent%printstep==0 && ievent!=0) cout<<"Event # "<<ievent<< " # hits "<<prt_event->GetHitSize()<<endl;
if(ievent == 0){
if(gROOT->GetApplication()){
prt_info += "beam test";
TIter next(gROOT->GetApplication()->InputFiles());
TObjString *os=0;
while((os = (TObjString*)next())){
prt_info += os->GetString()+" ";
}
prt_info += "\n";
}
prt_info += prt_event->PrintInfo();
prt_mom = prt_event->GetMomentum().Mag() +0.01;
prt_theta = prt_event->GetAngle();
prt_phi = prt_event->GetPhi();
prt_geometry= prt_event->GetGeometry();
prt_beamx= prt_event->GetBeamX();
prt_beamz= prt_event->GetBeamZ();
prt_test1 = prt_event->GetTest1();
prt_test2 = prt_event->GetTest2();
}
prt_particle = prt_event->GetParticle();
if(prt_event->GetParticle()<3000 && prt_event->GetParticle()>0){
prt_pid=prt_particleArray[prt_event->GetParticle()];
}
}
#endif
int prt_getColorId(int ind, int style =0){
int cid = 1;
if(style==0) {
cid=ind+1;
if(cid==5) cid =8;
if(cid==3) cid =kOrange+2;
}
if(style==1) cid=ind+300;
return cid;
}
int prt_shiftHist(TH1 *hist, double double_shift){
int bins=hist->GetXaxis()->GetNbins();
double xmin=hist->GetXaxis()->GetBinLowEdge(1);
double xmax=hist->GetXaxis()->GetBinUpEdge(bins);