Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:05

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // G4SingleParticleSource
0027 //
0028 // Class description:
0029 //
0030 // The Single Particle Source is designed to extend the functionality of the
0031 // G4ParticleGun class. It is designed to allow specification of input
0032 // particles in terms of position, direction (or angular) and energy
0033 // distributions. It is used by the General Particle source class
0034 // and it is derived from G4VPrimaryGenerator.
0035 //
0036 // Note on thread safety:
0037 // G4SingleParticleSource instances can be shared among threads.
0038 // GeneratePrimaryVertex is protected via a mutex because underlying
0039 // generators are not assumed to be thread-safe.
0040 // Note that internal status of this class is assumed to be changed by
0041 // master thread (typically via UI commands)
0042 // Only one thread should use the set-methods here.
0043 // If you use the set methods to set defaults in your
0044 // application take care that only one thread is executing them.
0045 // In addition take care of calling these methods before the run is started
0046 // Do not use these setters during the event loop
0047 
0048 // Author: Fan Lei, QinetiQ ltd.
0049 // Customer: ESA/ESTEC
0050 // History:
0051 // - 05/02/2004, Fan Lei - Created.
0052 //     Based on the G4GeneralParticleSource class
0053 // - 06/06/2014, Andrea Dotti
0054 //     Added a mutex to protect access to shared resources (data members)
0055 // --------------------------------------------------------------------
0056 #ifndef G4SingleParticleSource_hh
0057 #define G4SingleParticleSource_hh 1
0058 
0059 #include "G4VPrimaryGenerator.hh"
0060 #include "G4ParticleMomentum.hh"
0061 #include "G4ParticleDefinition.hh"
0062 
0063 #include "G4SPSPosDistribution.hh"
0064 #include "G4SPSAngDistribution.hh"
0065 #include "G4SPSEneDistribution.hh"
0066 #include "G4SPSRandomGenerator.hh"
0067 #include "G4Threading.hh"
0068 #include "G4Cache.hh"
0069 
0070 class G4SingleParticleSource : public G4VPrimaryGenerator
0071 {
0072   public:
0073 
0074     G4SingleParticleSource();
0075       // Constructor: initializes variables and instantiates the 
0076       // messenger and navigator classes
0077 
0078    ~G4SingleParticleSource() override;
0079       // Destructor: deletes messenger and prints out run information
0080 
0081     void GeneratePrimaryVertex(G4Event *evt) override;
0082       // Generate the particles initial parameters
0083 
0084     inline G4SPSPosDistribution* GetPosDist() const { return posGenerator; }
0085       // Return a pointer to the position distribution generator
0086 
0087     inline G4SPSAngDistribution* GetAngDist() const { return angGenerator; }
0088       // Return a pointer to the angular distribution generator
0089 
0090     inline G4SPSEneDistribution* GetEneDist() const { return eneGenerator; }
0091       // Return a pointer to the energy distribution generator
0092 
0093     inline G4SPSRandomGenerator* GetBiasRndm() const { return biasRndm; }
0094       // Return a pointer to the biased random number generator
0095 
0096     void SetVerbosity(G4int);
0097       // Set the verbosity level
0098 
0099     void SetParticleDefinition(G4ParticleDefinition* aParticleDefinition);
0100     inline G4ParticleDefinition* GetParticleDefinition() const
0101            { return definition; }
0102       // Get/Set the particle definition of the primary track
0103 
0104     inline void SetParticleCharge(G4double aCharge) { charge = aCharge; }
0105       // Set the charge state of the primary track
0106 
0107     inline void SetParticlePolarization(const G4ThreeVector& aVal)
0108            { polarization = aVal; }
0109     inline const G4ThreeVector& GetParticlePolarization() const
0110            { return polarization; }
0111       // Set/Get the polarization state of the primary track
0112 
0113     inline void SetParticleTime(G4double aTime) { time = aTime; }
0114     inline G4double GetParticleTime() const { return time; }
0115       // Set/Get the Time
0116 
0117     inline void SetNumberOfParticles(G4int i)
0118            { NumberOfParticlesToBeGenerated = i; }
0119     inline G4int GetNumberOfParticles() const
0120            { return NumberOfParticlesToBeGenerated; }
0121       // Set/get the number of particles to be generated in the primary track
0122 
0123     inline G4ThreeVector GetParticlePosition() const
0124            { return ParticleProperties.Get().position; }
0125     inline G4ThreeVector GetParticleMomentumDirection() const
0126            { return ParticleProperties.Get().momentum_direction; }
0127     inline G4double GetParticleEnergy() const
0128            { return ParticleProperties.Get().energy; }
0129       // Get the position, direction, and energy of the current particle 
0130 
0131   private:
0132 
0133     G4SPSPosDistribution* posGenerator = nullptr;
0134     G4SPSAngDistribution* angGenerator = nullptr;
0135     G4SPSEneDistribution* eneGenerator = nullptr;
0136     G4SPSRandomGenerator* biasRndm = nullptr;
0137 
0138     // Other particle properties
0139     // These need to be thread-local because a getter for them exits
0140     //
0141     struct part_prop_t
0142     {
0143       G4ParticleMomentum momentum_direction;
0144       G4double energy;
0145       G4ThreeVector position;
0146       part_prop_t();
0147     };
0148 
0149     G4Cache<part_prop_t> ParticleProperties;
0150     G4int NumberOfParticlesToBeGenerated;
0151     G4ParticleDefinition* definition = nullptr;
0152     G4double charge;
0153     G4double time;
0154     G4ThreeVector polarization;
0155 
0156     G4int verbosityLevel;
0157       // Verbosity
0158 
0159     G4Mutex mutex;
0160       // This can be a shared resource.
0161       // This mutex is uses in GeneratePrimaryVertex
0162 };
0163 
0164 #endif