Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4GeneralParticleSource Class Reference

#include <G4GeneralParticleSource.hh>

+ Inheritance diagram for G4GeneralParticleSource:

Public Member Functions

 G4GeneralParticleSource ()
 
 ~G4GeneralParticleSource () override
 
void GeneratePrimaryVertex (G4Event *) override
 
G4int GetNumberofSource ()
 
void ListSource ()
 
void SetCurrentSourceto (G4int)
 
void SetCurrentSourceIntensity (G4double)
 
G4SingleParticleSourceGetCurrentSource () const
 
G4int GetCurrentSourceIndex () const
 
G4double GetCurrentSourceIntensity () const
 
void ClearAll ()
 
void AddaSource (G4double)
 
void DeleteaSource (G4int)
 
void SetVerbosity (G4int i)
 
void SetMultipleVertex (G4bool av)
 
void SetFlatSampling (G4bool av)
 
void SetParticleDefinition (G4ParticleDefinition *aPDef)
 
G4ParticleDefinitionGetParticleDefinition () const
 
void SetParticleCharge (G4double aCharge)
 
void SetParticlePolarization (G4ThreeVector aVal)
 
G4ThreeVector GetParticlePolarization () const
 
void SetParticleTime (G4double aTime)
 
G4double GetParticleTime () const
 
void SetNumberOfParticles (G4int i)
 
G4int GetNumberOfParticles () const
 
G4ThreeVector GetParticlePosition () const
 
G4ThreeVector GetParticleMomentumDirection () const
 
G4double GetParticleEnergy () const
 
- Public Member Functions inherited from G4VPrimaryGenerator
 G4VPrimaryGenerator ()=default
 
virtual ~G4VPrimaryGenerator ()=default
 
G4ThreeVector GetParticlePosition ()
 
G4double GetParticleTime ()
 
void SetParticlePosition (G4ThreeVector aPosition)
 
void SetParticleTime (G4double aTime)
 

Additional Inherited Members

- Static Public Member Functions inherited from G4VPrimaryGenerator
static G4bool CheckVertexInsideWorld (const G4ThreeVector &pos)
 
- Protected Attributes inherited from G4VPrimaryGenerator
G4ThreeVector particle_position
 
G4double particle_time = 0.0
 

Detailed Description

Definition at line 58 of file G4GeneralParticleSource.hh.

Constructor & Destructor Documentation

◆ G4GeneralParticleSource()

G4GeneralParticleSource::G4GeneralParticleSource ( )

Definition at line 49 of file G4GeneralParticleSource.cc.

50{
52 // currentSource = GPSData->GetCurrentSource();
53 // currentSourceIdx = G4int(GPSData->GetSourceVectorSize() - 1);
54
55 // Messenger is special, only a worker should instantiate it.
56 // Singleton pattern
57 //
59
60 // Some initialization should be done only once
61 //
62 G4AutoLock l(&messangerInit);
63 static G4bool onlyOnce = false;
64 if ( !onlyOnce )
65 {
66 theMessenger->SetParticleGun(GPSData->GetCurrentSource());
67 IntensityNormalization();
68 onlyOnce = true;
69 }
70}
bool G4bool
Definition G4Types.hh:86
G4SingleParticleSource * GetCurrentSource(G4int idx)
static G4GeneralParticleSourceData * Instance()
static G4GeneralParticleSourceMessenger * GetInstance(G4GeneralParticleSource *)
void SetParticleGun(G4SingleParticleSource *fpg)

◆ ~G4GeneralParticleSource()

G4GeneralParticleSource::~G4GeneralParticleSource ( )
override

Definition at line 72 of file G4GeneralParticleSource.cc.

73{
74 theMessenger->Destroy();
75}

Member Function Documentation

◆ AddaSource()

void G4GeneralParticleSource::AddaSource ( G4double aV)

Definition at line 77 of file G4GeneralParticleSource.cc.

78{
79 GPSData->Lock();
80
81 GPSData->AddASource(aV);
82 theMessenger->SetParticleGun(GPSData->GetCurrentSource());
83
84 // TODO: But do we really normalize here after each source?
85 IntensityNormalization();
86
87 GPSData->Unlock();
88}

