CMS 3D CMS Logo

SimTrackManager Class Reference

Description: Holds tracking information used by the sensitive detectors. More...

#include <SimG4Core/Application/interface/SimTrackManager.h>

List of all members.

Public Types

typedef std::pair< int,
math::XYZVectorD
MapVertexPosition
 this map contains association between vertex number and position
typedef std::vector< std::pair
< int, math::XYZVectorD > > 
MapVertexPositionVector
typedef std::map< int,
MapVertexPositionVector
MotherParticleToVertexMap
typedef MotherParticleToVertexMap VertexMap

Public Member Functions

void addTkCaloStateInfo (uint32_t t, std::pair< math::XYZVectorD, math::XYZTLorentzVectorD > p)
void addTrack (TrackWithHistory *iTrack, bool inHistory)
void cleanTkCaloStateInfoMap ()
void deleteTracks ()
int idSavedTrack (int) const
void reset ()
void setCollapsePrimaryVertices (bool iSet)
 SimTrackManager (bool iCollapsePrimaryVertices=false)
void storeTracks (G4SimEvent *simEvent)
const TrackContainertrackContainer () const
virtual ~SimTrackManager ()

Private Member Functions

void cleanVertexMap ()
int getOrCreateVertex (TrackWithHistory *, int, G4SimEvent *simEvent)
const SimTrackManageroperator= (const SimTrackManager &)
void reallyStoreTracks (G4SimEvent *simEvent)
void saveTrackAndItsBranch (TrackWithHistory *)
 this saves a track and all its parents looping over the non ordered vector
 SimTrackManager (const SimTrackManager &)

Private Attributes

int avgcalomapsize
int avgsizeidsave
int avgvtxmapsize
int calomapsize
std::vector< intidsave
bool m_collapsePrimaryVertices
int m_nVertices
bool m_SaveSimTracks
TrackContainerm_trksForThisEvent
MotherParticleToVertexMap m_vertexMap
std::map< uint32_t, std::pair
< math::XYZVectorD,
math::XYZTLorentzVectorD > > 
mapTkCaloStateInfo
int niteration
int sizeidsave
int vtxmapsize

Classes

class  StrictWeakOrdering


Detailed Description

Description: Holds tracking information used by the sensitive detectors.

Usage: <usage>

Definition at line 33 of file SimTrackManager.h.


Member Typedef Documentation

typedef std::pair<int,math::XYZVectorD> SimTrackManager::MapVertexPosition

this map contains association between vertex number and position

Definition at line 44 of file SimTrackManager.h.

typedef std::vector<std::pair<int,math::XYZVectorD> > SimTrackManager::MapVertexPositionVector

Definition at line 45 of file SimTrackManager.h.

typedef std::map<int,MapVertexPositionVector> SimTrackManager::MotherParticleToVertexMap

Definition at line 46 of file SimTrackManager.h.

typedef MotherParticleToVertexMap SimTrackManager::VertexMap

Definition at line 47 of file SimTrackManager.h.


Constructor & Destructor Documentation

SimTrackManager::SimTrackManager ( bool  iCollapsePrimaryVertices = false  ) 

Definition at line 36 of file SimTrackManager.cc.

References avgcalomapsize, avgsizeidsave, avgvtxmapsize, calomapsize, idsave, niteration, sizeidsave, and vtxmapsize.

00036                                                               :
00037   m_trksForThisEvent(0),m_nVertices(0),
00038   m_collapsePrimaryVertices(iCollapsePrimaryVertices)
00039 {
00040   idsave.reserve(1000);
00041   niteration=1;
00042   avgsizeidsave=0;
00043   sizeidsave=0;
00044   avgcalomapsize=0;
00045   calomapsize=0;
00046   avgvtxmapsize=0;
00047   vtxmapsize=0;
00048 }

SimTrackManager::~SimTrackManager (  )  [virtual]

Definition at line 51 of file SimTrackManager.cc.

References deleteTracks(), and m_trksForThisEvent.

00052 {
00053    if ( m_trksForThisEvent != 0 ) deleteTracks() ;
00054 }

