Skip to content

Commit

Permalink
Backport AIDASoft#1260 (allow configuring of the unstable generator s…
Browse files Browse the repository at this point in the history
…tatus codes)

See this merge request from Andre:
https://patch-diff.githubusercontent.com/raw/AIDASoft/DD4hep/pull/1260.patch

The diff didn't apply perfectly cleanly. I applied it manually using `patch -p1`
rather than through git. But this is just a check to see if we can bring this
functionality back to an older version.
  • Loading branch information
TC01 committed May 21, 2024
1 parent 88c4905 commit 4e4e23d
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 17 deletions.
10 changes: 2 additions & 8 deletions DDG4/hepmc/HepMC3EventReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ HEPMC3EventReader::readParticles(int event_number, Vertices& vertices, Particles
const float spin[] = {0.0, 0.0, 0.0}; //mcp->getSpin(); // FIXME
const int color[] = {colorFlow[0][mcp->id()], colorFlow[1][mcp->id()]};
const int pdg = mcp->pid();
PropertyMask status(p->status);
p->pdgID = pdg;
p->charge = 0; // int(mcp->getCharge()*3.0); // FIXME
p->psx = mom.get_component(0) * mom_unit;
Expand All @@ -122,16 +121,11 @@ HEPMC3EventReader::readParticles(int event_number, Vertices& vertices, Particles
for(int num=par.size(), k=0; k<num; ++k)
p->parents.insert(GET_ENTRY(mcparts,par[k]));

PropertyMask status(p->status);
int genStatus = mcp->status();
if ( genStatus == 0 ) status.set(G4PARTICLE_GEN_EMPTY);
else if ( genStatus == 1 ) status.set(G4PARTICLE_GEN_STABLE);
else if ( genStatus == 2 ) status.set(G4PARTICLE_GEN_DECAYED);
else if ( genStatus == 3 ) status.set(G4PARTICLE_GEN_DOCUMENTATION);
else if ( genStatus == 4 ) status.set(G4PARTICLE_GEN_BEAM);
else
status.set(G4PARTICLE_GEN_OTHER);
// Copy raw generator status
p->genStatus = genStatus&G4PARTICLE_GEN_STATUS_MASK;
m_inputAction->setGeneratorStatus(genStatus, status);

if ( p->parents.size() == 0 ) {
// A particle without a parent in HepMC3 can only be (something like) a beam particle, and it is attached to the
Expand Down
10 changes: 9 additions & 1 deletion DDG4/include/DDG4/Geant4InputAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
#include "Parsers/Parsers.h"

// C/C++ include files
#include <vector>
#include <memory>
#include <set>
#include <vector>

// Forward declarations
class G4Event;
Expand Down Expand Up @@ -174,11 +175,18 @@ namespace dd4hep {
/// Property: named parameters to configure file readers or input actions
std::map< std::string, std::string> m_parameters;

/// Property: set of alternative decay statuses that MC generators might use for unstable particles
std::set<int> m_alternativeDecayStatuses = {};

public:
/// Read an event and return a LCCollectionVec of MCParticles.
int readParticles(int event_number,
Vertices& vertices,
Particles& particles);
using PropertyMask = dd4hep::detail::ReferenceBitMask<int>;
/// Convert the generator status into a common set of generator status bits
void setGeneratorStatus(int generatorStatus, PropertyMask& status);

/// helper to report Geant4 exceptions
std::string issue(int i) const;

Expand Down
10 changes: 2 additions & 8 deletions DDG4/lcio/LCIOEventReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ LCIOEventReader::readParticles(int event_number,
const float *spin = mcp->getSpin();
const int *color = mcp->getColorFlow();
const int pdg = mcp->getPDG();
PropertyMask status(p->status);
p->pdgID = pdg;
p->charge = int(mcp->getCharge()*3.0);
p->psx = mom[0]*CLHEP::GeV;
Expand All @@ -118,16 +117,11 @@ LCIOEventReader::readParticles(int event_number,
for(int num=par.size(),k=0; k<num; ++k)
p->parents.insert(GET_ENTRY(mcparts,par[k]));

PropertyMask status(p->status);
int genStatus = mcp->getGeneratorStatus();
if ( genStatus == 0 ) status.set(G4PARTICLE_GEN_EMPTY);
else if ( genStatus == 1 ) status.set(G4PARTICLE_GEN_STABLE);
else if ( genStatus == 2 ) status.set(G4PARTICLE_GEN_DECAYED);
else if ( genStatus == 3 ) status.set(G4PARTICLE_GEN_DOCUMENTATION);
else if ( genStatus == 4 ) status.set(G4PARTICLE_GEN_BEAM);
else
status.set(G4PARTICLE_GEN_OTHER);
// Copy raw generator status
p->genStatus = genStatus&G4PARTICLE_GEN_STATUS_MASK;
m_inputAction->setGeneratorStatus(genStatus, status);

//fg: we simply add all particles without parents as with their own vertex.
// This might include the incoming beam particles, e.g. in
Expand Down
1 change: 1 addition & 0 deletions DDG4/python/DDSim/DD4hepSimulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ def run(self):
else:
# this should never happen because we already check at the top, but in case of some LogicError...
raise RuntimeError("Unknown input file type: %s" % inputFile)
gen.AlternativeDecayStatuses = self.physics.alternativeDecayStatuses
gen.Sync = self.skipNEvents
gen.Mask = index
actionList.append(gen)
Expand Down
11 changes: 11 additions & 0 deletions DDG4/python/DDSim/Helper/Physics.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def __init__(self):
4101, 4103, 4201, 4203, 4301, 4303, 4403, # c? diquarks
5101, 5103, 5201, 5203, 5301, 5303, 5401, 5403, 5503} # b? diquarks
self._zeroTimePDGs = {11, 13, 15, 17}
self._alternativeDecayStatuses = set()
self._userFunctions = []

@property
Expand All @@ -54,6 +55,16 @@ def zeroTimePDGs(self):
def zeroTimePDGs(self, val):
self._zeroTimePDGs = self.makeSet(val)

@property
def alternativeDecayStatuses(self):
"""Set of Generator Statuses that are used to mark unstable particles that should decay inside of Geant4.
"""
return self._alternativeDecayStatuses

@alternativeDecayStatuses.setter
def alternativeDecayStatuses(self, val):
self._alternativeDecayStatuses = self.makeSet(val)

@property
def rangecut(self):
""" The global geant4 rangecut for secondary production
Expand Down
14 changes: 14 additions & 0 deletions DDG4/src/Geant4InputAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ Geant4InputAction::Geant4InputAction(Geant4Context* ctxt, const string& nam)
declareProperty("MomentumScale", m_momScale = 1.0);
declareProperty("HaveAbort", m_abort = true);
declareProperty("Parameters", m_parameters = {});
declareProperty("AlternativeDecayStatuses", m_alternativeDecayStatuses = {});
m_needsControl = true;
}

Expand Down Expand Up @@ -274,3 +275,16 @@ void Geant4InputAction::operator()(G4Event* event) {
p.dumpWithMomentumAndVertex(outputLevel()-1,name(),"->");
}
}

void Geant4InputAction::setGeneratorStatus(int genStatus, PropertyMask& status) {
if ( genStatus == 0 ) status.set(G4PARTICLE_GEN_EMPTY);
else if ( genStatus == 1 ) status.set(G4PARTICLE_GEN_STABLE);
else if ( genStatus == 2 ) status.set(G4PARTICLE_GEN_DECAYED);
else if ( genStatus == 3 ) status.set(G4PARTICLE_GEN_DOCUMENTATION);
else if ( genStatus == 4 ) status.set(G4PARTICLE_GEN_BEAM);
else if ( m_alternativeDecayStatuses.count(genStatus) ) status.set(G4PARTICLE_GEN_DECAYED);
else
status.set(G4PARTICLE_GEN_OTHER);

return;
}

0 comments on commit 4e4e23d

Please sign in to comment.