@@ -73,6 +73,15 @@ void SimTrackManager::addTrack(TrackWithHistory* iTrack, const G4Track* track, b
7373 std::pair<int , int > thePair (iTrack->trackID (), iTrack->parentID ());
7474 idsave.push_back (thePair);
7575 if (inHistory) {
76+ auto info = static_cast <const TrackInformation*>(track->GetUserInformation ());
77+ if (info->isInTrkFromBackscattering ())
78+ iTrack->setFromBackScattering ();
79+ // set there for the *non-primary* tracks the genParticle ID associated with the G4Track
80+ // for the primaries this is done in the TrackWithHistory constructor.
81+ // In the constructor of TrackWithHistory the info isPrimary is saved and used
82+ // to give -1 if the track is not a primary.
83+ if (not iTrack->isPrimary ())
84+ iTrack->setGenParticleID (info->mcTruthID ());
7685 m_trackContainer.push_back (iTrack);
7786 const auto & v = track->GetStep ()->GetPostStepPoint ()->GetPosition ();
7887 std::pair<int , math::XYZVectorD> p (iTrack->trackID (),
@@ -124,15 +133,18 @@ void SimTrackManager::storeTracks() {
124133void SimTrackManager::reallyStoreTracks () {
125134 // loop over the (now ordered) vector and really save the tracks
126135#ifdef DebugLog
127- edm::LogVerbatim (" SimTrackManager" ) << " reallyStoreTracks() NtracksWithHistory= " << m_trackContainer-> size ();
136+ edm::LogVerbatim (" SimTrackManager" ) << " reallyStoreTracks() NtracksWithHistory= " << m_trackContainer. size ();
128137#endif
129138
130139 int nn = m_endPoints.size ();
131140 for (auto & trkH : m_trackContainer) {
132141 // at this stage there is one vertex per track,
133142 // so the vertex id of track N is also N
134143 int iParentID = trkH->parentID ();
135- int ig = trkH->genParticleID ();
144+ int ig = trkH->genParticleID (); // filled only for primary tracks
145+ bool isBackScatter = trkH->isFromBackScattering ();
146+ bool isPrimary = trkH->isPrimary ();
147+ int primaryGenPartId = trkH->getPrimaryID (); // filled if the G4Track had this info
136148 int ivertex = getOrCreateVertex (trkH, iParentID);
137149
138150 auto ptr = trkH;
@@ -170,6 +182,11 @@ void SimTrackManager::reallyStoreTracks() {
170182 TmpSimTrack* g4simtrack =
171183 new TmpSimTrack (id, trkH->particleID (), trkH->momentum (), trkH->totalEnergy (), ivertex, ig, pm, spos, smom);
172184 g4simtrack->copyCrossedBoundaryVars (trkH);
185+ if (isBackScatter)
186+ g4simtrack->setFromBackScattering ();
187+ if (isPrimary)
188+ g4simtrack->setIsPrimary ();
189+ g4simtrack->setGenParticleID (primaryGenPartId);
173190 m_simEvent->addTrack (g4simtrack);
174191 }
175192}
@@ -304,7 +321,7 @@ void SimTrackManager::cleanTracksWithHistory() {
304321 std::stable_sort (idsave.begin (), idsave.end ());
305322
306323#ifdef DebugLog
307- LogDebug (" SimTrackManager" ) << " SimTrackManager::cleanTracksWithHistory knows " << m_trksForThisEvent-> size ()
324+ LogDebug (" SimTrackManager" ) << " SimTrackManager::cleanTracksWithHistory knows " << m_trackContainer. size ()
308325 << " tracks with history before branching" ;
309326 for (unsigned int it = 0 ; it < m_trackContainer.size (); it++) {
310327 LogDebug (" SimTrackManager" ) << " 1 - Track in position " << it << " G4 track number "
0 commit comments