DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4SensDetFilters.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
16 #include <DDG4/Geant4FastSimSpot.h>
17 
19 
21 class G4ParticleDefinition;
22 
24 namespace dd4hep {
25 
27  namespace sim {
28 
30 
35  struct ParticleFilter : public Geant4Filter {
36  protected:
38  std::string m_particle;
40  mutable G4ParticleDefinition* m_definition;
41  public:
43  ParticleFilter(Geant4Context* context, const std::string& name);
45  virtual ~ParticleFilter();
47  const G4ParticleDefinition* definition() const;
49  bool isSameType(const G4Track* track) const;
51  bool isGeantino(const G4Track* track) const;
53  const G4Track* getTrack(const G4Step* step) const {
54  return step->GetTrack();
55  }
57  const G4Track* getTrack(const Geant4FastSimSpot* spot) const {
58  return spot->primary;
59  }
61  const G4Track* getTrack(const G4FastTrack* fast) const {
62  return fast->GetPrimaryTrack();
63  }
64  };
65 
67 
74  ParticleRejectFilter(Geant4Context* c, const std::string& n);
76  virtual ~ParticleRejectFilter();
78  virtual bool operator()(const G4Step* step) const override final {
79  return !isSameType(getTrack(step));
80  }
82  virtual bool operator()(const Geant4FastSimSpot* spot) const override final {
83  return !isSameType(getTrack(spot));
84  }
85  };
86 
88 
95  ParticleSelectFilter(Geant4Context* c, const std::string& n);
97  virtual ~ParticleSelectFilter();
99  virtual bool operator()(const G4Step* step) const override final {
100  return isSameType(getTrack(step));
101  }
103  virtual bool operator()(const Geant4FastSimSpot* spot) const override final {
104  return isSameType(getTrack(spot));
105  }
106  };
107 
109 
116  GeantinoRejectFilter(Geant4Context* c, const std::string& n);
118  virtual ~GeantinoRejectFilter();
120  virtual bool operator()(const G4Step* step) const override final {
121  return !isGeantino(getTrack(step));
122  }
124  virtual bool operator()(const Geant4FastSimSpot* spot) const override final {
125  return !isGeantino(getTrack(spot));
126  }
127  };
128 
130 
137  double m_energyCut;
138  public:
140  EnergyDepositMinimumCut(Geant4Context* c, const std::string& n);
142  virtual ~EnergyDepositMinimumCut();
144  virtual bool operator()(const G4Step* step) const override final {
145  return step->GetTotalEnergyDeposit() > m_energyCut;
146  }
148  virtual bool operator()(const Geant4FastSimSpot* spot) const override final {
149  return spot->energy() > m_energyCut;
150  }
151  };
152  }
153 }
154 
156 #include <DD4hep/InstanceCount.h>
157 #include <DDG4/Factories.h>
158 
159 // Geant4 include files
160 #include <G4ParticleTable.hh>
161 #include <G4ChargedGeantino.hh>
162 #include <G4Geantino.hh>
163 #include <G4Track.hh>
164 #include <G4Step.hh>
165 
166 using namespace dd4hep::sim;
167 
168 //DECLARE_GEANT4ACTION()
173 
174 ParticleFilter::ParticleFilter(Geant4Context* ctxt, const std::string& nam)
176 : Geant4Filter(ctxt,nam), m_definition(0)
177 {
178  declareProperty("particle",m_particle);
180 }
181 
185 }
186 
188 const G4ParticleDefinition* ParticleFilter::definition() const {
189  if ( m_definition ) return m_definition;
190  m_definition = G4ParticleTable::GetParticleTable()->FindParticle(m_particle);
191  if ( 0 == m_definition ) {
192  throw std::runtime_error("Invalid particle name:'"+m_particle+"' [Not-in-particle-table]");
193  }
194  return m_definition;
195 }
196 
198 bool ParticleFilter::isSameType(const G4Track* track) const {
199  G4ParticleDefinition* def = track->GetDefinition();
200  return definition() == def;
201 }
202 
204 bool ParticleFilter::isGeantino(const G4Track* track) const {
205  if ( track ) {
206  G4ParticleDefinition* def = track->GetDefinition();
207  if ( def == G4ChargedGeantino::Definition() )
208  return true;
209  if ( def == G4Geantino::Definition() ) {
210  return true;
211  }
212  }
213  return false;
214 }
215 
218  : ParticleFilter(c,n) {
220 }
221 
225 }
226 
229  : ParticleFilter(c,n) {
231 }
232 
236 }
237 
240  : ParticleFilter(c,n) {
242 }
243 
247 }
248 
251  : Geant4Filter(c,n) {
253  declareProperty("Cut",m_energyCut=0.0);
254 }
255 
259 }
260 
dd4hep::sim::GeantinoRejectFilter::GeantinoRejectFilter
GeantinoRejectFilter(Geant4Context *c, const std::string &n)
Constructor.
Definition: Geant4SensDetFilters.cpp:217
dd4hep::sim::ParticleFilter::getTrack
const G4Track * getTrack(const Geant4FastSimSpot *spot) const
Access to the track from step.
Definition: Geant4SensDetFilters.cpp:57
dd4hep::sim::EnergyDepositMinimumCut::~EnergyDepositMinimumCut
virtual ~EnergyDepositMinimumCut()
Standard destructor.
Definition: Geant4SensDetFilters.cpp:257
dd4hep::sim::GeantinoRejectFilter::operator()
virtual bool operator()(const G4Step *step) const override final
Filter action. Return true if hits should be processed.
Definition: Geant4SensDetFilters.cpp:120
dd4hep::sim::ParticleRejectFilter
Geant4 sensitive detector filter implementing a particle rejector.
Definition: Geant4SensDetFilters.cpp:72
dd4hep::sim::ParticleFilter::definition
const G4ParticleDefinition * definition() const
Safe access to the definition.
Definition: Geant4SensDetFilters.cpp:188
dd4hep::sim::ParticleRejectFilter::operator()
virtual bool operator()(const G4Step *step) const override final
Filter action. Return true if hits should be processed.
Definition: Geant4SensDetFilters.cpp:78
Geant4SensDetAction.h
dd4hep::sim::ParticleRejectFilter::operator()
virtual bool operator()(const Geant4FastSimSpot *spot) const override final
GFlash/FastSim interface: Filter action. Return true if hits should be processed.
Definition: Geant4SensDetFilters.cpp:82
dd4hep::sim::GeantinoRejectFilter
Geant4 sensitive detector filter implementing a Geantino rejector.
Definition: Geant4SensDetFilters.cpp:114
dd4hep::InstanceCount::increment
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
dd4hep::sim::EnergyDepositMinimumCut::EnergyDepositMinimumCut
EnergyDepositMinimumCut(Geant4Context *c, const std::string &n)
Constructor.
Definition: Geant4SensDetFilters.cpp:250
DECLARE_GEANT4ACTION
#define DECLARE_GEANT4ACTION(name)
Plugin defintion to create Geant4Action objects.
Definition: Factories.h:210
dd4hep::sim::ParticleFilter::ParticleFilter
ParticleFilter(Geant4Context *context, const std::string &name)
Constructor.
Definition: Geant4SensDetFilters.cpp:175
dd4hep::sim::EnergyDepositMinimumCut
Geant4 sensitive detector filter implementing an energy cut.
Definition: Geant4SensDetFilters.cpp:135
dd4hep::sim::ParticleFilter::m_particle
std::string m_particle
name of the particle to be filtered
Definition: Geant4SensDetFilters.cpp:38
Geant4FastSimSpot.h
dd4hep::sim::Geant4FastSimSpot
Spot definition for fast simulation and GFlash.
Definition: Geant4FastSimSpot.h:71
dd4hep::sim::EnergyDepositMinimumCut::m_energyCut
double m_energyCut
Energy cut value.
Definition: Geant4SensDetFilters.cpp:137
dd4hep::sim::ParticleFilter::~ParticleFilter
virtual ~ParticleFilter()
Standard destructor.
Definition: Geant4SensDetFilters.cpp:183
dd4hep::sim::Geant4FastSimSpot::primary
const G4Track * primary
Definition: Geant4FastSimSpot.h:120
dd4hep::sim::ParticleRejectFilter::~ParticleRejectFilter
virtual ~ParticleRejectFilter()
Standard destructor.
Definition: Geant4SensDetFilters.cpp:234
dd4hep::sim::ParticleFilter::getTrack
const G4Track * getTrack(const G4Step *step) const
Access to the track from step.
Definition: Geant4SensDetFilters.cpp:53
dd4hep::sim::ParticleFilter::isGeantino
bool isGeantino(const G4Track *track) const
Check if the particle is a geantino.
Definition: Geant4SensDetFilters.cpp:204
dd4hep::sim::Geant4Action::declareProperty
Geant4Action & declareProperty(const std::string &nam, T &val)
Declare property.
Definition: Geant4Action.h:366
dd4hep::sim::ParticleRejectFilter::ParticleRejectFilter
ParticleRejectFilter(Geant4Context *c, const std::string &n)
Constructor.
Definition: Geant4SensDetFilters.cpp:228
dd4hep::InstanceCount::decrement
static void decrement(T *)
Decrement count according to type information.
Definition: InstanceCount.h:102
dd4hep::sim::GeantinoRejectFilter::operator()
virtual bool operator()(const Geant4FastSimSpot *spot) const override final
GFlash/FastSim interface: Filter action. Return true if hits should be processed.
Definition: Geant4SensDetFilters.cpp:124
dd4hep::sim::Geant4Action::name
const std::string & name() const
Access name of the action.
Definition: Geant4Action.h:280
dd4hep::sim::ParticleSelectFilter::operator()
virtual bool operator()(const G4Step *step) const override final
Filter action. Return true if hits should be processed.
Definition: Geant4SensDetFilters.cpp:99
dd4hep::sim::ParticleSelectFilter
Geant4 sensitive detector filter implementing a particle selector.
Definition: Geant4SensDetFilters.cpp:93
Factories.h
dd4hep::sim
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
Definition: Geant4Output2EDM4hep.cpp:49
dd4hep::sim::EnergyDepositMinimumCut::operator()
virtual bool operator()(const Geant4FastSimSpot *spot) const override final
GFlash/FastSim interface: Filter action. Return true if hits should be processed.
Definition: Geant4SensDetFilters.cpp:148
dd4hep::sim::ParticleSelectFilter::~ParticleSelectFilter
virtual ~ParticleSelectFilter()
Standard destructor.
Definition: Geant4SensDetFilters.cpp:245
dd4hep::sim::EnergyDepositMinimumCut::operator()
virtual bool operator()(const G4Step *step) const override final
Filter action. Return true if hits should be processed.
Definition: Geant4SensDetFilters.cpp:144
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::sim::ParticleFilter::getTrack
const G4Track * getTrack(const G4FastTrack *fast) const
Access originator track from G4 fast track.
Definition: Geant4SensDetFilters.cpp:61
dd4hep::sim::Geant4Filter
Base class to construct filters for Geant4 sensitive detectors.
Definition: Geant4SensDetAction.h:94
dd4hep::sim::ParticleFilter::isSameType
bool isSameType(const G4Track *track) const
Check if a track is of the same type.
Definition: Geant4SensDetFilters.cpp:198
InstanceCount.h
dd4hep::sim::GeantinoRejectFilter::~GeantinoRejectFilter
virtual ~GeantinoRejectFilter()
Standard destructor.
Definition: Geant4SensDetFilters.cpp:223
dd4hep::sim::ParticleSelectFilter::operator()
virtual bool operator()(const Geant4FastSimSpot *spot) const override final
GFlash/FastSim interface: Filter action. Return true if hits should be processed.
Definition: Geant4SensDetFilters.cpp:103
dd4hep::sim::ParticleFilter
Geant4 sensitive detector filter base class for particle filters.
Definition: Geant4SensDetFilters.cpp:35
dd4hep::sim::ParticleFilter::m_definition
G4ParticleDefinition * m_definition
Corresponding geant4 particle definiton.
Definition: Geant4SensDetFilters.cpp:40
dd4hep::sim::Geant4Context
Generic context to extend user, run and event information.
Definition: Geant4Context.h:201
dd4hep::sim::Geant4Action::context
Geant4Context * context() const
Access the context.
Definition: Geant4Action.h:270
dd4hep::sim::ParticleSelectFilter::ParticleSelectFilter
ParticleSelectFilter(Geant4Context *c, const std::string &n)
Constructor.
Definition: Geant4SensDetFilters.cpp:239