-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecoDataAnalysis.cc
More file actions
1685 lines (1369 loc) · 64.3 KB
/
RecoDataAnalysis.cc
File metadata and controls
1685 lines (1369 loc) · 64.3 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 "TFile.h"
#include "TTree.h"
#include "TString.h"
#include "TCanvas.h"
#include "TTree.h"
#include "TVector3.h"
#include "TMatrixDSym.h"
#include "TMatrixDSymEigen.h"
#include "TVectorD.h"
#include "TEfficiency.h"
#include <vector>
#include "Helpers.cc"
void RecoDataAnalysis() {
// Set defaults
gStyle->SetOptStat(0); // get rid of stats box
TH1D::SetDefaultSumw2();
TH2D::SetDefaultSumw2();
gStyle->SetPalette(kRainBow);
TGraph* gProton = new TGraph();
TGraph* gPion = new TGraph();
TGraph* gMuonTG = new TGraph();
// Initialize points
initializeProtonPoints(gProton);
initializePionPoints(gPion);
initializeMuonNoBraggPoints(gMuonTG);
int FontStyle = 132;
double TextSize = 0.06;
TString SaveDir = "/exp/lariat/app/users/epelaez/analysis/figs/RecoDataAnalysis/";
// Load file with NN data products
TString RootFilePath = "/exp/lariat/app/users/epelaez/files/DataAll_histo.root";
std::unique_ptr<TFile> File(TFile::Open(RootFilePath));
TDirectory* Directory = (TDirectory*)File->Get("RecoNNDataEval");
// Load file with MC comparison histograms
TString MCCompFilePath = "/exp/lariat/app/users/epelaez/files/DataMCComparisons.root";
std::unique_ptr<TFile> MCFile(TFile::Open(MCCompFilePath));
///////////////////
// Load branches //
///////////////////
// Load tree and branches
TTree* tree = (TTree*) Directory->Get<TTree>("RecoNNDataEvalTree");
int run, subrun, event; bool isData;
tree->SetBranchAddress("run", &run);
tree->SetBranchAddress("subrun", &subrun);
tree->SetBranchAddress("event", &event);
tree->SetBranchAddress("isData", &isData);
// WC match information
int WC2TPCtrkID, WC2TPCsize;
double WCTrackMomentum, WCTheta, WCPhi, WC4PrimaryX;
double WC2TPCPrimaryBeginX, WC2TPCPrimaryBeginY, WC2TPCPrimaryBeginZ;
double WC2TPCPrimaryEndX, WC2TPCPrimaryEndY, WC2TPCPrimaryEndZ;
std::vector<double>* wcMatchResR = nullptr;
std::vector<double>* wcMatchDEDX = nullptr;
std::vector<double>* wcMatchEDep = nullptr;
std::vector<double>* wcMatchXPos = nullptr;
std::vector<double>* wcMatchYPos = nullptr;
std::vector<double>* wcMatchZPos = nullptr;
tree->SetBranchAddress("WC2TPCtrkID", &WC2TPCtrkID);
tree->SetBranchAddress("WC2TPCsize", &WC2TPCsize);
tree->SetBranchAddress("WCTrackMomentum", &WCTrackMomentum);
tree->SetBranchAddress("WCTheta", &WCTheta);
tree->SetBranchAddress("WCPhi", &WCPhi);
tree->SetBranchAddress("WC4PrimaryX", &WC4PrimaryX);
tree->SetBranchAddress("WC2TPCPrimaryBeginX", &WC2TPCPrimaryBeginX);
tree->SetBranchAddress("WC2TPCPrimaryBeginY", &WC2TPCPrimaryBeginY);
tree->SetBranchAddress("WC2TPCPrimaryBeginZ", &WC2TPCPrimaryBeginZ);
tree->SetBranchAddress("WC2TPCPrimaryEndX", &WC2TPCPrimaryEndX);
tree->SetBranchAddress("WC2TPCPrimaryEndY", &WC2TPCPrimaryEndY);
tree->SetBranchAddress("WC2TPCPrimaryEndZ", &WC2TPCPrimaryEndZ);
tree->SetBranchAddress("wcMatchResR", &wcMatchResR);
tree->SetBranchAddress("wcMatchDEDX", &wcMatchDEDX);
tree->SetBranchAddress("wcMatchEDep", &wcMatchEDep);
tree->SetBranchAddress("wcMatchXPos", &wcMatchXPos);
tree->SetBranchAddress("wcMatchYPos", &wcMatchYPos);
tree->SetBranchAddress("wcMatchZPos", &wcMatchZPos);
// WC match location information
std::vector<double>* WC2TPCLocationsX = nullptr;
std::vector<double>* WC2TPCLocationsY = nullptr;
std::vector<double>* WC2TPCLocationsZ = nullptr;
tree->SetBranchAddress("WC2TPCLocationsX", &WC2TPCLocationsX);
tree->SetBranchAddress("WC2TPCLocationsY", &WC2TPCLocationsY);
tree->SetBranchAddress("WC2TPCLocationsZ", &WC2TPCLocationsZ);
// WC quality data
int wcNumHits;
std::vector<double>* wcHit0 = nullptr;
std::vector<double>* wcHit1 = nullptr;
std::vector<double>* wcHit2 = nullptr;
std::vector<double>* wcHit3 = nullptr;
tree->SetBranchAddress("wcNumHits", &wcNumHits);
tree->SetBranchAddress("wcHit0", &wcHit0);
tree->SetBranchAddress("wcHit1", &wcHit1);
tree->SetBranchAddress("wcHit2", &wcHit2);
tree->SetBranchAddress("wcHit3", &wcHit3);
// Reco information
std::vector<double>* recoMeanDEDX = nullptr;
std::vector<double>* recoEndX = nullptr;
std::vector<double>* recoEndY = nullptr;
std::vector<double>* recoEndZ = nullptr;
std::vector<double>* recoBeginX = nullptr;
std::vector<double>* recoBeginY = nullptr;
std::vector<double>* recoBeginZ = nullptr;
std::vector<int>* recoTrkID = nullptr;
std::vector<bool>* isTrackNearVertex = nullptr;
std::vector<bool>* isTrackInverted = nullptr;
tree->SetBranchAddress("recoMeanDEDX", &recoMeanDEDX);
tree->SetBranchAddress("recoEndX", &recoEndX);
tree->SetBranchAddress("recoEndY", &recoEndY);
tree->SetBranchAddress("recoEndZ", &recoEndZ);
tree->SetBranchAddress("recoBeginX", &recoBeginX);
tree->SetBranchAddress("recoBeginY", &recoBeginY);
tree->SetBranchAddress("recoBeginZ", &recoBeginZ);
tree->SetBranchAddress("recoTrkID", &recoTrkID);
tree->SetBranchAddress("isTrackNearVertex", &isTrackNearVertex);
tree->SetBranchAddress("isTrackInverted", &isTrackInverted);
// Calorimetry information
std::vector<std::vector<double>>* recoResR = nullptr;
std::vector<std::vector<double>>* recoDEDX = nullptr;
tree->SetBranchAddress("recoResR", &recoResR);
tree->SetBranchAddress("recoDEDX", &recoDEDX);
// Individual hit information
double primaryEndPointHitW, primaryEndPointHitX;
std::vector<int>* fHitKey = nullptr;
std::vector<int>* fHitPlane = nullptr;
std::vector<int>* hitRecoAsTrackKey = nullptr;
std::vector<float>* fHitT = nullptr;
std::vector<float>* fHitX = nullptr;
std::vector<float>* fHitW = nullptr;
std::vector<float>* fHitCharge = nullptr;
std::vector<float>* fHitChargeCol = nullptr;
std::vector<int>* hitWC2TPCKey = nullptr;
std::vector<int>* hitThroughTrack = nullptr;
tree->SetBranchAddress("primaryEndPointHitW", &primaryEndPointHitW);
tree->SetBranchAddress("primaryEndPointHitX", &primaryEndPointHitX);
tree->SetBranchAddress("fHitKey", &fHitKey);
tree->SetBranchAddress("fHitPlane", &fHitPlane);
tree->SetBranchAddress("hitRecoAsTrackKey", &hitRecoAsTrackKey);
tree->SetBranchAddress("fHitT", &fHitT);
tree->SetBranchAddress("fHitX", &fHitX);
tree->SetBranchAddress("fHitW", &fHitW);
tree->SetBranchAddress("fHitCharge", &fHitCharge);
tree->SetBranchAddress("fHitChargeCol", &fHitChargeCol);
tree->SetBranchAddress("hitWC2TPCKey", &hitWC2TPCKey);
tree->SetBranchAddress("hitThroughTrack", &hitThroughTrack);
// Information about hits in tracks
std::vector<std::vector<int>>* recoTrackHitIndices = nullptr;
std::vector<std::vector<double>>* recoTrackHitX = nullptr;
std::vector<std::vector<double>>* recoTrackHitY = nullptr;
std::vector<std::vector<double>>* recoTrackHitZ = nullptr;
tree->SetBranchAddress("recoTrackHitIndices", &recoTrackHitIndices);
tree->SetBranchAddress("recoTrackHitX", &recoTrackHitX);
tree->SetBranchAddress("recoTrackHitY", &recoTrackHitY);
tree->SetBranchAddress("recoTrackHitZ", &recoTrackHitZ);
// TOF information
double TOFMass, tofObject;
tree->SetBranchAddress("TOFMass", &TOFMass);
tree->SetBranchAddress("tofObject", &tofObject);
/////////////////////
// Load histograms //
/////////////////////
TH1D* hMCNumWC2TPCMatch = (TH1D*) MCFile->Get("hMCNumWC2TPCMatch");
TH1D* hMCTGTrackLengths = (TH1D*) MCFile->Get("hMCTGTrackLengths");
TH1D* hMCTracksNearVertex = (TH1D*) MCFile->Get("hMCTracksNearVertex");
TH1D* hMCTrackLengthsNearVertex = (TH1D*) MCFile->Get("hMCTrackLengthsNearVertex");
TH1D* hMCNumTGTracks = (TH1D*) MCFile->Get("hMCNumTGTracks");
TH2D* hMCSmallVsTGTracks = (TH2D*) MCFile->Get("hMCSmallVsTGTracks");
TH2D* hMCTGNumSmallTracksVsThresh = (TH2D*) MCFile->Get("hMCTGNumSmallTracksVsThresh");
TH2D* hMCPrimaryTrackPosition = (TH2D*) MCFile->Get("hMCPrimaryTrackPosition");
TH1D* hMCNumTracksInCylinder0TG = (TH1D*) MCFile->Get("hMCNumTracksInCylinder0TG");
TH1D* hMCNumTracksInCylinder1TG = (TH1D*) MCFile->Get("hMCNumTracksInCylinder1TG");
TH1D* hMCNumTracksInCylinder2TG = (TH1D*) MCFile->Get("hMCNumTracksInCylinder2TG");
TH1D* hMCNumSmallTracksInCylinder0TG = (TH1D*) MCFile->Get("hMCNumSmallTracksInCylinder0TG");
TH1D* hMCNumSmallTracksInCylinder1TG = (TH1D*) MCFile->Get("hMCNumSmallTracksInCylinder1TG");
TH1D* hMCNumSmallTracksInCylinder2TG = (TH1D*) MCFile->Get("hMCNumSmallTracksInCylinder2TG");
TH1D* hMCTGSmallTracks = (TH1D*) MCFile->Get("hMCTGSmallTracks");
TH1D* hMCTGSmallTracks0TG = (TH1D*) MCFile->Get("hMCTGSmallTracks0TG");
TH1D* hMCTGSmallTracks1TG = (TH1D*) MCFile->Get("hMCTGSmallTracks1TG");
TH1D* hMCTGSmallTracks2TG = (TH1D*) MCFile->Get("hMCTGSmallTracks2TG");
TH1D* hMCTGUnreconstructedHitsInduction0TG = (TH1D*) MCFile->Get("hMCTGUnreconstructedHitsInduction0TG");
TH1D* hMCTGUnreconstructedHitsInduction1TG = (TH1D*) MCFile->Get("hMCTGUnreconstructedHitsInduction1TG");
TH1D* hMCTGUnreconstructedHitsInduction2TG = (TH1D*) MCFile->Get("hMCTGUnreconstructedHitsInduction2TG");
TH1D* hMCTGUnreconstructedHitsCollection0TG = (TH1D*) MCFile->Get("hMCTGUnreconstructedHitsCollection0TG");
TH1D* hMCTGUnreconstructedHitsCollection1TG = (TH1D*) MCFile->Get("hMCTGUnreconstructedHitsCollection1TG");
TH1D* hMCTGUnreconstructedHitsCollection2TG = (TH1D*) MCFile->Get("hMCTGUnreconstructedHitsCollection2TG");
TH1D* hMCTGNumClustersInduction0TG = (TH1D*) MCFile->Get("hMCTGNumClustersInduction0TG");
TH1D* hMCTGNumClustersInduction1TG = (TH1D*) MCFile->Get("hMCTGNumClustersInduction1TG");
TH1D* hMCTGNumClustersInduction2TG = (TH1D*) MCFile->Get("hMCTGNumClustersInduction2TG");
TH1D* hMCTGClusterSizesInduction0TG = (TH1D*) MCFile->Get("hMCTGClusterSizesInduction0TG");
TH1D* hMCTGClusterSizesInduction1TG = (TH1D*) MCFile->Get("hMCTGClusterSizesInduction1TG");
TH1D* hMCTGClusterSizesInduction2TG = (TH1D*) MCFile->Get("hMCTGClusterSizesInduction2TG");
TH1D* hMCTGNumClustersCollection0TG = (TH1D*) MCFile->Get("hMCTGNumClustersCollection0TG");
TH1D* hMCTGNumClustersCollection1TG = (TH1D*) MCFile->Get("hMCTGNumClustersCollection1TG");
TH1D* hMCTGNumClustersCollection2TG = (TH1D*) MCFile->Get("hMCTGNumClustersCollection2TG");
TH1D* hMCTGClusterSizesCollection0TG = (TH1D*) MCFile->Get("hMCTGClusterSizesCollection0TG");
TH1D* hMCTGClusterSizesCollection1TG = (TH1D*) MCFile->Get("hMCTGClusterSizesCollection1TG");
TH1D* hMCTGClusterSizesCollection2TG = (TH1D*) MCFile->Get("hMCTGClusterSizesCollection2TG");
TH1D* hMCNumCandidateProtons = (TH1D*) MCFile->Get("hMCNumCandidateProtons");
TH1D* hMCLengthCandidateProtons = (TH1D*) MCFile->Get("hMCLengthCandidateProtons");
///////////////////////
// Create histograms //
///////////////////////
// TOF
TH1D* hTOFMass = new TH1D("hTOFMass", "TOF Mass Distribution", 50, 0, 1200);
TH1D* hTOF = new TH1D("hTOF", "TOF Distribution", 50, 0, 80);
// WC
TH1D* hNumWC2TPCMatch = new TH1D("hNumWC2TPCMatch", "NumWC2TPCMatch", 10, 0, 10);
TH1D* hNumWCHits = new TH1D("hNumWCHits", "hNumWCHits", 10, 0, 10);
// With primary TG
TH1D* hNumTracksInCylinder = new TH1D("hNumTracksInCylinder", "NumTracksInCylinder", 10, 0, 10);
TH1D* hTGTrackLengths = new TH1D("hTGTrackLengths", "TGTrackLengths", 25, 0, 50);
TH1D* hTGSmallTracks = new TH1D("hTGSmallTracks", "TGSmallTracks", 10, 0, 10);
TH1D* hNumTracksInCylinder0TG = new TH1D("hNumTracksInCylinder0TG", "NumTracksInCylinder0TG", 10, 0, 10);
TH1D* hNumSmallTracksInCylinder0TG = new TH1D("hNumSmallTracksInCylinder0TG", "NumSmallTracksInCylinder0TG", 10, 0, 10);
TH1D* hTGSmallTracks0TG = new TH1D("hTGSmallTracks0TG", "TGSmallTracks0TG", 10, 0, 10);
TH1D* hNumTracksInCylinder1TG = new TH1D("hNumTracksInCylinder1TG", "NumTracksInCylinder1TG", 10, 0, 10);
TH1D* hNumSmallTracksInCylinder1TG = new TH1D("hNumSmallTracksInCylinder1TG", "NumSmallTracksInCylinder1TG", 10, 0, 10);
TH1D* hTGSmallTracks1TG = new TH1D("hTGSmallTracks1TG", "TGSmallTracks1TG", 10, 0, 10);
TH1D* hNumTracksInCylinder2TG = new TH1D("hNumTracksInCylinder2TG", "NumTracksInCylinder2TG", 10, 0, 10);
TH1D* hNumSmallTracksInCylinder2TG = new TH1D("hNumSmallTracksInCylinder2TG", "NumSmallTracksInCylinder2TG", 10, 0, 10);
TH1D* hTGSmallTracks2TG = new TH1D("hTGSmallTracks2TG", "TGSmallTracks2TG", 10, 0, 10);
TH1D* hTGUnreconstructedHitsInduction0TG = new TH1D("hTGUnreconstructedHitsInduction0TG", "UnreconstructedInductionHits0TG;;", 30, 0, 30);
TH1D* hTGUnreconstructedHitsInduction1TG = new TH1D("hTGUnreconstructedHitsInduction1TG", "UnreconstructedInductionHits1TG;;", 30, 0, 30);
TH1D* hTGUnreconstructedHitsInduction2TG = new TH1D("hTGUnreconstructedHitsInduction2TG", "UnreconstructedInductionHits2TG;;", 30, 0, 30);
TH1D* hTGUnreconstructedHitsCollection0TG = new TH1D("hTGUnreconstructedHitsCollection0TG", "UnreconstructedCollectionHits0TG;;", 30, 0, 30);
TH1D* hTGUnreconstructedHitsCollection1TG = new TH1D("hTGUnreconstructedHitsCollection1TG", "UnreconstructedCollectionHits1TG;;", 30, 0, 30);
TH1D* hTGUnreconstructedHitsCollection2TG = new TH1D("hTGUnreconstructedHitsCollection2TG", "UnreconstructedCollectionHits2TG;;", 30, 0, 30);
TH1D* hTGNumClustersInduction0TG = new TH1D("hTGNumClustersInduction0TG", "NumClustersInduction0TG;;", 10, 0, 10);
TH1D* hTGNumClustersInduction1TG = new TH1D("hTGNumClustersInduction1TG", "NumClustersInduction1TG;;", 10, 0, 10);
TH1D* hTGNumClustersInduction2TG = new TH1D("hTGNumClustersInduction2TG", "NumClustersInduction2TG;;", 10, 0, 10);
TH1D* hTGNumClustersCollection0TG = new TH1D("hTGNumClustersCollection0TG", "NumClustersCollection0TG;;", 10, 0, 10);
TH1D* hTGNumClustersCollection1TG = new TH1D("hTGNumClustersCollection1TG", "NumClustersCollection1TG;;", 10, 0, 10);
TH1D* hTGNumClustersCollection2TG = new TH1D("hTGNumClustersCollection2TG", "NumClustersCollection2TG;;", 10, 0, 10);
TH1D* hTGClusterSizesInduction0TG = new TH1D("hTGClusterSizesInduction0TG", "ClusterSizesInduction0TG;;", 15, 0, 30);
TH1D* hTGClusterSizesInduction1TG = new TH1D("hTGClusterSizesInduction1TG", "ClusterSizesInduction1TG;;", 15, 0, 30);
TH1D* hTGClusterSizesInduction2TG = new TH1D("hTGClusterSizesInduction2TG", "ClusterSizesInduction2TG;;", 15, 0, 30);
TH1D* hTGClusterSizesCollection0TG = new TH1D("hTGClusterSizesCollection0TG", "ClusterSizesCollection0TG;;", 15, 0, 30);
TH1D* hTGClusterSizesCollection1TG = new TH1D("hTGClusterSizesCollection1TG", "ClusterSizesCollection1TG;;", 15, 0, 30);
TH1D* hTGClusterSizesCollection2TG = new TH1D("hTGClusterSizesCollection2TG", "ClusterSizesCollection2TG;;", 15, 0, 30);
// With primary interacting
TH1D* hTracksNearVertex = new TH1D("hTracksNearVertex", "TracksNearVertex", 10, 0, 10);
TH1D* hTrackLengthsNearVertex = new TH1D("hTrackLengthsNearVertex", "TrackLengthsNearVertex", 50, 0, 100);
// TG and small tracks
TH1D* hNumTGTracks = new TH1D("hNumTGTracks", "NumTGTracks", 10, 0, 10);
TH2D* hSmallVsTGTracks = new TH2D("hSmallVsTGTracks", "SmallVsTGTracks;Small Tracks;TG Tracks", 15, 0, 15, 15, 0, 15);
TH2D* hTGNumSmallTracksVsThresh = new TH2D("hTGNumSmallTracksVsThresh", "TGNumSmallTracksVsThresh;Small Track Length Threshold (cm);Num Small Tracks", 10, 0, 40, 15, 0, 15);
TH2D* hTOFVsTOFMass = new TH2D("hTOFVsTOFMass", "TOFVsTOFMass;TOF [ns];TOF Mass [MeV/c^2]", 35, 10, 80, 50, 0, 1200);
// Kinematics
TH1D* hNumCandidateProtons = new TH1D("hNumCandidateProtons", "NumCandidateProtons;;", 10, 0, 10);
TH1D* hLengthCandidateProtons = new TH1D("hLengthCandidateProtons", "LengthCandidateProtons;;", 40, 0, 80);
///////////////////////////////////
// Distribution of primary track //
///////////////////////////////////
TH2D* hPrimaryTrackPosition = new TH2D(
"hPrimaryTrackPosition", "PrimaryTrackPosition;x-position;y-position",
20, minX, maxX,
20, minY, maxY
);
///////////////////////////////////////
// Distribution of background tracks //
///////////////////////////////////////
TH2D* hBackgroundTracksPosition = new TH2D(
"hBackgroundTracksPosition", "BackgroundTracksPosition;x-position;y-position",
20, minX, maxX,
20, minY, maxY
);
TH2D* hBackgroundTracksDirection = new TH2D(
"hBackgroundTracksDirection", "BackgroundTracksDirection;#phi (x-y) [rad];#theta (forward) [rad]",
20, -TMath::Pi(), TMath::Pi(),
20, 0, TMath::Pi() / 2
);
/////////////////////////////
// Distribution of WC hits //
/////////////////////////////
TH2D* hProjVsRealWC4 = new TH2D(
"hProjVsRealWC4", "ProjVsRealWC4;p_{x} - WC_{x};p_{y} - WC_{y}",
100, -40., 40.,
100, -15., 15.
);
TH1D* hRadDistWC4 = new TH1D("hRadDistWC4", "RadDistWC4", 80, 0.0, 40.);
TH2D* hMidPlaneCoinc = new TH2D(
"hMidPlaneCoinc", "MidPlaneCoinc;up_{x} - down_{x};up_{y} - down_{y}",
100, -20., 20.,
100, -5., 5.
);
TH1D* hRadDistMidPlane = new TH1D("hRadDistMidPlane", "RadDistMidPlane", 60, 0.0, 30.);
///////////////////////////////////////////////////
// Distribution of hits matched to primary track //
///////////////////////////////////////////////////
TH1D* hTimePrimaryHits = new TH1D("hTimePrimaryHits", "hTimePrimaryHits", 60, -20, 300);
//////////////////////
// Loop over events //
//////////////////////
int candidateInteractingEvents = 0;
Int_t NumEntries = (Int_t) tree->GetEntries();
std::cout << "Num entries: " << NumEntries << std::endl;
// Keep track of event counts for stat estimations
int eventCount0TG = 0;
int eventCount1TG = 0;
int eventCount2TG = 0;
int numValidEvents = 0;
for (Int_t i = 0; i < NumEntries; ++i) {
tree->GetEntry(i);
// Make script go faster
if (i > 100000) break;
// Fill for all events
hTOFMass->Fill(std::abs(TOFMass));
hNumWC2TPCMatch->Fill(WC2TPCsize);
hNumWCHits->Fill(wcNumHits);
hTOF->Fill(tofObject);
hTOFVsTOFMass->Fill(tofObject, std::abs(TOFMass));
/////////////////////////////////////////
// Wire-chamber and other initial cuts //
/////////////////////////////////////////
if (wcNumHits != 8) continue;
// Project downstream to midplane @ -437.97 (without angular corrections)
std::vector<double> midUp = projToZ(*wcHit0, *wcHit1, -437.97);
// Use this point and WC3 to project up to WC4
std::vector<double> projDown = projToZ(midUp, *wcHit2, -95.0);
// Requires some corrections because magnets are not the same
projDown[0] -= tan(1.32 * TMath::Pi() / 180.0) * (-95.0 - -437.97);
// Compare x and y coordinate in projection and real hit for WC4
hProjVsRealWC4->Fill(projDown[0] - wcHit3->at(0), projDown[1] - wcHit3->at(1));
double radDistWC4 = TMath::Sqrt(pow(projDown[0] - wcHit3->at(0), 2.) + pow(projDown[1] - wcHit3->at(1), 2.));
hRadDistWC4->Fill(radDistWC4);
// if (radDistWC4 > 8.0) continue; // TODO: figure out number
// Project upstream to midplane @ -437.97
std::vector<double> midDown = projToZ(*wcHit3, *wcHit2, -437.97);
midDown[0] -= tan(1.32 * TMath::Pi() / 180.0) * (-339.57 - -437.97);
hMidPlaneCoinc->Fill(midUp[0] - midDown[0], midUp[1] - midDown[1]);
double midPlaneDist = TMath::Sqrt(pow(midUp[0] - midDown[0], 2) + pow(midUp[1] - midDown[1], 2));
hRadDistMidPlane->Fill(midPlaneDist);
// if (midPlaneDist > 3.0) continue;
// Check projected tracks go through all apertures
bool Magnet1ApertureCheck = CheckUpstreamMagnetAperture(*wcHit0, *wcHit1);
bool Magnet2ApertureCheck = CheckDownstreamMagnetAperture(*wcHit3, *wcHit2);
bool DSColApertureCheck = CheckDownstreamCollimatorAperture(*wcHit3, *wcHit2);
if (!Magnet1ApertureCheck || !Magnet2ApertureCheck || !DSColApertureCheck) continue;
// Candidate mass cut, keep pions, muons and electrons
if (std::abs(TOFMass) > PI_MU_EL_MASS_CUTOFF) continue;
// If no track matched to wire-chamber, skip
if (WC2TPCtrkID == -99999) continue;
//////////////////////////
// Analyze valid events //
//////////////////////////
numValidEvents++;
hPrimaryTrackPosition->Fill(WC2TPCPrimaryBeginX, WC2TPCPrimaryBeginY);
// Check if WC2TPC is through-going
bool isPrimaryTG = !isWithinReducedVolume(WC2TPCPrimaryEndX, WC2TPCPrimaryEndY, WC2TPCPrimaryEndZ);
// Loop over reconstructed tracks
int numSmallTracks = 0;
int numTracksNearVertex = 0;
int smallTracksTPCStart = 0;
int numTGTracks = 0;
int numTracksInCylinder = 0;
int numSmallTracksInCylinder = 0;
for (size_t trk_idx = 0; trk_idx < recoBeginX->size(); ++trk_idx) {
if (recoTrkID->at(trk_idx) == WC2TPCtrkID) continue;
double distanceFromStart = distance(
recoBeginX->at(trk_idx), WC2TPCPrimaryEndX,
recoBeginY->at(trk_idx), WC2TPCPrimaryEndY,
recoBeginZ->at(trk_idx), WC2TPCPrimaryEndZ
);
double distanceFromEnd = distance(
recoEndX->at(trk_idx), WC2TPCPrimaryEndX,
recoEndY->at(trk_idx), WC2TPCPrimaryEndY,
recoEndZ->at(trk_idx), WC2TPCPrimaryEndZ
);
double trackLength = sqrt(
pow(recoEndX->at(trk_idx) - recoBeginX->at(trk_idx), 2) +
pow(recoEndY->at(trk_idx) - recoBeginY->at(trk_idx), 2) +
pow(recoEndZ->at(trk_idx) - recoBeginZ->at(trk_idx), 2)
);
// Copy WC2TPCLocations
std::vector<double>* wcX = new std::vector<double>(*WC2TPCLocationsX);
std::vector<double>* wcY = new std::vector<double>(*WC2TPCLocationsY);
std::vector<double>* wcZ = new std::vector<double>(*WC2TPCLocationsZ);
// Get direction to end cylinder
int numPoints = wcX->size();
int numTail = std::min(10, numPoints - 1);
std::vector<std::vector<double>> points;
for (int j = numPoints - numTail; j < numPoints; ++j) {
points.push_back({
wcX->at(j),
wcY->at(j),
wcZ->at(j)
});
}
if (numTail > 0) {
std::vector<double> avgDir = getAverageDir(points);
// Extrapolate track to end
double scale = (maxZ - points.back()[2]) / avgDir[2];
wcX->push_back(points.back()[0] + scale * avgDir[0]);
wcY->push_back(points.back()[1] + scale * avgDir[1]);
wcZ->push_back(points.back()[2] + scale * avgDir[2]);
}
// Is track contained in 10 cm cylinder?
bool startInCylinder = IsPointInsideTrackCylinder(
wcX, wcY, wcZ,
recoBeginX->at(trk_idx), recoBeginY->at(trk_idx), recoBeginZ->at(trk_idx),
CYLINDER_RADIUS
);
bool endInCylinder = IsPointInsideTrackCylinder(
wcX, wcY, wcZ,
recoEndX->at(trk_idx), recoEndY->at(trk_idx), recoEndZ->at(trk_idx),
CYLINDER_RADIUS
);
if (startInCylinder && endInCylinder) {
numTracksInCylinder++;
if (trackLength < CYLINDER_SMALL_TRACK) numSmallTracksInCylinder++;
}
if (isPrimaryTG) hTGTrackLengths->Fill(trackLength);
if (
recoEndZ->at(trk_idx) < 30.0 &&
recoBeginZ->at(trk_idx) < 30.0
) {
if (trackLength < SMALL_TRACK_LENGTH_CHEX) smallTracksTPCStart++;
}
if (
!isWithinReducedVolume(recoBeginX->at(trk_idx), recoBeginY->at(trk_idx), recoBeginZ->at(trk_idx)) &&
!isWithinReducedVolume(recoEndX->at(trk_idx), recoEndY->at(trk_idx), recoEndZ->at(trk_idx))
) {
numTGTracks++;
if (isPrimaryTG) {
// Track information about background tracks
bool isBeginTrue = recoBeginZ->at(trk_idx) < recoEndZ->at(trk_idx);
const double xs = isBeginTrue ? recoBeginX->at(trk_idx) : recoEndX->at(trk_idx);
const double ys = isBeginTrue ? recoBeginY->at(trk_idx) : recoEndY->at(trk_idx);
const double zs = isBeginTrue ? recoBeginZ->at(trk_idx) : recoEndZ->at(trk_idx);
const double xe = isBeginTrue ? recoEndX->at(trk_idx) : recoBeginX->at(trk_idx);
const double ye = isBeginTrue ? recoEndY->at(trk_idx) : recoBeginY->at(trk_idx);
const double ze = isBeginTrue ? recoEndZ->at(trk_idx) : recoBeginZ->at(trk_idx);
hBackgroundTracksPosition->Fill(xs, ys);
auto [phi, theta] = azimuth_polar_from_points(
xs, ys, zs,
xe, ye, ze
);
hBackgroundTracksDirection->Fill(phi, theta);
}
}
if (
!isPrimaryTG &&
(distanceFromStart < VERTEX_RADIUS || distanceFromEnd < VERTEX_RADIUS)
) {
numTracksNearVertex++;
hTrackLengthsNearVertex->Fill(trackLength);
}
if (trackLength < SMALL_TRACK_LENGTH_CHEX) numSmallTracks++;
}
// Look at relevant quantities with different number of TG tracks
if (numTGTracks == 0 && isPrimaryTG) {
hNumTracksInCylinder0TG->Fill(numTracksInCylinder);
hNumSmallTracksInCylinder0TG->Fill(numSmallTracksInCylinder);
hTGSmallTracks0TG->Fill(numSmallTracks);
}
if (numTGTracks <= 1 && isPrimaryTG) {
hNumTracksInCylinder1TG->Fill(numTracksInCylinder);
hNumSmallTracksInCylinder1TG->Fill(numSmallTracksInCylinder);
hTGSmallTracks1TG->Fill(numSmallTracks);
}
if (numTGTracks <= 2 && isPrimaryTG) {
hNumTracksInCylinder2TG->Fill(numTracksInCylinder);
hNumSmallTracksInCylinder2TG->Fill(numSmallTracksInCylinder);
hTGSmallTracks2TG->Fill(numSmallTracks);
}
hNumTGTracks->Fill(numTGTracks);
if (!isPrimaryTG) hTracksNearVertex->Fill(numTracksNearVertex);
// Add to histogram of small tracks if primary is throughgoing
if (isPrimaryTG) {
hTGSmallTracks->Fill(numSmallTracks);
hSmallVsTGTracks->Fill(numSmallTracks, numTGTracks);
hNumTracksInCylinder->Fill(numTracksInCylinder);
// Scan over small track length thresholds and fill 2D histogram
for (int threshBin = 1; threshBin <= hTGNumSmallTracksVsThresh->GetNbinsX(); ++threshBin) {
double threshold = hTGNumSmallTracksVsThresh->GetXaxis()->GetBinCenter(threshBin);
int nSmallTracks = 0;
for (size_t trk_idx = 0; trk_idx < recoBeginX->size(); ++trk_idx) {
if (recoTrkID->at(trk_idx) == WC2TPCtrkID) continue;
double trackLength = sqrt(
pow(recoEndX->at(trk_idx) - recoBeginX->at(trk_idx), 2) +
pow(recoEndY->at(trk_idx) - recoBeginY->at(trk_idx), 2) +
pow(recoEndZ->at(trk_idx) - recoBeginZ->at(trk_idx), 2)
);
if (trackLength < threshold) nSmallTracks++;
}
hTGNumSmallTracksVsThresh->Fill(threshold, nSmallTracks);
}
}
//////////////////////////
// Unreconstructed hits //
//////////////////////////
// Look at unreconstructed hits
std::unordered_set<int> hitsInTracks(hitRecoAsTrackKey->begin(), hitRecoAsTrackKey->end());
// Reconstruct hit clusters
std::vector<int> candidateHits;
for (size_t iHit = 0; iHit < fHitKey->size(); ++iHit) {
// Skip hits already in tracks
if (hitsInTracks.count(iHit) > 0) continue;
double hitX = fHitX->at(iHit);
double hitW = fHitW->at(iHit);
int hitPlane = fHitPlane->at(iHit);
if (isHitNearPrimary(
hitWC2TPCKey,
fHitX,
fHitW,
fHitPlane,
hitX,
hitW,
hitPlane,
DISTANCE_TO_PRIMARY_THRESHOLD,
true
)) candidateHits.push_back(iHit);
}
// Now cluster using those hits as starting points
std::unordered_set<int> usedHits;
std::vector<HitCluster> hitClusters;
int nCandidateHits = candidateHits.size();
for (int iHit = 0; iHit < nCandidateHits; ++iHit) {
// The candidate hits are only STARTING points, as this could make up
// really long tracks in the induction plane that are no longer near
// the ending point of the primary track
// First, check if we have already used this hit
int thisHitKey = candidateHits.at(iHit);
int thisHitPlane = fHitPlane->at(thisHitKey);
float thisHitW = fHitW->at(thisHitKey);
float thisHitX = fHitX->at(thisHitKey);
float thisHitCharge = fHitCharge->at(thisHitKey);
float thisHitChargeCol = fHitChargeCol->at(thisHitKey);
if (usedHits.count(thisHitKey)) continue;
std::vector<int> clusterKeys;
std::vector<float> clusterX;
std::vector<float> clusterW;
std::vector<float> clusterCharge;
std::vector<float> clusterChargeCol;
clusterKeys.push_back(thisHitKey);
clusterX.push_back(thisHitX);
clusterW.push_back(thisHitW);
clusterCharge.push_back(thisHitCharge);
clusterChargeCol.push_back(thisHitChargeCol);
for (int iAllHit = 0; iAllHit < fHitKey->size(); ++iAllHit) {
// Skip already used hits, and those reconstructed in tracks
if (usedHits.count(iAllHit) || hitsInTracks.count(iAllHit)) continue;
// Clusters have to be in same plane
if (fHitPlane->at(iAllHit) != thisHitPlane) continue;
float internalHitW = fHitW->at(iAllHit);
float internalHitX = fHitX->at(iAllHit);
float dW = std::abs(internalHitW - thisHitW);
float dX = std::abs(internalHitX - thisHitX);
float distance = std::sqrt(std::pow(dW, 2) + std::pow(dX, 2));
int nClusterSoFar = clusterW.size();
for (int iCluster = 0; iCluster < nClusterSoFar; ++iCluster) {
float tempdW = std::abs(internalHitW - clusterW.at(iCluster));
float tempdX = std::abs(internalHitX - clusterX.at(iCluster));
float tempDistance = std::sqrt(std::pow(tempdW, 2) + std::pow(tempdX, 2));
if (tempDistance < distance) distance = tempDistance;
if (distance < MAX_IN_CLUSTER_SEPARATION) break;
}
if (distance < MAX_IN_CLUSTER_SEPARATION) {
usedHits.insert(iAllHit);
clusterKeys.push_back(iAllHit);
clusterX.push_back(fHitX->at(iAllHit));
clusterW.push_back(fHitW->at(iAllHit));
clusterCharge.push_back(fHitCharge->at(iAllHit));
clusterChargeCol.push_back(fHitChargeCol->at(iAllHit));
}
}
if (clusterKeys.size() > MINIMUM_HITS_FOR_CLUSTER) {
HitCluster thisCluster;
double clusterSize = 0;
for (int j = 0; j < clusterW.size() - 1; ++j) {
for (int k = j + 1; k < clusterW.size(); ++k) {
double wSeparation = clusterW[j] - clusterW[k];
double xSeparation = clusterX[j] - clusterX[k];
double thisDiameter = std::sqrt(
std::pow(wSeparation, 2) +
std::pow(xSeparation, 2)
);
if (thisDiameter > clusterSize) clusterSize = thisDiameter;
}
}
thisCluster.plane = thisHitPlane;
thisCluster.hitKeys = clusterKeys;
thisCluster.hitX = clusterX;
thisCluster.hitW = clusterW;
thisCluster.hitCharge = clusterCharge;
thisCluster.hitChargeCol = clusterChargeCol;
thisCluster.clusterSize = clusterSize;
usedHits.insert(thisHitKey);
hitClusters.push_back(thisCluster);
}
}
// Separate primary hits into collection and induction
std::vector<int> hitWC2TPCKeyInduction;
std::vector<int> hitWC2TPCKeyCollection;
for (size_t i = 0; i < hitWC2TPCKey->size(); ++i) {
// Only care about hits inside the reduced volume
auto [i_hit, j_hit] = find_unique_position(recoTrackHitIndices, hitWC2TPCKey->at(i));
if (!isWithinReducedVolume(
recoTrackHitX->at(i_hit)[j_hit],
recoTrackHitY->at(i_hit)[j_hit],
recoTrackHitZ->at(i_hit)[j_hit]
)) continue;
if (fHitPlane->at(hitWC2TPCKey->at(i)) == 0) hitWC2TPCKeyInduction.push_back(hitWC2TPCKey->at(i));
else if (fHitPlane->at(hitWC2TPCKey->at(i)) == 1) hitWC2TPCKeyCollection.push_back(hitWC2TPCKey->at(i));
hTimePrimaryHits->Fill(fHitT->at(hitWC2TPCKey->at(i)));
}
// First, get a random point in the primary track
std::vector<int> randomInduction; std::vector<int> randomCollection;
if (hitWC2TPCKeyInduction.size() != 0) {
randomInduction.push_back(0);
for (int i = 1; i < (int) hitWC2TPCKeyInduction.size(); ++i) {
double dX = std::abs(fHitX->at(hitWC2TPCKeyInduction[randomInduction[randomInduction.size() - 1]]) - fHitX->at(hitWC2TPCKeyInduction[i]));
double dW = std::abs(fHitW->at(hitWC2TPCKeyInduction[randomInduction[randomInduction.size() - 1]]) - fHitW->at(hitWC2TPCKeyInduction[i]));
if (dX > MAX_IN_CLUSTER_X_SEPARATION && dW > MAX_IN_CLUSTER_W_SEPARATION) randomInduction.push_back(i);
}
}
if (hitWC2TPCKeyCollection.size() != 0) {
randomCollection.push_back(0);
for (int i = 1; i < (int) hitWC2TPCKeyCollection.size(); ++i) {
double dX = std::abs(fHitX->at(hitWC2TPCKeyCollection[randomCollection[randomCollection.size() - 1]]) - fHitX->at(hitWC2TPCKeyCollection[i]));
double dW = std::abs(fHitW->at(hitWC2TPCKeyCollection[randomCollection[randomCollection.size() - 1]]) - fHitW->at(hitWC2TPCKeyCollection[i]));
if (dX > MAX_IN_CLUSTER_X_SEPARATION && dW > MAX_IN_CLUSTER_W_SEPARATION) randomCollection.push_back(i);
}
}
int numUnrecoHitsInduction = 0;
int numUnrecoHitsCollection = 0;
std::vector<int> candidateRandomHitsInduction;
std::vector<int> candidateRandomHitsCollection;
for (size_t iHit = 0; iHit < fHitKey->size(); ++iHit) {
// Skip hits already in tracks
if (hitsInTracks.count(iHit) > 0) continue;
double hitX = fHitX->at(iHit);
double hitW = fHitW->at(iHit);
int hitPlane = fHitPlane->at(iHit);
if (hitPlane == 0 && hitWC2TPCKeyInduction.size() > 0) {
for (int idx : randomInduction) {
double dW = (hitW - fHitW->at(hitWC2TPCKeyInduction[idx]));
double dX = (hitX - fHitX->at(hitWC2TPCKeyInduction[idx]));
double d = std::sqrt(std::pow(dW, 2) + std::pow(dX, 2));
if (d < DISTANCE_TO_PRIMARY_THRESHOLD) {
numUnrecoHitsInduction++;
candidateRandomHitsInduction.push_back(iHit);
}
}
} else if (hitPlane == 1 && hitWC2TPCKeyCollection.size() > 0) {
for (int idx : randomCollection) {
double dW = (hitW - fHitW->at(hitWC2TPCKeyCollection[idx]));
double dX = (hitX - fHitX->at(hitWC2TPCKeyCollection[idx]));
double d = std::sqrt(std::pow(dW, 2) + std::pow(dX, 2));
if (d < DISTANCE_TO_PRIMARY_THRESHOLD) {
numUnrecoHitsCollection++;
candidateRandomHitsCollection.push_back(iHit);
}
}
}
}
// Loop through clusters and see which would be close to random point
int numClustersInduction = 0; int numClustersCollection = 0;
for (size_t iCluster = 0; iCluster < hitClusters.size(); ++iCluster) {
HitCluster thisCluster = hitClusters[iCluster];
for (size_t iHit = 0; iHit < thisCluster.hitKeys.size(); ++iHit) {
if (std::find(candidateRandomHitsInduction.begin(), candidateRandomHitsInduction.end(), thisCluster.hitKeys[iHit]) != candidateRandomHitsInduction.end()) {
numClustersInduction++;
if (numTGTracks == 0 && isPrimaryTG) hTGClusterSizesInduction0TG->Fill(thisCluster.clusterSize);
else if (numTGTracks == 1 && isPrimaryTG) hTGClusterSizesInduction1TG->Fill(thisCluster.clusterSize);
else if (numTGTracks == 2 && isPrimaryTG) hTGClusterSizesInduction2TG->Fill(thisCluster.clusterSize);
break;
} else if (std::find(candidateRandomHitsCollection.begin(), candidateRandomHitsCollection.end(), thisCluster.hitKeys[iHit]) != candidateRandomHitsCollection.end()) {
numClustersCollection++;
if (numTGTracks == 0 && isPrimaryTG) hTGClusterSizesCollection0TG->Fill(thisCluster.clusterSize);
else if (numTGTracks == 1 && isPrimaryTG) hTGClusterSizesCollection1TG->Fill(thisCluster.clusterSize);
else if (numTGTracks == 2 && isPrimaryTG) hTGClusterSizesCollection2TG->Fill(thisCluster.clusterSize);
break;
}
}
}
if (numTGTracks == 0 && isPrimaryTG) {
hTGNumClustersInduction0TG->Fill(numClustersInduction);
hTGNumClustersCollection0TG->Fill(numClustersCollection);
hTGUnreconstructedHitsInduction0TG->Fill(numUnrecoHitsInduction);
hTGUnreconstructedHitsCollection0TG->Fill(numUnrecoHitsCollection);
}
if (numTGTracks <= 1 && isPrimaryTG) {
hTGNumClustersInduction1TG->Fill(numClustersInduction);
hTGNumClustersCollection1TG->Fill(numClustersCollection);
hTGUnreconstructedHitsInduction1TG->Fill(numUnrecoHitsInduction);
hTGUnreconstructedHitsCollection1TG->Fill(numUnrecoHitsCollection);
}
if (numTGTracks <= 2 && isPrimaryTG) {
hTGNumClustersInduction2TG->Fill(numClustersInduction);
hTGNumClustersCollection2TG->Fill(numClustersCollection);
hTGUnreconstructedHitsInduction2TG->Fill(numUnrecoHitsInduction);
hTGUnreconstructedHitsCollection2TG->Fill(numUnrecoHitsCollection);
}
//////////////////
// TG track cut //
//////////////////
// Grab data about number of events with each cutoff
if (numTGTracks <= 0) eventCount0TG++;
if (numTGTracks <= 1) eventCount1TG++;
if (numTGTracks <= 2) eventCount2TG++;
if (numTGTracks > MAX_NUM_TG_TRACKS) continue;
//////////////////
// Cylinder cut //
//////////////////
if (numSmallTracksInCylinder > ALLOWED_CYLINDER_SMALL_TRACKS) continue;
////////////////////////
// Reduced volume cut //
////////////////////////
candidateInteractingEvents++;
if (isPrimaryTG) continue;
///////////////////////////////////
// Secondary particle kinematics //
///////////////////////////////////
int numCandidateProtons = 0;
for (size_t trk_idx = 0; trk_idx < recoBeginX->size(); ++trk_idx) {
if (recoTrkID->at(trk_idx) == WC2TPCtrkID) continue;
double distanceFromStart = distance(
recoBeginX->at(trk_idx), WC2TPCPrimaryEndX,
recoBeginY->at(trk_idx), WC2TPCPrimaryEndY,
recoBeginZ->at(trk_idx), WC2TPCPrimaryEndZ
);
double distanceFromEnd = distance(
recoEndX->at(trk_idx), WC2TPCPrimaryEndX,
recoEndY->at(trk_idx), WC2TPCPrimaryEndY,
recoEndZ->at(trk_idx), WC2TPCPrimaryEndZ
);
double trackLength = sqrt(
pow(recoEndX->at(trk_idx) - recoBeginX->at(trk_idx), 2) +
pow(recoEndY->at(trk_idx) - recoBeginY->at(trk_idx), 2) +
pow(recoEndZ->at(trk_idx) - recoBeginZ->at(trk_idx), 2)
);
if (distanceFromStart < VERTEX_RADIUS || distanceFromEnd < VERTEX_RADIUS) {
numCandidateProtons++;
hLengthCandidateProtons->Fill(trackLength);
}
}
hNumCandidateProtons->Fill(numCandidateProtons);
}
std::cout << std::endl;
std::cout << "Number of events with at most 0 TG tracks: " << eventCount0TG << std::endl;
std::cout << "Number of events with at most 1 TG tracks: " << eventCount1TG << std::endl;
std::cout << "Number of events with at most 2 TG tracks: " << eventCount2TG << std::endl;
std::cout << std::endl;
std::cout << "Number of events before RV cut: " << candidateInteractingEvents << std::endl;
std::cout << std::endl;
double numMCEvents = hMCNumTGTracks->Integral(0, hMCNumTGTracks->GetNbinsX() + 1);
double numDataEvents = hNumTGTracks->Integral(0, hNumTGTracks->GetNbinsX() + 1);
double scaling = numDataEvents / numMCEvents;
std::cout << "Num valid MC events: " << numMCEvents << std::endl;
std::cout << "Num valid data events: " << numDataEvents << std::endl;
std::cout << "Scaling: " << scaling << std::endl;
std::cout << std::endl;
double numMCTGEvents = hMCTGSmallTracks->Integral(0, hMCTGSmallTracks->GetNbinsX() + 1);
double numDataTGEvents = hTGSmallTracks->Integral(0, hTGSmallTracks->GetNbinsX() + 1);
double scalingTG = numDataTGEvents / numMCTGEvents;
std::cout << "Num valid MC TG events: " << numMCTGEvents << std::endl;
std::cout << "Num valid data TG events: " << numDataTGEvents << std::endl;
std::cout << "Scaling TG: " << scalingTG << std::endl;
std::cout << std::endl;
double numMCNotTGEvents = hMCTracksNearVertex->Integral(0, hMCTracksNearVertex->GetNbinsX() + 1);
double numDataNoTGvents = hTracksNearVertex->Integral(0, hTracksNearVertex->GetNbinsX() + 1);
double scalingNoTG = numDataNoTGvents / numMCNotTGEvents;
std::cout << "Num valid MC not TG events: " << numMCNotTGEvents << std::endl;
std::cout << "Num valid data not TG events: " << numDataNoTGvents << std::endl;
std::cout << "Scaling not TG: " << scalingNoTG << std::endl;
std::cout << std::endl;
std::cout << "Num valid data TG events with no other TG: " << hNumTracksInCylinder0TG->Integral() << std::endl;
std::cout << "Num valid data TG events with at most one more TG: " << hNumTracksInCylinder1TG->Integral() << std::endl;
std::cout << "Num valid data TG events with at most two more TG: " << hNumTracksInCylinder2TG->Integral() << std::endl;
std::cout << std::endl;
double scaling0TG = hNumTracksInCylinder0TG->Integral() / hMCNumTracksInCylinder0TG->Integral();
double scaling1TG = hNumTracksInCylinder1TG->Integral() / hMCNumTracksInCylinder1TG->Integral();
double scaling2TG = hNumTracksInCylinder2TG->Integral() / hMCNumTracksInCylinder2TG->Integral();
double scalingKin = hNumCandidateProtons->Integral() / hMCNumCandidateProtons->Integral();
std::cout << "Scaling 0 TG: " << scaling0TG << std::endl;
std::cout << "Scaling 1 TG: " << scaling1TG << std::endl;
std::cout << "Scaling 2 TG: " << scaling2TG << std::endl;
std::cout << "Scaling Kin: " << scalingKin << std::endl;
std::cout << std::endl;
// Scale MC histograms to data histograms using event counts
hMCNumWC2TPCMatch->Scale(hNumWC2TPCMatch->Integral() / hMCNumWC2TPCMatch->Integral());
// all events
hMCNumTGTracks->Scale(scaling);
// primary not TG
hMCTracksNearVertex->Scale(scalingNoTG);
hMCTrackLengthsNearVertex->Scale(scalingNoTG);
// primary TG
hMCTGSmallTracks->Scale(scalingTG);
hMCTGTrackLengths->Scale(scalingTG);
hMCTGSmallTracks0TG->Scale(scaling0TG);
hMCTGSmallTracks1TG->Scale(scaling1TG);
hMCTGSmallTracks2TG->Scale(scaling2TG);
hMCNumTracksInCylinder0TG->Scale(scaling0TG);
hMCNumTracksInCylinder1TG->Scale(scaling1TG);
hMCNumTracksInCylinder2TG->Scale(scaling2TG);
hMCNumSmallTracksInCylinder0TG->Scale(scaling0TG);
hMCNumSmallTracksInCylinder1TG->Scale(scaling1TG);
hMCNumSmallTracksInCylinder2TG->Scale(scaling2TG);
hMCTGUnreconstructedHitsInduction0TG->Scale(scaling0TG);
hMCTGUnreconstructedHitsInduction1TG->Scale(scaling1TG);
hMCTGUnreconstructedHitsInduction2TG->Scale(scaling2TG);
hMCTGUnreconstructedHitsCollection0TG->Scale(scaling0TG);
hMCTGUnreconstructedHitsCollection1TG->Scale(scaling1TG);
hMCTGUnreconstructedHitsCollection2TG->Scale(scaling2TG);
hMCTGClusterSizesInduction0TG->Scale(scaling0TG);
hMCTGClusterSizesInduction1TG->Scale(scaling1TG);
hMCTGClusterSizesInduction2TG->Scale(scaling2TG);
hMCTGClusterSizesCollection0TG->Scale(scaling0TG);
hMCTGClusterSizesCollection1TG->Scale(scaling1TG);
hMCTGClusterSizesCollection2TG->Scale(scaling2TG);
hMCTGNumClustersCollection0TG->Scale(scaling0TG);
hMCTGNumClustersCollection1TG->Scale(scaling1TG);
hMCTGNumClustersCollection2TG->Scale(scaling2TG);
hMCTGNumClustersInduction0TG->Scale(scaling0TG);
hMCTGNumClustersInduction1TG->Scale(scaling1TG);
hMCTGNumClustersInduction2TG->Scale(scaling2TG);
// Secondary particle kinematics
hMCNumCandidateProtons->Scale(scalingKin);
hMCLengthCandidateProtons->Scale(scalingKin);
//////////////////
// Create plots //
//////////////////