File indexing completed on 2026-06-04 07:57:16
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include "Geant4UserParticleHandlerHelper.h"
0016 #include <DDG4/Geant4Particle.h>
0017 #include <DDG4/Geant4UserParticleHandler.h>
0018
0019
0020
0021 namespace dd4hep::sim {
0022
0023 void setReason(Geant4Particle& p, bool starts_in_trk_vol, bool ends_in_trk_vol) {
0024
0025 dd4hep::detail::ReferenceBitMask<int> reason(p.reason);
0026
0027 if( reason.isSet(G4PARTICLE_PRIMARY) ) {
0028
0029 return;
0030 } else if( starts_in_trk_vol && ! reason.isSet(G4PARTICLE_ABOVE_ENERGY_THRESHOLD) ) {
0031
0032 p.reason = 0;
0033 return;
0034 }
0035
0036 if(reason.isSet(G4PARTICLE_CREATED_TRACKER_HIT) && reason.isSet(G4PARTICLE_ABOVE_ENERGY_THRESHOLD)) {
0037 return;
0038 }
0039
0040
0041
0042
0043
0044
0045 if( !starts_in_trk_vol ) {
0046 if( !ends_in_trk_vol ){
0047 p.reason = 0;
0048 }
0049
0050 else if( ! reason.isSet(G4PARTICLE_CREATED_TRACKER_HIT) ) {
0051 p.reason = 0;
0052 }
0053 }
0054 }
0055
0056 void setSimulatorStatus(Geant4Particle& p, bool starts_in_trk_vol, bool ends_in_trk_vol) {
0057
0058 dd4hep::detail::ReferenceBitMask<int> simStatus(p.status);
0059
0060 if( ends_in_trk_vol ) {
0061 simStatus.set(G4PARTICLE_SIM_DECAY_TRACKER);
0062 }
0063
0064
0065 if( not ends_in_trk_vol && not simStatus.isSet(G4PARTICLE_SIM_LEFT_DETECTOR) ) {
0066 simStatus.set(G4PARTICLE_SIM_DECAY_CALO);
0067 }
0068
0069 if( not starts_in_trk_vol && ends_in_trk_vol ) {
0070 simStatus.set(G4PARTICLE_SIM_BACKSCATTER);
0071 }
0072 }
0073
0074 }