Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 
0014 /// Framework include files
0015 #include <DDG4/Geant4SensDetAction.h>
0016 #include <DDG4/Geant4FastSimSpot.h>
0017 
0018 /// Geant4 include files
0019 
0020 /// Forward declarations
0021 class G4ParticleDefinition;
0022 
0023 /// Namespace for the AIDA detector description toolkit
0024 namespace dd4hep {
0025 
0026   /// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit
0027   namespace sim {
0028 
0029     /// Geant4 sensitive detector filter base class for particle filters
0030     /**
0031      *
0032      * @author  M.Frank
0033      * @version 1.0
0034      */
0035     struct ParticleFilter : public Geant4Filter  {
0036     protected:
0037       /// name of the particle to be filtered
0038       std::string m_particle;
0039       /// Corresponding geant4 particle definiton
0040       mutable G4ParticleDefinition* m_definition;
0041     public:
0042       /// Constructor.
0043       ParticleFilter(Geant4Context* context, const std::string& name);
0044       /// Standard destructor
0045       virtual ~ParticleFilter();
0046       /// Safe access to the definition
0047       const G4ParticleDefinition* definition() const;
0048       /// Check if a track is of the same type
0049       bool isSameType(const G4Track* track)  const;
0050       /// Check if the particle is a geantino
0051       bool isGeantino(const G4Track* track) const;
0052       /// Access to the track from step
0053       const G4Track* getTrack(const G4Step* step)   const   {
0054         return step->GetTrack();
0055       }
0056       /// Access to the track from step
0057       const G4Track* getTrack(const Geant4FastSimSpot* spot)   const   {
0058         return spot->primary;
0059       }
0060       /// Access originator track from G4 fast track
0061       const G4Track* getTrack(const G4FastTrack* fast)   const   {
0062         return fast->GetPrimaryTrack();
0063       }
0064     };
0065 
0066     /// Geant4 sensitive detector filter implementing a particle rejector
0067     /**
0068      *
0069      * @author  M.Frank
0070      * @version 1.0
0071      */
0072     struct ParticleRejectFilter : public ParticleFilter  {
0073       /// Constructor.
0074       ParticleRejectFilter(Geant4Context* c, const std::string& n);
0075       /// Standard destructor
0076       virtual ~ParticleRejectFilter();
0077       /// Filter action. Return true if hits should be processed
0078       virtual bool operator()(const G4Step* step) const  override  final   {
0079         return !isSameType(getTrack(step));
0080       }
0081       /// GFlash/FastSim interface: Filter action. Return true if hits should be processed
0082       virtual bool operator()(const Geant4FastSimSpot* spot) const  override  final   {
0083         return !isSameType(getTrack(spot));
0084       }
0085     };
0086 
0087     /// Geant4 sensitive detector filter implementing a particle selector
0088     /**
0089      *
0090      * @author  M.Frank
0091      * @version 1.0
0092      */
0093     struct ParticleSelectFilter : public ParticleFilter  {
0094       /// Constructor.
0095       ParticleSelectFilter(Geant4Context* c, const std::string& n);
0096       /// Standard destructor
0097       virtual ~ParticleSelectFilter();
0098       /// Filter action. Return true if hits should be processed
0099       virtual bool operator()(const G4Step* step) const  override  final   {
0100         return isSameType(getTrack(step));
0101       }
0102       /// GFlash/FastSim interface: Filter action. Return true if hits should be processed
0103       virtual bool operator()(const Geant4FastSimSpot* spot) const  override  final   {
0104         return isSameType(getTrack(spot));
0105       }
0106     };
0107 
0108     /// Geant4 sensitive detector filter implementing a Geantino rejector
0109     /**
0110      *
0111      * @author  M.Frank
0112      * @version 1.0
0113      */
0114     struct GeantinoRejectFilter : public ParticleFilter  {
0115       /// Constructor.
0116       GeantinoRejectFilter(Geant4Context* c, const std::string& n);
0117       /// Standard destructor
0118       virtual ~GeantinoRejectFilter();
0119       /// Filter action. Return true if hits should be processed
0120       virtual bool operator()(const G4Step* step) const  override  final   {
0121         return !isGeantino(getTrack(step));
0122       }
0123       /// GFlash/FastSim interface: Filter action. Return true if hits should be processed
0124       virtual bool operator()(const Geant4FastSimSpot* spot) const  override  final   {
0125         return !isGeantino(getTrack(spot));
0126       }
0127     };
0128 
0129     /// Geant4 sensitive detector filter implementing an energy cut.
0130     /**
0131      *
0132      * @author  M.Frank
0133      * @version 1.0
0134      */
0135     struct EnergyDepositMinimumCut : public Geant4Filter  {
0136       /// Energy cut value
0137       double m_energyCut;
0138     public:
0139       /// Constructor.
0140       EnergyDepositMinimumCut(Geant4Context* c, const std::string& n);
0141       /// Standard destructor
0142       virtual ~EnergyDepositMinimumCut();
0143       /// Filter action. Return true if hits should be processed
0144       virtual bool operator()(const G4Step* step) const  override  final  {
0145         return step->GetTotalEnergyDeposit() > m_energyCut;
0146       }
0147       /// GFlash/FastSim interface: Filter action. Return true if hits should be processed
0148       virtual bool operator()(const Geant4FastSimSpot* spot) const  override  final  {
0149         return spot->energy() > m_energyCut;
0150       }
0151     };
0152   }
0153 }
0154 
0155 /// Framework include files
0156 #include <DD4hep/InstanceCount.h>
0157 #include <DDG4/Factories.h>
0158 
0159 // Geant4 include files
0160 #include <G4ParticleTable.hh>
0161 #include <G4ChargedGeantino.hh>
0162 #include <G4Geantino.hh>
0163 #include <G4Track.hh>
0164 #include <G4Step.hh>
0165 
0166 using namespace dd4hep::sim;
0167 
0168 //DECLARE_GEANT4ACTION()
0169 DECLARE_GEANT4ACTION(GeantinoRejectFilter)
0170 DECLARE_GEANT4ACTION(ParticleRejectFilter)
0171 DECLARE_GEANT4ACTION(ParticleSelectFilter)
0172 DECLARE_GEANT4ACTION(EnergyDepositMinimumCut)
0173 
0174 /// Constructor.
0175 ParticleFilter::ParticleFilter(Geant4Context* ctxt, const std::string& nam)
0176 : Geant4Filter(ctxt,nam), m_definition(0)
0177 {
0178   declareProperty("particle",m_particle);
0179   InstanceCount::increment(this);
0180 }
0181 
0182 /// Standard destructor
0183 ParticleFilter::~ParticleFilter()   {
0184   InstanceCount::decrement(this);
0185 }
0186 
0187 /// Safe access to the definition
0188 const G4ParticleDefinition* ParticleFilter::definition() const  {
0189   if ( m_definition ) return m_definition;
0190   m_definition = G4ParticleTable::GetParticleTable()->FindParticle(m_particle);
0191   if ( 0 == m_definition )  {
0192     throw std::runtime_error("Invalid particle name:'"+m_particle+"' [Not-in-particle-table]");
0193   }
0194   return m_definition;
0195 }
0196 
0197 /// Check if a track is of the same type
0198 bool ParticleFilter::isSameType(const G4Track* track)  const   {
0199   G4ParticleDefinition* def = track->GetDefinition();
0200   return definition() == def;
0201 }
0202 
0203 /// Check if the particle is a geantino
0204 bool ParticleFilter::isGeantino(const G4Track* track) const   {
0205   if ( track ) {
0206     G4ParticleDefinition* def = track->GetDefinition();
0207     if ( def == G4ChargedGeantino::Definition() )
0208       return true;
0209     if ( def == G4Geantino::Definition() ) {
0210       return true;
0211     }
0212   }
0213   return false;
0214 }
0215 
0216 /// Constructor.
0217 GeantinoRejectFilter::GeantinoRejectFilter(Geant4Context* c, const std::string& n)
0218   : ParticleFilter(c,n) {
0219   InstanceCount::increment(this);
0220 }
0221 
0222 /// Standard destructor
0223 GeantinoRejectFilter::~GeantinoRejectFilter() {
0224   InstanceCount::decrement(this);
0225 }
0226 
0227 /// Constructor.
0228 ParticleRejectFilter::ParticleRejectFilter(Geant4Context* c, const std::string& n)
0229   : ParticleFilter(c,n) {
0230   InstanceCount::increment(this);
0231 }
0232 
0233 /// Standard destructor
0234 ParticleRejectFilter::~ParticleRejectFilter() {
0235   InstanceCount::decrement(this);
0236 }
0237 
0238 /// Constructor.
0239 ParticleSelectFilter::ParticleSelectFilter(Geant4Context* c, const std::string& n)
0240   : ParticleFilter(c,n) {
0241   InstanceCount::increment(this);
0242 }
0243 
0244 /// Standard destructor
0245 ParticleSelectFilter::~ParticleSelectFilter() {
0246   InstanceCount::decrement(this);
0247 }
0248 
0249 /// Constructor.
0250 EnergyDepositMinimumCut::EnergyDepositMinimumCut(Geant4Context* c, const std::string& n)
0251   : Geant4Filter(c,n) {
0252   InstanceCount::increment(this);
0253   declareProperty("Cut",m_energyCut=0.0);
0254 }
0255 
0256 /// Standard destructor
0257 EnergyDepositMinimumCut::~EnergyDepositMinimumCut() {
0258   InstanceCount::decrement(this);
0259 }
0260