LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
sim::MCTrackRecoAlg Class Reference

#include "MCTrackRecoAlg.h"

Public Member Functions

 MCTrackRecoAlg (fhicl::ParameterSet const &pset)
 Default constructor with fhicl parameters. More...
 
std::unique_ptr< std::vector< sim::MCTrack > > Reconstruct (MCRecoPart &part_v, MCRecoEdep &edep_v)
 

Protected Attributes

bool fDebugMode
 

Detailed Description

Definition at line 38 of file MCTrackRecoAlg.h.

Constructor & Destructor Documentation

sim::MCTrackRecoAlg::MCTrackRecoAlg ( fhicl::ParameterSet const &  pset)
explicit

Default constructor with fhicl parameters.

Definition at line 19 of file MCTrackRecoAlg.cxx.

References fDebugMode, and fhicl::ParameterSet::get().

21  {
22  fDebugMode = pset.get<bool>("DebugMode");
23  }

Member Function Documentation

std::unique_ptr< std::vector< sim::MCTrack > > sim::MCTrackRecoAlg::Reconstruct ( MCRecoPart part_v,
MCRecoEdep edep_v 
)

Definition at line 25 of file MCTrackRecoAlg.cxx.

References sim::MCMiniPart::_end_mom, sim::MCMiniPart::_end_vtx, sim::MCRecoPart::_pdg_list, sim::MCMiniPart::_pdgcode, sim::MCMiniPart::_process, sim::MCMiniPart::_start_mom, sim::MCMiniPart::_start_vtx, sim::MCMiniPart::_track_id, sim::MCTrack::AncestorEnd(), sim::MCTrack::AncestorPdgCode(), sim::MCTrack::AncestorProcess(), sim::MCTrack::AncestorStart(), sim::MCTrack::AncestorTrackID(), sim::MCRecoPart::AncestorTrackID(), B, sim::details::createPlaneIndexMap(), d, E, edep, sim::MCTrack::End(), fDebugMode, sim::MCRecoEdep::GetEdepArrayAt(), sim::kINVALID_UINT, sim::MCTrack::MotherEnd(), sim::MCTrack::MotherPdgCode(), sim::MCTrack::MotherProcess(), sim::MCTrack::MotherStart(), sim::MCTrack::MotherTrackID(), sim::MCRecoPart::MotherTrackID(), sim::MCTrack::Origin(), sim::MCTrack::PdgCode(), sim::MCTrack::Process(), sim::MCTrack::Start(), sim::MCTrack::TrackID(), sim::MCRecoEdep::TrackToEdepIndex(), sim::MCRecoPart::TrackToParticleIndex(), X, Y, and Z.

Referenced by MCReco::produce().

