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 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 
39  explicit SimTrackManager(TmpSimEvent*);
41 
42  const std::vector<TrackWithHistory*>* trackContainer() const { return &m_trackContainer; }
43 
44  void storeTracks();
45  void reset();
46  void deleteTracks();
48 
49  void addTrack(TrackWithHistory* iTrack, const G4Track* track, bool inHistory, bool withAncestor);
50 
51  int giveMotherNeeded(int i) const {
52  int theResult = 0;
53  for (auto const& p : idsave) {
54  if (p.first == i) {
55  theResult = p.second;
56  break;
57  }
58  }
59  return theResult;
60  }
61 
62  bool trackExists(int i) const {
63  bool flag = false;
64  for (auto const& ptr : m_trackContainer) {
65  if (ptr->trackID() == i) {
66  flag = true;
67  break;
68  }
69  }
70  return flag;
71  }
72 
73  TrackWithHistory* getTrackByID(int trackID, bool strict = false) const {
74  TrackWithHistory* track = nullptr;
75  for (auto const& ptr : m_trackContainer) {
76  if (ptr->trackID() == trackID) {
77  track = ptr;
78  break;
79  }
80  }
81  if (nullptr == track && strict) {
82  ReportException(trackID);
83  }
84  return track;
85  }
86 
87  void setLHCTransportLink(const edm::LHCTransportLinkContainer* thisLHCTlink) { theLHCTlink = thisLHCTlink; }
88 
89  // stop default
90  SimTrackManager(const SimTrackManager&) = delete;
91  const SimTrackManager& operator=(const SimTrackManager&) = delete;
92 
93 private:
96  void cleanVertexMap();
97  void reallyStoreTracks();
98  void fillMotherList();
99  int idSavedTrack(int) const;
100  void ReportException(unsigned int id) const;
101 
102  // to restore the pre-LHC Transport GenParticle id link to a SimTrack
103  void resetGenID();
104 
105  // ---------- member data --------------------------------
106 
107  int m_nVertices{0};
108  unsigned int lastTrack{0};
109  unsigned int lastHist{0};
110 
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
SimTrackManager(TmpSimEvent *)
std::pair< int, math::XYZVectorD > VertexPosition
TrackWithHistory * getTrackByID(int trackID, bool strict=false) const
bool operator()(TrackWithHistory *trk1, TrackWithHistory *trk2) const
const SimTrackManager & operator=(const SimTrackManager &)=delete
unsigned int lastHist
TmpSimEvent * m_simEvent
bool operator()(TrackWithHistory *&p, const int &i) const
void cleanTracksWithHistory()
void addTrack(TrackWithHistory *iTrack, const G4Track *track, bool inHistory, bool withAncestor)
std::vector< std::pair< int, int > > idsave
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)
bool trackExists(int i) const
int trackID() const
std::vector< LHCTransportLink > LHCTransportLinkContainer
const edm::LHCTransportLinkContainer * theLHCTlink
int giveMotherNeeded(int i) const
int idSavedTrack(int) const
int getOrCreateVertex(TrackWithHistory *, int)
std::vector< std::pair< int, math::XYZVectorD > > VertexPositionVector
std::vector< std::pair< int, int > > ancestorList
void ReportException(unsigned int id) const
std::vector< std::pair< int, math::XYZVectorD > > m_endPoints