LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
MCTrackCollectionAnaAlg.cxx
Go to the documentation of this file.
1 
10 #include "TBranch.h"
11 #include "TTree.h"
13 #include <numeric>
14 
16 
18 {
19  fTree = tree;
20  fFillTree = fill;
21 
22  fTree->Branch("mct_run", &fRun, "mct_run/i");
23  fTree->Branch("mct_event", &fEvent, "mct_event/i");
24 
25  fTree->Branch("mct_nmctracks", &fNMCTracks, "mct_nmctracks/i");
26  fTree->Branch("mct_dp", &fDParticle, "mct_dp/i");
27  fTree->Branch("mct_dpfrac", &fDParticleFraction, "mct_dpfrac/F");
28 
29  fTree->Branch("mct_dporigin", &fDParticleOrigin, "mct_dporigin/I");
30  fTree->Branch("mct_dppdg", &fDParticlePdgCode, "mct_dppdg/I");
31  fTree->Branch("mct_dptrackid", &fDParticleTrackId, "mct_dptrackid/i");
32  fTree->Branch("mct_dpmpdg", &fDParticleMotherPdgCode, "mct_dpmpdg/I");
33  fTree->Branch("mct_dpmtrackid", &fDParticleMotherTrackId, "mct_dpmtrackid/i");
34  fTree->Branch("mct_dpapdg", &fDParticleAncestorPdgCode, "mct_dpapdg/I");
35  fTree->Branch("mct_dpatrackid", &fDParticleAncestorTrackId, "mct_dpatrackid/i");
36 
37  fTree->Branch("mct_dpstartx", &fDParticleStartX, "mct_dpstartx/F");
38  fTree->Branch("mct_dpstarty", &fDParticleStartY, "mct_dpstarty/F");
39  fTree->Branch("mct_dpstartz", &fDParticleStartZ, "mct_dpstartz/F");
40  fTree->Branch("mct_dpstarte", &fDParticleStartE, "mct_dpstarte/F");
41  fTree->Branch("mct_dpendx", &fDParticleEndX, "mct_dpendx/F");
42  fTree->Branch("mct_dpendy", &fDParticleEndY, "mct_dpendy/F");
43  fTree->Branch("mct_dpendz", &fDParticleEndZ, "mct_dpendz/F");
44  fTree->Branch("mct_dpende", &fDParticleEndE, "mct_dpende/F");
45 
46  fTree->Branch("mct_coly", &fCollectionY, "mct_coly/F");
47  fTree->Branch("mct_colz", &fCollectionZ, "mct_colz/F");
48  fTree->Branch("mct_colx", &fCollectionX, "mct_colx/F");
49  fTree->Branch("mct_colrmsy", &fCollectionRMSY, "mct_colrmsy/F");
50  fTree->Branch("mct_colrmsz", &fCollectionRMSZ, "mct_colrmsz/F");
51  fTree->Branch("mct_colrmsx", &fCollectionRMSX, "mct_colrmsx/F");
52  fTree->Branch("mct_colE", &fCollectionEnergy, "mct_colE/F");
53 
54  fTree->Branch("mct_miny", &fMinY, "mct_miny/F");
55  fTree->Branch("mct_maxy", &fMaxY, "mct_maxy/F");
56  fTree->Branch("mct_minz", &fMinZ, "mct_minz/F");
57  fTree->Branch("mct_maxz", &fMaxZ, "mct_maxz/F");
58  fTree->Branch("mct_minx", &fMinX, "mct_minx/F");
59  fTree->Branch("mct_maxx", &fMaxX, "mct_maxx/F");
60 }
61 
63  unsigned int event,
64  const std::vector<sim::MCTrack>& mctVec)
65 {
66  fRun = run;
67  fEvent = event;
68 
69  fNMCTracks = mctVec.size();
71 
72  fMinY = 99999;
73  fMinZ = 99999;
74  fMinX = 99999;
75  fMaxY = -99999;
76  fMaxZ = -99999;
77  fMaxX = -99999;
78 
79  if (mctVec.size() == 0) {
80  fTree->Fill();
81  return;
82  }
83 
84  std::vector<double> y_vals;
85  std::vector<double> z_vals;
86  std::vector<double> x_vals;
87  std::vector<double> stepL_vals;
88 
89  std::vector<double> mct_length(mctVec.size(), 0);
90  //int d_index = -1; // unused
91  for (size_t i_p = 0; i_p < mctVec.size(); i_p++) {
92 
93  fCollectionEnergy += mctVec[i_p].Start().E();
94 
95  //y_vals.reserve( y_vals.size() + mctVec[i_p].size()-1 );
96  //z_vals.reserve( z_vals.size() + mctVec[i_p].size()-1 );
97  //x_vals.reserve( x_vals.size() + mctVec[i_p].size()-1 );
98 
99  for (size_t i_s = 1; i_s < mctVec[i_p].size(); i_s++) {
100 
101  TVector3 const& vec1 = mctVec[i_p][i_s - 1].Position().Vect();
102  TVector3 const& vec2 = mctVec[i_p][i_s].Position().Vect();
103  double stepL = (vec2 - vec1).Mag();
104 
105  double thisy = 0.5 * (vec1.Y() + vec2.Y());
106  double thisz = 0.5 * (vec1.Z() + vec2.Z());
107  double thisx = 0.5 * (vec1.X() + vec2.X());
108 
109  y_vals.push_back(thisy);
110  z_vals.push_back(thisz);
111  x_vals.push_back(thisx);
112  stepL_vals.push_back(stepL);
113 
114  mct_length[i_p] += stepL;
115 
116  if (thisy > fMaxY) fMaxY = thisy;
117  if (thisy < fMinY) fMinY = thisy;
118  if (thisz > fMaxZ) fMaxZ = thisz;
119  if (thisz < fMinZ) fMinZ = thisz;
120  if (thisx > fMaxX) fMaxX = thisx;
121  if (thisx < fMinX) fMinX = thisx;
122 
123  } //end loop over steps
124  } //end loop over tracks
125 
126  double totalL = std::accumulate(mct_length.begin(), mct_length.end(), 0.0);
127 
128  fDParticle =
129  std::distance(mct_length.begin(), std::max_element(mct_length.begin(), mct_length.end()));
130  fDParticleFraction = mct_length.at(fDParticle) / totalL;
132 
133  double sumy = 0, sumz = 0, sumx = 0;
134  for (size_t i_step = 0; i_step < stepL_vals.size(); i_step++) {
135  sumy += stepL_vals[i_step] * y_vals[i_step];
136  sumz += stepL_vals[i_step] * z_vals[i_step];
137  sumx += stepL_vals[i_step] * x_vals[i_step];
138  }
139 
140  fCollectionY = sumy / totalL;
141  fCollectionZ = sumz / totalL;
142  fCollectionX = sumx / totalL;
143 
144  double sumy2 = 0, sumz2 = 0, sumx2 = 0;
145  for (size_t i_step = 0; i_step < stepL_vals.size(); i_step++) {
146  sumy2 += stepL_vals[i_step] * (y_vals[i_step] - fCollectionY) * (y_vals[i_step] - fCollectionY);
147  sumz2 += stepL_vals[i_step] * (z_vals[i_step] - fCollectionZ) * (z_vals[i_step] - fCollectionZ);
148  sumx2 += stepL_vals[i_step] * (x_vals[i_step] - fCollectionX) * (x_vals[i_step] - fCollectionX);
149  }
150 
151  fCollectionRMSY = std::sqrt(sumy2 / totalL);
152  fCollectionRMSZ = std::sqrt(sumz2 / totalL);
153  fCollectionRMSX = std::sqrt(sumx2 / totalL);
154 
155  if (fFillTree) fTree->Fill();
156 }
157 
159 {
160  size_t nsteps = mctrack.size();
161 
162  fDParticleOrigin = mctrack.Origin();
163  fDParticlePdgCode = mctrack.PdgCode();
164  fDParticleTrackId = mctrack.TrackID();
165  fDParticleStartY = mctrack[0].Y();
166  fDParticleStartZ = mctrack[0].Z();
167  fDParticleStartX = mctrack[0].X();
168  fDParticleStartE = mctrack[0].E();
169  fDParticleEndY = mctrack[nsteps - 1].Y();
170  fDParticleEndZ = mctrack[nsteps - 1].Z();
171  fDParticleEndX = mctrack[nsteps - 1].X();
172  fDParticleEndE = mctrack[nsteps - 1].E();
177 }
simb::Origin_t Origin() const
Definition: MCTrack.h:38
void SetOutputTree(TTree *, bool fill=true)
unsigned int AncestorTrackID() const
Definition: MCTrack.h:57
void FillTree(unsigned int, unsigned int, const std::vector< sim::MCTrack > &)
int AncestorPdgCode() const
Definition: MCTrack.h:56
unsigned int MotherTrackID() const
Definition: MCTrack.h:51
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
Class def header for mctrack data container.
int PdgCode() const
Definition: MCTrack.h:39
int MotherPdgCode() const
Definition: MCTrack.h:50
unsigned int TrackID() const
Definition: MCTrack.h:40
void FillDominantParticleInfo(const sim::MCTrack &)
Event finding and building.