27  {
28  auto result = std::make_unique<std::vector<sim::MCTrack>>();
29  auto& mctracks = *result;
30  auto pindex = details::createPlaneIndexMap();
31 
32  for(size_t i=0; i<part_v.size(); ++i) {
33  auto const& mini_part = part_v[i];
34  if( part_v._pdg_list.find(mini_part._pdgcode) == part_v._pdg_list.end() ) continue;
35 
36  ::sim::MCTrack mini_track;
37 
38  std::vector<double> dEdx;
39  std::vector<std::vector<double> > dQdx;
40  dQdx.resize(3);
41 
42  mini_track.Origin ( mini_part._origin );
43  mini_track.PdgCode ( mini_part._pdgcode );
44  mini_track.TrackID ( mini_part._track_id );
45  mini_track.Process ( mini_part._process );
46  mini_track.Start ( MCStep( mini_part._start_vtx, mini_part._start_mom ) );
47  mini_track.End ( MCStep( mini_part._end_vtx, mini_part._end_mom ) );
48 
49  unsigned int mother_track = part_v.MotherTrackID(i);
50  unsigned int ancestor_track = part_v.AncestorTrackID(i);
51 
52  if(mother_track == kINVALID_UINT || ancestor_track == kINVALID_UINT)
53 
54  throw cet::exception(__FUNCTION__) << "LOGIC ERROR: mother/ancestor track ID is invalid!";
55 
56  MCMiniPart mother_part;
57  MCMiniPart ancestor_part;
58 
59  unsigned int mother_index = part_v.TrackToParticleIndex(mother_track);
60  unsigned int ancestor_index = part_v.TrackToParticleIndex(ancestor_track);
61 
62  if(mother_index != kINVALID_UINT) mother_part = part_v[mother_index];
63  else mother_part._track_id = mother_track;
64 
65  if(ancestor_index != kINVALID_UINT) ancestor_part = part_v[ancestor_index];
66  else ancestor_part._track_id = ancestor_track;
67 
68  mini_track.MotherPdgCode ( mother_part._pdgcode );
69  mini_track.MotherTrackID ( mother_part._track_id );
70  mini_track.MotherProcess ( mother_part._process );
71  mini_track.MotherStart ( MCStep( mother_part._start_vtx, mother_part._start_mom ) );
72  mini_track.MotherEnd ( MCStep( mother_part._end_vtx, mother_part._end_mom ) );
73 
74  mini_track.AncestorPdgCode ( ancestor_part._pdgcode );
75  mini_track.AncestorTrackID ( ancestor_part._track_id );
76  mini_track.AncestorProcess ( ancestor_part._process );
77  mini_track.AncestorStart ( MCStep( ancestor_part._start_vtx, ancestor_part._start_mom ) );
78  mini_track.AncestorEnd ( MCStep( ancestor_part._end_vtx, ancestor_part._end_mom ) );
79 
80 
81  // Fill trajectory points
82 
83  for(auto const& vtx_mom : mini_part._det_path){
84  mini_track.push_back(MCStep(vtx_mom.first,vtx_mom.second));
85  }
86 
87  // No calorimetry for zero length tracks...
88  // JZ : I think we should remove zero length MCTracks because I do not see their utility
89  // JZ : Someone could make this a fcl parameter, I did not
90  if(mini_track.size() == 0){
91  mctracks.push_back(mini_track);
92  continue;
93  }
94 
95  auto const& edep_index = edep_v.TrackToEdepIndex(mini_part._track_id);
96  if(edep_index < 0 ) continue;
97  auto const& edeps = edep_v.GetEdepArrayAt(edep_index);
98 
99  //int n = 0; // unused
100 
101  for(auto const& step_trk : mini_track){
102 
103  if( int(&step_trk - &mini_track[0])+1 == int(mini_track.size()) ){ //annoying way to check if this is last step
104  continue;}
105 
106 
107  auto const& nxt_step_trk = mini_track.at(int(&step_trk - &mini_track[0])+1);
108 
109  //Defining the track step-by-step dEdx and dQdx
110 
111  //Find the distance between two adjacent MCSteps
112  double dist = sqrt(pow(step_trk.X() - nxt_step_trk.X(),2) +
113  pow(step_trk.Y() - nxt_step_trk.Y(),2) +
114  pow(step_trk.Z() - nxt_step_trk.Z(),2));
115 
116  //Make a plane at the step pointed at the next step
117 
118  //Need to define a plane through the first MCStep with a normal along the momentum vector of the step
119  //The plane will be defined in the typical way:
120  // a*x + b*y + c*z + d = 0
121  // where, a = dir_x, b = dir_y, c = dir_z, d = - (a*x_0+b*y_0+c*z_0)
122  // then the *signed* distance of any point (x_1, y_1, z_1) from this plane is:
123  // D = (a*x_1 + b*y_1 + c*z_1 + d )/sqrt( pow(a,2) + pow(b,2) + pow(c,2))
124 
125  double a = 0, b = 0, c = 0, d = 0;
126  a = nxt_step_trk.X() - step_trk.X();
127  b = nxt_step_trk.Y() - step_trk.Y();
128  c = nxt_step_trk.Z() - step_trk.Z();
129  d = -1*(a*step_trk.X() + b*step_trk.Y() + c*step_trk.Z());
130 
131  //Make a line connecting the two points and find the distance from that line
132  //
133  // [A dot B]^2 [A dot B]^2
134  // distance^2 = A^2 - 2* ____________ + ______________
135  // B^2 B^2
136  // Test point == x_0
137  // First Step == x_1
138  // Next step == x_2
139  // A = x_1 - x_0
140  // B = x_2 - x_1
141 
142  // 'B' definition
143  TVector3 B(nxt_step_trk.Position().X() - step_trk.Position().X(),
144  nxt_step_trk.Position().Y() - step_trk.Position().Y(),
145  nxt_step_trk.Position().Z() - step_trk.Position().Z());
146 
147 
148  //Initialize the step-by-step dEdx and dQdx containers
149  double step_dedx = 0;
150  std::vector<double> step_dqdx;
151  step_dqdx.resize(3);
152 
153  //Iterate through all the energy deposition points
154  for(auto const& edep : edeps){
155  // 'x_0' definition
156  TVector3 x_0(edep.pos._x, edep.pos._y, edep.pos._z);
157  // 'A' definition
158  TVector3 A(step_trk.Position().X() - x_0.X(),
159  step_trk.Position().Y() - x_0.Y(),
160  step_trk.Position().Z() - x_0.Z());
161 
162  // Distance from the line connecting x_1 and x_2
163  double LineDist = 0;
164 
165  if(B.Mag2() != 0){
166  LineDist = sqrt(A.Mag2() - 2*pow(A*B,2)/B.Mag2() + pow(A*B,2)/B.Mag2());
167  }
168  else{LineDist = 0;}
169 
170  //Planar Distance and Radial Line Distance Cuts
171  // Add in a voxel before and after to account for MCSteps
172  // the line distance allows for 1mm GEANT multiple columb scattering correction,
173  // small compared to average MCStep-to-MCStep distance
174  if( (a*edep.pos._x + b*edep.pos._y + c*edep.pos._z + d)/sqrt( pow(a,2) + pow(b,2) + pow(c,2)) <= dist + 0.03 &&
175  (a*edep.pos._x + b*edep.pos._y + c*edep.pos._z + d)/sqrt( pow(a,2) + pow(b,2) + pow(c,2)) >= 0 - 0.03 &&
176  LineDist < 0.1){
177 
178  //dEdx Calculation
179  int npid = 0;
180  double engy = 0;
181 
182  for(auto const& pid_energy : edep.deps){
183  engy += pid_energy.energy;
184  npid++;
185  }
186 
187  if(npid != 0){
188  engy /= npid;}
189  else{engy = 0;}
190 
191  step_dedx += engy;
192  auto const pid = edep.pid;
193  auto q_i = pindex.find(pid);
194  if(q_i != pindex.end())
195  step_dqdx[pid.Plane] += (double)(edep.deps[pindex[pid]].charge);
196  }
197  }
198 
199  // Normalize to the 3D distance between the MCSteps
200 
201  //Disregard any energy deposition when 2 MCSteps are separated less than the voxel size
202  if(dist > 0.03){
203  step_dedx /= dist;
204  step_dqdx[0] /= dist;
205  step_dqdx[1] /= dist;
206  step_dqdx[2] /= dist;
207  }
208  else{
209  step_dedx = 0;
210  step_dqdx[0] = 0;
211  step_dqdx[1] = 0;
212  step_dqdx[2] = 0;
213  }
214 
215  // Build the vector(s) to add to data product
216  dEdx.push_back(step_dedx);
217  dQdx[0].push_back(step_dqdx[0]);
218  dQdx[1].push_back(step_dqdx[1]);
219  dQdx[2].push_back(step_dqdx[2]);
220 
221 
222 
223  }
224 
225  //Add calorimetry to the data product
226  mini_track.dEdx(dEdx);
227  mini_track.dQdx(dQdx);
228 
229 
230  mctracks.push_back(mini_track);
231 
232 
233 
234  }
235 
236  if(fDebugMode) {
237 
238  for(auto const& prof : mctracks) {
239 
240  std::cout
241 
242  << Form(" Track particle: PDG=%d : Track ID=%d Start @ (%g,%g,%g,%g) with Momentum (%g,%g,%g,%g)",
243  prof.PdgCode(),prof.TrackID(),
244  prof.Start().X(),prof.Start().Y(),prof.Start().Z(),prof.Start().T(),
245  prof.Start().Px(),prof.Start().Py(),prof.Start().Pz(),prof.Start().E())
246  << std::endl
247  << Form(" Mother particle: PDG=%d : Track ID=%d Start @ (%g,%g,%g,%g) with Momentum (%g,%g,%g,%g)",
248  prof.MotherPdgCode(),prof.MotherTrackID(),
249  prof.MotherStart().X(),prof.MotherStart().Y(),prof.MotherStart().Z(),prof.MotherStart().T(),
250  prof.MotherStart().Px(),prof.MotherStart().Py(),prof.MotherStart().Pz(),prof.MotherStart().E())
251  << std::endl
252  << Form(" Ancestor particle: PDG=%d : Track ID=%d Start @ (%g,%g,%g,%g) with Momentum (%g,%g,%g,%g)",
253  prof.AncestorPdgCode(),prof.AncestorTrackID(),
254  prof.AncestorStart().X(),prof.AncestorStart().Y(),prof.AncestorStart().Z(),prof.AncestorStart().T(),
255  prof.AncestorStart().Px(),prof.AncestorStart().Py(),prof.AncestorStart().Pz(),prof.AncestorStart().E())
256  << std::endl
257  << Form(" ... with %zu trajectory points!",prof.size())
258  << std::endl;
259 
260  if(prof.size()) {
261  std::cout
262  << Form(" Start @ (%g,%g,%g,%g) with Momentum (%g,%g,%g,%g)",
263  prof[0].X(), prof[0].Y(), prof[0].Z(), prof[0].T(),
264  prof[0].Px(), prof[0].Py(), prof[0].Pz(), prof[0].E())
265  << std::endl
266  << Form(" End @ (%g,%g,%g,%g) with Momentum (%g,%g,%g,%g)",
267  (*prof.rbegin()).X(), (*prof.rbegin()).Y(), (*prof.rbegin()).Z(), (*prof.rbegin()).T(),
268  (*prof.rbegin()).Px(), (*prof.rbegin()).Py(), (*prof.rbegin()).Pz(), (*prof.rbegin()).E())
269  << std::endl;
270  }
271  }
272 
273  std::cout<<std::endl<<std::endl;
274  }
275  return result;
276  }
simb::Origin_t Origin() const
Definition: MCTrack.h:40
Float_t E
Definition: plot.C:23
const std::string & AncestorProcess() const
Definition: MCTrack.h:57
Int_t B
Definition: plot.C:25
Float_t Y
Definition: plot.C:39
const MCStep & MotherEnd() const
Definition: MCTrack.h:53
unsigned int AncestorTrackID() const
Definition: MCTrack.h:56
std::map< geo::PlaneID, size_t > createPlaneIndexMap()
Definition: MCRecoEdep.cxx:17
int AncestorPdgCode() const
Definition: MCTrack.h:55
const MCStep & End() const
Definition: MCTrack.h:45
unsigned int MotherTrackID() const
Definition: MCTrack.h:50
Float_t Z
Definition: plot.C:39
Float_t d
Definition: plot.C:237
const MCStep & AncestorStart() const
Definition: MCTrack.h:58
Double_t edep
Definition: macro.C:13
int PdgCode() const
Definition: MCTrack.h:41
const MCStep & MotherStart() const
Definition: MCTrack.h:52
int MotherPdgCode() const
Definition: MCTrack.h:49
const std::string & Process() const
Definition: MCTrack.h:43
const std::string & MotherProcess() const
Definition: MCTrack.h:51
const unsigned int kINVALID_UINT
Definition: MCLimits.h:14
const MCStep & Start() const
Definition: MCTrack.h:44
unsigned int TrackID() const
Definition: MCTrack.h:42
Float_t X
Definition: plot.C:39
const MCStep & AncestorEnd() const
Definition: MCTrack.h:59
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33

Member Data Documentation

bool sim::MCTrackRecoAlg::fDebugMode
protected

Definition at line 47 of file MCTrackRecoAlg.h.

Referenced by MCTrackRecoAlg(), and Reconstruct().


The documentation for this class was generated from the following files: