Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4GeneralParticleSource Class Reference

#include <G4GeneralParticleSource.hh>

Inheritance diagram for G4GeneralParticleSource:
Collaboration diagram for G4GeneralParticleSource:

Public Member Functions

 G4GeneralParticleSource ()
 
 ~G4GeneralParticleSource ()
 
void GeneratePrimaryVertex (G4Event *)
 
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 *aParticleDefinition)
 
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 ()
 
virtual ~G4VPrimaryGenerator ()
 
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
 

Detailed Description

Andrea Dotti Feb 2015 GPS messenger design requires some explanation for what distributions parameters are concerned : Each thread has its own GPS since primary generation is a user action. However to save memory the underlying structures that provide the GPS functionalities ( the G4SPS*Distribution classes and the G4SPSRandomGenerator class) are shared among threads. This implies that modifying parameters of sources requires some attention: 1- Only one thread should change source parameters. 2- Changing of parameters can happen only between runs, when is guaranteed that no thread is accessing them 2- UI commands require that even if messenger is instantiated in a thread the commands are executed in the master (this is possible since V10.1) The simplest solution is to use UI commands to change GPS parameters and avoid C++ APIs. If this is inevitable a simple solution is to instantiate an instance of G4GeneralParticleSource explicitly in the master thread (for example in G4VUserActionInitialization::BuildForMaster() and set the defaults parameter there).

Definition at line 179 of file G4GeneralParticleSource.hh.

Constructor & Destructor Documentation

G4GeneralParticleSource::G4GeneralParticleSource ( )

Definition at line 78 of file G4GeneralParticleSource.cc.

78  : normalised(false),
79  theMessenger(0)
80 {
82  //currentSource = GPSData->GetCurrentSource();
83  //currentSourceIdx = G4int(GPSData->GetSourceVectorSize() - 1);
84 
85  //Messenger is special, only a worker should instantiate it. Singleton pattern
87  //Some initialization should be done only once
88  G4AutoLock l(&messangerInit);
89  static G4bool onlyOnce = false;
90  if ( !onlyOnce ) {
91  theMessenger->SetParticleGun(GPSData->GetCurrentSource());
92  IntensityNormalization();
93  onlyOnce = true;
94  }
95 }
static G4GeneralParticleSourceMessenger * GetInstance(G4GeneralParticleSource *)
bool G4bool
Definition: G4Types.hh:79
void SetParticleGun(G4SingleParticleSource *fpg)
G4SingleParticleSource * GetCurrentSource(G4int idx)
static G4GeneralParticleSourceData * Instance()

Here is the call graph for this function:

G4GeneralParticleSource::~G4GeneralParticleSource ( )

Definition at line 97 of file G4GeneralParticleSource.cc.

98 {
99  theMessenger->Destroy();
100 }

Here is the call graph for this function:

Member Function Documentation

void G4GeneralParticleSource::AddaSource ( G4double  aV)

Definition at line 102 of file G4GeneralParticleSource.cc.

103 {
104  GPSData->Lock();
105  GPSData->AddASource(aV);
106  theMessenger->SetParticleGun(GPSData->GetCurrentSource());
107  //TODO: But do we really normalize here after each source?
108  IntensityNormalization();
109  GPSData->Unlock();
110 }
void SetParticleGun(G4SingleParticleSource *fpg)
G4SingleParticleSource * GetCurrentSource(G4int idx)

Here is the call graph for this function:

Here is the caller graph for this function:

void G4GeneralParticleSource::ClearAll ( )

Definition at line 166 of file G4GeneralParticleSource.cc.

167 {
168  GPSData->ClearSources();
169  normalised=GPSData->Normalised();
170 }

Here is the call graph for this function:

Here is the caller graph for this function:

void G4GeneralParticleSource::DeleteaSource ( G4int  aV)

Definition at line 172 of file G4GeneralParticleSource.cc.

173 {
174  G4int id = aV;
175  if ( id <= GPSData->GetIntensityVectorSize() )
176  {
177  GPSData->DeleteASource(aV);
178  normalised=GPSData->Normalised();
179  }
180  else
181  {
182  G4cout << " source index is invalid " << G4endl;
183  G4cout << " it shall be <= " << GPSData->GetIntensityVectorSize() << G4endl;
184  }
185 }
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61

Here is the call graph for this function:

Here is the caller graph for this function:

void G4GeneralParticleSource::GeneratePrimaryVertex ( G4Event evt)
virtual

Implements G4VPrimaryGenerator.

Definition at line 187 of file G4GeneralParticleSource.cc.

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

Here is the call graph for this function:

G4SingleParticleSource* G4GeneralParticleSource::GetCurrentSource ( ) const
inline

Definition at line 193 of file G4GeneralParticleSource.hh.

194  {return GPSData->GetCurrentSource();}
G4SingleParticleSource * GetCurrentSource(G4int idx)

Here is the call graph for this function:

G4int G4GeneralParticleSource::GetCurrentSourceIndex ( ) const
inline

Definition at line 195 of file G4GeneralParticleSource.hh.

196  { return GPSData->GetCurrentSourceIdx(); }

