CMS 3D CMS Logo

SimTrackManager.h
Go to the documentation of this file.
1 #ifndef Notification_SimTrackManager_h
2 #define Notification_SimTrackManager_h
3 // -*- C++ -*-
4 //
5 // Package: Notification
6 // Class : SimTrackManager
7 //
16 //
17 // Original Author:
18 // Created: Fri Nov 25 17:36:41 EST 2005
19 //
20 
21 // system include files
22 #include <map>
23 #include <vector>
24 
25 // user include files
30 
31 // forward declarations
32 
33 class G4SimEvent;
34 
36 public:
38  public:
39  bool operator()(TrackWithHistory*& p, const unsigned int& i) const { return p->trackID() < i; }
40  };
41  // enum SpecialNumbers {InvalidID = 65535};
43  typedef std::pair<int, math::XYZVectorD> MapVertexPosition;
44  typedef std::vector<std::pair<int, math::XYZVectorD> > MapVertexPositionVector;
45  typedef std::map<int, MapVertexPositionVector> MotherParticleToVertexMap;
47 
48  SimTrackManager(bool iCollapsePrimaryVertices = false);
49  virtual ~SimTrackManager();
50 
51  // ---------- const member functions ---------------------
53 
54  // ---------- member functions ---------------------------
55  void storeTracks(G4SimEvent* simEvent);
56 
57  void reset();
58  void deleteTracks();
60 
62 
63  void addTrack(TrackWithHistory* iTrack, bool inHistory, bool withAncestor) {
64  std::pair<int, int> thePair(iTrack->trackID(), iTrack->parentID());
65  idsave.push_back(thePair);
66  if (inHistory) {
67  m_trksForThisEvent->push_back(iTrack);
68  }
69  if (withAncestor) {
70  std::pair<int, int> thisPair(iTrack->trackID(), 0);
71  ancestorList.push_back(thisPair);
72  }
73  }
74 
75  void addTkCaloStateInfo(uint32_t t, const std::pair<math::XYZVectorD, math::XYZTLorentzVectorD>& p) {
76  std::map<uint32_t, std::pair<math::XYZVectorD, math::XYZTLorentzVectorD> >::const_iterator it =
77  mapTkCaloStateInfo.find(t);
78 
79  if (it == mapTkCaloStateInfo.end()) {
80  mapTkCaloStateInfo.insert(std::pair<uint32_t, std::pair<math::XYZVectorD, math::XYZTLorentzVectorD> >(t, p));
81  }
82  }
84  int giveMotherNeeded(int i) const {
85  int theResult = 0;
86  for (unsigned int itr = 0; itr < idsave.size(); itr++) {
87  if ((idsave[itr]).first == i) {
88  theResult = (idsave[itr]).second;
89  break;
90  }
91  }
92  return theResult;
93  }
94  bool trackExists(unsigned int i) const {
95  bool flag = false;
96  for (unsigned int itr = 0; itr < (*m_trksForThisEvent).size(); ++itr) {
97  if ((*m_trksForThisEvent)[itr]->trackID() == i) {
98  flag = true;
99  break;
100  }
101  }
102  return flag;
103  }
104  TrackWithHistory* getTrackByID(unsigned int trackID, bool strict = false) const {
105  bool trackFound = false;
107  if (m_trksForThisEvent == nullptr) {
108  throw cms::Exception("Unknown", "SimTrackManager") << "m_trksForThisEvent is a nullptr, cannot get any track!";
109  }
110  for (unsigned int itr = 0; itr < (*m_trksForThisEvent).size(); ++itr) {
111  if ((*m_trksForThisEvent)[itr]->trackID() == trackID) {
112  track = (*m_trksForThisEvent)[itr];
113  trackFound = true;
114  break;
115  }
116  }
117  if (!trackFound) {
118  if (strict) {
119  throw cms::Exception("Unknown", "SimTrackManager")
120  << "Attempted to get track " << trackID << " from SimTrackManager, but it's not in m_trksForThisEvent ("
121  << (*m_trksForThisEvent).size() << " tracks in m_trksForThisEvent)"
122  << "\n";
123  }
124  return nullptr;
125  }
126  return track;
127  }
128  void setLHCTransportLink(const edm::LHCTransportLinkContainer* thisLHCTlink) { theLHCTlink = thisLHCTlink; }
129 
130  // stop default
131  SimTrackManager(const SimTrackManager&) = delete;
132  const SimTrackManager& operator=(const SimTrackManager&) = delete;
133 
134 private:
136  int getOrCreateVertex(TrackWithHistory*, int, G4SimEvent* simEvent);
137  void cleanVertexMap();
138  void reallyStoreTracks(G4SimEvent* simEvent);
139  void fillMotherList();
140  int idSavedTrack(int) const;
141 
142  // to restore the pre-LHC Transport GenParticle id link to a SimTrack
143  void resetGenID();
144 
145  // ---------- member data --------------------------------
151  std::map<uint32_t, std::pair<math::XYZVectorD, math::XYZTLorentzVectorD> > mapTkCaloStateInfo;
152  std::vector<std::pair<int, int> > idsave;
153 
154  std::vector<std::pair<int, int> > ancestorList;
155 
156  unsigned int lastTrack;
157  unsigned int lastHist;
158 
160 };
161 
162 class trkIDLess {
163 public:
164  bool operator()(TrackWithHistory* trk1, TrackWithHistory* trk2) const { return (trk1->trackID() < trk2->trackID()); }
165 };
166 
167 #endif
void addTrack(TrackWithHistory *iTrack, bool inHistory, bool withAncestor)
int getOrCreateVertex(TrackWithHistory *, int, G4SimEvent *simEvent)
bool m_collapsePrimaryVertices
int parentID() const
bool operator()(TrackWithHistory *&p, const unsigned int &i) const
std::map< int, MapVertexPositionVector > MotherParticleToVertexMap
TrackWithHistory * getTrackByID(unsigned int trackID, bool strict=false) const
SimTrackManager(bool iCollapsePrimaryVertices=false)
bool operator()(TrackWithHistory *trk1, TrackWithHistory *trk2) const
const SimTrackManager & operator=(const SimTrackManager &)=delete
void cleanTkCaloStateInfoMap()
unsigned int lastHist
virtual ~SimTrackManager()
TrackContainer * m_trksForThisEvent
U second(std::pair< T, U > const &p)
void addTkCaloStateInfo(uint32_t t, const std::pair< math::XYZVectorD, math::XYZTLorentzVectorD > &p)
bool trackExists(unsigned int i) const
std::vector< TrackWithHistory * > TrackContainer
Definition: TrackContainer.h:8
void cleanTracksWithHistory()
MotherParticleToVertexMap m_vertexMap
void storeTracks(G4SimEvent *simEvent)
std::vector< std::pair< int, int > > idsave
std::map< uint32_t, std::pair< math::XYZVectorD, math::XYZTLorentzVectorD > > mapTkCaloStateInfo
const TrackContainer * trackContainer() const
std::pair< int, math::XYZVectorD > MapVertexPosition
this map contains association between vertex number and position
void saveTrackAndItsBranch(TrackWithHistory *)
this saves a track and all its parents looping over the non ordered vector
unsigned int lastTrack
void setLHCTransportLink(const edm::LHCTransportLinkContainer *thisLHCTlink)
std::vector< LHCTransportLink > LHCTransportLinkContainer
const edm::LHCTransportLinkContainer * theLHCTlink
void reallyStoreTracks(G4SimEvent *simEvent)
int giveMotherNeeded(int i) const
int idSavedTrack(int) const
std::vector< std::pair< int, int > > ancestorList
void setCollapsePrimaryVertices(bool iSet)
MotherParticleToVertexMap VertexMap
std::vector< std::pair< int, math::XYZVectorD > > MapVertexPositionVector
unsigned int trackID() const