Referenced by G4GeneralParticleSourceMessenger::SetNewValue().

◆ ClearAll()

void G4GeneralParticleSource::ClearAll ( )

Definition at line 158 of file G4GeneralParticleSource.cc.

159{
160 GPSData->ClearSources();
161 normalised=GPSData->Normalised();
162}

Referenced by G4GeneralParticleSourceMessenger::SetNewValue().

◆ DeleteaSource()

void G4GeneralParticleSource::DeleteaSource ( G4int aV)

Definition at line 164 of file G4GeneralParticleSource.cc.

165{
166 G4int id = aV;
167 if ( id <= GPSData->GetIntensityVectorSize() )
168 {
169 GPSData->DeleteASource(aV);
170 normalised=GPSData->Normalised();
171 }
172 else
173 {
174 G4cout << " source index is invalid " << G4endl;
175 G4cout << " it shall be <= "
176 << GPSData->GetIntensityVectorSize() << G4endl;
177 }
178}
int G4int
Definition G4Types.hh:85
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout

Referenced by G4GeneralParticleSourceMessenger::SetNewValue().

◆ GeneratePrimaryVertex()

void G4GeneralParticleSource::GeneratePrimaryVertex ( G4Event * evt)
overridevirtual

Implements G4VPrimaryGenerator.

Definition at line 180 of file G4GeneralParticleSource.cc.

181{
182 if (!GPSData->GetMultipleVertex())
183 {
184 G4SingleParticleSource* currentSource = GPSData->GetCurrentSource();
185 if (GPSData->GetIntensityVectorSize() > 1)
186 {
187 // Try to minimize locks
188 if (! normalised )
189 {
190 // According to local variable, normalization is needed
191 // Check with underlying shared resource, another
192 // thread could have already normalized this
193 GPSData->Lock();
194 G4bool norm = GPSData->Normalised();
195 if (!norm)
196 {
197 IntensityNormalization();
198 }
199 // This takes care of the case in which the local variable
200 // is False and the underlying resource is true.
201 normalised = GPSData->Normalised();
202 GPSData->Unlock();
203 }
204 G4double rndm = G4UniformRand();
205 G4int i = 0 ;
206 if (! GPSData->GetFlatSampling() )
207 {
208 while ( rndm > GPSData->GetSourceProbability(i) ) ++i;
209 currentSource = GPSData->GetCurrentSource(i);
210 }
211 else
212 {
213 i = G4int (GPSData->GetIntensityVectorSize()*rndm);
214 currentSource = GPSData->GetCurrentSource(i);
215 }
216 }
217 currentSource->GeneratePrimaryVertex(evt);
218 }
219 else
220 {
221 for (G4int i = 0; i < GPSData->GetIntensityVectorSize(); ++i)
222 {
223 GPSData->GetCurrentSource(i)->GeneratePrimaryVertex(evt);
224 }
225 }
226}
double G4double
Definition G4Types.hh:83
#define G4UniformRand()
Definition Randomize.hh:52
G4double GetSourceProbability(G4int idx) const
void GeneratePrimaryVertex(G4Event *evt) override

◆ GetCurrentSource()

G4SingleParticleSource * G4GeneralParticleSource::GetCurrentSource ( ) const
inline

Definition at line 84 of file G4GeneralParticleSource.hh.

85 { return GPSData->GetCurrentSource(); }

◆ GetCurrentSourceIndex()

G4int G4GeneralParticleSource::GetCurrentSourceIndex ( ) const
inline

◆ GetCurrentSourceIntensity()

G4double G4GeneralParticleSource::GetCurrentSourceIntensity ( ) const
inline

Definition at line 90 of file G4GeneralParticleSource.hh.

91 { return GPSData->GetIntensity(GetCurrentSourceIndex()); }

Referenced by G4GeneralParticleSourceMessenger::SetNewValue().

◆ GetNumberOfParticles()

G4int G4GeneralParticleSource::GetNumberOfParticles ( ) const
inline

Definition at line 135 of file G4GeneralParticleSource.hh.

136 { return GPSData->GetCurrentSource()->GetNumberOfParticles(); }

◆ GetNumberofSource()

G4int G4GeneralParticleSource::GetNumberofSource ( )
inline

