diff --git a/DDG4/include/DDG4/Geant4UserParticleHandler.h b/DDG4/include/DDG4/Geant4UserParticleHandler.h index 7d9b11109f21802400bdf5392963b6facb920970..5da782c7e5468580a80c38053e162ee0f6a06a38 100644 --- a/DDG4/include/DDG4/Geant4UserParticleHandler.h +++ b/DDG4/include/DDG4/Geant4UserParticleHandler.h @@ -37,7 +37,7 @@ namespace DD4hep { /// Geant4ParticleHandler user extension action called by the particle handler. /** - * Collect optional MC particle information and attacjh it to the particle object + * Collect optional MC particle information and attach it to the particle object * Clients may inherit from this class and override the approriate methods * to add additional information in form of a DataExtension object to the Particle. * diff --git a/DDG4/plugins/Geant4TCUserParticleHandler.cpp b/DDG4/plugins/Geant4TCUserParticleHandler.cpp index f32a73fa994b21fe2bc9e69101f555437be766d6..a4a2a9cc18ca85047753c2b3e316f83eeb0c5be4 100644 --- a/DDG4/plugins/Geant4TCUserParticleHandler.cpp +++ b/DDG4/plugins/Geant4TCUserParticleHandler.cpp @@ -15,6 +15,7 @@ #define DD4HEP_DDG4_GEANT4TCUSERPARTICLEHANDLER_H // Framework include files +#include "DD4hep/Primitives.h" #include "DDG4/Geant4UserParticleHandler.h" /// Namespace for the AIDA detector description toolkit @@ -86,7 +87,8 @@ Geant4TCUserParticleHandler::Geant4TCUserParticleHandler(Geant4Context* ctxt, co } /// Post-track action callback -void Geant4TCUserParticleHandler::end(const G4Track* /* track */, Particle& p) { +void Geant4TCUserParticleHandler::end(const G4Track* track, Particle& p) { + double r_prod = std::sqrt(p.vsx*p.vsx + p.vsy*p.vsy); double z_prod = std::fabs(p.vsz); bool starts_in_trk_vol = ( r_prod <= m_rTracker && z_prod <= m_zTracker ) ; @@ -111,7 +113,49 @@ void Geant4TCUserParticleHandler::end(const G4Track* /* track */, Particle& p) else if( !( p.reason & G4PARTICLE_CREATED_TRACKER_HIT ) ) p.reason = 0; } - + + // Set the simulator status bits + DD4hep::ReferenceBitMask<int> simStatus(p.status); + + if( ends_in_trk_vol ) { + simStatus.set(G4PARTICLE_SIM_DECAY_TRACKER); + } else { + // daughters inherit the status of the parent??? let's clear this + simStatus.clear(G4PARTICLE_SIM_DECAY_TRACKER); + } + + const G4Step* theLastStep = track->GetStep(); + G4StepPoint* theLastPostStepPoint = NULL; + if(theLastStep) theLastPostStepPoint = theLastStep->GetPostStepPoint(); + if( theLastPostStepPoint && + ( theLastPostStepPoint->GetStepStatus() == fWorldBoundary + //|| theLastPostStepPoint->GetStepStatus() == fGeomBoundary + ) + ){ //particle left world volume + simStatus.set(G4PARTICLE_SIM_LEFT_DETECTOR); + } else { + simStatus.clear(G4PARTICLE_SIM_LEFT_DETECTOR); + } + + // if the particle doesn't end in the tracker volume it must have ended in the calorimeter + if( not ends_in_trk_vol && not simStatus.isSet(G4PARTICLE_SIM_LEFT_DETECTOR) ) { + // need to check for decay process + simStatus.set(G4PARTICLE_SIM_DECAY_CALO); + } else { + simStatus.clear(G4PARTICLE_SIM_DECAY_CALO); + } + + if( not starts_in_trk_vol && ends_in_trk_vol ) { + simStatus.set(G4PARTICLE_SIM_BACKSCATTER); + } else { + simStatus.clear(G4PARTICLE_SIM_BACKSCATTER); + } + + if(track->GetKineticEnergy() <= 0.) { + simStatus.set(G4PARTICLE_SIM_STOPPED); + } else { + simStatus.clear(G4PARTICLE_SIM_STOPPED); + } return ; } diff --git a/DDG4/src/Geant4Particle.cpp b/DDG4/src/Geant4Particle.cpp index 9ba33508f2caa98918efe7721a5e648a10975d46..3cd0405aad2c0dfbc36459ce224472e9873d5dcc 100644 --- a/DDG4/src/Geant4Particle.cpp +++ b/DDG4/src/Geant4Particle.cpp @@ -358,7 +358,7 @@ void Geant4ParticleHandle::dump4(int level, const std::string& src, const char* ::snprintf(equiv,sizeof(equiv),"/%d",p->g4Parent); } printout((DD4hep::PrintLevel)level,src, - "+++ %s ID:%7d %12s %6d%-7s %7s %3s %5d %3s %+.3e %-4s %-7s %-3s %-3s %2d [%s%s%s] %c%c%c%c", + "+++ %s ID:%7d %12s %6d%-7s %7s %3s %5d %3s %+.3e %-4s %-7s %-3s %-3s %2d [%s%s%s] %c%c%c%c -- %c%c%c%c%c%c%c", tag, p->id, p.particleName().c_str(), @@ -379,7 +379,15 @@ void Geant4ParticleHandle::dump4(int level, const std::string& src, const char* status.isSet(G4PARTICLE_GEN_EMPTY) ? 'E' : '.', status.isSet(G4PARTICLE_GEN_STABLE) ? 'S' : '.', status.isSet(G4PARTICLE_GEN_DECAYED) ? 'D' : '.', - status.isSet(G4PARTICLE_GEN_DOCUMENTATION) ? 'd' : '.' + status.isSet(G4PARTICLE_GEN_DOCUMENTATION) ? 'd' : '.', + + status.isSet(G4PARTICLE_SIM_CREATED) ? 's' : '.', + status.isSet(G4PARTICLE_SIM_BACKSCATTER) ? 'b' : '.', + status.isSet(G4PARTICLE_SIM_PARENT_RADIATED) ? 'v' : '.', + status.isSet(G4PARTICLE_SIM_DECAY_TRACKER) ? 't' : '.', + status.isSet(G4PARTICLE_SIM_DECAY_CALO) ? 'c' : '.', + status.isSet(G4PARTICLE_SIM_LEFT_DETECTOR) ? 'l' : '.', + status.isSet(G4PARTICLE_SIM_STOPPED) ? 's' : '.' ); } diff --git a/DDG4/src/Geant4ParticleHandler.cpp b/DDG4/src/Geant4ParticleHandler.cpp index 5650d0793a976c7abe2a5653eac4096140972318..48ae05d415de76e4267b6c0bfbf085f06778a4da 100644 --- a/DDG4/src/Geant4ParticleHandler.cpp +++ b/DDG4/src/Geant4ParticleHandler.cpp @@ -195,7 +195,7 @@ void Geant4ParticleHandler::step(const G4Step* step_value, G4SteppingManager* mg // this criterium will anyhow take precedence. // const _Sec* sec=step_value->GetSecondaryInCurrentStep(); - if ( sec->size() > 0 ) { + if ( not sec->empty() ) { PropertyMask(m_currTrack.reason).set(G4PARTICLE_HAS_SECONDARIES); } }