#include <SimG4Core/Application/interface/SimTrackManager.h>
Description: Holds tracking information used by the sensitive detectors
Usage: <usage>
Definition at line 35 of file SimTrackManager.h.
typedef std::pair<int,math::XYZVectorD> SimTrackManager::MapVertexPosition |
this map contains association between vertex number and position
Definition at line 46 of file SimTrackManager.h.
typedef std::vector<std::pair<int,math::XYZVectorD> > SimTrackManager::MapVertexPositionVector |
Definition at line 47 of file SimTrackManager.h.
typedef std::map<int,MapVertexPositionVector> SimTrackManager::MotherParticleToVertexMap |
Definition at line 48 of file SimTrackManager.h.
Definition at line 49 of file SimTrackManager.h.
SimTrackManager::SimTrackManager | ( | bool | iCollapsePrimaryVertices = false | ) |
Definition at line 37 of file SimTrackManager.cc.
: m_trksForThisEvent(0),m_nVertices(0), m_collapsePrimaryVertices(iCollapsePrimaryVertices), lastTrack(0),lastHist(0),theLHCTlink(0){}
SimTrackManager::~SimTrackManager | ( | ) | [virtual] |
Definition at line 43 of file SimTrackManager.cc.
References deleteTracks(), and m_trksForThisEvent.
{ if ( m_trksForThisEvent != 0 ) deleteTracks() ; }
SimTrackManager::SimTrackManager | ( | const SimTrackManager & | ) | [private] |
void SimTrackManager::addTkCaloStateInfo | ( | uint32_t | t, |
std::pair< math::XYZVectorD, math::XYZTLorentzVectorD > | p | ||
) | [inline] |
Definition at line 74 of file SimTrackManager.h.
References mapTkCaloStateInfo.
Referenced by EventAction::addTkCaloStateInfo().
{ std::map<uint32_t,std::pair<math::XYZVectorD,math::XYZTLorentzVectorD> >::const_iterator it = mapTkCaloStateInfo.find(t); if (it == mapTkCaloStateInfo.end()) mapTkCaloStateInfo.insert(std::pair<uint32_t,std::pair<math::XYZVectorD,math::XYZTLorentzVectorD> >(t,p)); }
void SimTrackManager::addTrack | ( | TrackWithHistory * | iTrack, |
bool | inHistory, | ||
bool | withAncestor | ||
) | [inline] |
Definition at line 67 of file SimTrackManager.h.
References ancestorList, idsave, m_trksForThisEvent, TrackWithHistory::parentID(), and TrackWithHistory::trackID().
Referenced by EventAction::addTrack().
{ std::pair<int, int> thePair(iTrack->trackID(),iTrack->parentID()); idsave.push_back(thePair); if (inHistory) m_trksForThisEvent->push_back(iTrack); if (withAncestor) { std::pair<int,int> thisPair(iTrack->trackID(),0); ancestorList.push_back(thisPair); } }
void SimTrackManager::cleanTkCaloStateInfoMap | ( | ) |
Definition at line 210 of file SimTrackManager.cc.
References mapTkCaloStateInfo, and swap().
Referenced by EventAction::EndOfEventAction(), and reset().
{ mapTkCaloStateInfo.clear(); std::map<uint32_t,std::pair<math::XYZVectorD,math::XYZTLorentzVectorD > >().swap(mapTkCaloStateInfo); }
void SimTrackManager::cleanTracksWithHistory | ( | ) |
Definition at line 250 of file SimTrackManager.cc.
References fillMotherList(), idsave, lastTrack, LogDebug, m_trksForThisEvent, TrackWithHistory::saved(), saveTrackAndItsBranch(), edm::second(), lumiQTWidget::t, and TrackWithHistory::trackID().
Referenced by EventAction::prepareForNewPrimary(), and storeTracks().
{ using namespace std; if ((*m_trksForThisEvent).size() == 0 && idsave.size() == 0) return; #ifdef DebugLog LogDebug("SimTrackManager") << "SimTrackManager::cleanTracksWithHistory has " << idsave.size() << " mother-daughter relationships stored with lastTrack = " << lastTrack; #endif if ( lastTrack > 0 && lastTrack >= (*m_trksForThisEvent).size() ) { lastTrack = 0; edm::LogError("SimTrackManager") << " SimTrackManager::cleanTracksWithHistory track index corrupted"; } stable_sort(m_trksForThisEvent->begin()+lastTrack,m_trksForThisEvent->end(),trkIDLess()); stable_sort(idsave.begin(),idsave.end()); #ifdef DebugLog LogDebug("SimTrackManager") << " SimTrackManager::cleanTracksWithHistory knows " << m_trksForThisEvent->size() << " tracks with history before branching"; for (unsigned int it =0; it <(*m_trksForThisEvent).size(); it++) LogDebug("SimTrackManager") << " 1 - Track in position " << it << " G4 track number " << (*m_trksForThisEvent)[it]->trackID() << " mother " << (*m_trksForThisEvent)[it]->parentID() << " status " << (*m_trksForThisEvent)[it]->saved(); #endif for (unsigned int it = lastTrack; it < m_trksForThisEvent->size(); it++) { TrackWithHistory * t = (*m_trksForThisEvent)[it]; if (t->saved()) saveTrackAndItsBranch(t); } unsigned int num = lastTrack; for (unsigned int it = lastTrack; it < m_trksForThisEvent->size(); it++) { TrackWithHistory * t = (*m_trksForThisEvent)[it]; int g4ID = t->trackID(); if (t->saved() == true) { if (it>num) (*m_trksForThisEvent)[num] = t; num++; for (unsigned int itr=0; itr<idsave.size(); itr++) { if ((idsave[itr]).first == g4ID) { (idsave[itr]).second = g4ID; break; } } } else { delete t; } } (*m_trksForThisEvent).resize(num); #ifdef DebugLog LogDebug("SimTrackManager") << " AFTER CLEANING, I GET " << (*m_trksForThisEvent).size() << " tracks to be saved persistently"; for (unsigned int it = 0; it < (*m_trksForThisEvent).size(); it++) LogDebug("SimTrackManager") << " Track in position " << it << " G4 track number " << (*m_trksForThisEvent)[it]->trackID() << " mother " << (*m_trksForThisEvent)[it]->parentID() << " Status " << (*m_trksForThisEvent)[it]->saved(); #endif fillMotherList(); lastTrack = (*m_trksForThisEvent).size(); }
void SimTrackManager::cleanVertexMap | ( | ) | [private] |
Definition at line 204 of file SimTrackManager.cc.
References m_nVertices, and m_vertexMap.
Referenced by reset().
{ m_vertexMap.clear(); MotherParticleToVertexMap().swap(m_vertexMap); m_nVertices=0; }
void SimTrackManager::deleteTracks | ( | ) |
Definition at line 81 of file SimTrackManager.cc.
References i, and m_trksForThisEvent.
Referenced by EventAction::EndOfEventAction(), and ~SimTrackManager().
{ for (unsigned int i = 0; i < m_trksForThisEvent->size(); i++) delete (*m_trksForThisEvent)[i]; delete m_trksForThisEvent; m_trksForThisEvent = 0; }
void SimTrackManager::fillMotherList | ( | ) | [private] |
Definition at line 228 of file SimTrackManager.cc.
References ancestorList, first, idsave, idSavedTrack(), lastHist, LogDebug, and n.
Referenced by cleanTracksWithHistory().
{ if ( ancestorList.size() > 0 && lastHist > ancestorList.size() ) { lastHist = ancestorList.size(); edm::LogError("SimTrackManager") << " SimTrackManager::fillMotherList track index corrupted"; } for (unsigned int n = lastHist; n < ancestorList.size(); n++) { int theMotherId = idSavedTrack((ancestorList[n]).first); ancestorList[n].second = theMotherId; #ifdef DebugLog LogDebug("SimTrackManager") << "Track ID = " << (ancestorList[n]).first << " Mother ID = " << (ancestorList[n]).second; #endif } lastHist = ancestorList.size(); idsave.clear(); }
int SimTrackManager::getOrCreateVertex | ( | TrackWithHistory * | trkH, |
int | iParentID, | ||
G4SimEvent * | simEvent | ||
) | [private] |
Definition at line 172 of file SimTrackManager.cc.
References G4SimEvent::add(), CastorDataFrameFilter_impl::check(), first, TrackWithHistory::globalTime(), gen::k, m_nVertices, m_vertexMap, dbtoconf::parent, mathSSE::sqrt(), and TrackWithHistory::vertexPosition().
Referenced by reallyStoreTracks().
{ int parent = iParentID; int check = -1; for( std::vector<TrackWithHistory*>::const_iterator it = (*m_trksForThisEvent).begin(); it!= (*m_trksForThisEvent).end();it++){ if ((*it)->trackID() == uint32_t(parent)){ check = 0; break; } } if(check==-1) parent = -1; VertexMap::const_iterator iterator = m_vertexMap.find(parent); if (iterator != m_vertexMap.end()){ // loop over saved vertices for (unsigned int k=0; k<m_vertexMap[parent].size(); k++){ if (sqrt((trkH->vertexPosition()-(((m_vertexMap[parent])[k]).second)).Mag2())<0.001) return (((m_vertexMap[parent])[k]).first); } } simEvent->add(new G4SimVertex(trkH->vertexPosition(),trkH->globalTime(),parent)); m_vertexMap[parent].push_back(MapVertexPosition(m_nVertices,trkH->vertexPosition())); m_nVertices++; return (m_nVertices-1); }
int SimTrackManager::giveMotherNeeded | ( | int | i | ) | const [inline] |
Definition at line 85 of file SimTrackManager.h.
References i, idsave, and edm::second().
Referenced by CaloSD::saveHit().
int SimTrackManager::idSavedTrack | ( | int | i | ) | const [private] |
Definition at line 215 of file SimTrackManager.cc.
References i, errorMatrix2Lands_multiChannel::id, idsave, and edm::second().
Referenced by fillMotherList().
const SimTrackManager& SimTrackManager::operator= | ( | const SimTrackManager & | ) | [private] |
void SimTrackManager::reallyStoreTracks | ( | G4SimEvent * | simEvent | ) | [private] |
Definition at line 136 of file SimTrackManager.cc.
References G4SimEvent::add(), TrackWithHistory::genParticleID(), getOrCreateVertex(), LogDebug, m_trksForThisEvent, mapTkCaloStateInfo, TrackWithHistory::momentum(), TrackWithHistory::parentID(), TrackWithHistory::particleID(), TrackWithHistory::totalEnergy(), and TrackWithHistory::trackID().
Referenced by storeTracks().
{ // loop over the (now ordered) vector and really save the tracks #ifdef DebugLog LogDebug("SimTrackManager") << "Inside the reallyStoreTracks method object to be stored = " << m_trksForThisEvent->size(); #endif for (unsigned int it = 0; it < m_trksForThisEvent->size(); it++) { TrackWithHistory * trkH = (*m_trksForThisEvent)[it]; // at this stage there is one vertex per track, so the vertex id of track N is also N int ivertex = -1; int ig; math::XYZVectorD pm(0.,0.,0.); unsigned int iParentID = trkH->parentID(); for(unsigned int iit = 0; iit < m_trksForThisEvent->size(); iit++) { if((*m_trksForThisEvent)[iit]->trackID()==iParentID){ pm = (*m_trksForThisEvent)[iit]->momentum(); break; } } ig = trkH->genParticleID(); ivertex = getOrCreateVertex(trkH,iParentID,simEvent); std::map<uint32_t,std::pair<math::XYZVectorD,math::XYZTLorentzVectorD> >::const_iterator cit = mapTkCaloStateInfo.find(trkH->trackID()); std::pair<math::XYZVectorD,math::XYZTLorentzVectorD> tcinfo; if (cit != mapTkCaloStateInfo.end()){ tcinfo = cit->second; } simEvent->add(new G4SimTrack(trkH->trackID(),trkH->particleID(), trkH->momentum(),trkH->totalEnergy(),ivertex,ig,pm,tcinfo.first,tcinfo.second)); } }
void SimTrackManager::reset | ( | void | ) |
Definition at line 63 of file SimTrackManager.cc.
References ancestorList, cleanTkCaloStateInfoMap(), cleanVertexMap(), i, idsave, lastHist, lastTrack, m_trksForThisEvent, and swap().
Referenced by EventAction::BeginOfEventAction().
{ if (m_trksForThisEvent==0) m_trksForThisEvent = new TrackContainer(); else { for (unsigned int i = 0; i < m_trksForThisEvent->size(); i++) delete (*m_trksForThisEvent)[i]; delete m_trksForThisEvent; m_trksForThisEvent = new TrackContainer(); } cleanVertexMap(); cleanTkCaloStateInfoMap(); std::vector<std::pair <int, int> >().swap(idsave); ancestorList.clear(); lastTrack=0; lastHist=0; }
void SimTrackManager::resetGenID | ( | ) | [private] |
Definition at line 323 of file SimTrackManager.cc.
References TrackWithHistory::genParticleID(), m_trksForThisEvent, TrackWithHistory::setGenParticleID(), and theLHCTlink.
Referenced by storeTracks().
{ if ( theLHCTlink == 0 ) return; for (unsigned int it = 0; it < m_trksForThisEvent->size(); it++) { TrackWithHistory * trkH = (*m_trksForThisEvent)[it]; int genParticleID_ = trkH->genParticleID(); if ( genParticleID_ == -1 ) { continue; } else { for ( unsigned int itrlink = 0; itrlink < (*theLHCTlink).size(); itrlink++ ) { if ( (*theLHCTlink)[itrlink].afterHector() == genParticleID_ ) { trkH->setGenParticleID( (*theLHCTlink)[itrlink].beforeHector() ); continue; } } } } theLHCTlink = 0; }
void SimTrackManager::saveTrackAndItsBranch | ( | TrackWithHistory * | trkWHist | ) | [private] |
this saves a track and all its parents looping over the non ordered vector
Definition at line 89 of file SimTrackManager.cc.
References m_trksForThisEvent, and dbtoconf::parent.
Referenced by cleanTracksWithHistory().
{ using namespace std; TrackWithHistory * trkH = trkWHist; if (trkH == 0) { edm::LogError("SimTrackManager") << " SimTrackManager::saveTrackAndItsBranch got 0 pointer "; abort(); } trkH->save(); unsigned int parent = trkH->parentID(); bool parentExists=false; TrackContainer::const_iterator tk_itr = std::lower_bound((*m_trksForThisEvent).begin(),(*m_trksForThisEvent).end(), parent,SimTrackManager::StrictWeakOrdering()); TrackWithHistory * tempTk = *tk_itr; // TrackWithHistory * tempTk = new TrackWithHistory(**tk_itr); if (tk_itr!=m_trksForThisEvent->end() && (*tk_itr)->trackID()==parent) { parentExists=true; } if (parentExists) saveTrackAndItsBranch(tempTk); // delete tempTk; }
void SimTrackManager::setCollapsePrimaryVertices | ( | bool | iSet | ) | [inline] |
Definition at line 82 of file SimTrackManager.h.
References m_collapsePrimaryVertices.
Referenced by EventAction::EventAction().
{ m_collapsePrimaryVertices=iSet; }
void SimTrackManager::setLHCTransportLink | ( | const edm::LHCTransportLinkContainer * | thisLHCTlink | ) | [inline] |
Definition at line 100 of file SimTrackManager.h.
References theLHCTlink.
{ theLHCTlink = thisLHCTlink; }
void SimTrackManager::storeTracks | ( | G4SimEvent * | simEvent | ) |
Definition at line 117 of file SimTrackManager.cc.
References ancestorList, cleanTracksWithHistory(), idsave, m_trksForThisEvent, reallyStoreTracks(), resetGenID(), and swap().
Referenced by EventAction::EndOfEventAction().
{ cleanTracksWithHistory(); // fill the map with the final mother-daughter relationship idsave.swap(ancestorList); stable_sort(idsave.begin(),idsave.end()); std::vector<std::pair<int,int> >().swap(ancestorList); // to get a backward compatible order stable_sort(m_trksForThisEvent->begin(),m_trksForThisEvent->end(),trkIDLess()); // to reset the GenParticle ID of a SimTrack to its pre-LHCTransport value resetGenID(); reallyStoreTracks(simEvent); }
const TrackContainer* SimTrackManager::trackContainer | ( | ) | const [inline] |
Definition at line 55 of file SimTrackManager.h.
References m_trksForThisEvent.
Referenced by EventAction::trackContainer(), and CaloSD::update().
{ return m_trksForThisEvent; }
bool SimTrackManager::trackExists | ( | unsigned int | i | ) | const [inline] |
Definition at line 90 of file SimTrackManager.h.
References i, and m_trksForThisEvent.
Referenced by CaloSD::saveHit().
{ bool flag = false; for (unsigned int itr=0; itr<(*m_trksForThisEvent).size(); ++itr) { if ((*m_trksForThisEvent)[itr]->trackID() == i) { flag = true; break; } } return flag; }
std::vector<std::pair<int, int> > SimTrackManager::ancestorList [private] |
Definition at line 126 of file SimTrackManager.h.
Referenced by addTrack(), fillMotherList(), reset(), and storeTracks().
std::vector< std::pair<int, int> > SimTrackManager::idsave [private] |
Definition at line 124 of file SimTrackManager.h.
Referenced by addTrack(), cleanTracksWithHistory(), fillMotherList(), giveMotherNeeded(), idSavedTrack(), reset(), and storeTracks().
unsigned int SimTrackManager::lastHist [private] |
Definition at line 129 of file SimTrackManager.h.
Referenced by fillMotherList(), and reset().
unsigned int SimTrackManager::lastTrack [private] |
Definition at line 128 of file SimTrackManager.h.
Referenced by cleanTracksWithHistory(), and reset().
bool SimTrackManager::m_collapsePrimaryVertices [private] |
Definition at line 122 of file SimTrackManager.h.
Referenced by setCollapsePrimaryVertices().
int SimTrackManager::m_nVertices [private] |
Definition at line 121 of file SimTrackManager.h.
Referenced by cleanVertexMap(), and getOrCreateVertex().
bool SimTrackManager::m_SaveSimTracks [private] |
Definition at line 119 of file SimTrackManager.h.
Definition at line 118 of file SimTrackManager.h.
Referenced by addTrack(), cleanTracksWithHistory(), deleteTracks(), reallyStoreTracks(), reset(), resetGenID(), saveTrackAndItsBranch(), storeTracks(), trackContainer(), trackExists(), and ~SimTrackManager().
Definition at line 120 of file SimTrackManager.h.
Referenced by cleanVertexMap(), and getOrCreateVertex().
std::map<uint32_t,std::pair<math::XYZVectorD,math::XYZTLorentzVectorD > > SimTrackManager::mapTkCaloStateInfo [private] |
Definition at line 123 of file SimTrackManager.h.
Referenced by addTkCaloStateInfo(), cleanTkCaloStateInfoMap(), and reallyStoreTracks().
const edm::LHCTransportLinkContainer* SimTrackManager::theLHCTlink [private] |
Definition at line 131 of file SimTrackManager.h.
Referenced by resetGenID(), and setLHCTransportLink().