DD4hep  1.37.0
Detector Description Toolkit for High Energy Physics
Geant4HepEmTrackingPhysics.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 //==========================================================================
11 
50 #ifndef DDG4_GEANT4HEPEMTRACKINGPHYSICS_H
51 #define DDG4_GEANT4HEPEMTRACKINGPHYSICS_H 1
52 
54 #include <DDG4/Geant4PhysicsList.h>
55 
57 #include <G4Electron.hh>
58 #include <G4Gamma.hh>
59 #include <G4Positron.hh>
60 #include <G4VUserPhysicsList.hh>
61 
63 #include <G4HepEmConfig.hh>
64 #include <G4HepEmTrackingManager.hh>
65 
67 #include <string>
68 #include <vector>
69 
71 namespace dd4hep {
72 
74  namespace sim {
75 
77 
94  protected:
97 
99  std::vector<std::string> m_woodcockRegions;
100 
101  public:
104  : Geant4PhysicsList(context, nam) {
105  declareProperty("WoodcockRegions", m_woodcockRegions);
106  }
107 
109  virtual ~Geant4HepEmTrackingPhysics() = default;
110 
112 
122  virtual void constructProcesses(G4VUserPhysicsList* /* physics_list */) override {
123  // Allocate one tracking manager for this thread. G4HepEmTrackingManager
124  // handles e-/e+/gamma internally by dispatching on particle type, so one
125  // shared instance per thread suffices. Ownership lies with Geant4.
126  auto* tm = new G4HepEmTrackingManager();
127 
128  for (const auto& region : m_woodcockRegions) {
129  info("+++ Enabling Woodcock photon tracking in G4Region: %s", region.c_str());
130  tm->GetConfig()->SetWoodcockTrackingRegion(region);
131  }
132 
133  // Warn if another custom tracking manager is already installed —
134  // SetTrackingManager() is exclusive and will silently replace it.
135  auto warnIfConflict = [&](G4ParticleDefinition* particle) {
136  if (particle->GetTrackingManager() != nullptr) {
137  warning("+++ Replacing existing tracking manager for %s with G4HepEmTrackingManager",
138  particle->GetParticleName().c_str());
139  }
140  };
141  warnIfConflict(G4Electron::Definition());
142  warnIfConflict(G4Positron::Definition());
143  warnIfConflict(G4Gamma::Definition());
144 
145  G4Electron::Definition()->SetTrackingManager(tm);
146  G4Positron::Definition()->SetTrackingManager(tm);
147  G4Gamma::Definition() ->SetTrackingManager(tm);
148 
149  info("+++ Installed G4HepEmTrackingManager for e-/e+/gamma");
150  }
151  };
152  } // namespace sim
153 } // namespace dd4hep
154 
155 #endif // DDG4_GEANT4HEPEMTRACKINGPHYSICS_H
156 
157 #include <DDG4/Factories.h>
158 using namespace dd4hep::sim;
dd4hep::sim::Geant4HepEmTrackingPhysics::Geant4HepEmTrackingPhysics
Geant4HepEmTrackingPhysics(Geant4Context *context, const std::string &nam)
Standard constructor.
Definition: Geant4HepEmTrackingPhysics.cpp:103
dd4hep::sim::Geant4HepEmTrackingPhysics::constructProcesses
virtual void constructProcesses(G4VUserPhysicsList *) override
Callback to install the G4HepEmTrackingManager on e-, e+ and gamma.
Definition: Geant4HepEmTrackingPhysics.cpp:122
Geant4PhysicsList.h
DECLARE_GEANT4ACTION
#define DECLARE_GEANT4ACTION(name)
Plugin defintion to create Geant4Action objects.
Definition: Factories.h:210
dd4hep::sim::Geant4Action::warning
void warning(const char *fmt,...) const
Support of warning messages.
Definition: Geant4Action.cpp:223
dd4hep::sim::Geant4HepEmTrackingPhysics::m_woodcockRegions
std::vector< std::string > m_woodcockRegions
G4Region names in which Woodcock tracking is activated for photons.
Definition: Geant4HepEmTrackingPhysics.cpp:99
dd4hep::sim::Geant4Action::info
void info(const char *fmt,...) const
Support of info messages.
Definition: Geant4Action.cpp:215
dd4hep::sim::Geant4HepEmTrackingPhysics::~Geant4HepEmTrackingPhysics
virtual ~Geant4HepEmTrackingPhysics()=default
Default destructor.
Geant4HepEmTrackingPhysics
PhysicsConstructor enabling G4HepEm vectorised EM tracking for e-/e+/gamma.
dd4hep::sim::Geant4HepEmTrackingPhysics::DDG4_DEFINE_ACTION_CONSTRUCTORS
DDG4_DEFINE_ACTION_CONSTRUCTORS(Geant4HepEmTrackingPhysics)
Define standard assignments and constructors.
dd4hep::sim::Geant4Action::declareProperty
Geant4Action & declareProperty(const std::string &nam, T &val)
Declare property.
Definition: Geant4Action.h:366
dd4hep::sim::Geant4PhysicsList
Concrete basic implementation of a Geant4 physics list action.
Definition: Geant4PhysicsList.h:41
Factories.h
dd4hep::sim
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
Definition: EDM4hepFileReader.cpp:46
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
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