-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCCInclusiveEventSelectionEarlyFlashMatch.C
1127 lines (958 loc) · 56.8 KB
/
CCInclusiveEventSelectionEarlyFlashMatch.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
#include <iostream>
#include <fstream>
#include <cstring>
#include <string>
#include <utility>
#include <vector>
#include <map>
#include <TCanvas.h>
#include <TChain.h>
#include <TFile.h>
#include <TH1.h>
#include <TLine.h>
#include <TTree.h>
// using namespace std;
//This defines our current settings for the fiducial volume
double FVx = 256.35;
double FVy = 233;
double FVz = 1036.8;
double borderx = 10.;
double bordery = 20.;
double borderz = 10.;
//This function returns if a 3D point is within the fiducial volume
bool inFV(double x, double y, double z) {
if(x < (FVx - borderx) && (x > borderx) && (y < (FVy/2. - bordery)) && (y > (-FVy/2. + bordery)) && (z < (FVz - borderz)) && (z > borderz)) return true;
else return false;
}
//This function returns the distance between a flash and a track (in one dimension, here used only for z direction)
double FlashTrackDist(double flash, double start, double end) {
if(end >= start) {
if(flash < end && flash > start) return 0;
else return TMath::Min(fabs(flash-start), fabs(flash-end));
}
else {
if(flash > end && flash < start) return 0;
else return TMath::Min(fabs(flash-start), fabs(flash-end));
}
}
// Main function
int CCInclusiveEventSelectionEarlyFlashMatch(std::string GeneratorName, unsigned int ThreadNumber, unsigned int NumberOfThreads)
{
std::string Version = "v05_08_00";
// std::string GeneratorName = "prodgenie_bnb_nu_cosmic";
// std::string GeneratorName = "prodgenie_bnb_nu";
// std::string GeneratorName = "prodcosmics_corsika_inTime";
// std::string GeneratorName = "prodgenie_bnb_nu_cosmic_sc_uboone";
// std::string GeneratorName = "data_onbeam_bnb";
// std::string GeneratorName = "data_offbeam_bnbext";
// std::string GeneratorName = "prodgenie_bnb_nu_cosmic_uboone";
// Initialize and fill track reco product names
std::vector<std::string> TrackProdNameVec;
// TrackProdNameVec.push_back("pandoraNuKHit");
// TrackProdNameVec.push_back("pandoraCosmic");
TrackProdNameVec.push_back("pandoraNu");
// TrackProdNameVec.push_back("pmtrack");
// TrackProdNameVec.push_back("pandoraNuPMA");
// TrackProdNameVec.push_back("trackkalmanhit");
// Initialize and fill vertex reco product names
std::vector<std::string> VertexProdNameVec;
// VertexProdNameVec.push_back("nuvtx");
// VertexProdNameVec.push_back("pandoraCosmic");
VertexProdNameVec.push_back("pandoraNu");
// VertexProdNameVec.push_back("pmtrack");
std::string FileNumberStr;
if(NumberOfThreads > 1)
{
FileNumberStr = "_" + std::to_string(ThreadNumber);
}
else
{
FileNumberStr = "";
}
std::cout << "Data Sample : " << GeneratorName << std::endl;
TChain *treenc = new TChain("analysistree/anatree");
if(GeneratorName == "data_onbeam_bnb")
{
// treenc -> Add( ("/pnfs/uboone/persistent/users/aschu/onbeam_data_bnbSWtrigger/"+GeneratorName+"_"+Version+"_anatree.root").c_str() );
std::ifstream FileNames("/pnfs/uboone/persistent/users/aschu/devel/v05_11_01/hadd/GOODBNBBEAM/filesana.list");
std::string FileName;
while(std::getline(FileNames,FileName))
{
std::cout << FileName << std::endl;
treenc -> Add((FileName).c_str());
}
}
else if(GeneratorName == "data_offbeam_bnbext")
{
// treenc -> Add( ("/pnfs/uboone/persistent/users/aschu/offbeam_data_bnbSWtrigger/"+GeneratorName+"_"+Version+"_anatree.root").c_str() );
std::ifstream FileNames("/pnfs/uboone/persistent/users/aschu/devel/v05_11_01/hadd/GOODEXTBNB/filesana.list");
std::string FileName;
while(std::getline(FileNames,FileName))
{
std::cout << FileName << std::endl;
treenc -> Add((FileName).c_str());
}
}
else if(GeneratorName == "prodgenie_bnb_nu_cosmic_uboone")
{
treenc -> Add( ("/pnfs/uboone/persistent/users/aschu/MC_BNB_Cosmic/"+GeneratorName+"_"+Version+"_anatree.root").c_str() );
}
else if(GeneratorName == "TEM")
{
treenc -> Add( ("/pnfs/uboone/persistent/users/aschu/"+GeneratorName+"/*/anatree*.root").c_str() );
}
else if(GeneratorName == "MEC")
{
treenc -> Add( ("/pnfs/uboone/persistent/users/aschu/"+GeneratorName+"/*/anatree*.root").c_str() );
}
else
{
treenc -> Add( ("/lheppc46/data/uBData/anatrees/"+GeneratorName+"_"+Version+"_anatree.root").c_str() );
}
// treenc -> Add( ("/media/christoph/200EFBDA63AA160B/anatrees/"+GeneratorName+"_"+Version+"_anatree.root").c_str() );
std::vector<std::string> SelectionNames;
SelectionNames.push_back("NumberOfEvents_");
SelectionNames.push_back("FlashCut_");
SelectionNames.push_back("VertexInFV_");
SelectionNames.push_back("TrackToVtx_");
SelectionNames.push_back("FlashMatch_");
SelectionNames.push_back("ContainedTrack_");
SelectionNames.push_back("TrackRange_");
SelectionNames.push_back("SelectionEfficiency_");
SelectionNames.push_back("SelectionCorrectness_");
SelectionNames.push_back("N_sig_truth_");
SelectionNames.push_back("N_sig_truth_sel_");
SelectionNames.push_back("N_bg_NC_sel_");
SelectionNames.push_back("N_bg_numubar_sel_");
SelectionNames.push_back("N_bg_nue_sel_");
SelectionNames.push_back("N_bg_cosmicbnb_sel_");
// Initialize table file vector
std::vector<std::ofstream*> EventSelectionCuts;
// // Create files and write first line
for(const auto& SelName : SelectionNames)
{
// Fill vector of fstreams
EventSelectionCuts.push_back(new ofstream("cvsfiles/"+SelName+GeneratorName+"_"+Version+".cvs",std::ios::trunc));
// Fill Title
*EventSelectionCuts.back() << SelName + GeneratorName << "\n";
// Fill corner entry
*EventSelectionCuts.back() << "track\\vertex";
// Fill vertexing column labels
for(const auto& VertexingName : VertexProdNameVec)
{
*EventSelectionCuts.back() << "," + VertexingName;
}
// Jump to next line
*EventSelectionCuts.back() << "\n";
} // Table file loop
//maximum array sizes
const int maxentries = 35000;
const int maxtracks = 10000;
const int maxvtx = 500;
const int maxnu = 10;
const int maxmc = 10;
const int kMaxFlashes = 5000;
//Define variables to read from Tree
Int_t event;
Int_t run;
Int_t subrun;
Int_t triggerbits; //this is only important for data. 2048 = BNB stream
Double_t potbnb; //this is only important for data
Short_t ntracks_reco; //number of reco tracks
Short_t trkbestplane[maxtracks]; //plane that has most hits for a given track
Float_t trklen[maxtracks]; //track length
Float_t trkstartx[maxtracks];
Float_t trkstarty[maxtracks];
Float_t trkstartz[maxtracks];
Float_t trkendx[maxtracks];
Float_t trkendy[maxtracks];
Float_t trkendz[maxtracks];
Float_t trktheta[maxtracks];
Float_t trkphi[maxtracks];
Float_t trkmomrange[maxtracks]; //track momentum calculated from track range
Short_t trkId[maxtracks];
Short_t trkorigin[maxtracks][3]; //for MC only: which true particle contributes most hits to the reco track: 2 = cosmic. 1 = neutrino
Int_t TrackIDTruth[maxtracks][3]; // MC id matched with reco track
bool vertexatstart[maxtracks]; //for analysis: is the vertex at start of the track?
bool vertexatend[maxtracks]; //for analysis: ist the vertex at end of track?
Int_t no_flashes; //number of flashes in the event
Float_t flash_time[kMaxFlashes]; //flash time (in microseconds)
Float_t flash_pe[kMaxFlashes]; //total number of photoelectrons corresponding to the flash
Float_t flash_zcenter[kMaxFlashes]; //z center of flash (in cm)
Float_t flash_ycenter[kMaxFlashes]; //y center of flash (in cm)
Short_t nvtx;
Float_t vtxx[maxvtx];
Float_t vtxy[maxvtx];
Float_t vtxz[maxvtx];
//finding candidate nu interaction vertex in event
bool candvertex[maxvtx];
Short_t candtrack[maxvtx];
Float_t candlength[maxvtx];
Short_t numuvertex = -1;
Short_t mutrack = -1;
Float_t mutracklength = 0;
//MC truth
Int_t mcevts_truth; //neutrino interactions per event
Float_t nuvtxx_truth[maxmc]; //true vertex x (in cm)
Float_t nuvtxy_truth[maxmc];
Float_t nuvtxz_truth[maxmc];
Int_t ccnc_truth[maxmc]; //CC = 0, NC = 1
Int_t nuPDG_truth[maxmc]; //true neutrino pdg code. numu = 14
Int_t mode_truth[maxmc]; //QE = 0, RES = 1, DIS = 2
Int_t PDG_truth[maxtracks];
Int_t NumberOfMCTracks;
Float_t XMCTrackStart[maxtracks];
Float_t YMCTrackStart[maxtracks];
Float_t ZMCTrackStart[maxtracks];
Float_t XMCTrackEnd[maxtracks];
Float_t YMCTrackEnd[maxtracks];
Float_t ZMCTrackEnd[maxtracks];
Int_t MCTrackID[maxtracks];
//define cut variables
double flashwidth = 80; //cm. Distance flash-track
double distcut = 5; //cm. Distance track start/end to vertex
double lengthcut = 75; //cm. Length of longest track
double beammin = 3.55/*-0.36*/; //us. Beam window start
double beammax = 5.15/*-0.36*/; //us. Beam window end
double PEthresh = 50; //PE
double MCTrackToMCVtxDist = 1; //cm. distance between mc track start and mc vertex
double TrackToMCDist = 5; //cm. Distance track start/end to mcvertex
if(GeneratorName == "data_bnb" || GeneratorName == "data_onbeam_bnb")
{
std::cout << "Changed beam gate window for on-beam data" << std::endl;
beammin = 3.3;
beammax = 4.9;
}
if(GeneratorName == "data_offbeam_bnbext")
{
std::cout << "Changed beam gate window for off-beam data" << std::endl;
beammin = 3.65;
beammax = 5.25;
}
if(GeneratorName == "prodcosmics_corsika_inTime")
{
std::cout << "Changed beam gate window for Corsika sample" << std::endl;
beammin = 3.2;
beammax = 4.8;
}
// Loop over all product names
for(const auto& TrackingName : TrackProdNameVec)
{
// Write tracking methode to files, first column
for(auto& SelectionCut : EventSelectionCuts)
{
*SelectionCut << TrackingName;
}
for(const auto& VertexingName : VertexProdNameVec)
{
// Open output file
TFile* OutputFile = new TFile(("rootfiles/Hist_Track_"+TrackingName+ "_Vertex_" + VertexingName + "_"+GeneratorName+"_"+Version+FileNumberStr+"_New.root").c_str(),"RECREATE");
// Make a clone tree which gets filled
TTree *SelectionTree = treenc->CloneTree(0);
treenc -> SetBranchAddress("event", &event);
treenc -> SetBranchAddress("potbnb", &potbnb);
treenc -> SetBranchAddress("no_flashes", &no_flashes);
treenc -> SetBranchAddress("flash_time", flash_time);
treenc -> SetBranchAddress("flash_pe", flash_pe);
treenc -> SetBranchAddress("flash_zcenter", flash_zcenter);
treenc -> SetBranchAddress("flash_ycenter", flash_ycenter);
treenc -> SetBranchAddress("mcevts_truth", &mcevts_truth);
treenc -> SetBranchAddress("nuvtxx_truth", nuvtxx_truth);
treenc -> SetBranchAddress("nuvtxy_truth", nuvtxy_truth);
treenc -> SetBranchAddress("nuvtxz_truth", nuvtxz_truth);
treenc -> SetBranchAddress("ccnc_truth", ccnc_truth);
treenc -> SetBranchAddress("nuPDG_truth", nuPDG_truth);
treenc -> SetBranchAddress("pdg", PDG_truth);
treenc -> SetBranchAddress("mode_truth", mode_truth);
treenc -> SetBranchAddress("geant_list_size", &NumberOfMCTracks);
treenc -> SetBranchAddress("StartPointx", XMCTrackStart);
treenc -> SetBranchAddress("StartPointy", YMCTrackStart);
treenc -> SetBranchAddress("StartPointz", ZMCTrackStart);
treenc -> SetBranchAddress("EndPointx", XMCTrackEnd);
treenc -> SetBranchAddress("EndPointy", YMCTrackEnd);
treenc -> SetBranchAddress("EndPointz", ZMCTrackEnd);
treenc -> SetBranchAddress("TrackId", MCTrackID);
// Product specific stuff
treenc -> SetBranchAddress(("ntracks_"+TrackingName).c_str(),&ntracks_reco);
treenc -> SetBranchAddress(("trklen_"+TrackingName).c_str(), trklen);
treenc -> SetBranchAddress(("trkstartx_"+TrackingName).c_str(),trkstartx);
treenc -> SetBranchAddress(("trkstarty_"+TrackingName).c_str(),trkstarty);
treenc -> SetBranchAddress(("trkstartz_"+TrackingName).c_str(),trkstartz);
treenc -> SetBranchAddress(("trkendx_"+TrackingName).c_str(),trkendx);
treenc -> SetBranchAddress(("trkendy_"+TrackingName).c_str(),trkendy);
treenc -> SetBranchAddress(("trkendz_"+TrackingName).c_str(),trkendz);
treenc -> SetBranchAddress(("trktheta_"+TrackingName).c_str(),trktheta);
treenc -> SetBranchAddress(("trkphi_"+TrackingName).c_str(),trkphi);
treenc -> SetBranchAddress(("trkorigin_"+TrackingName).c_str(),trkorigin);
treenc -> SetBranchAddress(("trkidtruth_"+TrackingName).c_str(),TrackIDTruth);
treenc -> SetBranchAddress(("trkpidbestplane_"+TrackingName).c_str(), trkbestplane);
// Program hack to apply for non uniform naming of nuvtx
if(VertexingName != "nuvtx")
{
treenc -> SetBranchAddress(("nvtx_"+VertexingName).c_str(), &nvtx);
treenc -> SetBranchAddress(("vtxx_"+VertexingName).c_str(), vtxx);
treenc -> SetBranchAddress(("vtxy_"+VertexingName).c_str(), vtxy);
treenc -> SetBranchAddress(("vtxz_"+VertexingName).c_str(), vtxz);
}
else
{
treenc -> SetBranchAddress("nnuvtx", &nvtx);
treenc -> SetBranchAddress("nuvtxx", vtxx);
treenc -> SetBranchAddress("nuvtxy", vtxy);
treenc -> SetBranchAddress("nuvtxz", vtxz);
}
// Vertex position calues
TH1F *hXVertexPosition = new TH1F("X Vertex Distribution","X Vertex Distribution",256,0,FVx);
hXVertexPosition->SetStats(0);
hXVertexPosition->GetXaxis()->SetTitle("X position [cm]");
hXVertexPosition->GetYaxis()->SetTitle("Number of Vertices [ ]");
TLine XVertexMinCut(borderx, 0, borderx, 200);
TLine XVertexMaxCut(FVx-borderx, 0, FVx-borderx, 200);
XVertexMinCut.SetLineColor(kRed);
XVertexMaxCut.SetLineColor(kRed);
TH1F *hYVertexPosition = new TH1F("Y Vertex Distribution","Y Vertex Distribution",333,-FVy/2,(FVy+100)/2);
hYVertexPosition->SetStats(0);
hYVertexPosition->GetXaxis()->SetTitle("Y position [cm]");
hYVertexPosition->GetYaxis()->SetTitle("Number of Vertices [ ]");
TLine YVertexMinCut(-FVy/2+bordery, 0, -FVy/2+bordery, 200);
TLine YVertexMaxCut(FVy/2-bordery, 0, FVy/2-bordery, 200);
YVertexMinCut.SetLineColor(kRed);
YVertexMaxCut.SetLineColor(kRed);
TH1F *hZVertexPosition = new TH1F("Z Vertex Distribution","Z Vertex Distribution",1000,0,FVz);
hZVertexPosition->SetStats(0);
hZVertexPosition->GetXaxis()->SetTitle("Z position [cm]");
hZVertexPosition->GetYaxis()->SetTitle("Number of Vertices [ ]");
TLine ZVertexMinCut(borderz, 0, borderz, 200);
TLine ZVertexMaxCut(FVz-borderz, 0, FVz-borderz, 200);
ZVertexMinCut.SetLineColor(kRed);
ZVertexMaxCut.SetLineColor(kRed);
// Flash Time distribution
TH1F *hFlashTime = new TH1F("Flash Time","Flash Time",200,0,8.2);
hFlashTime->SetStats(0);
hFlashTime->GetXaxis()->SetTitle("Time [#mus]");
hFlashTime->GetYaxis()->SetTitle("Number of Flashes [ ]");
TLine FlashTimeMinCut(beammin, 0, beammin, 2000);
TLine FlashTimeMaxCut(beammax, 0, beammax, 2000);
FlashTimeMinCut.SetLineColor(kRed);
FlashTimeMaxCut.SetLineColor(kRed);
// Flash PE distirbution
TH1F *hIntesityPE = new TH1F("Flash Intensity in PE","Flash Intensity in PE",100,0,1000);
hIntesityPE->SetStats(0);
hIntesityPE->GetXaxis()->SetTitle("Number of P.E. [ ]");
hIntesityPE->GetYaxis()->SetTitle("Number of Flashes [ ]");
TLine FlashPEMinCut(PEthresh, 0, PEthresh, 20000);
FlashPEMinCut.SetLineColor(kRed);
// Flash to track distance
TH1F *hFlashTrackDist = new TH1F("Distance from Flash to Track","Distance between Flash and Track",500,0,500);
hFlashTrackDist->SetStats(0);
hFlashTrackDist->GetXaxis()->SetTitle("Distance [cm]");
hFlashTrackDist->GetYaxis()->SetTitle("Number of Events [ ]");
TLine FlashTrackMinCut(flashwidth, 0, flashwidth, 3000);
FlashTrackMinCut.SetLineColor(kRed);
// Vertex to Track distance
TH1F *hVertexTrackDist = new TH1F("Distance from Vertex to Track","Distance between Vertex and Track",200,0,100);
hVertexTrackDist->SetStats(0);
hVertexTrackDist->GetXaxis()->SetTitle("Distance [cm]");
hVertexTrackDist->GetYaxis()->SetTitle("Number of Tracks [ ]");
TLine VertexTrackMinCut(distcut, 0, distcut, 3000);
VertexTrackMinCut.SetLineColor(kRed);
// All TrackLength
TH1I *hAllTrackLength = new TH1I("Track Range of Longest Tracks","Track Range of Longest Tracks",1000,0,1000);
hAllTrackLength->SetStats(0);
hAllTrackLength->GetXaxis()->SetTitle("Track Range [cm]");
hAllTrackLength->GetYaxis()->SetTitle("Number of Tracks [ ]");
// TrackLength of longest tracks
TH1I *hTrackLength = new TH1I("Track Range Distribution","Track Range Distribution",1000,0,1000);
hTrackLength->SetStats(0);
hTrackLength->GetXaxis()->SetTitle("Track Range [cm]");
hTrackLength->GetYaxis()->SetTitle("Number of Tracks [ ]");
// Track Multiplicity at Vertex
TH1F *hTrackMultip = new TH1F("Track Multiplicity","Track Multiplicity at the Vertex",10,0,10);
hTrackMultip->SetStats(0);
hTrackMultip->GetXaxis()->SetTitle("Number of Tracks [ ]");
hTrackMultip->GetYaxis()->SetTitle("Number of Events [ ]");
// Track Vertex Distances
TH1F *hFlashVertexDist = new TH1F("Flash To Vertex Distance","Flash To Vertex Distance",1000,0,1000);
hFlashVertexDist->SetStats(0);
hFlashVertexDist->GetXaxis()->SetTitle("Distance [cm]");
hFlashVertexDist->GetYaxis()->SetTitle("Number of Vertices [ ]");
// Track True Track Distance
TH1F *hTrackStartDist = new TH1F("Track To MC-Track Start Distance","Track To MC-Track Start Distance",100,0,50);
hTrackStartDist->SetStats(0);
hTrackStartDist->GetXaxis()->SetTitle("Distance [cm]");
hTrackStartDist->GetYaxis()->SetTitle("Number of Tracks [ ]");
// Track True Track Distance
TH1F *hTrackEndDist = new TH1F("Track To MC-Track End Distance","Track To MC-Track End Distance",100,0,50);
hTrackEndDist->SetStats(0);
hTrackEndDist->GetXaxis()->SetTitle("Distance [cm]");
hTrackEndDist->GetYaxis()->SetTitle("Number of Tracks [ ]");
// Theta angle distirbution for selected events
TH1F *hSelectionTheta = new TH1F("#theta-Angle of Selected Track","#theta-Angle of Selected Track",90,0,3.142);
hSelectionTheta->SetStats(0);
hSelectionTheta->GetXaxis()->SetTitle("#theta angle [rad]");
hSelectionTheta->GetYaxis()->SetTitle("Number of Tracks [ ]");
// Theta angle distirbution for selected events
TH1F *hSelectionCCTheta = new TH1F("#theta-Angle of Selected CC Track","#theta-Angle of Selected CC Track",90,0,3.142);
hSelectionCCTheta->SetStats(0);
hSelectionCCTheta->GetXaxis()->SetTitle("#theta angle [rad]");
hSelectionCCTheta->GetYaxis()->SetTitle("Number of Tracks [ ]");
// Theta angle distirbution for selected events
TH1F *hSelectionNCTheta = new TH1F("#theta-Angle of Selected NC Track","#theta-Angle of Selected NC Track",90,0,3.142);
hSelectionNCTheta->SetStats(0);
hSelectionNCTheta->GetXaxis()->SetTitle("#theta angle [rad]");
hSelectionNCTheta->GetYaxis()->SetTitle("Number of Tracks [ ]");
// Theta angle distirbution for selected events
TH1F *hSelectionPhi = new TH1F("#phi-Angle of Selected Track","#phi-Angle of Selected Track",180,-3.142,3.142);
hSelectionPhi->SetStats(0);
hSelectionPhi->GetXaxis()->SetTitle("#phi angle [rad]");
hSelectionPhi->GetYaxis()->SetTitle("Number of Tracks [ ]");
// Theta angle distirbution for selected events
TH1F *hSelectionCCPhi = new TH1F("#phi-Angle of Selected CC Track","#phi-Angle of Selected CC Track",180,-3.142,3.142);
hSelectionCCPhi->SetStats(0);
hSelectionCCPhi->GetXaxis()->SetTitle("#phi angle [rad]");
hSelectionCCPhi->GetYaxis()->SetTitle("Number of Tracks [ ]");
// Theta angle distirbution for selected events
TH1F *hSelectionNCPhi = new TH1F("#phi-Angle of Selected NC Track","#phi-Angle of Selected NC Track",180,-3.142,3.142);
hSelectionNCPhi->SetStats(0);
hSelectionNCPhi->GetXaxis()->SetTitle("#phi angle [rad]");
hSelectionNCPhi->GetYaxis()->SetTitle("Number of Tracks [ ]");
// Track Range distirbution for selected events
TH1F *hSelectionTrackRange = new TH1F("Track Range of Selected Track","Track Range of Selected Track",100,0,1000);
hSelectionTrackRange->SetStats(0);
hSelectionTrackRange->GetXaxis()->SetTitle("Track Range [cm]");
hSelectionTrackRange->GetYaxis()->SetTitle("Number of Tracks [ ]");
// Track Range distirbution for selected events
TH1F *hSelectionCCTrackRange = new TH1F("Track Range of Selected CC Track","Track Range of Selected CC Track",100,0,1000);
hSelectionCCTrackRange->SetStats(0);
hSelectionCCTrackRange->GetXaxis()->SetTitle("Track Range [cm]");
hSelectionCCTrackRange->GetYaxis()->SetTitle("Number of Tracks [ ]");
TH1F *hSelectionNCTrackRange = new TH1F("Track Range of Selected NC Track","Track Range of Selected NC Track",100,0,1000);
hSelectionNCTrackRange->SetStats(0);
hSelectionNCTrackRange->GetXaxis()->SetTitle("Track Range [cm]");
hSelectionNCTrackRange->GetYaxis()->SetTitle("Number of Tracks [ ]");
// Vertex position selection
TH1F *hSelXVtxPosition= new TH1F("Selected X Vertices","Selected X Vertices",256,0,FVx);
hSelXVtxPosition->SetStats(0);
hSelXVtxPosition->GetXaxis()->SetTitle("X position [cm]");
hSelXVtxPosition->GetYaxis()->SetTitle("Number of Vertices [ ]");
TH1F *hSelYVtxPosition= new TH1F("Selected Y Vertices","Selected Y Vertices",333,-FVy/2,(FVy+100)/2);
hSelYVtxPosition->SetStats(0);
hSelYVtxPosition->GetXaxis()->SetTitle("Y position [cm]");
hSelYVtxPosition->GetYaxis()->SetTitle("Number of Vertices [ ]");
TH1F *hSelZVtxPosition= new TH1F("Selected Z Vertices","Selected Z Vertices",1000,0,FVz);
hSelZVtxPosition->SetStats(0);
hSelZVtxPosition->GetXaxis()->SetTitle("Z position [cm]");
hSelZVtxPosition->GetYaxis()->SetTitle("Number of Vertices [ ]");
// All Track Start and End postion
TH1F *hAllXTrackStartEnd = new TH1F("Start & End X-Position of longest Track","Start & End X-Position of longest Track",256,0,FVx);
hAllXTrackStartEnd->SetStats(0);
hAllXTrackStartEnd->GetXaxis()->SetTitle("X position [cm]");
hAllXTrackStartEnd->GetYaxis()->SetTitle("Number of Tracks [ ]");
TH1F *hAllYTrackStartEnd = new TH1F("Start & End Y-Position of longest Track","Start & End Y-Position of longest Track",233,-FVy/2,FVy/2);
hAllXTrackStartEnd->SetStats(0);
hAllYTrackStartEnd->GetXaxis()->SetTitle("Y position [cm]");
hAllYTrackStartEnd->GetYaxis()->SetTitle("Number of Tracks [ ]");
TH1F *hAllZTrackStartEnd = new TH1F("Start & End Z-Position of longest Track","Start & End Z-Position of longest Track",1000,0,FVz);
hAllXTrackStartEnd->SetStats(0);
hAllZTrackStartEnd->GetXaxis()->SetTitle("Z position [cm]");
hAllZTrackStartEnd->GetYaxis()->SetTitle("Number of Tracks [ ]");
// Track Start and End postion
TH1F *hXTrackStartEnd = new TH1F("X Track Start & End Position","X Track Start & End Position",256,0,FVx);
hXTrackStartEnd->SetStats(0);
hXTrackStartEnd->GetXaxis()->SetTitle("X position [cm]");
hXTrackStartEnd->GetYaxis()->SetTitle("Number of Tracks [ ]");
TH1F *hYTrackStartEnd = new TH1F("Y Track Start & End Position","Y Track Start & End Position",233,-FVy/2,FVy/2);
hYTrackStartEnd->SetStats(0);
hYTrackStartEnd->GetXaxis()->SetTitle("Y position [cm]");
hYTrackStartEnd->GetYaxis()->SetTitle("Number of Tracks [ ]");
TH1F *hZTrackStartEnd = new TH1F("Z Track Start & End Position","Z Track Start & End Position",1000,0,FVz);
hZTrackStartEnd->SetStats(0);
hZTrackStartEnd->GetXaxis()->SetTitle("Z position [cm]");
hZTrackStartEnd->GetYaxis()->SetTitle("Number of Tracks [ ]");
int theflash = -1;
double diststart = 0;
double distend = 0;
double TrackRange = 0;
int ntrue = 0;
int TrackCandidate;
int VertexCandidate;
int MCTrackCandidate;
int NuMuCCTrackCandidate;
unsigned int EventsWithFlash = 0;
unsigned int EventsVtxInFV = 0;
unsigned int EventsTrackNearVertex = 0;
unsigned int EventsFlashMatched = 0;
unsigned int EventsTracksInFV = 0;
unsigned int EventsNearVtx = 0;
unsigned int EventsTrackLong = 0;
unsigned int EventsTruelyReco = 0;
unsigned int MCEventsWithFlash = 0;
unsigned int MCEventsVtxInFV = 0;
unsigned int MCEventsTrackNearVertex = 0;
unsigned int MCEventsFlashMatched = 0;
unsigned int MCEventsTracksInFV = 0;
unsigned int MCEventsNearVtx = 0;
unsigned int MCEventsTrackLong = 0;
unsigned int NumberOfSignalTruth = 0;
unsigned int NumberOfSignalTruthSel = 0;
unsigned int NumberOfBgrNCTruthSel = 0;
unsigned int NumberOfBgrNumuBarTruthSel = 0;
unsigned int NumberOfBgrNueTruthSel = 0;
unsigned int NumberOfBgrCosmicSel = 0;
unsigned int NumberOfBgrNuOutFVSel = 0;
TBranch* BrTrackCand = SelectionTree->Branch("TrackCand",&TrackCandidate,"TrackCand/I");
TBranch* BrVtxCand = SelectionTree->Branch("VertexCand",&VertexCandidate,"VertexCand/I");
TBranch* BrMCTrackCand = SelectionTree->Branch("MCTrackCand",&MCTrackCandidate,"MCTrackCand/I");
double TotalPOT = 0.0;
unsigned long int Size = treenc -> GetEntries();
// Set start and end event number for multiple threads
unsigned long int StartEvent = Size*(ThreadNumber - 1)/NumberOfThreads;
unsigned long int EndEvent = Size*ThreadNumber/NumberOfThreads;
// if(Size > 20000) Size = 20000;
// Size = 200000;
std::cout << "number of events used is: " << EndEvent-StartEvent << " of " << Size << std::endl;
//Event Loop
for(int i = StartEvent; i < EndEvent; i++)
{
if(i%1000 == 0) std::cout << "\t... " << i << std::endl;
// Get tree entries
treenc -> GetEntry(i);
bool flashtag = false;
float flashmax = 0;
// Loop over all flashes
for(int f = 0; f < no_flashes; f++)
{
// Fill flash related histograms
hFlashTime->Fill(flash_time[f]);
hIntesityPE->Fill(flash_pe[f]);
// If the flash is in the beam window and above threshold set flashtag to true
if( (flash_time[f] > beammin && flash_time[f] < beammax) && flash_pe[f] > PEthresh )
{
flashtag = true; //the event does have a flash inside the beam window
// If the new flash has more PE than the current maximum, replace the maximum
if(flash_pe[f] > flashmax)
{
theflash = f;
flashmax = flash_pe[f];
}
}
} // flash loop
MCTrackCandidate = -1;
NuMuCCTrackCandidate = -1;
float MCTrackCandRange = 0;
// Loop over all MC neutrino vertices
for(unsigned vertex_no = 0; vertex_no < mcevts_truth; vertex_no++)
{
// Loop over all MC particles
for(unsigned track_no = 0; track_no < NumberOfMCTracks; track_no++)
{
// Calculate MCTrack length
float MCTrackLength = sqrt(pow(XMCTrackStart[track_no] - XMCTrackEnd[track_no],2) + pow(YMCTrackStart[track_no] - YMCTrackEnd[track_no],2) + pow(ZMCTrackStart[track_no] - ZMCTrackEnd[track_no],2));
// If the a muon is not contained in a singel neutrino event, set mc-track contained flag to false
if( ( abs(PDG_truth[track_no]) == 13 || abs(PDG_truth[track_no]) == 11 ) // Track has to be a muon or a electron
// && flashtag
&& inFV(nuvtxx_truth[0],nuvtxy_truth[0],nuvtxz_truth[0]) // true vertex has to be in FV
&& inFV(XMCTrackStart[track_no],YMCTrackStart[track_no],ZMCTrackStart[track_no]) // Track start has to be in FV
// && inFV(XMCTrackEnd[track_no],YMCTrackEnd[track_no],ZMCTrackEnd[track_no]) // Track end has to be in FV
&& sqrt(pow(XMCTrackStart[track_no] - nuvtxx_truth[vertex_no],2) + pow(YMCTrackStart[track_no] - nuvtxy_truth[vertex_no],2) + pow(ZMCTrackStart[track_no] - nuvtxz_truth[vertex_no],2)) < MCTrackToMCVtxDist // Track has to start at vertex
// && MCTrackLength > lengthcut // Track has to be long
// && MCTrackLength > MCTrackCandRange // If the current candidate length is shorter than the new length
)
{
// Fill new length and candidate index
MCTrackCandidate = track_no;
}
} // MC particle loop
} // MC vertex loop
// Count up the number of contained mc-tracks if there are mc candidates
if(MCTrackCandidate > -1 && ccnc_truth[0] == 0 && PDG_truth[MCTrackCandidate] == 13)
{
NumberOfSignalTruth++;
NuMuCCTrackCandidate = MCTrackCandidate;
}
// If there is a POT entry or we are not looking at beam data
// if(potbnb > 0.0 || (GeneratorName != "data_bnb" && GeneratorName !="data_onbeam_bnb"))
if(true)
{
// If the flash tag is ture and we have POT
if(flashtag)
{
// Prepare flags
bool VertexInFVFlag = true;
bool TrackDistanceFlag = true;
bool FlashMatchFlag = true;
// Increase events with flash > 50 PE and within beam window
EventsWithFlash++;
if(NuMuCCTrackCandidate > -1)
MCEventsWithFlash++;
// Initialize vertex candidates for flash matched clusters
std::vector<int> VertexCandidateVec;
// Here an early flash match is performed on all tracks. If the matched tracks have vertices in their vicinity the vertices are stored as candidates
// Loop over all tracks
for(int j = 0; j < ntracks_reco; j++)
{
// Fill histograms
hFlashTrackDist->Fill(FlashTrackDist(flash_zcenter[theflash], trkstartz[j], trkendz[j]));
// If the track is within flash distance
if(FlashTrackDist(flash_zcenter[theflash], trkstartz[j], trkendz[j]) < flashwidth)
{
// Loop over vertices
for(int v = 0; v < nvtx; v++)
{
// Calculate distances from track start/end to vertex and calculate track lenth
diststart = sqrt((vtxx[v] - trkstartx[j])*(vtxx[v] - trkstartx[j]) + (vtxy[v] - trkstarty[j])*(vtxy[v] - trkstarty[j]) + (vtxz[v] - trkstartz[j])*(vtxz[v] - trkstartz[j]));
distend = sqrt((vtxx[v] - trkendx[j])*(vtxx[v] - trkendx[j]) + (vtxy[v] - trkendy[j])*(vtxy[v] - trkendy[j]) + (vtxz[v] - trkendz[j])*(vtxz[v] - trkendz[j]));
// If the track vertex distance is within cut, increase track count
if(diststart < distcut || distend < distcut)
{
// Fill vertex candidate if it has a flash matched track starting within 5 cm
VertexCandidateVec.push_back(v);
if(FlashMatchFlag)
{
EventsFlashMatched++;
if(NuMuCCTrackCandidate > -1)
MCEventsFlashMatched++;
FlashMatchFlag = false;
}
} // if track starts within 5 cm distance
} // vertex loop
}// if flash matched
}// track loop
// Initialize a vertex and associated track collection
std::map< int,std::vector<int> > VertexTrackCollection;
// Here starts the track candidate selection, startig with the vertex candidates.
// First the flatness of all tracks originating in a vertex is calculated
// The flatest (lowest theta average) cluster is picked
// If the vertex is in the FV the longest track is considered the muon candidate
// Loop over candidate vertices (flash matched)
for(auto const& v : VertexCandidateVec)
{
// Reset track at vertex count
unsigned int TrackCountAtVertex = 0;
// Loop over all reconstructed tracks
for(int j = 0; j < ntracks_reco; j++)
{
// Calculate distances from track start/end to vertex and calculate track lenth
diststart = sqrt((vtxx[v] - trkstartx[j])*(vtxx[v] - trkstartx[j]) + (vtxy[v] - trkstarty[j])*(vtxy[v] - trkstarty[j]) + (vtxz[v] - trkstartz[j])*(vtxz[v] - trkstartz[j]));
distend = sqrt((vtxx[v] - trkendx[j])*(vtxx[v] - trkendx[j]) + (vtxy[v] - trkendy[j])*(vtxy[v] - trkendy[j]) + (vtxz[v] - trkendz[j])*(vtxz[v] - trkendz[j]));
TrackRange = sqrt(pow(trkstartx[j] - trkendx[j],2) + pow(trkstarty[j] - trkendy[j],2) + pow(trkstartz[j] - trkendz[j],2));
// If the track vertex distance is within cut, increase track count
if(diststart < distcut || distend < distcut)
{
// Increase count of events with a distance to vertex < 5 cm
if(TrackDistanceFlag)
{
EventsTrackNearVertex++;
if(NuMuCCTrackCandidate > -1)
MCEventsTrackNearVertex++;
TrackDistanceFlag = false;
}
// If we are looking at the first track which fulfills the distance to vertex cut
if(!TrackCountAtVertex)
{
// Fill vertex ID into the collection map
VertexTrackCollection.insert(std::pair< int,std::vector<int> >(v,std::vector<int>()));
}
// Push back track ID for vertex v
VertexTrackCollection.at(v).push_back(j);
// Increase track at vertex count
TrackCountAtVertex++;
}
} // track loop
// Fill vertex related histograms
hTrackMultip->Fill(TrackCountAtVertex);
hFlashVertexDist->Fill(fabs(flash_zcenter[theflash]-vtxz[v]));
} // vertex loop
// Vertex candidate properties
VertexCandidate = -1;
float VertexCosTheta = 0.0;
// Loop over the collection of vertices
for(auto const& VtxTrack : VertexTrackCollection)
{
// Get vertexID
int VertexID = VtxTrack.first;
// Weighted cos theta average
float WeightedCosTheta = 0.0;
// Normalization factor
float NormFactor = 0.0;
// Loop over all associated track IDs of this vertex
for(auto const& TrackID : VtxTrack.second)
{
// Add up numbers
NormFactor += trklen[TrackID];
WeightedCosTheta += trklen[TrackID]*cos(trktheta[TrackID]);
}// track loop
// Make average
WeightedCosTheta /= NormFactor;
// Check for flatest angle (also backwards pointing)
if(fabs(WeightedCosTheta) > VertexCosTheta)
{
VertexCandidate = VertexID;
VertexCosTheta = fabs(WeightedCosTheta);
}
}// vertex collection loop
// Fill vertex position to histogram
hXVertexPosition->Fill(vtxx[VertexCandidate]);
hYVertexPosition->Fill(vtxy[VertexCandidate]);
hZVertexPosition->Fill(vtxz[VertexCandidate]);
// Initialize Track Candidate properties
TrackCandidate = -1;
float TrackCandLength = 0.0;
// Check if vertex candidate is contained in FV
if(inFV(vtxx[VertexCandidate], vtxy[VertexCandidate], vtxz[VertexCandidate]))
{
// Increase count of events with a vertex in FV
if(VertexInFVFlag)
{
EventsVtxInFV++;
if(NuMuCCTrackCandidate > -1)
MCEventsVtxInFV++;
VertexInFVFlag = false;
}
// Looping over track IDs of tracks associated with the vertex candidate
for(auto const& TrackID : VertexTrackCollection.find(VertexCandidate)->second)
{
// Check for if track is longer
if(trklen[TrackID] > TrackCandLength)
{
TrackCandidate = TrackID;
TrackCandLength = trklen[TrackID];
}
}
} // if vertex is contained in FV
// If there is a track candidate further cuts are applied on it
// First it has to be contained in the FV
// Second it has to be longer than 75 cm
// If there is a track candidate
if(TrackCandidate > -1)
{
hAllTrackLength->Fill(TrackCandLength);
hAllXTrackStartEnd->Fill(trkstartx[TrackCandidate]);
hAllXTrackStartEnd->Fill(trkendx[TrackCandidate]);
hAllYTrackStartEnd->Fill(trkstarty[TrackCandidate]);
hAllYTrackStartEnd->Fill(trkendy[TrackCandidate]);
hAllZTrackStartEnd->Fill(trkstartz[TrackCandidate]);
hAllZTrackStartEnd->Fill(trkendz[TrackCandidate]);
// If the longest track is fully contained
if( inFV(trkstartx[TrackCandidate], trkstarty[TrackCandidate], trkstartz[TrackCandidate])
&& inFV(trkendx[TrackCandidate], trkendy[TrackCandidate], trkendz[TrackCandidate]) )
{
//Fill contained track histograms
hXTrackStartEnd->Fill(trkstartx[TrackCandidate]);
hXTrackStartEnd->Fill(trkendx[TrackCandidate]);
hYTrackStartEnd->Fill(trkstarty[TrackCandidate]);
hYTrackStartEnd->Fill(trkendy[TrackCandidate]);
hZTrackStartEnd->Fill(trkstartz[TrackCandidate]);
hZTrackStartEnd->Fill(trkendz[TrackCandidate]);
EventsTracksInFV++;
if(NuMuCCTrackCandidate > -1)
MCEventsTracksInFV++;
// Fill Track length
hTrackLength->Fill(TrackCandLength);
// If longest track is longer than 75 cm
if(TrackCandLength > lengthcut)
{
EventsTrackLong++;
if(NuMuCCTrackCandidate > -1)
MCEventsTrackLong++;
if(ccnc_truth[0] == 0 && trkorigin[TrackCandidate][trkbestplane[TrackCandidate]] == 1)
{
if(MCTrackCandidate > -1 && PDG_truth[MCTrackCandidate] == 13 && inFV(nuvtxx_truth[0],nuvtxy_truth[0],nuvtxz_truth[0]))
{
NumberOfSignalTruthSel++;
}
else if(MCTrackCandidate > -1 && PDG_truth[MCTrackCandidate] == -13)
{
NumberOfBgrNumuBarTruthSel++;
}
else if(MCTrackCandidate > -1 && abs(PDG_truth[MCTrackCandidate]) == 11)
{
NumberOfBgrNueTruthSel++;
}
else if(!inFV(nuvtxx_truth[0],nuvtxy_truth[0],nuvtxz_truth[0]))
{
NumberOfBgrNuOutFVSel++;
}
hSelectionCCTheta->Fill(trktheta[TrackCandidate]);
hSelectionCCPhi->Fill(trkphi[TrackCandidate]);
hSelectionCCTrackRange->Fill(TrackCandLength);
}
else if(ccnc_truth[0] == 1 && trkorigin[TrackCandidate][trkbestplane[TrackCandidate]] == 1)
{
NumberOfBgrNCTruthSel++;
hSelectionNCTheta->Fill(trktheta[TrackCandidate]);
hSelectionNCPhi->Fill(trkphi[TrackCandidate]);
hSelectionNCTrackRange->Fill(TrackCandLength);
}
else if(trkorigin[TrackCandidate][trkbestplane[TrackCandidate]] != 1)
{
NumberOfBgrCosmicSel++;
}
// Fill Selection Plots
hSelectionTheta->Fill(trktheta[TrackCandidate]);
hSelectionPhi->Fill(trkphi[TrackCandidate]);
hSelectionTrackRange->Fill(TrackCandLength);
hSelXVtxPosition->Fill(vtxx[VertexCandidate]);
hSelYVtxPosition->Fill(vtxy[VertexCandidate]);
hSelZVtxPosition->Fill(vtxz[VertexCandidate]);
SelectionTree -> Fill();
double TrkStartMCStartDist = sqrt(pow(XMCTrackStart[MCTrackCandidate] - trkstartx[TrackCandidate],2) + pow(YMCTrackStart[MCTrackCandidate] - trkstarty[TrackCandidate],2) + pow(ZMCTrackStart[MCTrackCandidate] - trkstartz[TrackCandidate],2));
double TrkEndMCEndDist = sqrt(pow(XMCTrackEnd[MCTrackCandidate] - trkendx[TrackCandidate],2) + pow(YMCTrackEnd[MCTrackCandidate] - trkendy[TrackCandidate],2) + pow(ZMCTrackEnd[MCTrackCandidate] - trkendz[TrackCandidate],2));
double TrkStartMCEndDist = sqrt(pow(XMCTrackEnd[MCTrackCandidate] - trkstartx[TrackCandidate],2) + pow(YMCTrackEnd[MCTrackCandidate] - trkstarty[TrackCandidate],2) + pow(ZMCTrackEnd[MCTrackCandidate] - trkstartz[TrackCandidate],2));
double TrkEndMCStartDist = sqrt(pow(XMCTrackStart[MCTrackCandidate] - trkendx[TrackCandidate],2) + pow(YMCTrackStart[MCTrackCandidate] - trkendy[TrackCandidate],2) + pow(ZMCTrackStart[MCTrackCandidate] - trkendz[TrackCandidate],2));
// Find if Track start or end ar closer to true track start
if(TrkStartMCStartDist < TrkEndMCStartDist)
{
hTrackStartDist->Fill(TrkStartMCStartDist);
hTrackEndDist->Fill(TrkEndMCEndDist);
}
else
{
hTrackStartDist->Fill(TrkEndMCStartDist);
hTrackEndDist->Fill(TrkStartMCEndDist);
}
// If track end or start are close to montecarlo vertex
// if( (TrkStartMCStartDist < TrackToMCDist && TrkEndMCEndDist < TrackToMCDist)
// ||(TrkStartMCEndDist < TrackToMCDist && TrkEndMCStartDist < TrackToMCDist)
// )
if( MCTrackID[NuMuCCTrackCandidate] == TrackIDTruth[TrackCandidate][trkbestplane[TrackCandidate]])
{
EventsTruelyReco++;
}
} // if track is longer than 75 cm
} // if track is contained
} // if there is a track candidate
} // if flashtag
// Increase the neutrino count
ntrue++;
// Add POT count
TotalPOT += potbnb;
} // if we have POT
}//loop over all events
OutputFile->cd();
// SelectionTree->Print();
SelectionTree->Write();
hXVertexPosition->Write();
hYVertexPosition->Write();
hZVertexPosition->Write();
hFlashTime->Write();
hIntesityPE->Write();
hFlashTrackDist->Write();
hVertexTrackDist->Write();
hAllTrackLength->Write();
hTrackLength->Write();