Here is the call graph for this function:

Here is the caller graph for this function:

G4double G4GeneralParticleSource::GetCurrentSourceIntensity ( ) const
inline

Definition at line 197 of file G4GeneralParticleSource.hh.

198  { return GPSData->GetIntensity(GetCurrentSourceIndex()); }
G4double GetIntensity(G4int idx) const

Here is the call graph for this function:

Here is the caller graph for this function:

G4int G4GeneralParticleSource::GetNumberOfParticles ( ) const
inline

Definition at line 238 of file G4GeneralParticleSource.hh.

239  { return GPSData->GetCurrentSource()->GetNumberOfParticles(); };
G4SingleParticleSource * GetCurrentSource(G4int idx)

Here is the call graph for this function:

G4int G4GeneralParticleSource::GetNumberofSource ( )
inline

Definition at line 189 of file G4GeneralParticleSource.hh.

189 { return GPSData->GetSourceVectorSize(); };

Here is the call graph for this function:

Here is the caller graph for this function:

G4ParticleDefinition* G4GeneralParticleSource::GetParticleDefinition ( ) const
inline

Definition at line 217 of file G4GeneralParticleSource.hh.

218  { return GPSData->GetCurrentSource()->GetParticleDefinition();} ;
G4SingleParticleSource * GetCurrentSource(G4int idx)
G4ParticleDefinition * GetParticleDefinition() const

Here is the call graph for this function:

G4double G4GeneralParticleSource::GetParticleEnergy ( ) const
inline

Definition at line 244 of file G4GeneralParticleSource.hh.

245  {return GPSData->GetCurrentSource()->GetParticleEnergy();};
G4SingleParticleSource * GetCurrentSource(G4int idx)
G4double GetParticleEnergy() const

Here is the call graph for this function:

G4ThreeVector G4GeneralParticleSource::GetParticleMomentumDirection ( ) const
inline

Definition at line 242 of file G4GeneralParticleSource.hh.

243  { return GPSData->GetCurrentSource()->GetParticleMomentumDirection();};
G4ThreeVector GetParticleMomentumDirection() const
G4SingleParticleSource * GetCurrentSource(G4int idx)

Here is the call graph for this function:

G4ThreeVector G4GeneralParticleSource::GetParticlePolarization ( ) const
inline

Definition at line 226 of file G4GeneralParticleSource.hh.

227  {return GPSData->GetCurrentSource()->GetParticlePolarization();};
G4ThreeVector GetParticlePolarization() const
G4SingleParticleSource * GetCurrentSource(G4int idx)

Here is the call graph for this function:

G4ThreeVector G4GeneralParticleSource::GetParticlePosition ( ) const
inline

Definition at line 240 of file G4GeneralParticleSource.hh.

241  { return GPSData->GetCurrentSource()->GetParticlePosition();};
G4ThreeVector GetParticlePosition() const
G4SingleParticleSource * GetCurrentSource(G4int idx)

Here is the call graph for this function:

G4double G4GeneralParticleSource::GetParticleTime ( ) const
inline

Definition at line 232 of file G4GeneralParticleSource.hh.

233  { return GPSData->GetCurrentSource()->GetParticleTime(); };
G4SingleParticleSource * GetCurrentSource(G4int idx)

Here is the call graph for this function:

void G4GeneralParticleSource::ListSource ( )

Definition at line 118 of file G4GeneralParticleSource.cc.

119 {
120  G4cout << "The number of particle sources is: " << GPSData->GetIntensityVectorSize() << G4endl;
121  G4cout <<" Multiple Vertex sources: "<<GPSData->GetMultipleVertex();
122  G4cout <<" Flat Sampling flag: "<<GPSData->GetFlatSampling()<<G4endl;
123  const G4int currentIdx = GPSData->GetCurrentSourceIdx();
124  for(G4int i=0; i<GPSData->GetIntensityVectorSize(); i++)
125  {
126  G4cout << "\tsource " << i << " with intensity: " << GPSData->GetIntensity(i) << G4endl;
127  const G4SingleParticleSource* thisSrc = GPSData->GetCurrentSource(i);
128  G4cout <<" \t\tNum Particles: "<<thisSrc->GetNumberOfParticles()<<"; Particle type: "<<thisSrc->GetParticleDefinition()->GetParticleName()<<G4endl;
129  G4cout <<" \t\tEnergy: "<<G4BestUnit(thisSrc->GetParticleEnergy(),"Energy")<<G4endl;
130  G4cout <<" \t\tDirection: "<<thisSrc->GetAngDist()->GetDirection()<<"; Position: ";
131  G4cout <<G4BestUnit(thisSrc->GetPosDist()->GetCentreCoords(),"Length")<<G4endl;
132  G4cout <<" \t\tAngular Distribution: "<<thisSrc->GetAngDist()->GetDistType()<<G4endl;
133  G4cout <<" \t\tEnergy Distribution: "<<thisSrc->GetEneDist()->GetEnergyDisType()<<G4endl;
134  G4cout <<" \t\tPosition Distribution Type: "<<thisSrc->GetPosDist()->GetPosDisType();
135  G4cout <<"; Position Shape: "<<thisSrc->GetPosDist()->GetPosDisShape()<<G4endl;
136  }
137  //Set back previous source
138  GPSData->GetCurrentSource(currentIdx);
139 }
G4SPSAngDistribution * GetAngDist() const
G4SPSEneDistribution * GetEneDist() const
G4SPSPosDistribution * GetPosDist() const
G4String GetPosDisShape() const
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
int G4int
Definition: G4Types.hh:78
const G4String & GetParticleName() const
G4GLOB_DLL std::ostream G4cout
G4ThreeVector GetCentreCoords() const
G4double GetIntensity(G4int idx) const
G4SingleParticleSource * GetCurrentSource(G4int idx)
G4String GetPosDisType() const
#define G4endl
Definition: G4ios.hh:61
G4double GetParticleEnergy() const
G4ParticleDefinition * GetParticleDefinition() const

Here is the call graph for this function:

Here is the caller graph for this function:

void G4GeneralParticleSource::SetCurrentSourceIntensity ( G4double  aV)

Definition at line 158 of file G4GeneralParticleSource.cc.

159 {
160  GPSData->Lock();
161  GPSData->SetCurrentSourceIntensity(aV);
162  GPSData->Unlock();
163  normalised = GPSData->Normalised();
164 }

Here is the call graph for this function:

Here is the caller graph for this function:

void G4GeneralParticleSource::SetCurrentSourceto ( G4int  aV)

Definition at line 141 of file G4GeneralParticleSource.cc.

142 {
143  G4int id = aV;
144  if ( id < GPSData->GetIntensityVectorSize() )
145  {
146  //currentSourceIdx = aV;
147  //currentSource = GPSData->GetCurrentSource(id);
148  theMessenger->SetParticleGun(GPSData->GetCurrentSource(id));
149  }
150  else
151  {
153  msg<<"Trying to set source to index "<<aV<<" but only "<<GPSData->GetIntensityVectorSize()<<" sources are defined.";
154  G4Exception("G4GeneralParticleSoruce::SetCurrentSourceto","G4GPS004",FatalException,msg);
155  }
156 }
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
int G4int
Definition: G4Types.hh:78
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
void SetParticleGun(G4SingleParticleSource *fpg)
G4SingleParticleSource * GetCurrentSource(G4int idx)

Here is the call graph for this function:

Here is the caller graph for this function:

void G4GeneralParticleSource::SetFlatSampling ( G4bool  av)
inline

Definition at line 211 of file G4GeneralParticleSource.hh.

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

Here is the call graph for this function:

Here is the caller graph for this function:

void G4GeneralParticleSource::SetMultipleVertex ( G4bool  av)
inline

Definition at line 207 of file G4GeneralParticleSource.hh.

207 { GPSData->SetMultipleVertex(av);} ;

Here is the call graph for this function:

Here is the caller graph for this function:

void G4GeneralParticleSource::SetNumberOfParticles ( G4int  i)
inline

Definition at line 235 of file G4GeneralParticleSource.hh.

236  { GPSData->GetCurrentSource()->SetNumberOfParticles(i); };
G4SingleParticleSource * GetCurrentSource(G4int idx)

Here is the call graph for this function:

void G4GeneralParticleSource::SetParticleCharge ( G4double  aCharge)
inline

Definition at line 220 of file G4GeneralParticleSource.hh.

221  { GPSData->GetCurrentSource()->SetParticleCharge(aCharge); } ;
G4SingleParticleSource * GetCurrentSource(G4int idx)
void SetParticleCharge(G4double aCharge)

Here is the call graph for this function:

void G4GeneralParticleSource::SetParticleDefinition ( G4ParticleDefinition aParticleDefinition)
inline

Definition at line 214 of file G4GeneralParticleSource.hh.

215  {GPSData->GetCurrentSource()->SetParticleDefinition(aParticleDefinition); } ;
void SetParticleDefinition(G4ParticleDefinition *aParticleDefinition)
G4SingleParticleSource * GetCurrentSource(G4int idx)

Here is the call graph for this function:

void G4GeneralParticleSource::SetParticlePolarization ( G4ThreeVector  aVal)
inline

Definition at line 224 of file G4GeneralParticleSource.hh.

225  {GPSData->GetCurrentSource()->SetParticlePolarization(aVal);};
void SetParticlePolarization(G4ThreeVector aVal)
G4SingleParticleSource * GetCurrentSource(G4int idx)

Here is the call graph for this function:

void G4GeneralParticleSource::SetParticleTime ( G4double  aTime)
inline

Definition at line 230 of file G4GeneralParticleSource.hh.

231  { GPSData->GetCurrentSource()->SetParticleTime(aTime); };
void SetParticleTime(G4double aTime)
G4SingleParticleSource * GetCurrentSource(G4int idx)

Here is the call graph for this function:

void G4GeneralParticleSource::SetVerbosity ( G4int  i)
inline

Definition at line 204 of file G4GeneralParticleSource.hh.

204 {GPSData->SetVerbosityAllSources(i);} ;

Here is the call graph for this function:

Here is the caller graph for this function:


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