Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4SingleParticleSource.hh
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// G4SingleParticleSource
27//
28// Class description:
29//
30// The Single Particle Source is designed to extend the functionality of the
31// G4ParticleGun class. It is designed to allow specification of input
32// particles in terms of position, direction (or angular) and energy
33// distributions. It is used by the General Particle source class
34// and it is derived from G4VPrimaryGenerator.
35//
36// Note on thread safety:
37// G4SingleParticleSource instances can be shared among threads.
38// GeneratePrimaryVertex is protected via a mutex because underlying
39// generators are not assumed to be thread-safe.
40// Note that internal status of this class is assumed to be changed by
41// master thread (typically via UI commands)
42// Only one thread should use the set-methods here.
43// If you use the set methods to set defaults in your
44// application take care that only one thread is executing them.
45// In addition take care of calling these methods before the run is started
46// Do not use these setters during the event loop
47
48// Author: Fan Lei, QinetiQ ltd.
49// Customer: ESA/ESTEC
50// History:
51// - 05/02/2004, Fan Lei - Created.
52// Based on the G4GeneralParticleSource class
53// - 06/06/2014, Andrea Dotti
54// Added a mutex to protect access to shared resources (data members)
55// --------------------------------------------------------------------
56#ifndef G4SingleParticleSource_hh
57#define G4SingleParticleSource_hh 1
58
60#include "G4ParticleMomentum.hh"
62
67#include "G4Threading.hh"
68#include "G4Cache.hh"
69
71{
72 public:
73
75 // Constructor: initializes variables and instantiates the
76 // messenger and navigator classes
77
79 // Destructor: deletes messenger and prints out run information
80
82 // Generate the particles initial parameters
83
84 inline G4SPSPosDistribution* GetPosDist() const { return posGenerator; }
85 // Return a pointer to the position distribution generator
86
87 inline G4SPSAngDistribution* GetAngDist() const { return angGenerator; }
88 // Return a pointer to the angular distribution generator
89
90 inline G4SPSEneDistribution* GetEneDist() const { return eneGenerator; }
91 // Return a pointer to the energy distribution generator
92
93 inline G4SPSRandomGenerator* GetBiasRndm() const { return biasRndm; }
94 // Return a pointer to the biased random number generator
95
96 void SetVerbosity(G4int);
97 // Set the verbosity level
98
99 void SetParticleDefinition(G4ParticleDefinition* aParticleDefinition);
101 { return definition; }
102 // Get/Set the particle definition of the primary track
103
104 inline void SetParticleCharge(G4double aCharge) { charge = aCharge; }
105 // Set the charge state of the primary track
106
107 inline void SetParticlePolarization(const G4ThreeVector& aVal)
108 { polarization = aVal; }
110 { return polarization; }
111 // Set/Get the polarization state of the primary track
112
113 inline void SetParticleTime(G4double aTime) { time = aTime; }
114 inline G4double GetParticleTime() const { return time; }
115 // Set/Get the Time
116
118 { NumberOfParticlesToBeGenerated = i; }
120 { return NumberOfParticlesToBeGenerated; }
121 // Set/get the number of particles to be generated in the primary track
122
124 { return ParticleProperties.Get().position; }
126 { return ParticleProperties.Get().momentum_direction; }
128 { return ParticleProperties.Get().energy; }
129 // Get the position, direction, and energy of the current particle
130
131 private:
132
133 G4SPSPosDistribution* posGenerator = nullptr;
134 G4SPSAngDistribution* angGenerator = nullptr;
135 G4SPSEneDistribution* eneGenerator = nullptr;
136 G4SPSRandomGenerator* biasRndm = nullptr;
137
138 // Other particle properties
139 // These need to be thread-local because a getter for them exits
140 //
141 struct part_prop_t
142 {
143 G4ParticleMomentum momentum_direction;
144 G4double energy;
146 part_prop_t();
147 };
148
149 G4Cache<part_prop_t> ParticleProperties;
150 G4int NumberOfParticlesToBeGenerated;
151 G4ParticleDefinition* definition = nullptr;
152 G4double charge;
153 G4double time;
154 G4ThreeVector polarization;
155
156 G4int verbosityLevel;
157 // Verbosity
158
160 // This can be a shared resource.
161 // This mutex is uses in GeneratePrimaryVertex
162};
163
164#endif
std::mutex G4Mutex
Definition: G4Threading.hh:81
double G4double
Definition: G4Types.hh:83
int G4int
Definition: G4Types.hh:85
value_type & Get() const
Definition: G4Cache.hh:315
G4ThreeVector GetParticlePosition() const
void SetParticleTime(G4double aTime)
void SetParticleDefinition(G4ParticleDefinition *aParticleDefinition)
G4SPSAngDistribution * GetAngDist() const
void GeneratePrimaryVertex(G4Event *evt)
const G4ThreeVector & GetParticlePolarization() const
G4SPSRandomGenerator * GetBiasRndm() const
G4SPSEneDistribution * GetEneDist() const
G4ThreeVector GetParticleMomentumDirection() const
void SetParticlePolarization(const G4ThreeVector &aVal)
void SetParticleCharge(G4double aCharge)
G4ParticleDefinition * GetParticleDefinition() const
G4SPSPosDistribution * GetPosDist() const