SimTrackManager::SimTrackManager ( const SimTrackManager  )  [private]


Member Function Documentation

void SimTrackManager::addTkCaloStateInfo ( uint32_t  t,
std::pair< math::XYZVectorD, math::XYZTLorentzVectorD p 
) [inline]

Definition at line 74 of file SimTrackManager.h.

References it, and mapTkCaloStateInfo.

Referenced by EventAction::addTkCaloStateInfo().

00074                                                                                       {
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   }

void SimTrackManager::addTrack ( TrackWithHistory iTrack,
bool  inHistory 
) [inline]

Definition at line 65 of file SimTrackManager.h.

References idsave, m_trksForThisEvent, TrackWithHistory::parentID(), and TrackWithHistory::trackID().

Referenced by EventAction::addTrack().

00065                                                           {
00066     if(idsave.size()<=iTrack->trackID()){
00067       int newsize = iTrack->trackID()*2;
00068       idsave.resize(newsize);
00069     }
00070     idsave[iTrack->trackID()] = iTrack->parentID();
00071     if (inHistory) m_trksForThisEvent->push_back(iTrack);
00072   }

void SimTrackManager::cleanTkCaloStateInfoMap (  ) 

Definition at line 260 of file SimTrackManager.cc.

References avgcalomapsize, calomapsize, mapTkCaloStateInfo, niteration, and swap().

Referenced by EventAction::EndOfEventAction(), and reset().

00260                                               { 
00261   avgcalomapsize+=mapTkCaloStateInfo.size();
00262   calomapsize=mapTkCaloStateInfo.size();
00263   mapTkCaloStateInfo.clear();
00264   if(niteration>30){
00265     if(calomapsize>(avgcalomapsize/niteration)*1.1){
00266       std::map<uint32_t,std::pair<math::XYZVectorD,math::XYZTLorentzVectorD > >().swap(mapTkCaloStateInfo);
00267     }
00268   }
00269 }

void SimTrackManager::cleanVertexMap (  )  [private]

Definition at line 248 of file SimTrackManager.cc.

References avgvtxmapsize, m_nVertices, m_vertexMap, niteration, and vtxmapsize.

Referenced by reset().

00248                                      { 
00249   avgvtxmapsize+=m_vertexMap.size();
00250   vtxmapsize=m_vertexMap.size();
00251   m_vertexMap.clear();
00252   if(niteration>30){
00253     if(vtxmapsize>(avgvtxmapsize/niteration)*1.1){
00254       MotherParticleToVertexMap().swap(m_vertexMap);
00255     }
00256   }
00257   m_nVertices=0; 
00258 }

void SimTrackManager::deleteTracks (  ) 

Definition at line 98 of file SimTrackManager.cc.

References i, and m_trksForThisEvent.

Referenced by EventAction::EndOfEventAction(), and ~SimTrackManager().

00099 {
00100     for (unsigned int i = 0; i < m_trksForThisEvent->size(); i++) delete (*m_trksForThisEvent)[i];
00101     delete m_trksForThisEvent;
00102     m_trksForThisEvent = 0;
00103 }

int SimTrackManager::getOrCreateVertex ( TrackWithHistory trkH,
int  iParentID,
G4SimEvent simEvent 
) [private]

Definition at line 216 of file SimTrackManager.cc.

References G4SimEvent::add(), HcalDataFrameFilter_impl::check(), first, TrackWithHistory::globalTime(), it, k, m_nVertices, m_vertexMap, dbtoconf::parent, funct::sqrt(), and TrackWithHistory::vertexPosition().

Referenced by reallyStoreTracks().

