From 7c6f17a95b401350fec7b38accf42626efc1a38f Mon Sep 17 00:00:00 2001 From: Andre Sailer <andre.philippe.sailer@cern.ch> Date: Fri, 15 Dec 2023 11:15:32 +0100 Subject: [PATCH] Geant4PrimaryHandling: fix issue with multiple vertices in Geant4 GeneralParticleSource --- DDG4/src/Geant4GeneratorWrapper.cpp | 6 ++++-- DDG4/src/Geant4InputHandling.cpp | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/DDG4/src/Geant4GeneratorWrapper.cpp b/DDG4/src/Geant4GeneratorWrapper.cpp index 7eb09b3f5..b79bed2f6 100644 --- a/DDG4/src/Geant4GeneratorWrapper.cpp +++ b/DDG4/src/Geant4GeneratorWrapper.cpp @@ -78,10 +78,12 @@ void Geant4GeneratorWrapper::operator()(G4Event* event) { generator()->GeneratePrimaryVertex(event); /// Add all the missing interactions (primary vertices) to the primary event record. + int maskCounter = 100000 + m_mask; for(G4PrimaryVertex* gv=event->GetPrimaryVertex(); gv; gv=gv->GetNext()) { if ( primaries.find(gv) == primaries.end() ) { - Geant4PrimaryInteraction* inter = createPrimary(m_mask, primaryMap, gv); - prim->add(m_mask, inter); + Geant4PrimaryInteraction* inter = createPrimary(maskCounter, primaryMap, gv); + prim->add(maskCounter, inter); + maskCounter += 1; } } } diff --git a/DDG4/src/Geant4InputHandling.cpp b/DDG4/src/Geant4InputHandling.cpp index fdc1468f5..e75a4f26f 100644 --- a/DDG4/src/Geant4InputHandling.cpp +++ b/DDG4/src/Geant4InputHandling.cpp @@ -180,13 +180,14 @@ static void appendInteraction(const Geant4Action* caller, } Geant4PrimaryInteraction::VertexMap::iterator ivfnd, iv, ivend; for( iv=input->vertices.begin(), ivend=input->vertices.end(); iv != ivend; ++iv ) { - ivfnd = output->vertices.find((*iv).first) ; //(*iv).second->mask); + int theMask = input->mask; + ivfnd = output->vertices.find(theMask); if ( ivfnd != output->vertices.end() ) { caller->abortRun("Duplicate primary interaction identifier!", "Cannot handle 2 interactions with identical identifiers!"); } for(Geant4Vertex* vtx : (*iv).second ) - output->vertices[(*iv).first].emplace_back( vtx->addRef() ); + output->vertices[theMask].emplace_back( vtx->addRef() ); } } -- GitLab