Definition at line 71 of file G4GeneralParticleSource.hh.

71{ return GPSData->GetSourceVectorSize(); }

Referenced by G4GeneralParticleSourceMessenger::SetNewValue().

◆ GetParticleDefinition()

G4ParticleDefinition * G4GeneralParticleSource::GetParticleDefinition ( ) const
inline

Definition at line 113 of file G4GeneralParticleSource.hh.

114 { return GPSData->GetCurrentSource()->GetParticleDefinition(); }
G4ParticleDefinition * GetParticleDefinition() const

◆ GetParticleEnergy()

G4double G4GeneralParticleSource::GetParticleEnergy ( ) const
inline

Definition at line 143 of file G4GeneralParticleSource.hh.

144 { return GPSData->GetCurrentSource()->GetParticleEnergy(); }

◆ GetParticleMomentumDirection()

G4ThreeVector G4GeneralParticleSource::GetParticleMomentumDirection ( ) const
inline

Definition at line 141 of file G4GeneralParticleSource.hh.

142 { return GPSData->GetCurrentSource()->GetParticleMomentumDirection(); }
G4ThreeVector GetParticleMomentumDirection() const

◆ GetParticlePolarization()

G4ThreeVector G4GeneralParticleSource::GetParticlePolarization ( ) const
inline

Definition at line 123 of file G4GeneralParticleSource.hh.

124 { return GPSData->GetCurrentSource()->GetParticlePolarization(); }
const G4ThreeVector & GetParticlePolarization() const

◆ GetParticlePosition()

G4ThreeVector G4GeneralParticleSource::GetParticlePosition ( ) const
inline

Definition at line 139 of file G4GeneralParticleSource.hh.

140 { return GPSData->GetCurrentSource()->GetParticlePosition(); }
G4ThreeVector GetParticlePosition() const

◆ GetParticleTime()

G4double G4GeneralParticleSource::GetParticleTime ( ) const
inline

Definition at line 129 of file G4GeneralParticleSource.hh.

130 { return GPSData->GetCurrentSource()->GetParticleTime(); }

◆ ListSource()

void G4GeneralParticleSource::ListSource ( )

Definition at line 96 of file G4GeneralParticleSource.cc.

97{
98 G4cout << "The number of particle sources is: "
99 << GPSData->GetIntensityVectorSize() << G4endl;
100 G4cout << " Multiple Vertex sources: " << GPSData->GetMultipleVertex();
101 G4cout << " Flat Sampling flag: " << GPSData->GetFlatSampling() << G4endl;
102 const G4int currentIdx = GPSData->GetCurrentSourceIdx();
103 for(G4int i=0; i<GPSData->GetIntensityVectorSize(); ++i)
104 {
105 G4cout << "\tsource " << i << " with intensity: "
106 << GPSData->GetIntensity(i) << G4endl;
107 const G4SingleParticleSource* thisSrc = GPSData->GetCurrentSource(i);
108 G4cout << " \t\tNum Particles: "<<thisSrc->GetNumberOfParticles()
109 << "; Particle type: "
110 << thisSrc->GetParticleDefinition()->GetParticleName() << G4endl;
111 G4cout << " \t\tEnergy: "
112 << G4BestUnit(thisSrc->GetEneDist()->GetMonoEnergy(),"Energy") << G4endl;
113 G4cout << " \t\tDirection: "
114 << thisSrc->GetAngDist()->GetDirection() << "; Position: ";
115 G4cout << G4BestUnit(thisSrc->GetPosDist()->GetCentreCoords(),"Length")
116 << G4endl;
117 G4cout << " \t\tAngular Distribution: "
118 << thisSrc->GetAngDist()->GetDistType() << G4endl;
119 G4cout << " \t\tEnergy Distribution: "
120 << thisSrc->GetEneDist()->GetEnergyDisType() << G4endl;
121 G4cout << " \t\tPosition Distribution Type: "
122 << thisSrc->GetPosDist()->GetPosDisType();
123 G4cout << "; Position Shape: "
124 << thisSrc->GetPosDist()->GetPosDisShape() << G4endl;
125 }
126
127 // Set back previous source
128 GPSData->GetCurrentSource(currentIdx);
129}
#define G4BestUnit(a, b)
const G4String & GetParticleName() const
const G4String & GetEnergyDisType()
const G4ThreeVector & GetCentreCoords() const
const G4String & GetPosDisType() const
const G4String & GetPosDisShape() const
G4SPSAngDistribution * GetAngDist() const
G4SPSEneDistribution * GetEneDist() const
G4SPSPosDistribution * GetPosDist() const