00217                                                              {
00218 
00219   int parent = iParentID;
00220   int check = -1;
00221 
00222   for( std::vector<TrackWithHistory*>::const_iterator it = (*m_trksForThisEvent).begin(); 
00223        it!= (*m_trksForThisEvent).end();it++){
00224     if ((*it)->trackID() == uint32_t(parent)){
00225       check = 0;
00226       break;
00227     }
00228   }
00229 
00230   if(check==-1) parent = -1;
00231 
00232   VertexMap::const_iterator iterator = m_vertexMap.find(parent);
00233   if (iterator != m_vertexMap.end()){
00234     // loop over saved vertices
00235     for (unsigned int k=0; k<m_vertexMap[parent].size(); k++){
00236       if (sqrt((trkH->vertexPosition()-(((m_vertexMap[parent])[k]).second)).Mag2())<0.001)
00237         return (((m_vertexMap[parent])[k]).first);
00238     }
00239   }
00240   
00241   simEvent->add(new G4SimVertex(trkH->vertexPosition(),trkH->globalTime(),parent));
00242   m_vertexMap[parent].push_back(MapVertexPosition(m_nVertices,trkH->vertexPosition()));
00243   m_nVertices++;
00244   return (m_nVertices-1);
00245 
00246 }

int SimTrackManager::idSavedTrack ( int  i  )  const

Definition at line 271 of file SimTrackManager.cc.

References idsave.

Referenced by CaloSD::saveHit().

00272 {
00273   int id = 0;  
00274   if (i > 0) {
00275     id = idsave[i];
00276     if(id<0)
00277       id=0;
00278   }
00279   return id;
00280 }

const SimTrackManager& SimTrackManager::operator= ( const SimTrackManager  )  [private]

void SimTrackManager::reallyStoreTracks ( G4SimEvent simEvent  )  [private]

Definition at line 182 of file SimTrackManager.cc.

References G4SimEvent::add(), TrackWithHistory::genParticleID(), getOrCreateVertex(), it, LogDebug, m_trksForThisEvent, mapTkCaloStateInfo, TrackWithHistory::momentum(), TrackWithHistory::parentID(), TrackWithHistory::particleID(), TrackWithHistory::totalEnergy(), and TrackWithHistory::trackID().

Referenced by storeTracks().

00183 {
00184     // loop over the (now ordered) vector and really save the tracks
00185   LogDebug("SimTrackManager")  << "Inside the reallyStoreTracks method object to be stored = " 
00186             << m_trksForThisEvent->size();
00187 
00188     for (unsigned int it = 0; it < m_trksForThisEvent->size(); it++)
00189     {
00190         TrackWithHistory * trkH = (*m_trksForThisEvent)[it];
00191         // at this stage there is one vertex per track, so the vertex id of track N is also N
00192         int ivertex = -1;
00193         int ig;
00194 
00195         math::XYZVectorD pm(0.,0.,0.);
00196         unsigned int iParentID = trkH->parentID();
00197         for(unsigned int iit = 0; iit < m_trksForThisEvent->size(); iit++)
00198           {
00199             if((*m_trksForThisEvent)[iit]->trackID()==iParentID){
00200               pm = (*m_trksForThisEvent)[iit]->momentum();
00201               break;
00202             }
00203           }
00204         ig = trkH->genParticleID();
00205         ivertex = getOrCreateVertex(trkH,iParentID,simEvent);
00206         std::map<uint32_t,std::pair<math::XYZVectorD,math::XYZTLorentzVectorD> >::const_iterator it = mapTkCaloStateInfo.find(trkH->trackID());
00207         std::pair<math::XYZVectorD,math::XYZTLorentzVectorD> tcinfo;
00208         if (it !=  mapTkCaloStateInfo.end()){
00209           tcinfo =  it->second;
00210         }
00211         simEvent->add(new G4SimTrack(trkH->trackID(),trkH->particleID(),
00212                                      trkH->momentum(),trkH->totalEnergy(),ivertex,ig,pm,tcinfo.first,tcinfo.second));
00213     }
00214 }

void SimTrackManager::reset ( void   ) 

Definition at line 71 of file SimTrackManager.cc.

References avgsizeidsave, cleanTkCaloStateInfoMap(), cleanVertexMap(), i, idsave, m_trksForThisEvent, niteration, sizeidsave, and swap().

Referenced by EventAction::BeginOfEventAction().

