-
Notifications
You must be signed in to change notification settings - Fork 0
/
MCAnalysis_module.cc
1542 lines (1188 loc) · 57.8 KB
/
MCAnalysis_module.cc
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
////////////////////////////////////////////////////////////////////////
// Class: MCAnalysis
// Module Type: analyzer
// File: MCAnalysis_module.cc
//
// Generated at Tue Jul 14 11:21:46 2015 by Roberto Acciarri using artmod
// from cetpkgsupport v1_08_06.
////////////////////////////////////////////////////////////////////////
// ##########################
// ### Framework includes ###
// ##########################
#include "art/Framework/Core/EDAnalyzer.h"
#include "art/Framework/Core/ModuleMacros.h"
#include "art/Framework/Principal/Event.h"
#include "fhiclcpp/ParameterSet.h"
#include "art/Framework/Principal/Run.h"
#include "art/Framework/Principal/SubRun.h"
#include "art/Framework/Principal/Handle.h"
#include "canvas/Persistency/Common/Ptr.h"
#include "canvas/Persistency/Common/PtrVector.h"
#include "art/Framework/Services/Registry/ServiceHandle.h"
#include "art/Framework/Services/Optional/TFileService.h"
#include "art/Framework/Services/Optional/TFileDirectory.h"
#include "canvas/Persistency/Common/FindOneP.h"
#include "canvas/Persistency/Common/FindManyP.h"
#include "messagefacility/MessageLogger/MessageLogger.h"
//#include "cetlib/maybe_ref.h"
// ########################
// ### LArSoft includes ###
// ########################
#include "larcoreobj/SimpleTypesAndConstants/geo_types.h"
#include "larcoreobj/SimpleTypesAndConstants/RawTypes.h" // raw::ChannelID_t
#include "larcore/Geometry/Geometry.h"
#include "larcore/Geometry/CryostatGeo.h"
#include "larcore/Geometry/TPCGeo.h"
#include "larcore/Geometry/PlaneGeo.h"
#include "larcore/Geometry/WireGeo.h"
#include "lardataobj/RecoBase/Wire.h"
#include "lardataobj/RecoBase/Hit.h"
#include "lardataobj/RecoBase/Cluster.h"
#include "lardataobj/RecoBase/Track.h"
#include "lardataobj/RecoBase/TrackHitMeta.h"
#include "lardataobj/RecoBase/Vertex.h"
#include "lardataobj/RecoBase/SpacePoint.h"
#include "lardata/DetectorInfoServices/LArPropertiesService.h"
#include "lardata/DetectorInfoServices/DetectorPropertiesService.h"
#include "lardata/Utilities/AssociationUtil.h"
//#include "RawData/ExternalTrigger.h"
#include "lardataobj/RawData/RawDigit.h"
#include "lardataobj/RawData/raw.h"
#include "larsim/MCCheater/BackTracker.h"
#include "lardataobj/Simulation/SimChannel.h"
#include "nusimdata/SimulationBase/MCTruth.h"
#include "larevt/Filters/ChannelFilter.h"
#include "lardataobj/AnalysisBase/Calorimetry.h"
#include "lardataobj/AnalysisBase/ParticleID.h"
#include "larreco/RecoAlg/TrackMomentumCalculator.h"
#include "LArIATDataProducts/WCTrack.h"
#include "LArIATDataProducts/TOF.h"
#include "LArIATDataProducts/AGCounter.h"
#include "RawDataUtilities/TriggerDigitUtility.h"
#include "lardataobj/RecoBase/Shower.h"
#include "lardataobj/RecoBase/EndPoint2D.h"
#include "lardataobj/MCBase/MCShower.h"
#include "lardataobj/MCBase/MCStep.h"
#include "larreco/Calorimetry/CalorimetryAlg.h"
// #####################
// ### ROOT includes ###
// #####################
#include "TComplex.h"
#include "TFile.h"
#include "TH2D.h"
#include "TF1.h"
#include "TTree.h"
#include "TTimeStamp.h"
#include <TStyle.h>
#include <THStack.h>
const int kMaxTrack = 1000; //maximum number of tracks
const int kMaxTrackHits = 1000; //maximum number of space points
const int kMaxTrajHits = 1000; //maximum number of trajectory points
const int kMaxPrimaries = 20000; //maximum number of primary particles
const int kMaxTruePrimaryPts = 100000; //maximum number of truth trajectory points
// ### Number of centimeters in Z we require a track ###
// ### to have a space point within (default = 2 cm) ###
const double FirstSpacePointZPos = 2.0;
// ##############################################################
// ### Delta X Between Extrapolated MC Particle and TPC Track ###
// ##############################################################
const double DeltaXLowerBound = -2.0;
const double DeltaXUpperBound = 6.0;
// ##############################################################
// ### Delta Y Between Extrapolated MC Particle and TPC Track ###
// ##############################################################
const double DeltaYLowerBound = -3.0;
const double DeltaYUpperBound = 6.0;
// ########################################################################
// ### Fiducial Boundry Cuts (used to determine if a track is stopping) ###
// ########################################################################
const double XLowerFid = 0;
const double XUpperFid = 47;
const double YLowerFid = -20;
const double YUpperFid = 20;
const double ZLowerFid = 0;
const double ZUpperFid = 90;
// ########################################################################
// ### Definition of the upstream part of the TPC where we restrict the ###
// ### number of tracks which can be present ###
// ########################################################################
const int UpperPartOfTPC = 14.0;
// #####################################################
// ### Number of tracks allowed in the upstream part ###
// #####################################################
const int nLowZTracksAllowed = 4;
// ############################
// ### Alpha Cut in degrees ###
// ############################
const double alphaCut = 10;
//Create the cross section from the incident and interaction plots
const float rho = 1400; //kg/m^3
// float cm_per_m = 100;
const float molar_mass = 39.9; //g/mol
const float g_per_kg = 1000;
const float avogadro = 6.02e+23; //number/mol
const float number_density = rho*g_per_kg/molar_mass*avogadro;
const float slab_width = 0.0045;//in m
namespace lariat
{
class MCAnalysis;
}
class lariat::MCAnalysis : public art::EDAnalyzer
{
public:
explicit MCAnalysis(fhicl::ParameterSet const & p);
virtual ~MCAnalysis();
// Required functions.
void analyze(art::Event const & e) override;
// Selected optional functions.
void beginJob();
void reconfigure(fhicl::ParameterSet const & p);
void endJob() override;
private:
// === Function used to reset all the variables ===
void ResetVars();
//=== Storing Run Information ===
int run; //<---Run Number
int subrun; //<---SubRun Number
int event; //<---Event Number
double trkidpri;
double trkidmot;
//####### dummy variable ##############//
double dummyTrkX[kMaxTrack];
double dummyTrkY[kMaxTrack];
double dummyTrkZ[kMaxTrack];
double dummyTrk_pHat0X[kMaxTrack];
double dummyTrk_pHat0Y[kMaxTrack];
double dummyTrk_pHat0Z[kMaxTrack];
double dummyTrk_Index[kMaxTrack];
double dummyTrk_Theta[kMaxTrack];
double dummyTrk_Phi[kMaxTrack];
// === Storing the tracks Calorimetry Information
int trkhits[kMaxTrack][2];
// double trkpida[kMaxTrack][2];
double trkke[kMaxTrack][2];
double trkdedx[kMaxTrack][2][1000];
double trkrr[kMaxTrack][2][1000];
double trkpitchhit[kMaxTrack][2][1000];
double trjPt_dmX[kMaxTrack][kMaxTrajHits]; //<---Storing the trajector point location in X
double trjPt_dmY[kMaxTrack][kMaxTrajHits]; //<---Storing the trajector point location in Y
double trjPt_dmZ[kMaxTrack][kMaxTrajHits]; //<---Storing the trajector point location in Z
// === dummy variable ===
double dummyXpoint, dummyYpoint, dummyZpoint;
double dummypoint_TempTrjX, dummypoint_TempTrjY,dummypoint_TempTrjZ,dummyPointTrkInd;
int nEvtsMCTrackMatch=0;
int nEventsPassingAlpha=0;
int nEvtsTrackZPos =0;
int nEvtsGoodMC = 0;
int nLowZTrkEvents =0;
float mcPhi = 0;
float mcTheta = 0;
double NTpts;
double alpha, DeltaX, DeltaY, DeltaZ;
// === Storing Geant4 MC Truth Information ===
double g4Primary_X0[kMaxPrimaries];
double g4Primary_Y0[kMaxPrimaries];
double g4Primary_Z0[kMaxPrimaries];
double g4Primary_Px[kMaxPrimaries];
double g4Primary_Py[kMaxPrimaries];
double g4Primary_Pz[kMaxPrimaries];
double g4Primary_Xf[kMaxPrimaries];
double g4Primary_Yf[kMaxPrimaries];
double g4Primary_Zf[kMaxPrimaries];
double g4Primary_ProjX0[kMaxPrimaries];
double g4Primary_ProjY0[kMaxPrimaries];
double g4Primary_ProjZ0[kMaxPrimaries];
double g4PrimaryProcess[kMaxPrimaries];
// === Storing additionnal Geant4 MC Truth Information for the primary track only ===
//int NTrTrajPts[kMaxPrimaries]; //<--Nb. of true points in the true primary trajectories
double MidE[kMaxTruePrimaryPts]; //<--E Energy of a point in the true primary trajectory
//################# Histogram for the Analysis ####################
// ###################################
// ### MC Starting Point Histogram ###
// ###################################
TH1D *fStartXMC;
TH1D *fStartYMC;
TH1D *fStartZMC;
// ######################################
// ### MC Starting Momentum Histogram ###
// ######################################
TH1D *fStartPxMC;
TH1D *fStartPyMC;
TH1D *fStartPzMC;
// #################################
// ### MC Ending Point Histogram ###
// #################################
TH1D *fEndXMC;
TH1D *fEndYMC;
TH1D *fEndZMC;
// ################################################
// ### Extrapolated MC Starting Point Histogram ###
// ################################################
TH1D *fProjX0;
TH1D *fProjY0;
TH1D *fProjZ0;
TH1D *fProcess;
// ###################################
// ### Primary Particle Z_f vs X_f ###
// ###################################
TH2D *fPrimaryEndXvsZ;
// ###################################
// ### Primary Particle Y_f vs Z_f ###
// ###################################
TH2D *fPrimaryEndYvsZ;
// ##########################
// ### Histogram for cuts ###
// ##########################
TH1D *fAlpha;
TH1D *fDeltaX;
TH1D *fDeltaY;
TH1D *fDeltaZ;
TH1D *fUpstZpts;
TH1D *fMCInitalKE;
TH1D *fDeltaEndX;
TH1D *fDeltaEndY;
TH1D *fDeltaEndZ;
TH1F *fCutHistogram;
TH1D *fnUpstmTrk;
// ############################################
// ### Histogram for Delta End Z vs process ###
// ############################################
TH1D *fDeltaEndZInElastic;
TH1D *fDeltaEndZNeutronInElastic;
TH1D *fDeltaEndZHadElastic;
TH1D *fDeltaEndZnCap;
TH1D *fDeltaEndZnuclearCapatureAtRest;
TH1D *fDeltaEndZDecay;
TH1D *fDeltaEndZKaonZeroInElastic;
TH1D *fDeltaEndZCoulombScat;
TH1D *fDeltaEndZMuMinusCapture;
TH1D *fDeltaEndZProtonInelastic;
TH1D *fDeltaEndZPiMinusAbsorptionAtRest;
// ############################################
// ### Histogram for Delta End Y vs process ###
// ############################################
TH1D *fDeltaEndYInElastic;
TH1D *fDeltaEndYNeutronInElastic;
TH1D *fDeltaEndYHadElastic;
TH1D *fDeltaEndYnCap;
TH1D *fDeltaEndYnuclearCapatureAtRest;
TH1D *fDeltaEndYDecay;
TH1D *fDeltaEndYKaonZeroInElastic;
TH1D *fDeltaEndYCoulombScat;
TH1D *fDeltaEndYMuMinusCapture;
TH1D *fDeltaEndYProtonInelastic;
TH1D *fDeltaEndYPiMinusAbsorptionAtRest;
// ############################################
// ### Histogram for Delta End X vs process ###
// ############################################
TH1D *fDeltaEndXInElastic;
TH1D *fDeltaEndXNeutronInElastic;
TH1D *fDeltaEndXHadElastic;
TH1D *fDeltaEndXnCap;
TH1D *fDeltaEndXnuclearCapatureAtRest;
TH1D *fDeltaEndXDecay;
TH1D *fDeltaEndXKaonZeroInElastic;
TH1D *fDeltaEndXCoulombScat;
TH1D *fDeltaEndXMuMinusCapture;
TH1D *fDeltaEndXProtonInelastic;
TH1D *fDeltaEndXPiMinusAbsorptionAtRest;
// #########################################################
// ### Histograms tracks which go into the Cross-Section ###
// #########################################################
TH1D *fdataPiondEdX;
TH1D *fdataPionRR;
TH1D *fdataPionTrkPitch;
TH2D *fdataPiondEdXvsRR;
//################### Cross-section ####################################//
TH1D *fdataPionIncidentKE;
TH1D *fPionInteractions;
TH1F *fCrossSection;
TH1D *fTruthIncidentKE;
TH1D *fTruthInteractingKE;
//std::string fTrigModuleLabel;
std::string fClusterModuleLabel;
std::string fHitsModuleLabel;
std::string fTrackModuleLabel;
std::string fCalorimetryModuleLabel;
std::string fParticleIDModuleLabel;
std::string fG4ModuleLabel;
std::string fShowerModuleLabel; // Producer that makes showers from clustering
std::string fMCShowerModuleLabel; // Producer name that makes MCShower Object
calo::CalorimetryAlg fCalorimetryAlg;
};
lariat::MCAnalysis::MCAnalysis(fhicl::ParameterSet const & pset)
: EDAnalyzer(pset)
, fCalorimetryAlg(pset.get<fhicl::ParameterSet>("CalorimetryAlg"))
{
this->reconfigure(pset);
}
lariat::MCAnalysis::~MCAnalysis()
{
// Clean up dynamic memory and other resources here.
}
void lariat::MCAnalysis::reconfigure(fhicl::ParameterSet const & pset)
{
//fTrigModuleLabel = pset.get< std::string >("TriggerUtility");
fHitsModuleLabel = pset.get< std::string >("HitsModuleLabel");
fTrackModuleLabel = pset.get< std::string >("TrackModuleLabel");
fCalorimetryModuleLabel = pset.get< std::string >("CalorimetryModuleLabel");
fParticleIDModuleLabel = pset.get< std::string >("ParticleIDModuleLabel");
fClusterModuleLabel = pset.get< std::string >("ClusterModuleLabel");
fG4ModuleLabel = pset.get< std::string >("G4ModuleLabel");
fShowerModuleLabel = pset.get< std::string >("ShowerModuleLabel");
fMCShowerModuleLabel = pset.get< std::string >("MCShowerModuleLabel");
return;
}
void lariat::MCAnalysis::analyze(art::Event const & evt)
{
// #############################################
// ### Reset variables before we get started ###
// #############################################
ResetVars();
// #######################################
// ### Get potentially useful services ###
// #######################################
// === Geometry Service ===
art::ServiceHandle<geo::Geometry> geom;
// === BackTracker service ===
art::ServiceHandle<cheat::BackTracker> bt;
const sim::ParticleList& plist = bt->ParticleList();
// === Run Number ===
run = evt.run();
// === Sub-Run Number ===
subrun = evt.subRun();
// === Event Number ===
event = evt.id().event();
std::cout<<std::endl;
std::cout<<"========================================="<<std::endl;
std::cout<<"Run = "<<run<<", SubRun = "<<subrun<<", Evt = "<<event<<std::endl;
std::cout<<"========================================="<<std::endl;
std::cout<<std::endl;
// #####################################
// ### Getting the Track Information ###
// #####################################
art::Handle< std::vector<recob::Track> > trackListHandle; //<---Define trackListHandle as a vector of recob::Track objects
std::vector<art::Ptr<recob::Track> > tracklist; //<---Define tracklist as a pointer to recob::tracks
// === Filling the tracklist from the tracklistHandle ===
if (evt.getByLabel(fTrackModuleLabel,trackListHandle))
{art::fill_ptr_vector(tracklist, trackListHandle);}
// ###################################
// ### Getting the Hit Information ###
// ###################################
art::Handle< std::vector<recob::Hit> > hitListHandle; //<---Define hitListHandle as a vector of recob::Track objects
std::vector<art::Ptr<recob::Hit> > hitlist; //<---Define tracklist as a pointer to recob::tracks
// === Filling the hitlist from the hitlistHandle ===
if (evt.getByLabel(fHitsModuleLabel,hitListHandle))
{art::fill_ptr_vector(hitlist, hitListHandle);}
// ##########################################
// ### Getting the 2D Cluster Information ###
// ##########################################
art::Handle< std::vector<recob::Cluster> > clusterListHandle; //<---Define clusterListHandle as a vector of recob::Track objects
std::vector<art::Ptr<recob::Cluster> > clusterlist; //<---Define cluster as a pointer to recob::cluster
// === Filling the clusterlist from the clusterlistHandle ===
if (evt.getByLabel(fClusterModuleLabel,clusterListHandle))
{art::fill_ptr_vector(clusterlist, clusterListHandle);}
// #####################################
// ### Getting the Shower Information ###
// #####################################
art::Handle< std::vector<recob::Shower> > shwListHandle;
std::vector<art::Ptr<recob::Shower> > shwlist;
// === Filling the shwlist from the shwlistHandle ===
if (evt.getByLabel(fShowerModuleLabel,shwListHandle))
{art::fill_ptr_vector(shwlist, shwListHandle);}
// ##########################################################
// ### Grabbing associations for use later in the AnaTool ###
// ##########################################################
// === Associations between hits and raw digits ===
art::FindOne<raw::RawDigit> ford(hitListHandle, evt, fHitsModuleLabel);
// === Association between SpacePoints and Tracks ===
art::FindManyP<recob::SpacePoint> fmsp(trackListHandle, evt, fTrackModuleLabel);
// === Association between Tracks and 2d Hits ===
art::FindManyP<recob::Track> fmtk(hitListHandle, evt, fTrackModuleLabel);
// === Association between Calorimetry objects and Tracks ===
art::FindManyP<anab::Calorimetry> fmcal(trackListHandle, evt, fCalorimetryModuleLabel);
// === Association between Particle ID objects (PID) and Tracks ===
art::FindManyP<anab::ParticleID> fmpid(trackListHandle, evt, fParticleIDModuleLabel);
// ==== Association between Clusters and Hits ===
art::FindManyP<recob::Cluster> fmc(hitListHandle, evt, fClusterModuleLabel);
// ==== Association between Clusters and Showers ===
art::FindManyP<recob::Shower> fms (clusterListHandle, evt, fShowerModuleLabel);
// ==== Association between Tracks and Hits
art::FindManyP<recob::Hit> fmth(trackListHandle, evt, fTrackModuleLabel);
art::FindManyP<recob::Hit, recob::TrackHitMeta> fmthm(trackListHandle, evt, fTrackModuleLabel);
// ### Something to do with SimChannels...need to come back to ###
std::vector<const sim::SimChannel*> fSimChannels;
try
{evt.getView("largeant", fSimChannels);}
catch (art::Exception const&e){ }
// ###################################################################
// ### Setting a boolian to only output MC info if this is MC-info ###
// ###################################################################
bool isdata = false;
if (evt.isRealData())
{isdata = true;}
else isdata = false;
// ----------------------------------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------------------------------------
// FILLING THE MCTruth Geant4 INFORMATION
// ----------------------------------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------------------------------------
int primary=0;
if(!isdata)
{
// ### Filling all MC Events in the Cut histogram ###
fCutHistogram->Fill(0);
// ######################################
// ### Making a vector of MCParticles ###
// ######################################
std::vector<const simb::MCParticle* > geant_part;
// ### Looping over all the Geant4 particles from the BackTracker ###
for(size_t p = 0; p < plist.size(); ++p)
{
// ### Filling the vector with MC Particles ###
geant_part.push_back(plist.Particle(p));
}
// ### Setting a string for primary ###
std::string pri("primary");
// ### Setting a string for PionMinusInelastic ###
std::string PionMinusInelastic("PionMinusInelastic");
// ### Setting a string for NeutronInelastic ###
std::string NeutronInelastic("NeutronInelastic");
// ### Setting a string for hadElastic ###
std::string hadElastic("hadElastic");
// ### Setting a string for nCapture ###
std::string nCapture("nCapture");
// ### Setting a string for CHIPSNuclearCaptureAtRest ###
std::string CHIPSNuclearCaptureAtRest("CHIPSNuclearCaptureAtRest");
// ### Setting a string for Decay ###
std::string Decay("Decay");
// ### Setting a string for KaonZeroLInelastic ###
std::string KaonZeroLInelastic("KaonZeroLInelastic");
// ### Setting a string for CoulombScat ###
std::string CoulombScat("CoulombScat");
// ### Setting a string for muMinusCaptureAtRest ###
std::string muMinusCaptureAtRest("muMinusCaptureAtRest");
// ### Setting a string for ProtonInelastic ###
std::string ProtonInelastic("ProtonInelastic");
// ### Setting a string for PiMinusAbsorptionAtRest ###
std::string PiMinusAbsorptionAtRest("PiMinusAbsorptionAtRest");
int geant_particle=0;
// float g4PrimaryProcess[100] = {0};
int g4Primary_TrkID[100] = {999};
// ############################################################
// ### Determine the number of primary particles from geant ###
// ############################################################
for( unsigned int i = 0; i < geant_part.size(); ++i )
{
geant_particle++;
// ##################################################
// ### Grabbing the primary particles information ###
// ##################################################
if(geant_part[i]->Process()==pri)
{
// ##############################################################
// ### Getting the trajectory points for the primary particle ###
// ##############################################################
simb::MCTrajectory truetraj = geant_part[i]->Trajectory();
// ### Number of MC trajectory points ###
int iPrimPt = 0;
for(auto itTraj = truetraj.begin(); itTraj != truetraj.end(); ++itTraj)
{
MidE[iPrimPt] = truetraj.E(iPrimPt)*1000;
iPrimPt++;
}//<--End loop on true trajectory points
NTpts = iPrimPt;
// ### Getting the primary particles starting information ###
g4Primary_X0[primary] = geant_part[i]->Vx();
g4Primary_Y0[primary] = geant_part[i]->Vy();
g4Primary_Z0[primary] = geant_part[i]->Vz();
g4Primary_Px[primary] = geant_part[i]->Px()*1000;
g4Primary_Py[primary] = geant_part[i]->Py()*1000;
g4Primary_Pz[primary] = geant_part[i]->Pz()*1000;
// #########################################################################
// ## Extrapolating the MC Primary particle to the front face of the TPC ###
// #########################################################################
double PX0 = -999, PY0 = -999;
if(geant_part[i]->Vz() < 0)
{
double b1 = geant_part[i]->Vz() - geant_part[i]->Vx()*geant_part[i]->Pz()/geant_part[i]->Px();
double b2 = geant_part[i]->Vz() - geant_part[i]->Vy()*geant_part[i]->Pz()/geant_part[i]->Py();
PX0 = -b1*geant_part[i]->Px()/geant_part[i]->Pz();
PY0 = -b2*geant_part[i]->Py()/geant_part[i]->Pz();
g4Primary_ProjX0[primary] = PX0;
g4Primary_ProjY0[primary] = PY0;
g4Primary_ProjZ0[primary] = 0.0;
}//<---End projecting the particle if it started outside the TPC
// ### Getting the primary particles ending information ###
g4Primary_TrkID[primary] = geant_part[i]->TrackId();
g4Primary_Xf[primary] =geant_part[i]->EndPosition()[0];
g4Primary_Yf[primary] =geant_part[i]->EndPosition()[1];
g4Primary_Zf[primary] =geant_part[i]->EndPosition()[2];
// ##########################
// ### Filling Histograms ###
// ##########################
fProjX0->Fill(PX0);
fProjY0->Fill(PY0);
fProjZ0->Fill(0.0);
fStartXMC->Fill(geant_part[i]->Vx());
fStartYMC->Fill(geant_part[i]->Vy());
fStartZMC->Fill(geant_part[i]->Vz());
fStartPxMC->Fill(geant_part[i]->Px()*1000);
fStartPyMC->Fill(geant_part[i]->Py()*1000);
fStartPzMC->Fill(geant_part[i]->Pz()*1000);
fEndXMC->Fill(geant_part[i]->EndPosition()[0]);
fEndYMC->Fill(geant_part[i]->EndPosition()[1]);
fEndZMC->Fill(geant_part[i]->EndPosition()[2]);
fPrimaryEndXvsZ->Fill(geant_part[i]->EndPosition()[2],geant_part[i]->EndPosition()[0]);
fPrimaryEndYvsZ->Fill(geant_part[i]->EndPosition()[2],geant_part[i]->EndPosition()[1]);
// ### Counting the number of primaries
primary++;
} // End of if particle is primary
trkidmot = geant_part[i]->Mother();
} // End of geant_part size
// ############################################
// ### Storing the process name for primary ###
// ############################################
for( unsigned int i = 0; i < geant_part.size(); ++i )
{
for( int jprime = 0; jprime < primary; jprime++)
{
if(geant_part[i]->Mother() == g4Primary_TrkID[jprime])
{
if(geant_part[i]->Process() == PionMinusInelastic)
{g4PrimaryProcess[primary -1] = 1;}
if(geant_part[i]->Process() == NeutronInelastic)
{g4PrimaryProcess[primary -1] = 2;}
if(geant_part[i]->Process() == hadElastic)
{g4PrimaryProcess[primary -1] = 3;}
if(geant_part[i]->Process() == nCapture)
{g4PrimaryProcess[primary -1] = 4;}
if(geant_part[i]->Process() == CHIPSNuclearCaptureAtRest)
{g4PrimaryProcess[primary -1] = 5;}
if(geant_part[i]->Process() == Decay)
{g4PrimaryProcess[primary -1] = 6;}
if(geant_part[i]->Process() == KaonZeroLInelastic)
{g4PrimaryProcess[primary -1] = 7;}
if(geant_part[i]->Process() == CoulombScat)
{g4PrimaryProcess[primary -1] = 8;}
if(geant_part[i]->Process() == muMinusCaptureAtRest)
{g4PrimaryProcess[primary -1] = 9;}
if(geant_part[i]->Process() == ProtonInelastic)
{g4PrimaryProcess[primary -1] = 10;}
if(geant_part[i]->Process()==PiMinusAbsorptionAtRest)
{g4PrimaryProcess[primary -1] = 0;}
}//<---End getting the particles associated with the primary
fProcess->Fill(g4PrimaryProcess[jprime]);
}//<---End jprime loop
}//<--End i loop over all geant4 particles
}//<---End checking if this is data
//=======================================================================================================================
// Only looking at events where the primary particle enters the TPC
//=======================================================================================================================
bool GoodMCEventInTPC = true;
// ##############################################
// ### Looping over all the primary particles ###
// ##############################################
for(int npri = 0; npri < primary; npri++)
{
if(g4Primary_Zf[npri] < 0){GoodMCEventInTPC = false;}
}//<---End npri loop
// ### Filling the cut histogram if the primary enters the TPC ###
if(GoodMCEventInTPC){fCutHistogram->Fill(1);}
//=======================================================================================================================
// Low Z Spacepoint Track Cut
//=======================================================================================================================
bool TrackTrjPtsZCut = false;
int nUpStreamTrk = 0;
// ##################################################
// ### Loop over all the Reconstructed TPC Tracks ###
// ##################################################
for(size_t iTrk = 0; iTrk<tracklist.size(); iTrk++)
{
TVector3 p_hat_dm0;
// ### Resetting the variables for each track ###
dummyXpoint = 999, dummyYpoint = 999, dummyZpoint = 999;
// ########################################################
// ### Looping over the trajectory points for the track ###
// ########################################################
for(size_t iTrjPt = 0; iTrjPt<tracklist[iTrk]->NumberTrajectoryPoints(); iTrjPt++)
{
p_hat_dm0 = tracklist[iTrk]->DirectionAtPoint(iTrjPt);
// ### Need to understand this .... ###
if( p_hat_dm0.Z() < 0 )
{
p_hat_dm0.SetX(p_hat_dm0.X()*-1);
p_hat_dm0.SetY(p_hat_dm0.Y()*-1);
p_hat_dm0.SetZ(p_hat_dm0.Z()*-1);
}
trjPt_dmX[iTrk][iTrjPt] = tracklist[iTrk]->LocationAtPoint(iTrjPt).X();
trjPt_dmY[iTrk][iTrjPt] = tracklist[iTrk]->LocationAtPoint(iTrjPt).Y();
trjPt_dmZ[iTrk][iTrjPt] = tracklist[iTrk]->LocationAtPoint(iTrjPt).Z();
// ###########################################################################
// ### Setting our dummypoints if this is the lowest Z point on this track ###
// ### and still within the active volume of the TPC ###
// ###########################################################################
if(trjPt_dmZ[iTrk][iTrjPt] < dummyZpoint && trjPt_dmZ[iTrk][iTrjPt] > 0.0 &&
trjPt_dmY[iTrk][iTrjPt] > -20.0 && trjPt_dmY[iTrk][iTrjPt] < 20.0 &&
trjPt_dmX[iTrk][iTrjPt] > 0.0 && trjPt_dmX[iTrk][iTrjPt] < 47 )
{
dummyXpoint = trjPt_dmX[iTrk][iTrjPt];
dummyYpoint = trjPt_dmY[iTrk][iTrjPt];
dummyZpoint = trjPt_dmZ[iTrk][iTrjPt];
dummypoint_TempTrjX = p_hat_dm0.X();
dummypoint_TempTrjY = p_hat_dm0.Y();
dummypoint_TempTrjZ = p_hat_dm0.Z();
dummyPointTrkInd = iTrk;
} //--End sorting for the lowest point in Z
} //---End iTrjPt loop
// ################################################################
// ### Record this track if the upstream point is less than 2cm ###
// ################################################################
if(dummyZpoint < 2)
{
dummyTrkX[nUpStreamTrk] = dummyXpoint;
dummyTrkY[nUpStreamTrk] = dummyYpoint;
dummyTrkZ[nUpStreamTrk] = dummyZpoint;
dummyTrk_pHat0X[nUpStreamTrk] = dummypoint_TempTrjX;
dummyTrk_pHat0Y[nUpStreamTrk] = dummypoint_TempTrjY;
dummyTrk_pHat0Z[nUpStreamTrk] = dummypoint_TempTrjZ;
dummyTrk_Index[nUpStreamTrk] = dummyPointTrkInd;
nUpStreamTrk++;
TrackTrjPtsZCut = true;
} // End of If loop
//} //End of Spacept Loop
fUpstZpts->Fill(dummyZpoint);
} // End iTrk
fnUpstmTrk->Fill(nUpStreamTrk);
// ###############################################
// ### Skipping events that don't have a track ###
// ### in the front of the TPC (Z) Position ###
// ###############################################
if(TrackTrjPtsZCut)
{
// ### Counting Events w/ front face TPC Track ###
nEvtsTrackZPos++;
fCutHistogram->Fill(2);
// ----------------------------------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------------------------------------
// FILLING THE 3-D TRACK INFORMATION
// ----------------------------------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------------------------------------
//####################Filling Trk Pitchhit, dE/dX info for all tracks###########################################
// ### Looping over tracks ###
for(size_t i=0; i<tracklist.size();++i)
{
// ##########################################################
// ### Looping over Calorimetry information for the track ###
// ##########################################################
if (fmcal.isValid())
{
// ### Putting calo information for this track (i) into pointer vector ###
std::vector<art::Ptr<anab::Calorimetry> > calos = fmcal.at(i);
// ### Looping over each calorimetry point (similar to SpacePoint) ###
for (size_t j = 0; j<calos.size(); ++j)
{
// ### If we don't have calorimetry information for this plane skip ###
if (!calos[j]->PlaneID().isValid) continue;
// ### Grabbing this calorimetry points plane number (0 == induction, 1 == collection) ###
int pl = calos[j]->PlaneID().Plane;
// ### Skipping this point if the plane number doesn't make sense ###
if (pl<0||pl>1) continue;
// ### Recording the number of calorimetry points for this track in this plane ####
trkhits[i][pl] = calos[j]->dEdx().size();
// #### Recording the kinetic energy for this track in this plane ###
trkke[i][pl] = calos[j]->KineticEnergy();
// ###############################################
// ### Looping over all the calorimetry points ###
// ###############################################
for (size_t k = 0; k<calos[j]->dEdx().size(); ++k)
{
// ### If we go over 1000 points just skip them ###
if (k>=1000) continue;
// ### Recording the dE/dX information for this calo point along the track in this plane ###
trkdedx[i][pl][k] = calos[j]->dEdx()[k];
// ### Recording the residual range for this calo point along the track in this plane ###
trkrr[i][pl][k] = calos[j]->ResidualRange()[k];
// ### Recording the pitch of this calo point along the track in this plane ###
trkpitchhit[i][pl][k] = calos[j]->TrkPitchVec()[k];
}//<---End calo points (k)
}//<---End looping over calo points (j)
}//<---End checking Calo info is valid
}
//=======================================================================================================================
// Cutting on the number of tracks in the upstream TPC
//=======================================================================================================================
int nLowZTracksInTPC = 0;
// ################################################################
// ### Initializing variables for study of low Z track location ###
// ################################################################
bool LowZTrackInTPC = false;
// float templowz1 = 0;
// #################################################################
// ### Only keeping events if there is less than N tracks in the ###
// ### first ## cm of the TPC (to help cut out EM Showers ###
// #################################################################
for(size_t iTrk = 0; iTrk<tracklist.size(); iTrk++)
{
// ### Start by assuming this track is not in the ###
// ### low Z part of the TPC ###
LowZTrackInTPC = false;
// ##################################################
// ### Looping over the spacepoints for the track ###
// ##################################################
for(size_t iTrjPt = 0; iTrjPt<tracklist[iTrk]->NumberTrajectoryPoints(); iTrjPt++)
{
// ##################################################
// ### Count this track if it has a spacepoint in ###
// ### the low Z region of the TPC ###
// ##################################################
if(trjPt_dmZ[iTrk][iTrjPt] < UpperPartOfTPC)
{
if(trjPt_dmY[iTrk][iTrjPt] > YLowerFid && trjPt_dmY[iTrk][iTrjPt] < YUpperFid &&
trjPt_dmX[iTrk][iTrjPt] > XLowerFid && trjPt_dmX[iTrk][iTrjPt] < XUpperFid)
{LowZTrackInTPC = true; }
}//<---End counting if
}//<---End nspts loop
// ##################################################################
// ### If the track was in the "UpperPartOfTPC", bump the counter ###
// ##################################################################
if(LowZTrackInTPC)
{
nLowZTracksInTPC++;
}//<---End counting track in the Upstream part
}//<---End nTPCtrk
// ### Skipping the event if there are too many ###
// ### low Z tracks in the event ###
if((nLowZTracksInTPC <= nLowZTracksAllowed) && (nLowZTracksInTPC > 0))
{
fCutHistogram->Fill(3);
// ### Counting the event if it passes ###
nLowZTrkEvents++;
//=======================================================================================================================
// Matching the MC Particle to the Reco Track (similar to the WC Track match)
//=======================================================================================================================
// ################################################
// ### Calculating the angles for the Geant4 MC ###
// ################################################
TVector3 z_hat_MC(0,0,1);
TVector3 p_hat_0_MC;
// ### Setting the vector for the MC using the ###
// ### extrapolated Momentum vector ###
p_hat_0_MC.SetX(g4Primary_Px[0]);
p_hat_0_MC.SetY(g4Primary_Py[0]);
p_hat_0_MC.SetZ(g4Primary_Pz[0]);
// ### Getting everything in the same convention ###
float mcPhi = 0;
float mcTheta = 0;
// === Calculating Theta for MC ===
mcTheta = acos(z_hat_MC.Dot(p_hat_0_MC)/p_hat_0_MC.Mag());
// std::cout<<"Truth Theta"<<mcTheta<<std::endl;
// === Calculating Phi for MC ===
if( p_hat_0_MC.Y() > 0 && p_hat_0_MC.X() > 0 ){ mcPhi = atan(p_hat_0_MC.Y()/p_hat_0_MC.X()); }
else if( p_hat_0_MC.Y() > 0 && p_hat_0_MC.X() < 0 ){ mcPhi = atan(p_hat_0_MC.Y()/p_hat_0_MC.X())+3.141592654; }
else if( p_hat_0_MC.Y() < 0 && p_hat_0_MC.X() < 0 ){ mcPhi = atan(p_hat_0_MC.Y()/p_hat_0_MC.X())+3.141592654; }
else if( p_hat_0_MC.Y() < 0 && p_hat_0_MC.X() > 0 ){ mcPhi = atan(p_hat_0_MC.Y()/p_hat_0_MC.X())+6.28318; }
else if( p_hat_0_MC.Y() == 0 && p_hat_0_MC.X() == 0 ){ mcPhi = 0; }//defined by convention
else if( p_hat_0_MC.Y() == 0 )
{
if( p_hat_0_MC.X() > 0 ){ mcPhi = 0; }
else{ mcPhi = 3.141592654; }
}
else if( p_hat_0_MC.X() == 0 )
{