Referenced by G4GeneralParticleSourceMessenger::SetNewValue().

◆ SetCurrentSourceIntensity()

void G4GeneralParticleSource::SetCurrentSourceIntensity ( G4double aV)

Definition at line 150 of file G4GeneralParticleSource.cc.

151{
152 GPSData->Lock();
153 GPSData->SetCurrentSourceIntensity(aV);
154 GPSData->Unlock();
155 normalised = GPSData->Normalised();
156}

Referenced by G4GeneralParticleSourceMessenger::SetNewValue().

◆ SetCurrentSourceto()

void G4GeneralParticleSource::SetCurrentSourceto ( G4int aV)

Definition at line 131 of file G4GeneralParticleSource.cc.

132{
133 G4int id = aV;
134 if ( id < GPSData->GetIntensityVectorSize() )
135 {
136 // currentSourceIdx = aV;
137 // currentSource = GPSData->GetCurrentSource(id);
138 theMessenger->SetParticleGun(GPSData->GetCurrentSource(id));
139 }
140 else
141 {
143 msg << "Trying to set source to index " << aV << " but only "
144 << GPSData->GetIntensityVectorSize() << " sources are defined.";
145 G4Exception("G4GeneralParticleSoruce::SetCurrentSourceto", "G4GPS004",
146 FatalException, msg);
147 }
148}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription

Referenced by G4GeneralParticleSourceMessenger::SetNewValue().

◆ SetFlatSampling()

void G4GeneralParticleSource::SetFlatSampling ( G4bool av)
inline

Definition at line 107 of file G4GeneralParticleSource.hh.

108 { GPSData->SetFlatSampling(av); normalised = false;}

Referenced by G4GeneralParticleSourceMessenger::SetNewValue().

◆ SetMultipleVertex()

void G4GeneralParticleSource::SetMultipleVertex ( G4bool av)
inline

Definition at line 104 of file G4GeneralParticleSource.hh.

104{ GPSData->SetMultipleVertex(av); }

Referenced by G4GeneralParticleSourceMessenger::SetNewValue().

◆ SetNumberOfParticles()

void G4GeneralParticleSource::SetNumberOfParticles ( G4int i)
inline

Definition at line 133 of file G4GeneralParticleSource.hh.

134 { GPSData->GetCurrentSource()->SetNumberOfParticles(i); }

◆ SetParticleCharge()

void G4GeneralParticleSource::SetParticleCharge ( G4double aCharge)
inline

Definition at line 117 of file G4GeneralParticleSource.hh.

118 { GPSData->GetCurrentSource()->SetParticleCharge(aCharge); }
void SetParticleCharge(G4double aCharge)

◆ SetParticleDefinition()

void G4GeneralParticleSource::SetParticleDefinition ( G4ParticleDefinition * aPDef)
inline

Definition at line 111 of file G4GeneralParticleSource.hh.

112 { GPSData->GetCurrentSource()->SetParticleDefinition(aPDef); }
void SetParticleDefinition(G4ParticleDefinition *aParticleDefinition)

◆ SetParticlePolarization()

void G4GeneralParticleSource::SetParticlePolarization ( G4ThreeVector aVal)
inline

Definition at line 121 of file G4GeneralParticleSource.hh.

122 { GPSData->GetCurrentSource()->SetParticlePolarization(aVal); }
void SetParticlePolarization(const G4ThreeVector &aVal)

◆ SetParticleTime()

void G4GeneralParticleSource::SetParticleTime ( G4double aTime)
inline

Definition at line 127 of file G4GeneralParticleSource.hh.

128 { GPSData->GetCurrentSource()->SetParticleTime(aTime); }
void SetParticleTime(G4double aTime)

◆ SetVerbosity()

void G4GeneralParticleSource::SetVerbosity ( G4int i)
inline

The documentation for this class was generated from the following files: