Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DDG4: allow configuring of the unstable generator status codes. #1260

Merged
merged 1 commit into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -178,6 +179,9 @@ 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 = {};

/// Perform some actions before the run starts, like opening the event inputs
void beginRun(const G4Run*);

Expand All @@ -188,6 +192,10 @@ namespace dd4hep {
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 @@ -440,6 +440,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 @@ -26,6 +26,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 = []
self._closeProperties()

Expand Down Expand Up @@ -53,6 +54,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 std::string& nam
declareProperty("MomentumScale", m_momScale = 1.0);
declareProperty("HaveAbort", m_abort = true);
declareProperty("Parameters", m_parameters = {});
declareProperty("AlternativeDecayStatuses", m_alternativeDecayStatuses = {});
m_needsControl = true;

runAction().callAtBegin(this, &Geant4InputAction::beginRun);
Expand Down Expand Up @@ -285,3 +286,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;
}
Loading