Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-04 07:57:16

0001 
0002 //==========================================================================
0003 //  AIDA Detector description implementation
0004 //--------------------------------------------------------------------------
0005 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0006 // All rights reserved.
0007 //
0008 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0009 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0010 //
0011 // Author     : M.Frank
0012 //
0013 //==========================================================================
0014 
0015 #include "Geant4UserParticleHandlerHelper.h"
0016 #include <DDG4/Geant4Particle.h>
0017 #include <DDG4/Geant4UserParticleHandler.h>
0018 
0019 // using namespace dd4hep::sim;
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     //do nothing
0029     return;
0030   } else if( starts_in_trk_vol && ! reason.isSet(G4PARTICLE_ABOVE_ENERGY_THRESHOLD) )  {
0031     // created in tracking volume but below energy cut
0032     p.reason = 0;
0033     return;
0034   }
0035   //keep particles that left tracker hits if they are above threshold.
0036   if(reason.isSet(G4PARTICLE_CREATED_TRACKER_HIT) && reason.isSet(G4PARTICLE_ABOVE_ENERGY_THRESHOLD))  {
0037     return;
0038   }
0039 
0040   // created and ended in calo but not primary particle
0041   //
0042   // we can have particles from the generator only in the calo, if we have a
0043   // long particle with preassigned decay, we need to keep the reason or the
0044   // MChistory will not be updated later on
0045   if( !starts_in_trk_vol ) {
0046     if( !ends_in_trk_vol ){
0047       p.reason = 0;
0048     }
0049     //fg: dont keep backscatter that did not create a tracker hit
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   // Set the simulator status bits
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   // if the particle doesn't end in the tracker volume it must have ended in the calorimeter
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 }