Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:55:24

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 = 0;
0096       public:
0097         /// Default constructor
0098         PhysicsConstructor() = default;
0099         /// Copy constructor
0100         PhysicsConstructor(const PhysicsConstructor& c) = default;
0101         /// Initalizing constructor
0102         PhysicsConstructor(const std::string& s) : std::string(s), pointer(0)  {}
0103         /// Assignment operator
0104         PhysicsConstructor& operator=(const PhysicsConstructor& c) = default;
0105       };
0106       typedef std::vector<PhysicsConstructor> PhysicsConstructors;
0107 
0108       PhysicsProcesses     m_processes;
0109       PhysicsProcesses     m_discreteProcesses;
0110       PhysicsConstructors  m_physics;
0111       ParticleConstructors m_particles;
0112       ParticleConstructors m_particlegroups;
0113 
0114     public:
0115       /// Standard constructor with initailization parameters
0116       Geant4PhysicsList(Geant4Context* context, const std::string& nam);
0117       /// Default destructor
0118       virtual ~Geant4PhysicsList();
0119 
0120       /// Dump content to stdout
0121       void dump();
0122 
0123       /// Install command control messenger if wanted
0124       virtual void installCommandMessenger();
0125       /// Access all physics processes
0126       PhysicsProcesses& processes() {
0127         return m_processes;
0128       }
0129       /// Access all physics processes
0130       const PhysicsProcesses& processes() const {
0131         return m_processes;
0132       }
0133       /// Access processes for one particle type
0134       ParticleProcesses& processes(const std::string& part_name);
0135       /// Access processes for one particle type (CONST)
0136       const ParticleProcesses& processes(const std::string& part_name) const;
0137 
0138       /// Access all physics discrete processes
0139       PhysicsProcesses& discreteProcesses() {
0140         return m_discreteProcesses;
0141       }
0142       /// Access all physics discrete processes
0143       const PhysicsProcesses& discreteProcesses() const {
0144         return m_discreteProcesses;
0145       }
0146       /// Access discrete processes for one particle type
0147       ParticleProcesses& discreteProcesses(const std::string& part_name);
0148       /// Access discrete processes for one particle type (CONST)
0149       const ParticleProcesses& discreteProcesses(const std::string& part_name) const;
0150 
0151       /// Access physics constructor by name
0152       PhysicsConstructor physics(const std::string& name)  const;
0153       
0154       /// Access all physics particles
0155       ParticleConstructors& particles() {
0156         return m_particles;
0157       }
0158       /// Access all physics particles
0159       const ParticleConstructors& particles() const {
0160         return m_particles;
0161       }
0162       /// Access all physics particlegroups
0163       ParticleConstructors& particlegroups() {
0164         return m_particlegroups;
0165       }
0166       /// Access all physics particlegroups
0167       const ParticleConstructors& particlegroups() const {
0168         return m_particlegroups;
0169       }
0170       /// Access all physics constructors
0171       PhysicsConstructors& physics() {
0172         return m_physics;
0173       }
0174       /// Access all physics constructors
0175       const PhysicsConstructors& physics() const {
0176         return m_physics;
0177       }
0178 
0179       /// Add physics particle constructor by name
0180       void addParticleConstructor(const std::string& part_name);
0181       /// Add physics particle group constructor by name (Leptons, Bosons, Mesons, etc.)
0182       void addParticleGroup(const std::string& part_name);
0183       /// Add particle process by name with arguments
0184       void addParticleProcess(const std::string& part_name, const std::string& proc_name,
0185                               int ordAtRestDoIt,int ordAlongSteptDoIt,int ordPostStepDoIt);
0186       /// Add discrete particle process by name with arguments
0187       void addDiscreteParticleProcess(const std::string& part_name, const std::string& proc_name);
0188       /// Add PhysicsConstructor by name
0189       /** This constructor is used for intrinsic Geant4 defined physics constructors.
0190        *  Such physics constructors are only created by the factory and attached
0191        *  to the physics list object.
0192        */
0193       void addPhysicsConstructor(const std::string& physics_name);
0194       /// Add PhysicsConstructor as Geant4Action object
0195       /** The action object must be a sub-class of type G4VPhysicsConstructor.
0196        *  -- The Geant4Action object to supports properties.
0197        *  -- Specific user actions may be implemented in the 
0198        *     base class calls to 'ConstructParticle' or 'ConstructProcess'.
0199        *     Both calls are invoked by the framework when the physics list
0200        *     is configured for the use in the run-manager.
0201        */
0202       void adoptPhysicsConstructor(Geant4Action* action);
0203 
0204       /// constructPhysics callback
0205       virtual void constructPhysics(G4VModularPhysicsList* physics);
0206       /// Callback to construct particles
0207       virtual void constructParticles(G4VUserPhysicsList* physics);
0208       /// Callback to construct processes (uses the G4 particle table)
0209       virtual void constructProcesses(G4VUserPhysicsList* physics);
0210       /// Enable physics list: actions necessary to be propagated to Geant4.
0211       virtual void enable(G4VUserPhysicsList* physics);
0212     };
0213 
0214     /// The implementation of the single Geant4 physics list action sequence
0215     /**
0216      * Concrete implementation of the Geant4 physics list sequence.
0217      * A list to setup the physics content in a modular form
0218      *
0219      *  \author  M.Frank
0220      *  \version 1.0
0221      *  \ingroup DD4HEP_SIMULATION
0222      */
0223     class Geant4PhysicsListActionSequence: public Geant4Action {
0224     public:
0225 
0226     protected:
0227       /// Callback sequence for G4 physics constructors
0228       CallbackSequence m_physics;
0229       /// Callback sequence for G4 process constructors
0230       CallbackSequence m_process;
0231       /// Callback sequence for G4 particle constructors
0232       CallbackSequence m_particle;
0233       /// The list of action objects to be called
0234       Actors<Geant4PhysicsList> m_actors;
0235 
0236       /// Callback to construct particle decays
0237       virtual void constructDecays(G4VUserPhysicsList* physics);
0238     public:
0239       /// Flag if particle transportation is to be added
0240       bool m_transportation  { false };
0241       /// Flag if particle decays are to be added
0242       bool m_decays          { false };
0243       /// Property: Store name of basic predefined Geant4 physics list
0244       std::string m_extends;
0245       /// global range cut for secondary productions
0246       double m_rangecut;
0247 
0248     public:
0249       /// Standard constructor
0250       Geant4PhysicsListActionSequence(Geant4Context* context, const std::string& nam);
0251       /// Default destructor
0252       virtual ~Geant4PhysicsListActionSequence();
0253       /// Dump content to stdout
0254       void dump();
0255       /// Install command control messenger if wanted
0256       virtual void installCommandMessenger();
0257       /// Update transportation flag
0258       void setTransportation(bool value) {
0259         m_transportation = value;
0260       }
0261       /// Access the transportation flag
0262       bool transportation() const {
0263         return m_transportation;
0264       }
0265       /// Register physics construction callback
0266       template <typename Q, typename T>
0267       void constructPhysics(Q* p, void (T::*f)(G4VModularPhysicsList*)) {
0268         m_physics.add(p, f);
0269       }
0270       /// Register process construction callback
0271       template <typename Q, typename T>
0272       void constructProcess(Q* p, void (T::*f)(G4VUserPhysicsList*)) {
0273         m_process.add(p, f);
0274       }
0275       /// Register particle construction callback
0276       template <typename Q, typename T>
0277       void constructParticle(Q* p, void (T::*f)(G4VUserPhysicsList*)) {
0278         m_particle.add(p, f);
0279       }
0280       /// Add an actor responding to all callbacks. Sequence takes ownership.
0281       void adopt(Geant4PhysicsList* action);
0282 
0283       /// Execute sequence of G4 physics constructors
0284       virtual void constructProcesses(G4VUserPhysicsList* physics);
0285       /// Execute sequence of G4 particle constructors
0286       virtual void constructParticles(G4VUserPhysicsList* physics);
0287       /// Execute sequence of G4  physics constructors
0288       virtual void constructPhysics(G4VModularPhysicsList* physics);
0289       /// Enable physics list: actions necessary to be propagated to Geant4.
0290       virtual void enable(G4VUserPhysicsList* physics);
0291       /// Extend physics list from factory:
0292       G4VUserPhysicsList* extensionList();
0293     };
0294 
0295   }    // End namespace sim
0296 }      // End namespace dd4hep
0297 
0298 #endif // DDG4_GEANT4PHYSICSLIST_H