Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4GeneralParticleSource.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// G4GeneralParticleSource
27//
28// Class Description:
29//
30// The General Particle Source is designed to replace the G4ParticleGun class.
31// It is designed to allow specification of mutiple particle sources, each with
32// independent definitions of particle type, position, direction (or angular)
33// and energy distributions.
34
35// Author: Fan Lei, QinetiQ ltd
36// Customer: ESA/ESTEC
37// Version: 2.0
38// History:
39// - 05/02/2004, F.Lei - Version 2.0. Created.
40// - 26/10/2004, F.Lei - Added the Multiple_vertex capability.
41// - 25/03/2014, A.Green - Various changes to use the new class
42// G4GeneralParticleSourceData, mostly just transparent wrappers
43// around the thread safe object.
44// --------------------------------------------------------------------
45#ifndef G4GeneralParticleSource_hh
46#define G4GeneralParticleSource_hh 1
47
48#include "globals.hh"
49#include <vector>
50
51#include "G4Event.hh"
55
57
59{
60 public:
61
63 // Initialize variables and instantiates the messenger and
64 // generator classes
65
67 // Delete messenger and others
68
70
71 inline G4int GetNumberofSource() { return GPSData->GetSourceVectorSize(); }
72 // Return the number of particle gun defined
73
74 void ListSource();
75 // List the particle guns defined
76
78 // Set the current gun to the specified one so its definition
79 // can be changed
80
82 // Change the current particle gun strength
83
85 { return GPSData->GetCurrentSource(); }
86 // Return the pointer to current particle gun
88 { return GPSData->GetCurrentSourceIdx(); }
89 // Return the index of the current particle gun
91 { return GPSData->GetIntensity(GetCurrentSourceIndex()); }
92 // Return the strength of the current gun
93
94 void ClearAll();
95 // Remove all defined particle gun
96 void AddaSource (G4double);
97 // Add a new particle gun with the specified strength
98 void DeleteaSource(G4int);
99 // Delete the specified particle gun
100
101 inline void SetVerbosity(G4int i) { GPSData->SetVerbosityAllSources(i); }
102 // Set the verbosity level.
103
104 inline void SetMultipleVertex(G4bool av) { GPSData->SetMultipleVertex(av); }
105 // Set if multiple vertex per event.
106
107 inline void SetFlatSampling(G4bool av)
108 { GPSData->SetFlatSampling(av); normalised = false;}
109 // Set if flat_sampling is applied in multiple source case
110
112 { GPSData->GetCurrentSource()->SetParticleDefinition(aPDef); }
114 { return GPSData->GetCurrentSource()->GetParticleDefinition(); }
115 // Set/Get the particle definition of the primary track
116
117 inline void SetParticleCharge(G4double aCharge)
118 { GPSData->GetCurrentSource()->SetParticleCharge(aCharge); }
119 // Set the charge state of the primary track
120
122 { GPSData->GetCurrentSource()->SetParticlePolarization(aVal); }
124 { return GPSData->GetCurrentSource()->GetParticlePolarization(); }
125 // Set/Get polarization state of the primary track
126
127 inline void SetParticleTime(G4double aTime)
128 { GPSData->GetCurrentSource()->SetParticleTime(aTime); }
130 { return GPSData->GetCurrentSource()->GetParticleTime(); }
131 // Set/Get the Time.
132
134 { GPSData->GetCurrentSource()->SetNumberOfParticles(i); }
136 { return GPSData->GetCurrentSource()->GetNumberOfParticles(); }
137 // Set/Get the number of particles to be generated in the primary track
138
140 { return GPSData->GetCurrentSource()->GetParticlePosition(); }
142 { return GPSData->GetCurrentSource()->GetParticleMomentumDirection(); }
144 { return GPSData->GetCurrentSource()->GetParticleEnergy(); }
145 // Get the position, direction, and energy of the current particle
146
147 private:
148
149 void IntensityNormalization();
150
151 private:
152
153 G4bool normalised = false;
154 // Helper Boolean, used to reduce number of locks
155 // at run time (see GeneratePrimaryVertex)
156
157 G4GeneralParticleSourceMessenger* theMessenger = nullptr;
158 // Note this is a shared resource among MT workers
159 G4GeneralParticleSourceData* GPSData = nullptr;
160 // Note this is a shared resource among MT workers
161
162/** Andrea Dotti Feb 2015
163 * GPS messenger design requires some explanation for what distributions
164 * parameters are concerned : Each thread has its own GPS
165 * since primary generation is a user action.
166 * However to save memory the underlying structures that provide the
167 * GPS functionalities ( the G4SPS*Distribution classes and the
168 * G4SPSRandomGenerator class)
169 * are shared among threads. This implies that modifying parameters of sources
170 * requires some attention:
171 * 1- Only one thread should change source parameters.
172 * 2- Changing of parameters can happen only between runs, when is guaranteed
173 * that no thread is accessing them
174 * 2- UI commands require that even if messenger is instantiated in a thread
175 * the commands are executed in the master (this is possible since V10.1)
176 * The simplest solution is to use UI commands to change GPS parameters and
177 * avoid C++ APIs. If this is inevitable a simple solution is to instantiate
178 * an instance of G4GeneralParticleSource explicitly in the master thread
179 * (for example in G4VUserActionInitialization::BuildForMaster() and set the
180 * defaults parameter there).
181 */
182
183};
184
185#endif
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
G4SingleParticleSource * GetCurrentSource(G4int idx)
G4double GetIntensity(G4int idx) const
void SetParticleTime(G4double aTime)
void SetParticleDefinition(G4ParticleDefinition *aPDef)
G4double GetCurrentSourceIntensity() const
G4SingleParticleSource * GetCurrentSource() const
G4ThreeVector GetParticleMomentumDirection() const
G4ThreeVector GetParticlePolarization() const
void SetParticlePolarization(G4ThreeVector aVal)
void SetParticleCharge(G4double aCharge)
G4ParticleDefinition * GetParticleDefinition() const
G4ThreeVector GetParticlePosition() const
G4ThreeVector GetParticlePosition() const
void SetParticleTime(G4double aTime)
void SetParticleDefinition(G4ParticleDefinition *aParticleDefinition)
const G4ThreeVector & GetParticlePolarization() const
G4ThreeVector GetParticleMomentumDirection() const
void SetParticlePolarization(const G4ThreeVector &aVal)
void SetParticleCharge(G4double aCharge)
G4ParticleDefinition * GetParticleDefinition() const