00072 {
00073   if (m_trksForThisEvent==0) m_trksForThisEvent = new TrackContainer();
00074   else
00075     {
00076       for (unsigned int i = 0; i < m_trksForThisEvent->size(); i++) 
00077         delete (*m_trksForThisEvent)[i];
00078       delete m_trksForThisEvent;
00079         m_trksForThisEvent = new TrackContainer();
00080     }
00081   cleanVertexMap();
00082   cleanTkCaloStateInfoMap();
00083   avgsizeidsave+=idsave.size();
00084   sizeidsave=idsave.size();
00085   if(niteration>30){
00086     if(sizeidsave>(avgsizeidsave/niteration)*1.5){
00087       std::vector<int>().swap(idsave);
00088       idsave.reserve(1000);
00089     }else{
00090       idsave.clear();
00091     }
00092   }else{
00093     idsave.clear();
00094   }
00095   niteration++;
00096 }

void SimTrackManager::saveTrackAndItsBranch ( TrackWithHistory trkWHist  )  [private]

this saves a track and all its parents looping over the non ordered vector

Definition at line 106 of file SimTrackManager.cc.

References m_trksForThisEvent, dbtoconf::parent, TrackWithHistory::parentID(), TrackWithHistory::save(), and std.

Referenced by storeTracks().

00107 {
00108     using namespace std;
00109     TrackWithHistory * trkH = trkWHist;
00110     if (trkH == 0)
00111     {
00112         edm::LogError("SimG4CoreApplication") << " SimTrackManager::saveTrackAndItsBranch got 0 pointer ";
00113         abort();
00114     }
00115     trkH->save();
00116     unsigned int parent = trkH->parentID();
00117     bool parentExists=false;
00118 
00119     TrackContainer::const_iterator tk_itr = std::lower_bound((*m_trksForThisEvent).begin(),(*m_trksForThisEvent).end(),
00120                                                       parent,SimTrackManager::StrictWeakOrdering());
00121     TrackWithHistory * tempTk = new TrackWithHistory(**tk_itr);
00122     if (tk_itr!=m_trksForThisEvent->end() && (*tk_itr)->trackID()==parent) { 
00123       parentExists=true;  
00124     }
00125 
00126     if (parentExists) saveTrackAndItsBranch(tempTk);
00127 
00128     delete tempTk;
00129 
00130 }

void SimTrackManager::setCollapsePrimaryVertices ( bool  iSet  )  [inline]

Definition at line 82 of file SimTrackManager.h.

References m_collapsePrimaryVertices.

Referenced by EventAction::EventAction().

00082                                              {
00083     m_collapsePrimaryVertices=iSet;
00084   }

void SimTrackManager::storeTracks ( G4SimEvent simEvent  ) 

Definition at line 132 of file SimTrackManager.cc.

References i, idsave, it, LogDebug, m_trksForThisEvent, funct::num(), reallyStoreTracks(), TrackWithHistory::saved(), saveTrackAndItsBranch(), std, and t.

Referenced by EventAction::EndOfEventAction().

