Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-03-31 08:18:17

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 #ifndef DDG4_GEANT4PHYSICSLIST_H
0015 #define DDG4_GEANT4PHYSICSLIST_H
0016 
0017 // Framework include files
0018 #include <DDG4/Geant4Action.h>
0019 
0020 // C/C++ include files
0021 #include <map>
0022 #include <vector>
0023 
0024 // Forward declarations
0025 class G4VPhysicsConstructor;
0026 class G4VModularPhysicsList;
0027 class G4VUserPhysicsList;
0028 
0029 /// Namespace for the AIDA detector description toolkit
0030 namespace dd4hep {
0031 
0032   /// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit
0033   namespace sim {
0034 
0035     /// Concrete basic implementation of a Geant4 physics list action
0036     /**
0037      *  \author  M.Frank
0038      *  \version 1.0
0039      *  \ingroup DD4HEP_SIMULATION
0040      */
0041     class Geant4PhysicsList: public Geant4Action {
0042     public:
0043 
0044       /// Structure describing a G4 process
0045       /**
0046        * Image of a physics constructor holding all stub information to attach
0047        * the concrete process contributing to the user physics list.
0048        *
0049        *  \author  M.Frank
0050        *  \version 1.0
0051        *  \ingroup DD4HEP_SIMULATION
0052        */
0053       class Process {
0054       public:
0055         std::string name;
0056         int ordAtRestDoIt=-1, ordAlongSteptDoIt=-1, ordPostStepDoIt=-1;
0057         /// Default constructor
0058         Process();
0059         /// Copy constructor
0060         Process(const Process& p);
0061         /// Assignment operator
0062         Process& operator=(const Process& p);
0063       };
0064       typedef std::vector<Process> ParticleProcesses;
0065       typedef std::map<std::string, ParticleProcesses> PhysicsProcesses;
0066 
0067       /// Structure describing a G4 particle constructor
0068       /**
0069        *  \author  M.Frank
0070        *  \version 1.0
0071        *  \ingroup DD4HEP_SIMULATION
0072        */
0073       class ParticleConstructor : public std::string {
0074       public:
0075         /// Default constructor
0076         ParticleConstructor() = default;
0077         /// Default constructor
0078         ParticleConstructor(const ParticleConstructor& copy) = default;
0079         /// Initalizing constructor
0080         ParticleConstructor(const std::string& s) : std::string(s) { }
0081         /// Assignment operator
0082         ParticleConstructor& operator=(const ParticleConstructor& c) = default;
0083       };
0084       typedef std::vector<ParticleConstructor> ParticleConstructors;
0085 
0086       /// Structure describing a G4 physics constructor
0087       /**
0088        *  \author  M.Frank
0089        *  \version 1.0
0090        *  \ingroup DD4HEP_SIMULATION
0091        */
0092       class PhysicsConstructor: public std::string {
0093       public:
0094         /// Pointer to physics constructor object
0095         G4VPhysicsConstructor* pointer      { nullptr };
0096         /// Pointer to the physics list the constructor belongs
0097         G4VModularPhysicsList* physics_list { nullptr };
0098       public:
0099         /// Default constructor
0100         PhysicsConstructor() = default;
0101         /// Copy constructor
0102         PhysicsConstructor(const PhysicsConstructor& c) = default;
0103         /// Initalizing constructor
0104         PhysicsConstructor(const std::string& s) : std::string(s), pointer(0)  {}
0105         /// Assignment operator
0106         PhysicsConstructor& operator=(const PhysicsConstructor& c) = default;
0107       };
0108       typedef std::vector<PhysicsConstructor> PhysicsConstructors;
0109 
0110       PhysicsProcesses     m_processes;
0111       PhysicsProcesses     m_discreteProcesses;
0112       PhysicsConstructors  m_physics;
0113       ParticleConstructors m_particles;
0114       ParticleConstructors m_particlegroups;
0115 
0116     public:
0117       /// Standard constructor with initailization parameters
0118       Geant4PhysicsList(Geant4Context* context, const std::string& nam);
0119       /// Default destructor
0120       virtual ~Geant4PhysicsList();
0121 
0122       /// Dump content to stdout
0123       void dump();
0124 
0125       /// Install command control messenger if wanted
0126       virtual void installCommandMessenger()  override;
0127       /// Access all physics processes
0128       PhysicsProcesses& processes() {
0129         return m_processes;
0130       }
0131       /// Access all physics processes
0132       const PhysicsProcesses& processes() const {
0133         return m_processes;
0134       }
0135       /// Access processes for one particle type
0136       ParticleProcesses& processes(const std::string& part_name);
0137       /// Access processes for one particle type (CONST)
0138       const ParticleProcesses& processes(const std::string& part_name) const;
0139 
0140       /// Access all physics discrete processes
0141       PhysicsProcesses& discreteProcesses() {
0142         return m_discreteProcesses;
0143       }
0144       /// Access all physics discrete processes
0145       const PhysicsProcesses& discreteProcesses() const {
0146         return m_discreteProcesses;
0147       }
0148       /// Access discrete processes for one particle type
0149       ParticleProcesses& discreteProcesses(const std::string& part_name);
0150       /// Access discrete processes for one particle type (CONST)
0151       const ParticleProcesses& discreteProcesses(const std::string& part_name) const;
0152 
0153       /// Access physics constructor by name
0154       PhysicsConstructor physics(const std::string& name)  const;
0155       
0156       /// Access all physics particles
0157       ParticleConstructors& particles() {
0158         return m_particles;
0159       }
0160       /// Access all physics particles
0161       const ParticleConstructors& particles() const {
0162         return m_particles;
0163       }
0164       /// Access all physics particlegroups
0165       ParticleConstructors& particlegroups() {
0166         return m_particlegroups;
0167       }
0168       /// Access all physics particlegroups
0169       const ParticleConstructors& particlegroups() const {
0170         return m_particlegroups;
0171       }
0172       /// Access all physics constructors
0173       PhysicsConstructors& physics() {
0174         return m_physics;
0175       }
0176       /// Access all physics constructors
0177       const PhysicsConstructors& physics() const {
0178         return m_physics;
0179       }
0180 
0181       /// Add physics particle constructor by name
0182       void addParticleConstructor(const std::string& part_name);
0183       /// Add physics particle group constructor by name (Leptons, Bosons, Mesons, etc.)
0184       void addParticleGroup(const std::string& part_name);
0185       /// Add particle process by name with arguments
0186       void addParticleProcess(const std::string& part_name, const std::string& proc_name,
0187                               int ordAtRestDoIt,int ordAlongSteptDoIt,int ordPostStepDoIt);
0188       /// Add discrete particle process by name with arguments
0189       void addDiscreteParticleProcess(const std::string& part_name, const std::string& proc_name);
0190       /// Add PhysicsConstructor by name
0191       /** This constructor is used for intrinsic Geant4 defined physics constructors.
0192        *  Such physics constructors are only created by the factory and attached
0193        *  to the physics list object.
0194        */
0195       void addPhysicsConstructor(const std::string& physics_name);
0196       /// Add PhysicsConstructor as Geant4Action object
0197       /** The action object must be a sub-class of type G4VPhysicsConstructor.
0198        *  -- The Geant4Action object to supports properties.
0199        *  -- Specific user actions may be implemented in the 
0200        *     base class calls to 'ConstructParticle' or 'ConstructProcess'.
0201        *     Both calls are invoked by the framework when the physics list
0202        *     is configured for the use in the run-manager.
0203        */
0204       void adoptPhysicsConstructor(Geant4Action* action);
0205       /// Callback to add a physics type to the physics list
0206       G4VPhysicsConstructor* addPhysicsConstructorType(const std::string& physics_name);
0207 
0208       /// constructPhysics callback
0209       virtual void constructPhysics(G4VModularPhysicsList* physics);
0210       /// Callback to construct particles
0211       virtual void constructParticles(G4VUserPhysicsList* physics);
0212       /// Callback to construct processes (uses the G4 particle table)
0213       virtual void constructProcesses(G4VUserPhysicsList* physics);
0214       /// Enable physics list: actions necessary to be propagated to Geant4.
0215       virtual void enable(G4VUserPhysicsList* physics);
0216     };
0217 
0218     /// The implementation of the single Geant4 physics list action sequence
0219     /**
0220      * Concrete implementation of the Geant4 physics list sequence.
0221      * A list to setup the physics content in a modular form
0222      *
0223      *  \author  M.Frank
0224      *  \version 1.0
0225      *  \ingroup DD4HEP_SIMULATION
0226      */
0227     class Geant4PhysicsListActionSequence: public Geant4Action {
0228     public:
0229 
0230     protected:
0231       /// Callback sequence for G4 physics constructors
0232       CallbackSequence m_physics          { };
0233       /// Callback sequence for G4 process constructors
0234       CallbackSequence m_process          { };
0235       /// Callback sequence for G4 particle constructors
0236       CallbackSequence m_particle         { };
0237       /// The list of action objects to be called
0238       Actors<Geant4PhysicsList> m_actors  { };
0239 
0240       /// Callback to construct particle decays
0241       virtual void constructDecays(G4VUserPhysicsList* physics);
0242     public:
0243       /// Property: Flag if particle transportation is to be added
0244       bool m_transportation         { false };
0245       /// Property: Flag if particle decays are to be added
0246       bool m_decays                 { false };
0247       /// Property: verbosity level for the physics list
0248       int m_verbosity               {     1 };
0249       /// Property: Verbosity level for G4VUserPhysicsList instance (See G4VUserPhysicsList.hh for details)
0250       int m_physics_verbosity       {    -1 };
0251       /// Property: global range cut for secondary productions
0252       double m_rangecut;
0253       /// Property: Store name of basic predefined Geant4 physics list
0254       std::string m_extends;
0255 
0256     public:
0257       /// Standard constructor
0258       Geant4PhysicsListActionSequence(Geant4Context* context, const std::string& nam);
0259       /// Default destructor
0260       virtual ~Geant4PhysicsListActionSequence();
0261       /// Dump content to stdout
0262       void dump();
0263       /// Install command control messenger if wanted
0264       virtual void installCommandMessenger()  override;
0265       /// Update transportation flag
0266       void setTransportation(bool value) {
0267         m_transportation = value;
0268       }
0269       /// Access the transportation flag
0270       bool transportation() const {
0271         return m_transportation;
0272       }
0273       /// Register physics construction callback
0274       template <typename Q, typename T>
0275       void constructPhysics(Q* p, void (T::*f)(G4VModularPhysicsList*)) {
0276         m_physics.add(p, f);
0277       }
0278       /// Register process construction callback
0279       template <typename Q, typename T>
0280       void constructProcess(Q* p, void (T::*f)(G4VUserPhysicsList*)) {
0281         m_process.add(p, f);
0282       }
0283       /// Register particle construction callback
0284       template <typename Q, typename T>
0285       void constructParticle(Q* p, void (T::*f)(G4VUserPhysicsList*)) {
0286         m_particle.add(p, f);
0287       }
0288       /// Add an actor responding to all callbacks. Sequence takes ownership.
0289       void adopt(Geant4PhysicsList* action);
0290 
0291       /// Execute sequence of G4 physics constructors
0292       virtual void constructProcesses(G4VUserPhysicsList* physics);
0293       /// Execute sequence of G4 particle constructors
0294       virtual void constructParticles(G4VUserPhysicsList* physics);
0295       /// Execute sequence of G4  physics constructors
0296       virtual void constructPhysics(G4VModularPhysicsList* physics);
0297       /// Enable physics list: actions necessary to be propagated to Geant4.
0298       virtual void enable(G4VUserPhysicsList* physics);
0299       /// Extend physics list from factory:
0300       G4VUserPhysicsList* extensionList();
0301     };
0302 
0303   }    // End namespace sim
0304 }      // End namespace dd4hep
0305 
0306 #endif // DDG4_GEANT4PHYSICSLIST_H