EDepSimTrajectoryMap.cc
Go to the documentation of this file.
2 #include "EDepSimTrajectory.hh"
3 #include "EDepSimException.hh"
4 
5 #include <G4VTrajectory.hh>
6 #include <G4VTrajectoryPoint.hh>
7 #include <G4ThreeVector.hh>
8 
9 #include <EDepSimLog.hh>
10 
11 std::map<int, G4VTrajectory*> EDepSim::TrajectoryMap::fMap;
12 
14  fMap.clear();
15 }
16 
17 void EDepSim::TrajectoryMap::Add(G4VTrajectory* traj) {
18  int trackId = traj->GetTrackID();
19  fMap[trackId] = traj;
20 }
21 
23  int currentId = trackId;
24  int parentId = trackId;
25  int loopCount=0;
26  for (loopCount=0;loopCount<10000;++loopCount) {
27  G4VTrajectory* t = Get(currentId);
28  if (!t) break;
29  parentId = t->GetParentID();
30  // Check to see the search loop should terminate.
31  G4VTrajectory* p = Get(parentId);
32  // There is no parent so break so this is a primary trajectory.
33  if (!p) break;
34  // Decay products are primary trajectories since they should be
35  // independently reconstructed
36  EDepSim::Trajectory * edepTraj = dynamic_cast<EDepSim::Trajectory*>(t);
37  if (!edepTraj) EDepSimThrow("Invalid Trajectory");
38  if (edepTraj->GetProcessName() == "Decay") break;
39  // A parent ID of zero means that this particle is a primary particle,
40  // so that makes it a primary trajectory too.
41  if (parentId == 0) break;
42  currentId = parentId;
43  }
44  if (loopCount>9999) {
45  EDepSimLog("Infinite Loop in EDepSim::TrajectoryMap::FindPrimaryId(): "
46  << "Track Id: " << trackId);
47  }
48 
49  return currentId;
50 }
51 
52 G4VTrajectory* EDepSim::TrajectoryMap::Get(int trackId) {
54  if (t == fMap.end()) {
55  return NULL;
56  }
57  return t->second;
58 }
59 
#define EDepSimLog(outStream)
Definition: EDepSimLog.hh:717
intermediate_table::iterator iterator
static int FindPrimaryId(int trackId)
#define EDepSimThrow(message)
Print an error message, and then throw an exception.
static std::map< int, G4VTrajectory * > fMap
G4String GetProcessName() const
Get the interaction process that created the trajectory.
static void Add(G4VTrajectory *traj)
Add a trajectory to the map.
p
Definition: test.py:223
static G4VTrajectory * Get(int trackId)
Provide a map between the track id and the trajectory object.