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
SimTrackManager
Definition: SimTrackManager.h:35
SimTrackManager::m_trksForThisEvent
TrackContainer * m_trksForThisEvent
Definition: SimTrackManager.h:146
mps_fire.i
i
Definition: mps_fire.py:428
SimTrackManager::m_vertexMap
MotherParticleToVertexMap m_vertexMap
Definition: SimTrackManager.h:148
SimTrackManager::MapVertexPositionVector
std::vector< std::pair< int, math::XYZVectorD > > MapVertexPositionVector
Definition: SimTrackManager.h:44
edm::LHCTransportLinkContainer
std::vector< LHCTransportLink > LHCTransportLinkContainer
Definition: LHCTransportLinkContainer.h:8
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11713
SimTrackManager::cleanVertexMap
void cleanVertexMap()
Definition: SimTrackManager.cc:191
TrackWithHistory::parentID
int parentID() const
Definition: TrackWithHistory.h:30
SimTrackManager::storeTracks
void storeTracks(G4SimEvent *simEvent)
Definition: SimTrackManager.cc:91
SimTrackManager::reset
void reset()
Definition: SimTrackManager.cc:44
G4SimEvent
Definition: G4SimEvent.h:14
SimTrackManager::mapTkCaloStateInfo
std::map< uint32_t, std::pair< math::XYZVectorD, math::XYZTLorentzVectorD > > mapTkCaloStateInfo
Definition: SimTrackManager.h:151
trkIDLess
Definition: SimTrackManager.h:162
SimTrackManager::trackExists
bool trackExists(unsigned int i) const
Definition: SimTrackManager.h:94
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
TrackWithHistory
Definition: TrackWithHistory.h:16
SimTrackManager::VertexMap
MotherParticleToVertexMap VertexMap
Definition: SimTrackManager.h:46
SimTrackManager::MapVertexPosition
std::pair< int, math::XYZVectorD > MapVertexPosition
this map contains association between vertex number and position
Definition: SimTrackManager.h:43
SimTrackManager::StrictWeakOrdering
Definition: SimTrackManager.h:37
SimTrackManager::lastHist
unsigned int lastHist
Definition: SimTrackManager.h:157
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
SimTrackManager::setCollapsePrimaryVertices
void setCollapsePrimaryVertices(bool iSet)
Definition: SimTrackManager.h:83
SimTrackManager::resetGenID
void resetGenID()
Definition: SimTrackManager.cc:368
SimTrackManager::~SimTrackManager
virtual ~SimTrackManager()
Definition: SimTrackManager.cc:36
SimTrackManager::theLHCTlink
const edm::LHCTransportLinkContainer * theLHCTlink
Definition: SimTrackManager.h:159
SimTrackManager::reallyStoreTracks
void reallyStoreTracks(G4SimEvent *simEvent)
Definition: SimTrackManager.cc:109
SimTrackManager::giveMotherNeeded
int giveMotherNeeded(int i) const
Definition: SimTrackManager.h:84
SimTrackManager::m_collapsePrimaryVertices
bool m_collapsePrimaryVertices
Definition: SimTrackManager.h:150
SimTrackManager::lastTrack
unsigned int lastTrack
Definition: SimTrackManager.h:156
SimTrackManager::deleteTracks
void deleteTracks()
Definition: SimTrackManager.cc:62
SimTrackManager::addTkCaloStateInfo
void addTkCaloStateInfo(uint32_t t, const std::pair< math::XYZVectorD, math::XYZTLorentzVectorD > &p)
Definition: SimTrackManager.h:75
SimTrackManager::getOrCreateVertex
int getOrCreateVertex(TrackWithHistory *, int, G4SimEvent *simEvent)
Definition: SimTrackManager.cc:153
SimTrackManager::ancestorList
std::vector< std::pair< int, int > > ancestorList
Definition: SimTrackManager.h:154
SimTrackManager::MotherParticleToVertexMap
std::map< int, MapVertexPositionVector > MotherParticleToVertexMap
Definition: SimTrackManager.h:45
SimTrackManager::cleanTkCaloStateInfoMap
void cleanTkCaloStateInfoMap()
Definition: SimTrackManager.cc:197
SimTrackManager::idsave
std::vector< std::pair< int, int > > idsave
Definition: SimTrackManager.h:152
SimTrackManager::addTrack
void addTrack(TrackWithHistory *iTrack, bool inHistory, bool withAncestor)
Definition: SimTrackManager.h:63
SimTrackManager::getTrackByID
TrackWithHistory * getTrackByID(unsigned int trackID, bool strict=false) const
Definition: SimTrackManager.h:104
SimTrackManager::m_SaveSimTracks
bool m_SaveSimTracks
Definition: SimTrackManager.h:147
SimTrackManager::cleanTracksWithHistory
void cleanTracksWithHistory()
Definition: SimTrackManager.cc:293
SimTrackManager::saveTrackAndItsBranch
void saveTrackAndItsBranch(TrackWithHistory *)
this saves a track and all its parents looping over the non ordered vector
Definition: SimTrackManager.cc:71
SimTrackManager::m_nVertices
int m_nVertices
Definition: SimTrackManager.h:149
SimTrackManager::setLHCTransportLink
void setLHCTransportLink(const edm::LHCTransportLinkContainer *thisLHCTlink)
Definition: SimTrackManager.h:128
TrackWithHistory::trackID
unsigned int trackID() const
Definition: TrackWithHistory.h:28
TrackContainer
std::vector< TrackWithHistory * > TrackContainer
Definition: TrackContainer.h:8
trkIDLess::operator()
bool operator()(TrackWithHistory *trk1, TrackWithHistory *trk2) const
Definition: SimTrackManager.h:164
SimTrackManager::operator=
const SimTrackManager & operator=(const SimTrackManager &)=delete
SimTrackManager::fillMotherList
void fillMotherList()
Definition: SimTrackManager.cc:261
Exception
Definition: hltDiff.cc:245
Exception.h
SimTrackManager::SimTrackManager
SimTrackManager(bool iCollapsePrimaryVertices=false)
Definition: SimTrackManager.cc:28
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
TrackContainer.h
SimTrackManager::idSavedTrack
int idSavedTrack(int) const
Definition: SimTrackManager.cc:202
SimTrackManager::trackContainer
const TrackContainer * trackContainer() const
Definition: SimTrackManager.h:52
SimTrackManager::StrictWeakOrdering::operator()
bool operator()(TrackWithHistory *&p, const unsigned int &i) const
Definition: SimTrackManager.h:39
RemoveAddSevLevel.flag
flag
Definition: RemoveAddSevLevel.py:116
TrackWithHistory.h