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 //
15 // system include files
16 #include <map>
17 #include <vector>
18 
19 // user include files
22 
23 // forward declarations
24 
25 class TmpSimEvent;
26 class G4Track;
27 
29 public:
31  public:
32  bool operator()(TrackWithHistory*& p, const unsigned int& i) const { return p->trackID() < i; }
33  };
34 
35  typedef std::pair<int, math::XYZVectorD> VertexPosition;
36  typedef std::vector<std::pair<int, math::XYZVectorD> > VertexPositionVector;
37  typedef std::map<int, VertexPositionVector> VertexMap;
38 
40  virtual ~SimTrackManager();
41 
42  const std::vector<TrackWithHistory*>* trackContainer() const { return &m_trackContainer; }
43 
44  void storeTracks(TmpSimEvent* simEvent);
45 
46  void reset();
47  void deleteTracks();
49 
50  void addTrack(TrackWithHistory* iTrack, const G4Track* track, bool inHistory, bool withAncestor);
51 
52  int giveMotherNeeded(int i) const {
53  int theResult = 0;
54  for (auto& p : idsave) {
55  if (p.first == i) {
56  theResult = p.second;
57  break;
58  }
59  }
60  return theResult;
61  }
62 
63  bool trackExists(unsigned int i) const {
64  bool flag = false;
65  for (auto& ptr : m_trackContainer) {
66  if (ptr->trackID() == i) {
67  flag = true;
68  break;
69  }
70  }
71  return flag;
72  }
73 
74  TrackWithHistory* getTrackByID(unsigned int trackID, bool strict = false) const {
75  TrackWithHistory* track = nullptr;
76  for (auto& ptr : m_trackContainer) {
77  if (ptr->trackID() == trackID) {
78  track = ptr;
79  break;
80  }
81  }
82  if (nullptr == track && strict) {
83  ReportException(trackID);
84  }
85  return track;
86  }
87 
88  void setLHCTransportLink(const edm::LHCTransportLinkContainer* thisLHCTlink) { theLHCTlink = thisLHCTlink; }
89 
90  // stop default
91  SimTrackManager(const SimTrackManager&) = delete;
92  const SimTrackManager& operator=(const SimTrackManager&) = delete;
93 
94 private:
96  int getOrCreateVertex(TrackWithHistory*, int, TmpSimEvent* simEvent);
97  void cleanVertexMap();
98  void reallyStoreTracks(TmpSimEvent* simEvent);
99  void fillMotherList();
100  int idSavedTrack(int) const;
101  void ReportException(unsigned int id) const;
102 
103  // to restore the pre-LHC Transport GenParticle id link to a SimTrack
104  void resetGenID();
105 
106  // ---------- member data --------------------------------
107 
108  int m_nVertices{0};
109  unsigned int lastTrack{0};
110  unsigned int lastHist{0};
111 
113 
115  std::vector<std::pair<int, int> > idsave;
116  std::vector<std::pair<int, int> > ancestorList;
117  std::vector<std::pair<int, math::XYZVectorD> > m_endPoints;
118  std::vector<TrackWithHistory*> m_trackContainer;
119 };
120 
121 class trkIDLess {
122 public:
123  bool operator()(TrackWithHistory* trk1, TrackWithHistory* trk2) const { return (trk1->trackID() < trk2->trackID()); }
124 };
125 
126 #endif
std::vector< TrackWithHistory * > m_trackContainer
VertexMap m_vertexMap
bool operator()(TrackWithHistory *&p, const unsigned int &i) const
std::pair< int, math::XYZVectorD > VertexPosition
TrackWithHistory * getTrackByID(unsigned int trackID, bool strict=false) const
bool operator()(TrackWithHistory *trk1, TrackWithHistory *trk2) const
const SimTrackManager & operator=(const SimTrackManager &)=delete
unsigned int lastHist
virtual ~SimTrackManager()
int getOrCreateVertex(TrackWithHistory *, int, TmpSimEvent *simEvent)
bool trackExists(unsigned int i) const
void cleanTracksWithHistory()
void reallyStoreTracks(TmpSimEvent *simEvent)
void addTrack(TrackWithHistory *iTrack, const G4Track *track, bool inHistory, bool withAncestor)
std::vector< std::pair< int, int > > idsave
void storeTracks(TmpSimEvent *simEvent)
void saveTrackAndItsBranch(TrackWithHistory *)
this saves a track and all its parents looping over the non ordered vector
unsigned int lastTrack
std::map< int, VertexPositionVector > VertexMap
const std::vector< TrackWithHistory * > * trackContainer() const
void setLHCTransportLink(const edm::LHCTransportLinkContainer *thisLHCTlink)
std::vector< LHCTransportLink > LHCTransportLinkContainer
const edm::LHCTransportLinkContainer * theLHCTlink
int giveMotherNeeded(int i) const
int idSavedTrack(int) const
std::vector< std::pair< int, math::XYZVectorD > > VertexPositionVector
std::vector< std::pair< int, int > > ancestorList
void ReportException(unsigned int id) const
unsigned int trackID() const
std::vector< std::pair< int, math::XYZVectorD > > m_endPoints