Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:12:42

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_GEANT4PRIMARY_H
0015 #define DDG4_GEANT4PRIMARY_H
0016 
0017 // Framework include files
0018 #include <DD4hep/Memory.h>
0019 #include <DDG4/Geant4Vertex.h>
0020 #include <DDG4/Geant4Particle.h>
0021 
0022 // C/C++ include files
0023 #include <set>
0024 #include <map>
0025 #include <vector>
0026 #include <memory>
0027 
0028 // Forward declarations
0029 class G4PrimaryParticle;
0030 
0031 /// Namespace for the AIDA detector description toolkit
0032 namespace dd4hep {
0033 
0034   /// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit
0035   namespace sim {
0036 
0037     // Forward declarations
0038     class Geant4Particle;
0039     class Geant4Vertex;
0040 
0041     /// Base structure to extend primary information with user data
0042     /**
0043      *  \author  M.Frank
0044      *  \version 1.0
0045      *  \ingroup DD4HEP_SIMULATION
0046      */
0047     class PrimaryExtension  {
0048     public:
0049       /// Default constructor
0050       PrimaryExtension() = default;
0051       /// Default destructor
0052       virtual ~PrimaryExtension();
0053     };
0054 
0055     /// Data structure to map primaries to particles.
0056     /**
0057      *  This data structure is added to the Geant4Event data extensions
0058      *  by the Geant4GenerationInit action.
0059      *
0060      *  \author  M.Frank
0061      *  \version 1.0
0062      *  \ingroup DD4HEP_SIMULATION
0063      */
0064     class Geant4PrimaryMap  {
0065     public:
0066       typedef std::map<const G4PrimaryParticle*,Geant4Particle*> Primaries;
0067     private:
0068       /// Mapping of primary particles of this event
0069       Primaries       m_primaryMap; //! not persistent
0070 
0071     public:
0072       /// Default constructor
0073       Geant4PrimaryMap() = default;
0074       /// Default destructor
0075       virtual ~Geant4PrimaryMap();
0076       /// Add a new object pair (G4 primary particle, DDG4 particle) into the maps
0077       void insert(G4PrimaryParticle* g4_particle,Geant4Particle* particle);
0078       /// Access DDG4 particle by G4 primary particle
0079       Geant4Particle* get(const G4PrimaryParticle* particle);
0080       /// Access DDG4 particle by G4 primary particle (const)
0081       const Geant4Particle* get(const G4PrimaryParticle* particle) const;
0082       /// Access primary map directly
0083       Primaries& primaries()  {  return m_primaryMap;  }
0084       /// Access primary map directly (const)
0085       const Primaries& primaries() const  {  return m_primaryMap;  }
0086     };
0087 
0088 
0089     /// Class modelling a single interaction with multiple primary vertices and particles
0090     /*
0091      *  \author  M.Frank
0092      *  \version 1.0
0093      *  \ingroup DD4HEP_SIMULATION
0094      */
0095     class Geant4PrimaryInteraction   {
0096     private:
0097       /// Copy constructor
0098       Geant4PrimaryInteraction(const Geant4PrimaryInteraction& c) = delete;
0099       /// Assignment operator
0100       Geant4PrimaryInteraction& operator=(const Geant4PrimaryInteraction& c) = delete;
0101 
0102     public:
0103       typedef Geant4Particle                     Particle;
0104       typedef Geant4Vertex                       Vertex;
0105       typedef std::map<int,Particle*>            ParticleMap;
0106       typedef std::map<int,std::vector<Vertex*>> VertexMap;
0107       typedef dd4hep_ptr<PrimaryExtension>       ExtensionHandle;
0108 
0109       /// The map of primary vertices for the particles.
0110       VertexMap       vertices;
0111       /// The map of particles participating in this primary interaction
0112       ParticleMap     particles;
0113       /// User data extension if required
0114       ExtensionHandle extension;
0115       /// User mask to flag the interaction. Also unique identifier
0116       int             mask = 0;
0117       /// Flag that the event is locked for G4 native generators
0118       int             locked = 0;
0119       /// Next PID indentifier
0120       int             next_particle_identifier = -1;
0121       
0122     public:
0123       /// Default constructor
0124       Geant4PrimaryInteraction() = default;
0125       /// Default destructor
0126       virtual ~Geant4PrimaryInteraction();
0127       /// Access a new particle identifier within the interaction
0128       int nextPID();
0129       /// Set the next PID value
0130       void setNextPID(int value);
0131       /// Apply mask to all contained vertices (max. 1) and particles
0132       bool applyMask();
0133     };
0134 
0135     /// Class modelling a complete primary event with multiple interactions
0136     /*
0137      *  Multiple interactions allow a simple handling of overlay events
0138      *
0139      *  \author  M.Frank
0140      *  \version 1.0
0141      *  \ingroup DD4HEP_SIMULATION
0142      */
0143     class Geant4PrimaryEvent   {
0144     private:
0145       /// Copy constructor
0146       Geant4PrimaryEvent(const Geant4PrimaryEvent& c) = delete;
0147       /// Assignment operator
0148       Geant4PrimaryEvent& operator=(const Geant4PrimaryEvent& c) = delete;
0149 
0150     public:
0151       typedef Geant4PrimaryInteraction     Interaction;
0152       typedef std::map<int,Interaction*>   Interactions;
0153       typedef dd4hep_ptr<PrimaryExtension> ExtensionHandle;
0154 
0155     protected:
0156       /// Set of primary interactions
0157       Interactions    m_interactions;
0158 
0159     public:
0160       /// User data extension if required
0161       ExtensionHandle extension;
0162 
0163     public:
0164       /// Default constructor
0165       Geant4PrimaryEvent() = default;
0166       /// Default destructor
0167       virtual ~Geant4PrimaryEvent();
0168       /// Add a new interaction object to the event
0169       void add(int id, Geant4PrimaryInteraction* interaction);
0170       /// Retrieve an interaction by its ID
0171       Geant4PrimaryInteraction* get(int id) const;
0172       /// Number of interaction contained in the primary event
0173       size_t size()  const      {        return m_interactions.size();      }
0174       /// Retrieve all interactions
0175       std::vector<Geant4PrimaryInteraction*> interactions() const;
0176     };
0177 
0178   }    // End namespace sim
0179 }      // End namespace dd4hep
0180 #endif // DDG4_GEANT4PRIMARY_H