forked from pwittich/mictest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlotValidation.cpp
More file actions
2019 lines (1741 loc) · 87.2 KB
/
PlotValidation.cpp
File metadata and controls
2019 lines (1741 loc) · 87.2 KB
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
#include "PlotValidation.hh"
#include "TLegend.h"
PlotValidation::PlotValidation(TString inName, TString outName, TString outType){
// ++++ Get Root File ++++ //
fInName = inName;
fInRoot = TFile::Open(Form("%s",fInName.Data()));
// ++++ Define Output Parameters, Make Directory/File ++++ //
fOutName = outName;
fOutType = outType;
// make output directory
FileStat_t dummyFileStat;
if (gSystem->GetPathInfo(fOutName.Data(), dummyFileStat) == 1){
TString mkDir = "mkdir -p ";
mkDir += fOutName.Data();
gSystem->Exec(mkDir.Data());
}
// make output root file
fOutRoot = new TFile(Form("%s/%s.root",fOutName.Data(),fOutName.Data()), "RECREATE");
// General style
gROOT->Reset();
gStyle->SetOptStat("emou");
//gStyle->SetOptStat(0);
gStyle->SetTitleFontSize(0.04);
gStyle->SetOptFit(1011);
gStyle->SetStatX(0.9);
gStyle->SetStatW(0.1);
gStyle->SetStatY(1.0);
gStyle->SetStatH(0.08);
fTH1Canv = new TCanvas();
fTH2Canv = new TCanvas();
// fColorBase
fColors.push_back(kBlue);
fColors.push_back(kOrange+8);
fColors.push_back(kGreen+1);
fColors.push_back(kRed);
fColors.push_back(kYellow+1);
fColors.push_back(kViolet+2);
fColors.push_back(kCyan);
fColors.push_back(kPink);
fColors.push_back(kPink+6);
fColors.push_back(kSpring+10);
fColors.push_back(kBlack);
fColorSize = fColors.size();
}
PlotValidation::~PlotValidation(){
delete fInRoot;
delete fOutRoot; // will delete all pointers to subdirectory
delete fTH1Canv;
delete fTH2Canv;
}
void PlotValidation::Validation(Bool_t fullVal, Bool_t mvInput){
PlotValidation::PlotEfficiency();
PlotValidation::PlotFakeRate();
PlotValidation::PlotDuplicateRate();
PlotValidation::PlotNHits();
PlotValidation::PlotTiming();
PlotValidation::PlotMomResolutionPull();
if (fullVal) {
PlotValidation::PlotSegment();
PlotValidation::PlotBranching();
PlotValidation::PlotSimGeo();
PlotValidation::PlotPosResolutionPull();
PlotValidation::PlotCFResidual();
PlotValidation::PlotCFResolutionPull();
}
PlotValidation::PrintTotals();
if (mvInput) {
PlotValidation::MoveInput();
}
}
void PlotValidation::PlotEfficiency(){
// Get tree
TTree * efftree = (TTree*)fInRoot->Get("efftree");
// make output subdirectory and subdir in ROOT file, and cd to it.
TString subdirname = "efficiency";
PlotValidation::MakeSubDirectory(subdirname);
PlotValidation::MakeSubDirectory(Form("%s/lin",subdirname.Data()));
PlotValidation::MakeSubDirectory(Form("%s/log",subdirname.Data()));
TDirectory * subdir = fOutRoot->mkdir(subdirname.Data());
subdir->cd();
//Declare strings for branches and plots
Bool_t zeroSupLin = true;
TStrVec vars = {"pt","eta","phi"};
TStrVec svars = {"p_{T}","#eta","#phi"}; // svars --> labels for histograms for given variable
TStrVec sunits= {" [GeV/c]","",""}; // units --> labels for histograms for given variable
IntVec nBins = {60,60,80};
FltVec xlow = {0,-3,-4};
FltVec xhigh = {15,3,4};
TStrVec trks = {"seed","build","fit"};
TStrVec strks = {"Seed","Build","Fit"}; // strk --> labels for histograms for given track type
// Floats/Ints to be filled for trees
FltVec mcvars_val(vars.size()); // first index is var. only for mc values! so no extra index
IntVec mcmask_trk(trks.size()); // need to know if sim track associated to a given reco track type
// Create plots
TH1FRefVecVec varsNumerPlot(vars.size());
TH1FRefVecVec varsDenomPlot(vars.size());
TH1FRefVecVec varsEffPlot(vars.size());
for (UInt_t i = 0; i < vars.size(); i++){
varsNumerPlot[i].resize(trks.size());
varsDenomPlot[i].resize(trks.size());
varsEffPlot[i].resize(trks.size());
}
for (UInt_t i = 0; i < vars.size(); i++){
for (UInt_t j = 0; j < trks.size(); j++){
// Numerator
varsNumerPlot[i][j] = new TH1F(Form("h_sim_%s_numer_%s_eff",vars[i].Data(),trks[j].Data()),Form("%s Track vs MC %s (Numer) Eff",strks[j].Data(),svars[i].Data()),nBins[i],xlow[i],xhigh[i]);
varsNumerPlot[i][j]->GetXaxis()->SetTitle(Form("%s%s",svars[i].Data(),sunits[i].Data()));
varsNumerPlot[i][j]->GetYaxis()->SetTitle("nTracks");
// Denominator
varsDenomPlot[i][j] = new TH1F(Form("h_sim_%s_denom_%s_eff",vars[i].Data(),trks[j].Data()),Form("%s Track vs MC %s (Denom) Eff",strks[j].Data(),svars[i].Data()),nBins[i],xlow[i],xhigh[i]);
varsDenomPlot[i][j]->GetXaxis()->SetTitle(Form("%s%s",svars[i].Data(),sunits[i].Data()));
varsDenomPlot[i][j]->GetYaxis()->SetTitle("nTracks");
// Effiency
varsEffPlot[i][j] = new TH1F(Form("h_sim_%s_eff_%s_eff",vars[i].Data(),trks[j].Data()),Form("%s Track Effiency vs MC %s",strks[j].Data(),svars[i].Data()),nBins[i],xlow[i],xhigh[i]);
varsEffPlot[i][j]->GetXaxis()->SetTitle(Form("%s%s",svars[i].Data(),sunits[i].Data()));
varsEffPlot[i][j]->GetYaxis()->SetTitle("Efficiency");
}
}
//Initialize var_val/err arrays, SetBranchAddress
for (UInt_t i = 0; i < vars.size(); i++){ // loop over trks index
// initialize var
mcvars_val[i] = 0.;
//Set var+trk branch
efftree->SetBranchAddress(Form("%s_mc_gen",vars[i].Data()),&(mcvars_val[i]));
}
//Initialize masks, set branch addresses
for (UInt_t j = 0; j < trks.size(); j++){ // loop over trks index
mcmask_trk[j] = 0;
efftree->SetBranchAddress(Form("mcmask_%s",trks[j].Data()),&(mcmask_trk[j]));
}
// Fill histos, compute eff from tree branches
for (Int_t k = 0; k < efftree->GetEntries(); k++){
efftree->GetEntry(k);
for (UInt_t i = 0; i < vars.size(); i++){ // loop over vars index
for (UInt_t j = 0; j < trks.size(); j++){ // loop over trks index
varsDenomPlot[i][j]->Fill(mcvars_val[i]);
if (mcmask_trk[j] == 1){ // must be associated
varsNumerPlot[i][j]->Fill(mcvars_val[i]);
} // must be a matched track for effiency
} // end loop over trks
} // end loop over vars
} // end loop over entry in tree
// Draw, divide, and save efficiency plots
for (UInt_t i = 0; i < vars.size(); i++){
for (UInt_t j = 0; j < trks.size(); j++){
PlotValidation::ComputeRatioPlot(varsNumerPlot[i][j],varsDenomPlot[i][j],varsEffPlot[i][j]);
PlotValidation::WriteTH1FPlot(subdir,varsNumerPlot[i][j]);
PlotValidation::WriteTH1FPlot(subdir,varsDenomPlot[i][j]);
PlotValidation::DrawWriteSaveTH1FPlot(subdir,varsEffPlot[i][j],subdirname,Form("%s_eff_%s",vars[i].Data(),trks[j].Data()),zeroSupLin);
delete varsNumerPlot[i][j];
delete varsDenomPlot[i][j];
delete varsEffPlot[i][j];
}
}
delete efftree;
}
void PlotValidation::PlotFakeRate(){
// Get tree
TTree * fakeratetree = (TTree*)fInRoot->Get("fakeratetree");
// make output subdirectory and subdir in ROOT file, and cd to it.
TString subdirname = "fakerate";
PlotValidation::MakeSubDirectory(subdirname);
PlotValidation::MakeSubDirectory(Form("%s/lin",subdirname.Data()));
PlotValidation::MakeSubDirectory(Form("%s/log",subdirname.Data()));
TDirectory * subdir = fOutRoot->mkdir(subdirname.Data());
subdir->cd();
//Declare strings for branches and plots
Bool_t zeroSupLin = true;
TStrVec vars = {"pt","eta","phi"};
TStrVec svars = {"p_{T}","#eta","#phi"}; // svars --> labels for histograms for given variable
TStrVec sunits= {" [GeV/c]","",""}; // units --> labels for histograms for given variable
IntVec nBins = {60,60,80};
FltVec xlow = {0,-3,-4};
FltVec xhigh = {15,3,4};
TStrVec trks = {"seed","build","fit"};
TStrVec strks = {"Seed","Build","Fit"}; // strk --> labels for histograms for given track type
// Floats/Ints to be filled for trees
FltVecVec recovars_val(vars.size()); // first index is var, second is type of track
for (UInt_t i = 0; i < vars.size(); i++){
recovars_val[i].resize(trks.size());
}
IntVec mcmask_trk(trks.size()); // need to know if sim track associated to a given reco track type
IntVec seedmask_trk(trks.size()); // need to know if sim track associated to a given reco track type
// Create FR plots
TH1FRefVecVec varsNumerPlot(vars.size());
TH1FRefVecVec varsDenomPlot(vars.size());
TH1FRefVecVec varsFRPlot(vars.size());
for (UInt_t i = 0; i < vars.size(); i++){
varsNumerPlot[i].resize(trks.size());
varsDenomPlot[i].resize(trks.size());
varsFRPlot[i].resize(trks.size());
}
for (UInt_t i = 0; i < vars.size(); i++){
for (UInt_t j = 0; j < trks.size(); j++){
// Numerator
varsNumerPlot[i][j] = new TH1F(Form("h_reco_%s_numer_%s_FR",vars[i].Data(),trks[j].Data()),Form("%s Track vs Reco %s (Numer) FR",strks[j].Data(),svars[i].Data()),nBins[i],xlow[i],xhigh[i]);
varsNumerPlot[i][j]->GetXaxis()->SetTitle(Form("%s%s",svars[i].Data(),sunits[i].Data()));
varsNumerPlot[i][j]->GetYaxis()->SetTitle("nTracks");
// Denominator
varsDenomPlot[i][j] = new TH1F(Form("h_reco_%s_denom_%s_FR",vars[i].Data(),trks[j].Data()),Form("%s Track vs Reco %s (Denom) FR",strks[j].Data(),svars[i].Data()),nBins[i],xlow[i],xhigh[i]);
varsDenomPlot[i][j]->GetXaxis()->SetTitle(Form("%s%s",svars[i].Data(),sunits[i].Data()));
varsDenomPlot[i][j]->GetYaxis()->SetTitle("nTracks");
// Fake Rate
varsFRPlot[i][j] = new TH1F(Form("h_reco_%s_FR_%s_FR",vars[i].Data(),trks[j].Data()),Form("%s Track Fake Rate vs Reco %s",strks[j].Data(),svars[i].Data()),nBins[i],xlow[i],xhigh[i]);
varsFRPlot[i][j]->GetXaxis()->SetTitle(Form("%s%s",svars[i].Data(),sunits[i].Data()));
varsFRPlot[i][j]->GetYaxis()->SetTitle("Fake Rate");
}
}
//Initialize var_val/err arrays, SetBranchAddress
for (UInt_t i = 0; i < vars.size(); i++){ // loop over vars index
for (UInt_t j = 0; j < trks.size(); j++){ // loop over trks index
// initialize var
recovars_val[i][j] = 0.;
//Set var+trk branch
fakeratetree->SetBranchAddress(Form("%s_%s",vars[i].Data(),trks[j].Data()),&(recovars_val[i][j]));
}
}
//Initialize masks, set branch addresses
for (UInt_t j = 0; j < trks.size(); j++){ // loop over trks index
mcmask_trk[j] = 0;
seedmask_trk[j] = 0;
fakeratetree->SetBranchAddress(Form("mcmask_%s",trks[j].Data()),&(mcmask_trk[j]));
fakeratetree->SetBranchAddress(Form("seedmask_%s",trks[j].Data()),&(seedmask_trk[j]));
}
// Fill histos, compute fake rate from tree branches
for (Int_t k = 0; k < fakeratetree->GetEntries(); k++){
fakeratetree->GetEntry(k);
for (UInt_t i = 0; i < vars.size(); i++){ // loop over vars index
for (UInt_t j = 0; j < trks.size(); j++){ // loop over trks index
if (seedmask_trk[j] == 1) { // make sure it is actually a reco track matched to a seed
varsDenomPlot[i][j]->Fill(recovars_val[i][j]); // all reco tracks fill denom
if (mcmask_trk[j] == 0){ // only completely unassociated reco tracks enter FR
varsNumerPlot[i][j]->Fill(recovars_val[i][j]);
} // must be an unmatched track for FR
} // must be a real reco track for FR
} // end loop over trks
} // end loop over vars
} // end loop over entry in tree
// Draw, divide, and save fake rate plots --> then delete!
for (UInt_t i = 0; i < vars.size(); i++){
for (UInt_t j = 0; j < trks.size(); j++){
PlotValidation::ComputeRatioPlot(varsNumerPlot[i][j],varsDenomPlot[i][j],varsFRPlot[i][j]);
PlotValidation::WriteTH1FPlot(subdir,varsNumerPlot[i][j]);
PlotValidation::WriteTH1FPlot(subdir,varsDenomPlot[i][j]);
PlotValidation::DrawWriteSaveTH1FPlot(subdir,varsFRPlot[i][j],subdirname,Form("%s_FR_%s",vars[i].Data(),trks[j].Data()),zeroSupLin);
delete varsNumerPlot[i][j];
delete varsDenomPlot[i][j];
delete varsFRPlot[i][j];
}
}
delete fakeratetree;
}
void PlotValidation::PlotDuplicateRate(){
// Get tree
TTree * efftree = (TTree*)fInRoot->Get("efftree");
// make output subdirectory and subdir in ROOT file, and cd to it.
TString subdirname = "duplicaterate";
PlotValidation::MakeSubDirectory(subdirname);
PlotValidation::MakeSubDirectory(Form("%s/lin",subdirname.Data()));
PlotValidation::MakeSubDirectory(Form("%s/log",subdirname.Data()));
TDirectory * subdir = fOutRoot->mkdir(subdirname.Data());
subdir->cd();
//Declare strings for branches and plots
Bool_t zeroSupLin = true;
TStrVec vars = {"pt","eta","phi"};
TStrVec svars = {"p_{T}","#eta","#phi"}; // svars --> labels for histograms for given variable
TStrVec sunits= {" [GeV/c]","",""}; // units --> labels for histograms for given variable
IntVec nBins = {60,60,80};
FltVec xlow = {0,-3,-4};
FltVec xhigh = {15,3,4};
TStrVec trks = {"seed","build","fit"};
TStrVec strks = {"Seed","Build","Fit"}; // strk --> labels for histograms for given track type
// Floats/Ints to be filled for trees
FltVec mcvars_val(vars.size()); // first index is var. only for mc values! so no extra index
IntVec mcmask_trk(trks.size()); // need to know if sim track associated to a given reco track type
IntVec nTkMatches_trk(trks.size()); // need to know how many duplicates each mc track produces. nDupl == 1 means one reco track
// Create DR plots
TH1FRefVecVec varsNumerPlot(vars.size());
TH1FRefVecVec varsDenomPlot(vars.size());
TH1FRefVecVec varsDRPlot(vars.size());
for (UInt_t i = 0; i < vars.size(); i++){
varsNumerPlot[i].resize(trks.size());
varsDenomPlot[i].resize(trks.size());
varsDRPlot[i].resize(trks.size());
}
for (UInt_t i = 0; i < vars.size(); i++){
for (UInt_t j = 0; j < trks.size(); j++){
// Numerator
varsNumerPlot[i][j] = new TH1F(Form("h_sim_%s_numer_%s_DR",vars[i].Data(),trks[j].Data()),Form("%s Track vs MC %s (Numer) DR",strks[j].Data(),svars[i].Data()),nBins[i],xlow[i],xhigh[i]);
varsNumerPlot[i][j]->GetXaxis()->SetTitle(Form("%s%s",svars[i].Data(),sunits[i].Data()));
varsNumerPlot[i][j]->GetYaxis()->SetTitle("nTracks");
// Denominator
varsDenomPlot[i][j] = new TH1F(Form("h_sim_%s_denom_%s_DR",vars[i].Data(),trks[j].Data()),Form("%s Track vs MC %s (Denom) DR",strks[j].Data(),svars[i].Data()),nBins[i],xlow[i],xhigh[i]);
varsDenomPlot[i][j]->GetXaxis()->SetTitle(Form("%s%s",svars[i].Data(),sunits[i].Data()));
varsDenomPlot[i][j]->GetYaxis()->SetTitle("nTracks");
// Duplicate Rate
varsDRPlot[i][j] = new TH1F(Form("h_sim_%s_DR_%s_DR",vars[i].Data(),trks[j].Data()),Form("%s Track Duplicate Rate vs MC %s",strks[j].Data(),svars[i].Data()),nBins[i],xlow[i],xhigh[i]);
varsDRPlot[i][j]->GetXaxis()->SetTitle(Form("%s%s",svars[i].Data(),sunits[i].Data()));
varsDRPlot[i][j]->GetYaxis()->SetTitle("Duplicate Rate");
}
}
//Initialize var_val/err arrays, SetBranchAddress
for (UInt_t i = 0; i < vars.size(); i++){ // loop over trks index
// initialize var
mcvars_val[i] = 0.;
//Set var+trk branch
efftree->SetBranchAddress(Form("%s_mc_gen",vars[i].Data()),&(mcvars_val[i]));
}
//Initialize masks, set branch addresses
for (UInt_t j = 0; j < trks.size(); j++){ // loop over trks index
mcmask_trk[j] = 0;
nTkMatches_trk[j] = 0;
efftree->SetBranchAddress(Form("mcmask_%s",trks[j].Data()),&(mcmask_trk[j]));
efftree->SetBranchAddress(Form("nTkMatches_%s",trks[j].Data()),&(nTkMatches_trk[j]));
}
// Fill histos, compute DR from tree branches
for (Int_t k = 0; k < efftree->GetEntries(); k++){
efftree->GetEntry(k);
for (UInt_t i = 0; i < vars.size(); i++){ // loop over vars index
for (UInt_t j = 0; j < trks.size(); j++){ // loop over trks index
if (mcmask_trk[j] == 1) {
varsDenomPlot[i][j]->Fill(mcvars_val[i]);
for (Int_t n = 0; n < nTkMatches_trk[j]; n++){
varsNumerPlot[i][j]->Fill(mcvars_val[i]);
} // fill n times sim track is matched. filled once is one sim to one reco. filled twice is two reco to one sim
} // must be a matched track for proper denom
} // end loop over trks
} // end loop over vars
} // end loop over entry in tree
// Draw, divide, and save DR plots
for (UInt_t i = 0; i < vars.size(); i++){
for (UInt_t j = 0; j < trks.size(); j++){
PlotValidation::ComputeRatioPlot(varsNumerPlot[i][j],varsDenomPlot[i][j],varsDRPlot[i][j]);
PlotValidation::WriteTH1FPlot(subdir,varsNumerPlot[i][j]);
PlotValidation::WriteTH1FPlot(subdir,varsDenomPlot[i][j]);
PlotValidation::DrawWriteSaveTH1FPlot(subdir,varsDRPlot[i][j],subdirname,Form("%s_DR_%s",vars[i].Data(),trks[j].Data()),zeroSupLin);
delete varsNumerPlot[i][j];
delete varsDenomPlot[i][j];
delete varsDRPlot[i][j];
}
}
delete efftree;
}
void PlotValidation::PlotNHits(){
// Get tree --> can do this all with fake rate tree
TTree * fakeratetree = (TTree*)fInRoot->Get("fakeratetree");
// make output subdirectory and subdir in ROOT file, and cd to it.
TString subdirname = "nHits";
PlotValidation::MakeSubDirectory(subdirname);
PlotValidation::MakeSubDirectory(Form("%s/lin",subdirname.Data()));
PlotValidation::MakeSubDirectory(Form("%s/log",subdirname.Data()));
TDirectory * subdir = fOutRoot->mkdir(subdirname.Data());
subdir->cd();
//Declare strings for branches and plots
Bool_t zeroSupLin = false;
TStrVec trks = {"seed","build","fit"};
TStrVec strks = {"Seed","Build","Fit"}; // strk --> labels for histograms for given track type
TStrVec coll = {"allreco","fake","allmatch","bestmatch"};
TStrVec scoll = {"All Reco","Fake","All Match","Best Match"};
// Floats/Ints to be filled for trees
IntVec nHits_trk(trks.size());
FltVec fracHitsMatched_trk(trks.size());
// masks
IntVec mcmask_trk(trks.size()); // need to know if sim track associated to a given reco track type
IntVec seedmask_trk(trks.size()); // need to know if reco track associated to a seed track
IntVec iTkMatches_trk(trks.size());
// Create plots
TH1FRefVecVec nHitsPlot(trks.size());
TH1FRefVecVec fracHitsMatchedPlot(trks.size());
for (UInt_t j = 0; j < trks.size(); j++){
nHitsPlot[j].resize(coll.size());
fracHitsMatchedPlot[j].resize(coll.size());
}
for (UInt_t j = 0; j < trks.size(); j++){
for (UInt_t c = 0; c < coll.size(); c++){
// Numerator only type plots only!
nHitsPlot[j][c] = new TH1F(Form("h_nHits_%s_%s",coll[c].Data(),trks[j].Data()),Form("%s %s Track vs nHits / Track",scoll[c].Data(),strks[j].Data()),11,0,11);
nHitsPlot[j][c]->GetXaxis()->SetTitle("nHits / Track");
nHitsPlot[j][c]->GetYaxis()->SetTitle("nTracks");
nHitsPlot[j][c]->Sumw2();
fracHitsMatchedPlot[j][c] = new TH1F(Form("h_fracHitsMatched_%s_%s",coll[c].Data(),trks[j].Data()),Form("%s %s Track vs Highest Fraction of Matched Hits / Track",scoll[c].Data(),strks[j].Data()),4000,0,1.1);
fracHitsMatchedPlot[j][c]->GetXaxis()->SetTitle("Highest Fraction of Matched Hits / Track");
fracHitsMatchedPlot[j][c]->GetYaxis()->SetTitle("nTracks");
fracHitsMatchedPlot[j][c]->Sumw2();
}
}
//Initialize masks and variables, set branch addresses
for (UInt_t j = 0; j < trks.size(); j++){ // loop over trks index
mcmask_trk[j] = 0;
seedmask_trk[j] = 0;
iTkMatches_trk[j] = 0;
nHits_trk[j] = 0;
fracHitsMatched_trk[j] = 0;
fakeratetree->SetBranchAddress(Form("mcmask_%s",trks[j].Data()),&(mcmask_trk[j]));
fakeratetree->SetBranchAddress(Form("seedmask_%s",trks[j].Data()),&(seedmask_trk[j]));
fakeratetree->SetBranchAddress(Form("iTkMatches_%s",trks[j].Data()),&(iTkMatches_trk[j]));
fakeratetree->SetBranchAddress(Form("nHits_%s",trks[j].Data()),&(nHits_trk[j]));
fakeratetree->SetBranchAddress(Form("fracHitsMatched_%s",trks[j].Data()),&(fracHitsMatched_trk[j]));
}
// Fill histos, compute res/pull from tree branches
for (Int_t k = 0; k < fakeratetree->GetEntries(); k++){
fakeratetree->GetEntry(k);
for (UInt_t j = 0; j < trks.size(); j++){ // loop over trks index
for (UInt_t c = 0; c < coll.size(); c++){ // loop over trk collection type
if (c == 0) { // all reco
if (seedmask_trk[j] == 1){
nHitsPlot[j][c]->Fill(nHits_trk[j]);
fracHitsMatchedPlot[j][c]->Fill(fracHitsMatched_trk[j]);
}
}
else if (c == 1) { // fake
if ((seedmask_trk[j] == 1) && (mcmask_trk[j] == 0)) {
nHitsPlot[j][c]->Fill(nHits_trk[j]);
fracHitsMatchedPlot[j][c]->Fill(fracHitsMatched_trk[j]);
}
}
else if (c == 2) { // all matches
if ((seedmask_trk[j] == 1) && (mcmask_trk[j] == 1)) {
nHitsPlot[j][c]->Fill(nHits_trk[j]);
fracHitsMatchedPlot[j][c]->Fill(fracHitsMatched_trk[j]);
}
}
else if (c == 3) { // best matches only
if ((seedmask_trk[j] == 1) && (mcmask_trk[j] == 1) && (iTkMatches_trk[j] == 0)) {
nHitsPlot[j][c]->Fill(nHits_trk[j]);
fracHitsMatchedPlot[j][c]->Fill(fracHitsMatched_trk[j]);
}
}
} // end loop over trk type collection
} // end loop over trks
} // end loop over entry in tree
// Draw and save nHits plots
for (UInt_t j = 0; j < trks.size(); j++){
for (UInt_t c = 0; c < coll.size(); c++){ // loop over trk collection type
PlotValidation::DrawWriteSaveTH1FPlot(subdir,nHitsPlot[j][c],subdirname,Form("nHits_%s_%s",coll[c].Data(),trks[j].Data()),zeroSupLin);
PlotValidation::DrawWriteSaveTH1FPlot(subdir,fracHitsMatchedPlot[j][c],subdirname,Form("fracHitsMatched_%s_%s",coll[c].Data(),trks[j].Data()),zeroSupLin);
delete nHitsPlot[j][c];
delete fracHitsMatchedPlot[j][c];
}
}
delete fakeratetree;
}
void PlotValidation::PlotTiming(){
// get input tree
TTree * configtree = (TTree*)fInRoot->Get("configtree");
// labels for histos (x-axis)
TStrVec stime = {"Simulate","Segment","Seed","Build","Fit","Validate"};
// make subdirectory
TString subdirname = "timing";
PlotValidation::MakeSubDirectory(subdirname);
PlotValidation::MakeSubDirectory(Form("%s/lin",subdirname.Data()));
PlotValidation::MakeSubDirectory(Form("%s/log",subdirname.Data()));
TDirectory * subdir = fOutRoot->mkdir(subdirname.Data());
subdir->cd();
// output plots
Bool_t zeroSupLin = true;
// make new timing plots
TH1F * tottime = new TH1F("h_total_timing","Total Time Spent in Simulation",6,0,6);
tottime->GetXaxis()->SetTitle("Event Function Call");
tottime->GetYaxis()->SetTitle("Time [s]");
tottime->SetStats(0);
tottime->Sumw2();
for (Int_t t = 1; t <= tottime->GetNbinsX(); t++){
tottime->GetXaxis()->SetBinLabel(t,stime[t-1].Data());
}
TH1F * rectime = new TH1F("h_reco_timing_norm","Normalized Time Spent in Reconstruction",4,0,4);
tottime->GetXaxis()->SetTitle("Event Function Call");
rectime->GetYaxis()->SetTitle("Fraction of Time in Reco");
rectime->SetStats(0);
rectime->Sumw2();
for (Int_t t = 1; t <= rectime->GetNbinsX(); t++){
rectime->GetXaxis()->SetBinLabel(t,stime[t].Data());
}
Float_t simtime = 0., segtime = 0., seedtime = 0., buildtime = 0., fittime = 0., hlvtime = 0.;
configtree->SetBranchAddress("simtime",&simtime);
configtree->SetBranchAddress("segtime",&segtime);
configtree->SetBranchAddress("seedtime",&seedtime);
configtree->SetBranchAddress("buildtime",&buildtime);
configtree->SetBranchAddress("fittime",&fittime);
configtree->SetBranchAddress("hlvtime",&hlvtime);
configtree->GetEntry(0);
// fill histos
tottime->SetBinContent(1,simtime);
tottime->SetBinContent(2,segtime);
tottime->SetBinContent(3,seedtime);
tottime->SetBinContent(4,buildtime);
tottime->SetBinContent(5,fittime);
tottime->SetBinContent(6,hlvtime);
rectime->SetBinContent(1,segtime);
rectime->SetBinContent(2,seedtime);
rectime->SetBinContent(3,buildtime);
rectime->SetBinContent(4,fittime);
// normalize rec time
rectime->Scale(1.0/rectime->Integral());
// draw and save stuff
PlotValidation::DrawWriteSaveTH1FPlot(subdir,tottime,subdirname,"total_time_sim",zeroSupLin);
PlotValidation::DrawWriteSaveTH1FPlot(subdir,rectime,subdirname,"norm_time_reco",zeroSupLin);
delete tottime;
delete rectime;
delete configtree;
}
void PlotValidation::PlotMomResolutionPull(){
// Get tree
TTree * efftree = (TTree*)fInRoot->Get("efftree");
// make output subdirectory and subdir in ROOT file, and cd to it.
TString subdirname = "momentum_resolutionpull";
PlotValidation::MakeSubDirectory(subdirname);
PlotValidation::MakeSubDirectory(Form("%s/lin",subdirname.Data()));
PlotValidation::MakeSubDirectory(Form("%s/log",subdirname.Data()));
TDirectory * subdir = fOutRoot->mkdir(subdirname.Data());
subdir->cd();
//Declare strings for branches and plots
TStrVec vars = {"pt","eta","phi"};
TStrVec evars = {"ept","eeta","ephi"};
TStrVec svars = {"p_{T}","#eta","#phi"}; // svars --> labels for histograms for given variable
TStrVec sunits = {" [GeV/c]","",""}; // units --> labels for histograms for given variable
IntVec nBinsRes = {100,100,100};
FltVec xlowRes = {-0.5,-0.5,-0.5};
FltVec xhighRes = {0.5,0.5,0.5};
FltVec gausRes = {0.3,0.3,0.3}; // symmetric bounds for gaussian fit
IntVec nBinsPull = {100,100,100};
FltVec xlowPull = {-5,-5,-5};
FltVec xhighPull = {5,5,5};
FltVec gausPull = {3,3,3}; // symmetric bounds for gaussian fit
TStrVec trks = {"seed","build","fit"};
TStrVec strks = {"Seed","Build","Fit"}; // strk --> labels for histograms for given track type
// Floats/Ints to be filled for trees
FltVecVec mcvars_val(vars.size());
IntVec mcmask_trk(trks.size()); // need to know if sim track associated to a given reco track type
FltVecVec recovars_val(vars.size()); // first index is nVars, second is nTrkTypes
FltVecVec recovars_err(vars.size());
for (UInt_t i = 0; i < vars.size(); i++){
mcvars_val[i].resize(trks.size());
recovars_val[i].resize(trks.size());
recovars_err[i].resize(trks.size());
}
FltVec vars_out = {0.,0.}; // res/pull output
// Create pos plots
TH1FRefVecVec varsResPlot(vars.size());
TH1FRefVecVec varsPullPlot(vars.size());
for (UInt_t i = 0; i < vars.size(); i++){
varsResPlot[i].resize(trks.size());
varsPullPlot[i].resize(trks.size());
}
for (UInt_t i = 0; i < vars.size(); i++){
for (UInt_t j = 0; j < trks.size(); j++){
//Res
varsResPlot[i][j] = new TH1F(Form("h_%s_res_%s",vars[i].Data(),trks[j].Data()),Form("%s Resolution (%s Track vs. MC Track)",svars[i].Data(),strks[j].Data()),nBinsRes[i],xlowRes[i],xhighRes[i]);
varsResPlot[i][j]->GetXaxis()->SetTitle(Form("(%s^{%s}%s - %s^{mc}%s)/%s^{mc}%s",svars[i].Data(),strks[j].Data(),sunits[i].Data(),svars[i].Data(),sunits[i].Data(),svars[i].Data(),sunits[i].Data()));
varsResPlot[i][j]->GetYaxis()->SetTitle("nTracks");
varsResPlot[i][j]->Sumw2();
//Pull
varsPullPlot[i][j] = new TH1F(Form("h_%s_pull_%s",vars[i].Data(),trks[j].Data()),Form("%s Pull (%s Track vs. MC Track)",svars[i].Data(),strks[j].Data()),nBinsPull[i],xlowPull[i],xhighPull[i]);
varsPullPlot[i][j]->GetXaxis()->SetTitle(Form("(%s^{%s}%s - %s^{mc}%s)/#sigma(%s^{%s})%s",svars[i].Data(),strks[j].Data(),sunits[i].Data(),svars[i].Data(),sunits[i].Data(),svars[i].Data(),strks[j].Data(),sunits[i].Data()));
varsPullPlot[i][j]->GetYaxis()->SetTitle("nTracks");
varsPullPlot[i][j]->Sumw2();
}
}
//Initialize var_val/err arrays, SetBranchAddress
for (UInt_t i = 0; i < vars.size(); i++){ // loop over var index
for (UInt_t j = 0; j < trks.size(); j++){ // loop over trks index
// initialize var + errors
mcvars_val[i][j] = 0.;
recovars_val[i][j] = 0.;
recovars_err[i][j] = 0.;
//Set var+trk branch
efftree->SetBranchAddress(Form("%s_mc_%s",vars[i].Data(),trks[j].Data()),&(mcvars_val[i][j]));
efftree->SetBranchAddress(Form("%s_%s",vars[i].Data(),trks[j].Data()),&(recovars_val[i][j]));
efftree->SetBranchAddress(Form("%s_%s",evars[i].Data(),trks[j].Data()),&(recovars_err[i][j]));
}
}
//Initialize masks, set branch addresses
for (UInt_t j = 0; j < trks.size(); j++){ // loop over trks index
mcmask_trk[j] = 0;
efftree->SetBranchAddress(Form("mcmask_%s",trks[j].Data()),&(mcmask_trk[j]));
}
// Fill histos, compute res/pull from tree branches
for (Int_t k = 0; k < efftree->GetEntries(); k++){
efftree->GetEntry(k);
for (UInt_t i = 0; i < vars.size(); i++){ // loop over vars index
for (UInt_t j = 0; j < trks.size(); j++){ // loop over trks index
if (mcmask_trk[j] == 1){ // must be associated
PlotValidation::ComputeResolutionPull(mcvars_val[i][j],recovars_val[i][j],recovars_err[i][j],vars_out);
if (!isnan(vars_out[0])){ // fill if not nan
varsResPlot[i][j]->Fill(vars_out[0]);
}
if (!isnan(vars_out[1])){ // fill if not nan
varsPullPlot[i][j]->Fill(vars_out[1]);
}
} // must be a matched track to make resolution plots
} // end loop over trks
} // end loop over vars
} // end loop over entry in tree
// Draw, fit, and save plots
for (UInt_t i = 0; i < vars.size(); i++){
for (UInt_t j = 0; j < trks.size(); j++){
PlotValidation::DrawWriteFitSaveTH1FPlot(subdir,varsResPlot[i][j],subdirname,Form("%s_resolution_%s",vars[i].Data(),trks[j].Data()),gausRes[i]);
PlotValidation::DrawWriteFitSaveTH1FPlot(subdir,varsPullPlot[i][j],subdirname,Form("%s_pull_%s",vars[i].Data(),trks[j].Data()),gausPull[i]);
delete varsResPlot[i][j];
delete varsPullPlot[i][j];
}
}
delete efftree;
}
void PlotValidation::PlotSegment(){
// Get trees and set addresses
TTree * segtree = (TTree*)fInRoot->Get("segtree");
Int_t event = 0;
Int_t layer = 0;
Int_t etabin = 0;
Int_t phibin = 0;
Int_t nHits = 0;
segtree->SetBranchAddress("evtID",&event);
segtree->SetBranchAddress("layer",&layer);
segtree->SetBranchAddress("etabin",&etabin);
segtree->SetBranchAddress("phibin",&phibin);
segtree->SetBranchAddress("nHits",&nHits);
// get config info
TTree * configtree = (TTree*)fInRoot->Get("configtree");
Int_t nEvents = 0;
Int_t nLayers = 0;
Int_t nEtaPart = 0;
Int_t nPhiPart = 0;
configtree->SetBranchAddress("Nevents",&nEvents);
configtree->SetBranchAddress("nLayers",&nLayers);
configtree->SetBranchAddress("nEtaPart",&nEtaPart);
configtree->SetBranchAddress("nPhiPart",&nPhiPart);
configtree->GetEntry(0);
////////////////////////////////////////
// Store the info in relevant vectors //
////////////////////////////////////////
// initialize the relevant vectors here
FltVecVec nHitsEtaVV(nLayers); // vector to store how many hits in given eta bin (sum over the phi bins)
FltVecVecVec nHitsPhiVVV(nLayers); // vector to store how many hits in given eta-phi bin
for (Int_t ilay = 0; ilay < nLayers; ilay++){
nHitsEtaVV[ilay].resize(nEtaPart);
nHitsPhiVVV[ilay].resize(nEtaPart);
for (Int_t ieta = 0; ieta < nEtaPart; ieta++){
nHitsEtaVV[ilay][ieta] = 0;
nHitsPhiVVV[ilay][ieta].resize(nPhiPart);
for (Int_t iphi = 0; iphi < nPhiPart; iphi++){
nHitsPhiVVV[ilay][ieta][iphi] = 0;
}
}
}
// just fill the eta-phi bin vector, and then sum over phi bins for the eta vector
for (Int_t i = 0; i < segtree->GetEntries(); i++) {
segtree->GetEntry(i);
nHitsPhiVVV[layer][etabin][phibin] += nHits;
}
// sum over phi bins into eta bin vector
for (Int_t ilay = 0; ilay < nLayers; ilay++){
for (Int_t ieta = 0; ieta < nEtaPart; ieta++){
for (Int_t iphi = 0; iphi < nPhiPart; iphi++){
nHitsEtaVV[ilay][ieta] += nHitsPhiVVV[ilay][ieta][iphi];
}
}
}
// average over events
for (Int_t ilay = 0; ilay < nLayers; ilay++){
for (Int_t ieta = 0; ieta < nEtaPart; ieta++){
nHitsEtaVV[ilay][ieta] /= nEvents;
for (Int_t iphi = 0; iphi < nPhiPart; iphi++){
nHitsPhiVVV[ilay][ieta][iphi] /= nEvents;
}
}
}
// initialize plot vectors
TH1FRefVec nHitsplots(nLayers);
TH1FRefVec etabinplots(nLayers);
TH1FRefVecVec phibinplots(nLayers);
for (Int_t ilay = 0; ilay < nLayers; ilay++){
phibinplots[ilay].resize(nEtaPart);
}
// make output subdirectory and subdir in ROOT file, and cd to it.
TString subdirname = "segment";
PlotValidation::MakeSubDirectory(subdirname);
TDirectory * subdir = fOutRoot->mkdir(subdirname.Data());
subdir->cd();
// new and fill!
for (Int_t ilay = 0; ilay < nLayers; ilay++){
nHitsplots[ilay] = new TH1F(Form("h_nHits_perEtaPhiBin_lay%u",ilay),Form("nHits per EtaPhiBin (Layer: %u)",ilay),20,0,20);
nHitsplots[ilay]->GetXaxis()->SetTitle("nHits per EtaPhiBin");
nHitsplots[ilay]->GetYaxis()->SetTitle("nEtaPhiBins");
etabinplots[ilay] = new TH1F(Form("h_nHits_vs_etabin_lay%u",ilay),Form("nHits vs EtaBin (Layer: %u)",ilay),nEtaPart,0,nEtaPart);
etabinplots[ilay]->GetXaxis()->SetTitle("Eta Bin Number");
etabinplots[ilay]->GetYaxis()->SetTitle("nHits in Eta Bin");
for (Int_t ieta = 0; ieta < nEtaPart; ieta++){
//fill the eta bin plots
etabinplots[ilay]->SetBinContent(ieta+1,nHitsEtaVV[ilay][ieta]);
// eta-phi bin plots new
phibinplots[ilay][ieta] = new TH1F(Form("h_nHits_vs_phibin_lay%u_eta%u",ilay,ieta),Form("nHits vs PhiBin (Layer: %u, EtaBin: %u)",ilay,ieta),nPhiPart,0,nPhiPart);
phibinplots[ilay][ieta]->GetXaxis()->SetTitle("Phi Bin Number");
phibinplots[ilay][ieta]->GetYaxis()->SetTitle("nHits in Phi Bin");
// fill eta-phi bin plots
for (Int_t iphi = 0; iphi < nPhiPart; iphi++){
phibinplots[ilay][ieta]->SetBinContent(iphi+1,nHitsPhiVVV[ilay][ieta][iphi]);
nHitsplots[ilay]->Fill(nHitsPhiVVV[ilay][ieta][iphi]);
}
}
}
// write out the individual plots to the root file
for (Int_t ilay = 0; ilay < nLayers; ilay++){
PlotValidation::WriteTH1FPlot(subdir,nHitsplots[ilay]);
PlotValidation::WriteTH1FPlot(subdir,etabinplots[ilay]);
for (Int_t ieta = 0; ieta < nEtaPart; ieta++){
PlotValidation::WriteTH1FPlot(subdir,phibinplots[ilay][ieta]);
}
}
///////////////////////////////
// Plot segment results here //
///////////////////////////////
// first do the nHits plot
fTH1Canv->cd();
fTH1Canv->SetLogy(0);
Float_t max = 0;
for (Int_t ilay = 0; ilay < nLayers; ilay++){
Float_t tmpmax = nHitsplots[ilay]->GetBinContent(nHitsplots[ilay]->GetMaximumBin());
if (tmpmax > max) {
max = tmpmax;
}
}
// overplot
TLegend * legnhit = new TLegend(0.75,0.7,0.9,0.9);
for (Int_t ilay = 0; ilay < nLayers; ilay++){
nHitsplots[ilay]->SetStats(0);
nHitsplots[ilay]->SetTitle("Average nHits per Event per EtaPhiBin for All Layers");
nHitsplots[ilay]->SetMaximum(1.1*max);
nHitsplots[ilay]->SetLineColor(fColors[ilay%fColorSize]+(ilay/fColorSize)); // allow colors to loop over base!
nHitsplots[ilay]->SetLineWidth(2);
nHitsplots[ilay]->Draw((ilay>0)?"SAME":"");
legnhit->AddEntry(nHitsplots[ilay],Form("Layer %u",ilay),"L");
}
legnhit->Draw("SAME");
fTH1Canv->SaveAs(Form("%s/%s/nHits_perEtaPhiBin_allLayers.%s",fOutName.Data(),subdirname.Data(),fOutType.Data()));
for (Int_t ilay = 0; ilay < nLayers; ilay++){ // delete all histos, including layers not filled in
delete nHitsplots[ilay];
}
delete legnhit;
// now we want to overplot the eta plots second
max = 0;
for (Int_t ilay = 0; ilay < nLayers; ilay++){
Float_t tmpmax = etabinplots[ilay]->GetBinContent(etabinplots[ilay]->GetMaximumBin());
if (tmpmax > max) {
max = tmpmax;
}
}
// overplot
TLegend * legeta = new TLegend(0.75,0.7,0.9,0.9);
for (Int_t ilay = 0; ilay < nLayers; ilay++){
etabinplots[ilay]->SetStats(0);
etabinplots[ilay]->SetTitle("Average nHits per Event vs EtaBin for All Layers");
etabinplots[ilay]->SetMaximum(1.1*max);
etabinplots[ilay]->SetLineColor(fColors[ilay%fColorSize]+(ilay/fColorSize)); // allow colors to loop over base!
etabinplots[ilay]->SetLineWidth(2);
etabinplots[ilay]->Draw((ilay>0)?"SAME":"");
legeta->AddEntry(etabinplots[ilay],Form("Layer %u",ilay),"L");
}
legeta->Draw("SAME");
fTH1Canv->SaveAs(Form("%s/%s/nHits_vs_Etabin_allLayers.%s",fOutName.Data(),subdirname.Data(),fOutType.Data()));
for (Int_t ilay = 0; ilay < nLayers; ilay++){ // delete all histos, including layers not filled in
delete etabinplots[ilay];
}
delete legeta;
// now we want to overplot the phi plots second ... a bit more complicated
// first do the phi bin plots for a given eta bin, overplot layer
// then do the phi bin plots for a given layer, overplot eta bin
// so fix the eta bin, then overplot layers
for (Int_t ieta = 0; ieta < nEtaPart; ieta++){
Float_t max = 0;
for (Int_t ilay = 0; ilay < nLayers; ilay++){
Float_t tmpmax = phibinplots[ilay][ieta]->GetBinContent(phibinplots[ilay][ieta]->GetMaximumBin());
if (tmpmax > max) {
max = tmpmax;
}
}
// overplot
TLegend * legphi = new TLegend(0.75,0.7,0.9,0.9);
for (Int_t ilay = 0; ilay < nLayers; ilay++){
phibinplots[ilay][ieta]->SetStats(0);
phibinplots[ilay][ieta]->SetTitle(Form("Average nHits per Event vs PhiBin for All Layers (EtaBin: %u)",ieta));
phibinplots[ilay][ieta]->SetMaximum(1.1*max);
phibinplots[ilay][ieta]->SetLineColor(fColors[ilay%fColorSize]+(ilay/fColorSize)); // allow colors to loop over base!
phibinplots[ilay][ieta]->SetLineWidth(2);
phibinplots[ilay][ieta]->Draw((ilay>0)?"SAME":"");
legphi->AddEntry(phibinplots[ilay][ieta],Form("Layer %u",ilay),"L");
}
legphi->Draw("SAME");
fTH1Canv->SaveAs(Form("%s/%s/nHits_vs_Phibin_allLayers_etabin%u.%s",fOutName.Data(),subdirname.Data(),ieta,fOutType.Data()));
delete legphi;
}
// now fix layer, overplot eta bins
for (Int_t ilay = 0; ilay < nLayers; ilay++){
Float_t max = 0;
for (Int_t ieta = 0; ieta < nEtaPart; ieta++){
Float_t tmpmax = phibinplots[ilay][ieta]->GetBinContent(phibinplots[ilay][ieta]->GetMaximumBin());
if (tmpmax > max) {
max = tmpmax;
}
}
// overplot
TLegend * legphi = new TLegend(0.75,0.7,0.9,0.9);
for (Int_t ieta = 0; ieta < nEtaPart; ieta++){
phibinplots[ilay][ieta]->SetStats(0);
phibinplots[ilay][ieta]->SetTitle(Form("Average nHits per Event vs PhiBin for All EtaBins (Layer: %u)",ilay));
phibinplots[ilay][ieta]->SetMaximum(1.1*max);
phibinplots[ilay][ieta]->SetLineColor(fColors[ieta%fColorSize]+(ieta/fColorSize)); // allow colors to loop over base!
phibinplots[ilay][ieta]->SetLineWidth(2);
phibinplots[ilay][ieta]->Draw((ieta>0)?"SAME":"");
legphi->AddEntry(phibinplots[ilay][ieta],Form("EtaBin %u",ieta),"L");
}
legphi->Draw("SAME");
fTH1Canv->SaveAs(Form("%s/%s/nHits_vs_Phibin_allEtaBins_layer%u.%s",fOutName.Data(),subdirname.Data(),ilay,fOutType.Data()));
delete legphi;
}
for (Int_t ilay = 0; ilay < nLayers; ilay++){
for (Int_t ieta = 0; ieta < nEtaPart; ieta++){
delete phibinplots[ilay][ieta];
}
}
delete configtree;
delete segtree;
}
void PlotValidation::PlotBranching(){
// Get tree
TTree * tree_br = (TTree*)fInRoot->Get("tree_br");
// Get config tree for printing out info
TTree * configtree = (TTree*)fInRoot->Get("configtree"); // use to get nLayers
Int_t nLayers = 0;
Int_t nlayers_per_seed = 0;
Int_t nEvents = 0;
configtree->SetBranchAddress("nLayers",&nLayers);
configtree->SetBranchAddress("nlayers_per_seed",&nlayers_per_seed);
configtree->SetBranchAddress("Nevents",&nEvents);
configtree->GetEntry(0);
// make output subdirectory and subdir in ROOT file, and cd to it.
TString subdirname = "branching";
PlotValidation::MakeSubDirectory(subdirname);
TDirectory * subdir = fOutRoot->mkdir(subdirname.Data());
subdir->cd();
// make plots, ensure in right directory
TH2F * laycands = new TH2F("h_lay_vs_cands","Layer vs nCandidates",20,0,20,nLayers,0,nLayers);
laycands->GetXaxis()->SetTitle("nInputCands / Layer / Seed");
laycands->GetYaxis()->SetTitle("Layer");
TH2F * layetaphibins = new TH2F("h_lay_vs_etaphibins","Layer vs nEtaPhiBins",20,0,20,nLayers,0,nLayers);
layetaphibins->GetXaxis()->SetTitle("Total nEtaPhiBins Explored / Layer / Seed");
layetaphibins->GetYaxis()->SetTitle("Layer");
TH2F * layhits = new TH2F("h_lay_vs_hits","Layer vs nHits",50,0,50,nLayers,0,nLayers);
layhits->GetXaxis()->SetTitle("Total nHits Explored / Layer / Seed");
layhits->GetYaxis()->SetTitle("Layer");
TH2F * laybranches = new TH2F("h_lay_vs_branches","Layer vs nBranches",20,0,20,nLayers,0,nLayers);
laybranches->GetXaxis()->SetTitle("Total nTempCandBranches Produced / Layer / Seed");
laybranches->GetYaxis()->SetTitle("Layer");
TH2F * layetaphibins_unique = new TH2F("h_lay_vs_etaphibins_unique","Layer vs nUniqueEtaPhiBins",20,0,20,nLayers,0,nLayers);
layetaphibins_unique->GetXaxis()->SetTitle("Total nUniqueEtaPhiBins Explored / Layer / Seed");
layetaphibins_unique->GetYaxis()->SetTitle("Layer");
TH2F * layhits_unique = new TH2F("h_lay_vs_hits_unique","Layer vs nUniqueHits",50,0,50,nLayers,0,nLayers);
layhits_unique->GetXaxis()->SetTitle("Total nUniqueHits Explored / Layer / Seed");
layhits_unique->GetYaxis()->SetTitle("Layer");
TH2F * laybranches_unique = new TH2F("h_lay_vs_braches_unique","Layer vs nUniqueBranches",20,0,20,nLayers,0,nLayers);
laybranches_unique->GetXaxis()->SetTitle("Total nTempCandUniqueBranches Produced / Layer / Seed");
laybranches_unique->GetYaxis()->SetTitle("Layer");
TH2F * layetaphibins_percand = new TH2F("h_lay_vs_etaphibins_percand","Layer vs nEtaPhiBins per InputCand",20,0,20,nLayers,0,nLayers);
layetaphibins_percand->GetXaxis()->SetTitle("nEtaPhiBins Explored per InputCand / Layer / Seed");
layetaphibins_percand->GetYaxis()->SetTitle("Layer");
TH2F * layhits_percand = new TH2F("h_lay_vs_hits_percand","Layer vs nHits per InputCand",50,0,50,nLayers,0,nLayers);
layhits_percand->GetXaxis()->SetTitle("nHits Explored per InputCand / Layer / Seed");
layhits_percand->GetYaxis()->SetTitle("Layer");