Skip to content

Commit 26b0572

Browse files
committed
fix genParticle index
1 parent 774e317 commit 26b0572

File tree

4 files changed

+29
-10
lines changed

4 files changed

+29
-10
lines changed

SimDataFormats/Track/src/classes_def.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@
99
<version ClassVersion="12" checksum="3470347245"/>
1010
<version ClassVersion="11" checksum="1785575744"/>
1111
<version ClassVersion="10" checksum="1430205451"/>
12+
<ioread sourceClass = "SimTrack" version="[-12]" targetClass="SimTrack" source="" target="">
13+
<![CDATA[
14+
SimTrack tmp(newObj->type(), newObj->momentum(), newObj->vertIndex(), newObj->genpartIndex(), newObj->trackerSurfacePosition(), newObj->trackerSurfaceMomentum());
15+
tmp.setTrackId(newObj->trackId());
16+
tmp.setEventId(newObj->eventId());
17+
tmp.setCrossedBoundaryVars(
18+
newObj->crossedBoundary(), newObj->getIDAtBoundary(), newObj->getPositionAtBoundary(), newObj->getMomentumAtBoundary());
19+
if (newObj->isFromBackScattering()) {
20+
tmp.setFromBackScattering();
21+
}
22+
if (newObj->genpartIndex() != -1) {
23+
tmp.setIsPrimary();
24+
}
25+
*newObj=tmp;
26+
]]>
27+
</ioread>
1228
</class>
1329
<class name="edm::Wrapper<std::vector<SimTrack> >" />
1430
<class name="edm::RefProd<std::vector<SimTrack> >"/>

SimG4Core/Application/plugins/OscarMTProducer.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,14 +260,14 @@ void OscarMTProducer::produce(edm::Event& e, const edm::EventSetup& es) {
260260
}
261261
edm::LogVerbatim("SimG4CoreApplication")
262262
<< "Produced " << p1->size()
263-
<< " SimTracks: G4 Id, pdg, 4-momentum(GeV), vertexID, mcTruthID, crossedBoundary, trackID at boundary, from "
264-
"backscattering, isPrimary, getPrimary";
263+
<< " SimTracks: G4 Id, pdg, 4-momentum(GeV), vertexID, mcTruthID, crossedBoundary -> trackID at boundary, from "
264+
"backscattering, isPrimary -> getPrimary";
265265
if (1 < m_verbose) {
266266
int nn = p1->size();
267267
for (int i = 0; i < nn; ++i) {
268-
edm::LogVerbatim("Track") << " " << i << ". " << (*p1)[i].trackId() << " " << (*p1)[i] << " "
269-
<< (*p1)[i].crossedBoundary() << " " << (*p1)[i].getIDAtBoundary() << " "
270-
<< (*p1)[i].isFromBackScattering() << " " << (*p1)[i].isPrimary() << " "
268+
edm::LogVerbatim("Track") << " " << i << ". " << (*p1)[i].trackId() << ", " << (*p1)[i] << ", "
269+
<< (*p1)[i].crossedBoundary() << "-> " << (*p1)[i].getIDAtBoundary() << ", "
270+
<< (*p1)[i].isFromBackScattering() << ", " << (*p1)[i].isPrimary() << "-> "
271271
<< (*p1)[i].getPrimaryID();
272272
}
273273
}

SimG4Core/Notification/src/SimTrackManager.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,12 @@ void SimTrackManager::addTrack(TrackWithHistory* iTrack, const G4Track* track, b
7676
auto info = static_cast<const TrackInformation*>(track->GetUserInformation());
7777
if (info->isInTrkFromBackscattering())
7878
iTrack->setFromBackScattering();
79-
// set there *for all the tracks* the genParticle ID associated with the G4Track
80-
// in the constructor of TrackWithHistory the info isPrimary is saved and used
81-
// to give -1 if the track is not a primary
82-
iTrack->setGenParticleID(info->mcTruthID());
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());
8385
m_trackContainer.push_back(iTrack);
8486
const auto& v = track->GetStep()->GetPostStepPoint()->GetPosition();
8587
std::pair<int, math::XYZVectorD> p(iTrack->trackID(),

SimG4Core/Notification/src/TmpSimEvent.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ void TmpSimEvent::load(edm::SimTrackContainer& c) const {
5353
t.setFromBackScattering();
5454
if (isPrimary)
5555
t.setIsPrimary();
56-
t.setGenParticleID(primaryGenPartId);
56+
else
57+
t.setGenParticleID(primaryGenPartId);
5758
c.push_back(t);
5859
}
5960
std::stable_sort(c.begin(), c.end(), IdSort());

0 commit comments

Comments
 (0)