DD4hep  1.34.0
Detector Description Toolkit for High Energy Physics
Geant4ParticleMaskAction.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 
14 // Framework include files
15 #include <DD4hep/Primitives.h>
16 #include <DD4hep/InstanceCount.h>
17 #include <DDG4/Geant4Particle.h>
20 
21 // Geant4 header files
22 #include <G4Track.hh>
23 #include <G4VSensitiveDetector.hh>
24 
25 // C/C++ include files
26 #include <cstdint>
27 
29 namespace dd4hep {
30 
32  namespace sim {
33 
35 
51  protected:
53  std::map<std::string, int32_t> m_nameMasks;
55  std::map<std::string, int32_t> m_typeMasks;
56 
57  public:
59  Geant4ParticleMaskAction(Geant4Context* ctxt, const std::string& nam)
60  : Geant4UserParticleHandler(ctxt,nam)
61  {
62  declareProperty("DetectorNameMasks", m_nameMasks );
63  declareProperty("DetectorTypeMasks", m_typeMasks );
64  m_needsControl = true;
65  }
66 
68  void mark_track(const G4Track* track, Particle* curr_track ) override final {
69  G4LogicalVolume* vol = track->GetVolume()->GetLogicalVolume();
70  G4VSensitiveDetector* g4 = vol->GetSensitiveDetector();
71  Geant4ActionSD* sd = dynamic_cast<Geant4ActionSD*>(g4);
72 
73  if( !sd ) {
74  return;
75  }
76  Geant4SensDetActionSequence* sens_det = sd->sequence();
77  if( sens_det ) {
78  using PropertyMask = dd4hep::detail::ReferenceBitMask<int>;
79  PropertyMask mask(curr_track->reason);
80  if( !m_nameMasks.empty() ) {
81  auto it = m_nameMasks.begin();
82  auto nam = sens_det->name();
83  for( ; it != m_nameMasks.end(); ++it ) {
84  if( it->first == nam || it->first == "*" ) {
85  print("+++ Detector: name: %s Masking track %d with mask: %08X",
86  nam.c_str(), curr_track->id, it->second);
87  mask.set(it->second);
88  }
89  }
90  }
91  if( !m_typeMasks.empty() ) {
92  auto it = m_typeMasks.begin();
93  auto nam = sens_det->sensitiveType();
94  for( ; it != m_typeMasks.end(); ++it ) {
95  if( it->first == nam || it->first == "*" ) {
96  print("+++ Detector: type: %s Masking track %d with mask: %08X",
97  nam.c_str(), curr_track->id, it->second);
98  mask.set(it->second);
99  }
100  }
101  }
102  }
103  }
104  }; // End class Geant4ParticleMaskAction
105  } // End namespace sim
106 } // End namespace dd4hep
107 
108 #include <DDG4/Geant4Particle.h>
109 #include <DDG4/Factories.h>
110 using namespace dd4hep::sim;
dd4hep::sim::Geant4Action::m_needsControl
bool m_needsControl
Default property: Flag to create control instance.
Definition: Geant4Action.h:123
dd4hep::sim::Geant4ParticleMaskAction::Geant4ParticleMaskAction
Geant4ParticleMaskAction(Geant4Context *ctxt, const std::string &nam)
Standard constructor.
Definition: Geant4ParticleMaskAction.cpp:59
Geant4SensDetAction.h
dd4hep::sim::Geant4SensDetActionSequence::sensitiveType
virtual const std::string & sensitiveType() const
Access to the sensitive type of the detector.
Definition: Geant4SensDetAction.h:378
DECLARE_GEANT4ACTION
#define DECLARE_GEANT4ACTION(name)
Plugin defintion to create Geant4Action objects.
Definition: Factories.h:210
Geant4UserParticleHandler.h
dd4hep::sim::Geant4ParticleMaskAction::mark_track
void mark_track(const G4Track *track, Particle *curr_track) override final
User overload to handle particle settings when processing the track in the Geant4ParticleHandler.
Definition: Geant4ParticleMaskAction.cpp:68
dd4hep::sim::Geant4ParticleMaskAction::m_nameMasks
std::map< std::string, int32_t > m_nameMasks
Map of Subdetector names to trigger setting of the mask : Bit mask to be set to particle.
Definition: Geant4ParticleMaskAction.cpp:53
Geant4UserParticleHandler
Geant4ParticleHandler user extension action called by the particle handler.
G4VSensitiveDetector
Class of the Geant4 toolkit. See http://www-geant4.kek.jp/Reference.
Definition: Geant4Classes.h:59
dd4hep::sim::Geant4Action::declareProperty
Geant4Action & declareProperty(const std::string &nam, T &val)
Declare property.
Definition: Geant4Action.h:366
dd4hep::sim::Geant4Action::name
const std::string & name() const
Access name of the action.
Definition: Geant4Action.h:280
dd4hep::sim::Geant4ActionSD
Interface class to access properties of the underlying Geant4 sensitive detector structure.
Definition: Geant4SensDetAction.h:61
dd4hep::sim::Geant4Action::print
void print(const char *fmt,...) const
Support for messages with variable output level using output level.
Definition: Geant4Action.cpp:144
Factories.h
Primitives.h
dd4hep::sim
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
Definition: EDM4hepFileReader.cpp:46
dd4hep::sim::Geant4SensDetActionSequence
The sequencer to host Geant4 sensitive actions called if particles interact with sensitive elements.
Definition: Geant4SensDetAction.h:330
dd4hep::sim::Geant4ParticleMaskAction::m_typeMasks
std::map< std::string, int32_t > m_typeMasks
Map of Subdetector types to trigger setting of the mask : Bit mask to be set to particle.
Definition: Geant4ParticleMaskAction.cpp:55
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
Geant4Particle.h
dd4hep::sim::Geant4Particle
Data structure to store the MC particle information.
Definition: Geant4Particle.h:103
PropertyMask
dd4hep::detail::ReferenceBitMask< int > PropertyMask
Definition: EDM4hepFileReader.cpp:43
InstanceCount.h
dd4hep::sim::Geant4ParticleMaskAction
Geant4ParticleHandler user extension action to modify the particle reason mask.
Definition: Geant4ParticleMaskAction.cpp:50
dd4hep::sim::Geant4Context
Generic context to extend user, run and event information.
Definition: Geant4Context.h:201
dd4hep::sim::Geant4ActionSD::sequence
virtual Geant4SensDetActionSequence * sequence() const =0
Access the DDG4 action sequence.