24 #include "G4VProcess.hh"
29 : m_trksForThisEvent(nullptr),
31 m_collapsePrimaryVertices(iCollapsePrimaryVertices),
34 theLHCTlink(nullptr) {}
49 delete (*m_trksForThisEvent)[
i];
56 std::vector<std::pair<int, int> >().
swap(
idsave);
64 delete (*m_trksForThisEvent)[
i];
74 if (trkH ==
nullptr) {
75 edm::LogError(
"SimTrackManager") <<
" SimTrackManager::saveTrackAndItsBranch got 0 pointer ";
76 throw cms::Exception(
"SimTrackManager::saveTrackAndItsBranch") <<
" cannot handle hits for tracking";
79 unsigned int parent = trkH->parentID();
112 LogDebug(
"SimTrackManager") <<
"Inside the reallyStoreTracks method object to be stored = "
124 unsigned int iParentID = trkH->
parentID();
127 pm = (*m_trksForThisEvent)[iit]->momentum();
133 std::map<uint32_t, std::pair<math::XYZVectorD, math::XYZTLorentzVectorD> >::const_iterator cit =
135 std::pair<math::XYZVectorD, math::XYZTLorentzVectorD> tcinfo;
137 tcinfo = cit->second;
149 simEvent->
add(g4simtrack);
157 for (std::vector<TrackWithHistory*>::const_iterator it = (*m_trksForThisEvent).begin();
158 it != (*m_trksForThisEvent).end();
160 if ((*it)->trackID() == uint32_t(parent)) {
170 VertexMap::const_iterator iterator =
m_vertexMap.find(parent);
180 unsigned int ptype = 0;
183 ptype = pr->GetProcessSubType();
205 unsigned int n =
idsave.size();
212 for (j = 0; j <= jmax; ++
j) {
215 if (0 == id1 || id1 == idMother) {
232 for (j = jmax; j >= 0; --
j) {
233 if ((
idsave[j]).first == idMother) {
235 if (0 == id1 || id1 == idMother) {
247 for (j = jmax; j >= 0; --
j) {
264 edm::LogError(
"SimTrackManager") <<
" SimTrackManager::fillMotherList track index corrupted";
294 if ((*m_trksForThisEvent).empty() &&
idsave.empty()) {
299 LogDebug(
"SimTrackManager") <<
"SimTrackManager::cleanTracksWithHistory has " <<
idsave.size()
300 <<
" mother-daughter relationships stored with lastTrack = " <<
lastTrack;
305 edm::LogError(
"SimTrackManager") <<
" SimTrackManager::cleanTracksWithHistory track index corrupted";
314 <<
" tracks with history before branching";
315 for (
unsigned int it = 0; it < (*m_trksForThisEvent).size(); it++) {
316 LogDebug(
"SimTrackManager") <<
" 1 - Track in position " << it <<
" G4 track number "
317 << (*m_trksForThisEvent)[it]->trackID() <<
" mother "
318 << (*m_trksForThisEvent)[it]->parentID() <<
" status "
319 << (*m_trksForThisEvent)[it]->saved();
333 if (t->
saved() ==
true) {
335 (*m_trksForThisEvent)[
num] =
t;
337 for (
unsigned int itr = 0; itr <
idsave.size(); itr++) {
338 if ((
idsave[itr]).first == g4ID) {
348 (*m_trksForThisEvent).resize(num);
351 LogDebug(
"SimTrackManager") <<
" AFTER CLEANING, I GET " << (*m_trksForThisEvent).size()
352 <<
" tracks to be saved persistently";
353 for (
unsigned int it = 0; it < (*m_trksForThisEvent).size(); it++) {
354 LogDebug(
"SimTrackManager") <<
" Track in position " << it <<
" G4 track number "
355 << (*m_trksForThisEvent)[it]->trackID() <<
" mother "
356 << (*m_trksForThisEvent)[it]->parentID() <<
" Status "
357 << (*m_trksForThisEvent)[it]->saved() <<
" id "
358 << (*m_trksForThisEvent)[it]->particleID()
359 <<
" E(MeV)= " << (*m_trksForThisEvent)[it]->totalEnergy();
365 lastTrack = (*m_trksForThisEvent).size();
375 if (genParticleID_ == -1) {
378 for (
unsigned int itrlink = 0; itrlink < (*theLHCTlink).size(); itrlink++) {
379 if ((*
theLHCTlink)[itrlink].afterHector() == genParticleID_) {
void copyCrossedBoundaryVars(const TrackWithHistory *track)
int getOrCreateVertex(TrackWithHistory *, int, G4SimEvent *simEvent)
uint16_t *__restrict__ id
std::map< int, MapVertexPositionVector > MotherParticleToVertexMap
double totalEnergy() const
SimTrackManager(bool iCollapsePrimaryVertices=false)
void setGenParticleID(int i)
Log< level::Error, false > LogError
void cleanTkCaloStateInfoMap()
void swap(Association< C > &lhs, Association< C > &rhs)
virtual ~SimTrackManager()
TrackContainer * m_trksForThisEvent
U second(std::pair< T, U > const &p)
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > XYZVectorD
spatial vector with cartesian internal representation
std::vector< TrackWithHistory * > TrackContainer
unsigned int trackID() const
void cleanTracksWithHistory()
MotherParticleToVertexMap m_vertexMap
void storeTracks(G4SimEvent *simEvent)
int idSavedTrack(int) const
const G4VProcess * creatorProcess() const
std::vector< std::pair< int, int > > idsave
std::map< uint32_t, std::pair< math::XYZVectorD, math::XYZTLorentzVectorD > > mapTkCaloStateInfo
std::pair< int, math::XYZVectorD > MapVertexPosition
this map contains association between vertex number and position
const math::XYZVectorD & momentum() const
void saveTrackAndItsBranch(TrackWithHistory *)
this saves a track and all its parents looping over the non ordered vector
double globalTime() const
static const GlobalPoint notFound(0, 0, 0)
__host__ __device__ constexpr RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
const edm::LHCTransportLinkContainer * theLHCTlink
void reallyStoreTracks(G4SimEvent *simEvent)
std::vector< std::pair< int, int > > ancestorList
const math::XYZVectorD & vertexPosition() const
int genParticleID() const