00133 {
00134     using namespace std;
00135 
00136     stable_sort(m_trksForThisEvent->begin(),m_trksForThisEvent->end(),trkIDLess());
00137     
00138     LogDebug("SimTrackManager")  << " SimTrackManager::storeTracks knows " << m_trksForThisEvent->size()
00139               << " tracks with history before branching";
00140     for (unsigned int it =0;  it <(*m_trksForThisEvent).size(); it++)
00141       LogDebug("SimTrackManager")   << " 1 - Track in position " << it << " G4 track number "
00142                  << (*m_trksForThisEvent)[it]->trackID()
00143                  << " mother " << (*m_trksForThisEvent)[it]->parentID()
00144                  << " status " << (*m_trksForThisEvent)[it]->saved();
00145 
00146     for (unsigned int i = 0; i < m_trksForThisEvent->size(); i++)
00147       {
00148         TrackWithHistory * t = (*m_trksForThisEvent)[i];
00149         if (t->saved()) saveTrackAndItsBranch(t);
00150       }
00151     
00152     // now eliminate from the vector the tracks with only history but not save
00153     unsigned int num = 0;
00154     for (unsigned int it = 0;  it < (*m_trksForThisEvent).size(); it++)
00155       {
00156         int g4ID = (*m_trksForThisEvent)[it]->trackID();
00157         if ((*m_trksForThisEvent)[it]->saved() == true)
00158           {
00159             if (it>num) (*m_trksForThisEvent)[num] = (*m_trksForThisEvent)[it];
00160             num++;
00161             idsave[g4ID] = g4ID;
00162           }
00163         else 
00164           {     
00165             delete (*m_trksForThisEvent)[it];
00166           }
00167       }
00168     
00169     (*m_trksForThisEvent).resize(num);
00170     
00171     LogDebug("SimTrackManager")  << " AFTER CLEANING, I GET " << (*m_trksForThisEvent).size()
00172               << " tracks to be saved persistently";
00173     for (unsigned int it = 0;  it < (*m_trksForThisEvent).size(); it++)
00174       LogDebug("SimTrackManager")   << " Track in position " << it
00175                  << " G4 track number " << (*m_trksForThisEvent)[it]->trackID()
00176                  << " mother " << (*m_trksForThisEvent)[it]->parentID()
00177                  << " Status " << (*m_trksForThisEvent)[it]->saved();
00178     
00179     reallyStoreTracks(simEvent);
00180 }

const TrackContainer* SimTrackManager::trackContainer (  )  const [inline]

Definition at line 53 of file SimTrackManager.h.

References m_trksForThisEvent.

Referenced by EventAction::trackContainer(), and CaloSD::update().

00053                                                 { 
00054     return m_trksForThisEvent; 
00055   }


Member Data Documentation

int SimTrackManager::avgcalomapsize [private]

Definition at line 109 of file SimTrackManager.h.

Referenced by cleanTkCaloStateInfoMap(), and SimTrackManager().

int SimTrackManager::avgsizeidsave [private]

Definition at line 106 of file SimTrackManager.h.

Referenced by reset(), and SimTrackManager().

int SimTrackManager::avgvtxmapsize [private]

Definition at line 112 of file SimTrackManager.h.

Referenced by cleanVertexMap(), and SimTrackManager().

int SimTrackManager::calomapsize [private]

Definition at line 110 of file SimTrackManager.h.

Referenced by cleanTkCaloStateInfoMap(), and SimTrackManager().

std::vector<int> SimTrackManager::idsave [private]

Definition at line 103 of file SimTrackManager.h.

Referenced by addTrack(), idSavedTrack(), reset(), SimTrackManager(), and storeTracks().

bool SimTrackManager::m_collapsePrimaryVertices [private]

Definition at line 101 of file SimTrackManager.h.

Referenced by setCollapsePrimaryVertices().

int SimTrackManager::m_nVertices [private]

Definition at line 100 of file SimTrackManager.h.

Referenced by cleanVertexMap(), and getOrCreateVertex().

bool SimTrackManager::m_SaveSimTracks [private]

Definition at line 98 of file SimTrackManager.h.

TrackContainer* SimTrackManager::m_trksForThisEvent [private]

Definition at line 97 of file SimTrackManager.h.

Referenced by addTrack(), deleteTracks(), reallyStoreTracks(), reset(), saveTrackAndItsBranch(), storeTracks(), trackContainer(), and ~SimTrackManager().

MotherParticleToVertexMap SimTrackManager::m_vertexMap [private]

Definition at line 99 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 102 of file SimTrackManager.h.

Referenced by addTkCaloStateInfo(), cleanTkCaloStateInfoMap(), and reallyStoreTracks().

int SimTrackManager::niteration [private]

Definition at line 105 of file SimTrackManager.h.

Referenced by cleanTkCaloStateInfoMap(), cleanVertexMap(), reset(), and SimTrackManager().

int SimTrackManager::sizeidsave [private]

Definition at line 107 of file SimTrackManager.h.

Referenced by reset(), and SimTrackManager().

int SimTrackManager::vtxmapsize [private]

Definition at line 113 of file SimTrackManager.h.

Referenced by cleanVertexMap(), and SimTrackManager().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:31:45 2009 for CMSSW by  doxygen 1.5.4