Go to the documentation of this file.00001 #ifndef Application_SimTrackManager_h
00002 #define Application_SimTrackManager_h
00003
00004
00005
00006
00007
00016
00017
00018
00019
00020
00021
00022
00023 #include <map>
00024 #include <vector>
00025
00026
00027 #include "SimG4Core/Application/interface/G4SimEvent.h"
00028 #include "SimG4Core/Notification/interface/TrackWithHistory.h"
00029 #include "SimG4Core/Notification/interface/TrackContainer.h"
00030
00031 #include "SimDataFormats/Forward/interface/LHCTransportLinkContainer.h"
00032
00033
00034
00035 class SimTrackManager
00036 {
00037
00038 public:
00039
00040 class StrictWeakOrdering{
00041 public:
00042 bool operator() ( TrackWithHistory * & p,const unsigned int& i) const {return p->trackID() < i;}
00043 };
00044
00046 typedef std::pair<int,math::XYZVectorD> MapVertexPosition;
00047 typedef std::vector<std::pair<int,math::XYZVectorD> > MapVertexPositionVector;
00048 typedef std::map<int,MapVertexPositionVector> MotherParticleToVertexMap;
00049 typedef MotherParticleToVertexMap VertexMap;
00050
00051 SimTrackManager(bool iCollapsePrimaryVertices =false);
00052 virtual ~SimTrackManager();
00053
00054
00055 const TrackContainer * trackContainer() const {
00056 return m_trksForThisEvent;
00057 }
00058
00059
00060
00061 void storeTracks(G4SimEvent * simEvent);
00062
00063 void reset();
00064 void deleteTracks();
00065 void cleanTkCaloStateInfoMap();
00066
00067 void addTrack(TrackWithHistory* iTrack, bool inHistory, bool withAncestor) {
00068 std::pair<int, int> thePair(iTrack->trackID(),iTrack->parentID());
00069 idsave.push_back(thePair);
00070 if (inHistory) m_trksForThisEvent->push_back(iTrack);
00071 if (withAncestor) { std::pair<int,int> thisPair(iTrack->trackID(),0); ancestorList.push_back(thisPair); }
00072 }
00073
00074 void addTkCaloStateInfo(uint32_t t,std::pair<math::XYZVectorD,math::XYZTLorentzVectorD> p){
00075 std::map<uint32_t,std::pair<math::XYZVectorD,math::XYZTLorentzVectorD> >::const_iterator it =
00076 mapTkCaloStateInfo.find(t);
00077
00078 if (it == mapTkCaloStateInfo.end())
00079 mapTkCaloStateInfo.insert(std::pair<uint32_t,std::pair<math::XYZVectorD,math::XYZTLorentzVectorD> >(t,p));
00080
00081 }
00082 void setCollapsePrimaryVertices(bool iSet) {
00083 m_collapsePrimaryVertices=iSet;
00084 }
00085 int giveMotherNeeded(int i) const {
00086 int theResult = 0;
00087 for (unsigned int itr=0; itr<idsave.size(); itr++) { if ((idsave[itr]).first == i) { theResult = (idsave[itr]).second; break; } }
00088 return theResult ;
00089 }
00090 bool trackExists(unsigned int i) const {
00091 bool flag = false;
00092 for (unsigned int itr=0; itr<(*m_trksForThisEvent).size(); ++itr) {
00093 if ((*m_trksForThisEvent)[itr]->trackID() == i) {
00094 flag = true; break;
00095 }
00096 }
00097 return flag;
00098 }
00099 void cleanTracksWithHistory();
00100 void setLHCTransportLink( const edm::LHCTransportLinkContainer * thisLHCTlink ) { theLHCTlink = thisLHCTlink; }
00101
00102 private:
00103 SimTrackManager(const SimTrackManager&);
00104
00105 const SimTrackManager& operator=(const SimTrackManager&);
00106
00107 void saveTrackAndItsBranch(TrackWithHistory *);
00108 int getOrCreateVertex(TrackWithHistory *,int,G4SimEvent * simEvent);
00109 void cleanVertexMap();
00110 void reallyStoreTracks(G4SimEvent * simEvent);
00111 void fillMotherList();
00112 int idSavedTrack (int) const;
00113
00114
00115 void resetGenID();
00116
00117
00118 TrackContainer * m_trksForThisEvent;
00119 bool m_SaveSimTracks;
00120 MotherParticleToVertexMap m_vertexMap;
00121 int m_nVertices;
00122 bool m_collapsePrimaryVertices;
00123 std::map<uint32_t,std::pair<math::XYZVectorD,math::XYZTLorentzVectorD > > mapTkCaloStateInfo;
00124 std::vector< std::pair<int, int> > idsave;
00125
00126 std::vector<std::pair<int, int> > ancestorList;
00127
00128 unsigned int lastTrack;
00129 unsigned int lastHist;
00130
00131 const edm::LHCTransportLinkContainer * theLHCTlink;
00132
00133 };
00134
00135
00136 class trkIDLess
00137 {
00138 public:
00139 bool operator()(TrackWithHistory * trk1, TrackWithHistory * trk2) const
00140 { return (trk1->trackID() < trk2->trackID()); }
00141 };
00142
00143 #endif