File indexing completed on 2025-01-30 09:17:27
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <DDG4/Geant4SensDetAction.h>
0016 #include <DDG4/Geant4FastSimSpot.h>
0017
0018
0019
0020
0021 class G4ParticleDefinition;
0022
0023
0024 namespace dd4hep {
0025
0026
0027 namespace sim {
0028
0029
0030
0031
0032
0033
0034
0035 struct ParticleFilter : public Geant4Filter {
0036 protected:
0037
0038 std::string m_particle;
0039
0040 mutable G4ParticleDefinition* m_definition;
0041 public:
0042
0043 ParticleFilter(Geant4Context* context, const std::string& name);
0044
0045 virtual ~ParticleFilter();
0046
0047 const G4ParticleDefinition* definition() const;
0048
0049 bool isSameType(const G4Track* track) const;
0050
0051 bool isGeantino(const G4Track* track) const;
0052
0053 const G4Track* getTrack(const G4Step* step) const {
0054 return step->GetTrack();
0055 }
0056
0057 const G4Track* getTrack(const Geant4FastSimSpot* spot) const {
0058 return spot->primary;
0059 }
0060
0061 const G4Track* getTrack(const G4FastTrack* fast) const {
0062 return fast->GetPrimaryTrack();
0063 }
0064 };
0065
0066
0067
0068
0069
0070
0071
0072 struct ParticleRejectFilter : public ParticleFilter {
0073
0074 ParticleRejectFilter(Geant4Context* c, const std::string& n);
0075
0076 virtual ~ParticleRejectFilter();
0077
0078 virtual bool operator()(const G4Step* step) const override final {
0079 return !isSameType(getTrack(step));
0080 }
0081
0082 virtual bool operator()(const Geant4FastSimSpot* spot) const override final {
0083 return !isSameType(getTrack(spot));
0084 }
0085 };
0086
0087
0088
0089
0090
0091
0092
0093 struct ParticleSelectFilter : public ParticleFilter {
0094
0095 ParticleSelectFilter(Geant4Context* c, const std::string& n);
0096
0097 virtual ~ParticleSelectFilter();
0098
0099 virtual bool operator()(const G4Step* step) const override final {
0100 return isSameType(getTrack(step));
0101 }
0102
0103 virtual bool operator()(const Geant4FastSimSpot* spot) const override final {
0104 return isSameType(getTrack(spot));
0105 }
0106 };
0107
0108
0109
0110
0111
0112
0113
0114 struct GeantinoRejectFilter : public ParticleFilter {
0115
0116 GeantinoRejectFilter(Geant4Context* c, const std::string& n);
0117
0118 virtual ~GeantinoRejectFilter();
0119
0120 virtual bool operator()(const G4Step* step) const override final {
0121 return !isGeantino(getTrack(step));
0122 }
0123
0124 virtual bool operator()(const Geant4FastSimSpot* spot) const override final {
0125 return !isGeantino(getTrack(spot));
0126 }
0127 };
0128
0129
0130
0131
0132
0133
0134
0135 struct EnergyDepositMinimumCut : public Geant4Filter {
0136
0137 double m_energyCut;
0138 public:
0139
0140 EnergyDepositMinimumCut(Geant4Context* c, const std::string& n);
0141
0142 virtual ~EnergyDepositMinimumCut();
0143
0144 virtual bool operator()(const G4Step* step) const override final {
0145 return step->GetTotalEnergyDeposit() > m_energyCut;
0146 }
0147
0148 virtual bool operator()(const Geant4FastSimSpot* spot) const override final {
0149 return spot->energy() > m_energyCut;
0150 }
0151 };
0152 }
0153 }
0154
0155
0156 #include <DD4hep/InstanceCount.h>
0157 #include <DDG4/Factories.h>
0158
0159
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
0169 DECLARE_GEANT4ACTION(GeantinoRejectFilter)
0170 DECLARE_GEANT4ACTION(ParticleRejectFilter)
0171 DECLARE_GEANT4ACTION(ParticleSelectFilter)
0172 DECLARE_GEANT4ACTION(EnergyDepositMinimumCut)
0173
0174
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
0183 ParticleFilter::~ParticleFilter() {
0184 InstanceCount::decrement(this);
0185 }
0186
0187
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
0198 bool ParticleFilter::isSameType(const G4Track* track) const {
0199 G4ParticleDefinition* def = track->GetDefinition();
0200 return definition() == def;
0201 }
0202
0203
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
0217 GeantinoRejectFilter::GeantinoRejectFilter(Geant4Context* c, const std::string& n)
0218 : ParticleFilter(c,n) {
0219 InstanceCount::increment(this);
0220 }
0221
0222
0223 GeantinoRejectFilter::~GeantinoRejectFilter() {
0224 InstanceCount::decrement(this);
0225 }
0226
0227
0228 ParticleRejectFilter::ParticleRejectFilter(Geant4Context* c, const std::string& n)
0229 : ParticleFilter(c,n) {
0230 InstanceCount::increment(this);
0231 }
0232
0233
0234 ParticleRejectFilter::~ParticleRejectFilter() {
0235 InstanceCount::decrement(this);
0236 }
0237
0238
0239 ParticleSelectFilter::ParticleSelectFilter(Geant4Context* c, const std::string& n)
0240 : ParticleFilter(c,n) {
0241 InstanceCount::increment(this);
0242 }
0243
0244
0245 ParticleSelectFilter::~ParticleSelectFilter() {
0246 InstanceCount::decrement(this);
0247 }
0248
0249
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
0257 EnergyDepositMinimumCut::~EnergyDepositMinimumCut() {
0258 InstanceCount::decrement(this);
0259 }
0260