Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:17:27

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   } else if( starts_in_trk_vol && ! reason.isSet(G4PARTICLE_ABOVE_ENERGY_THRESHOLD) )  {
0030     // created in tracking volume but below energy cut
0031     p.reason = 0;
0032     return;
0033   }
0034 
0035   // created and ended in calo but not primary particle
0036   //
0037   // we can have particles from the generator only in the calo, if we have a
0038   // long particle with preassigned decay, we need to keep the reason or the
0039   // MChistory will not be updated later on
0040   if( not reason.isSet(G4PARTICLE_PRIMARY) ) {
0041     if( !starts_in_trk_vol ) {
0042       if( !ends_in_trk_vol ){
0043     p.reason = 0;
0044       }
0045       //fg: dont keep backscatter that did not create a tracker hit
0046       else if( ! reason.isSet(G4PARTICLE_CREATED_TRACKER_HIT) ) {
0047     p.reason = 0;
0048       }
0049     }
0050   }
0051 }
0052 
0053 void setSimulatorStatus(Geant4Particle& p, bool starts_in_trk_vol, bool ends_in_trk_vol) {
0054   // Set the simulator status bits
0055   dd4hep::detail::ReferenceBitMask<int> simStatus(p.status);
0056 
0057   if( ends_in_trk_vol ) {
0058     simStatus.set(G4PARTICLE_SIM_DECAY_TRACKER);
0059   }
0060 
0061   // if the particle doesn't end in the tracker volume it must have ended in the calorimeter
0062   if( not ends_in_trk_vol && not simStatus.isSet(G4PARTICLE_SIM_LEFT_DETECTOR) ) {
0063     simStatus.set(G4PARTICLE_SIM_DECAY_CALO);
0064   }
0065 
0066   if( not starts_in_trk_vol && ends_in_trk_vol ) {
0067     simStatus.set(G4PARTICLE_SIM_BACKSCATTER);
0068   }
0069 }
0070 
0071 }