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
28 
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;
46  typedef MotherParticleToVertexMap VertexMap;
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  void setLHCTransportLink(const edm::LHCTransportLinkContainer* thisLHCTlink) { theLHCTlink = thisLHCTlink; }
105 
106 private:
107  // stop default
108  SimTrackManager(const SimTrackManager&) = delete;
109  const SimTrackManager& operator=(const SimTrackManager&) = delete;
110 
112  int getOrCreateVertex(TrackWithHistory*, int, G4SimEvent* simEvent);
113  void cleanVertexMap();
114  void reallyStoreTracks(G4SimEvent* simEvent);
115  void fillMotherList();
116  int idSavedTrack(int) const;
117 
118  // to restore the pre-LHC Transport GenParticle id link to a SimTrack
119  void resetGenID();
120 
121  // ---------- member data --------------------------------
124  MotherParticleToVertexMap m_vertexMap;
127  std::map<uint32_t, std::pair<math::XYZVectorD, math::XYZTLorentzVectorD> > mapTkCaloStateInfo;
128  std::vector<std::pair<int, int> > idsave;
129 
130  std::vector<std::pair<int, int> > ancestorList;
131 
132  unsigned int lastTrack;
133  unsigned int lastHist;
134 
136 };
137 
138 class trkIDLess {
139 public:
140  bool operator()(TrackWithHistory* trk1, TrackWithHistory* trk2) const { return (trk1->trackID() < trk2->trackID()); }
141 };
142 
143 #endif
void addTrack(TrackWithHistory *iTrack, bool inHistory, bool withAncestor)
int getOrCreateVertex(TrackWithHistory *, int, G4SimEvent *simEvent)
bool m_collapsePrimaryVertices
std::map< int, MapVertexPositionVector > MotherParticleToVertexMap
SimTrackManager(bool iCollapsePrimaryVertices=false)
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)
const TrackContainer * trackContainer() const
std::vector< TrackWithHistory * > TrackContainer
Definition: TrackContainer.h:8
unsigned int trackID() const
bool trackExists(unsigned int i) const
void cleanTracksWithHistory()
MotherParticleToVertexMap m_vertexMap
int giveMotherNeeded(int i) const
void storeTracks(G4SimEvent *simEvent)
int idSavedTrack(int) const
int parentID() const
std::vector< std::pair< int, int > > idsave
std::map< uint32_t, std::pair< math::XYZVectorD, math::XYZTLorentzVectorD > > mapTkCaloStateInfo
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)
std::vector< std::pair< int, int > > ancestorList
void setCollapsePrimaryVertices(bool iSet)
bool operator()(TrackWithHistory *&p, const unsigned int &i) const
MotherParticleToVertexMap VertexMap
std::vector< std::pair< int, math::XYZVectorD > > MapVertexPositionVector
bool operator()(TrackWithHistory *trk1, TrackWithHistory *trk2) const