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

#include <G4SingleParticleSource.hh>

Inheritance diagram for G4SingleParticleSource:
Collaboration diagram for G4SingleParticleSource:

Public Member Functions

 G4SingleParticleSource ()
 
 ~G4SingleParticleSource ()
 
void GeneratePrimaryVertex (G4Event *evt)
 
G4SPSPosDistributionGetPosDist () const
 
G4SPSAngDistributionGetAngDist () const
 
G4SPSEneDistributionGetEneDist () const
 
G4SPSRandomGeneratorGetBiasRndm () const
 
void SetVerbosity (G4int)
 
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 Important: This is a shared class between threads. Only one thread should use the set-methods here. Note that this is exactly what is achieved using UI commands. If you use the set methods to set defaults in your application take care that only one thread is executing them. In addition take care of calling these methods before the run is started Do not use these setters during the event loop

Definition at line 141 of file G4SingleParticleSource.hh.

Constructor & Destructor Documentation

G4SingleParticleSource::G4SingleParticleSource ( )

Definition at line 71 of file G4SingleParticleSource.cc.

71  {
72 // // Initialise all variables
73 // // Position distribution Variables
74 //
75  NumberOfParticlesToBeGenerated = 1;
76  definition = G4Geantino::GeantinoDefinition();
77 // G4ThreeVector zero;
78 // particle_momentum_direction = G4ParticleMomentum(1, 0, 0);
79 // particle_energy = 1.0 * MeV;
80 // particle_position = zero;
81 // particle_time = 0.0;
82 // particle_polarization = zero;
83  charge = 0.0;
84  time = 0;
85  polarization = G4ThreeVector();
86 
87  biasRndm = new G4SPSRandomGenerator();
88  posGenerator = new G4SPSPosDistribution();
89  posGenerator->SetBiasRndm(biasRndm);
90  angGenerator = new G4SPSAngDistribution();
91  angGenerator->SetPosDistribution(posGenerator);
92  angGenerator->SetBiasRndm(biasRndm);
93  eneGenerator = new G4SPSEneDistribution();
94  eneGenerator->SetBiasRndm(biasRndm);
95 
96  // verbosity
97  verbosityLevel = 0;
98 
100 
101 }
static G4Geantino * GeantinoDefinition()
Definition: G4Geantino.cc:82
void SetBiasRndm(G4SPSRandomGenerator *a)
CLHEP::Hep3Vector G4ThreeVector
#define G4MUTEXINIT(mutex)
Definition: G4Threading.hh:177
void SetBiasRndm(G4SPSRandomGenerator *a)
void SetBiasRndm(G4SPSRandomGenerator *a)
void SetPosDistribution(G4SPSPosDistribution *a)

Here is the call graph for this function:

G4SingleParticleSource::~G4SingleParticleSource ( )

Definition at line 103 of file G4SingleParticleSource.cc.

103  {
104  delete biasRndm;
105  delete posGenerator;
106  delete angGenerator;
107  delete eneGenerator;
109 }
#define G4MUTEXDESTROY(mutex)
Definition: G4Threading.hh:178

Member Function Documentation

void G4SingleParticleSource::GeneratePrimaryVertex ( G4Event evt)
virtual

Implements G4VPrimaryGenerator.

Definition at line 126 of file G4SingleParticleSource.cc.

126  {
127 
128  //G4AutoLock l(&mutex);
129  //part_prop_t& pp = ParticleProperties.Get();
130  if (definition == NULL) {
131  //TODO: Should this rise an exception???
132  return ;
133  }
134  //return;
135 
136  if (verbosityLevel > 1)
137  G4cout << " NumberOfParticlesToBeGenerated: "
138  <<NumberOfParticlesToBeGenerated << G4endl;
139 
140  part_prop_t& pp = ParticleProperties.Get();
141  // Position stuff
142  pp.position = posGenerator->GenerateOne();
143 
144  // create a new vertex
145  G4PrimaryVertex* vertex = new G4PrimaryVertex(pp.position,time);
146 
147  for (G4int i = 0; i < NumberOfParticlesToBeGenerated; i++) {
148  // Angular stuff
149  pp.momentum_direction = angGenerator->GenerateOne();
150  // Energy stuff
151  pp.energy = eneGenerator->GenerateOne(definition);
152 
153  if (verbosityLevel >= 2)
154  G4cout << "Creating primaries and assigning to vertex" << G4endl;
155  // create new primaries and set them to the vertex
156  G4double mass = definition->GetPDGMass();
157  G4PrimaryParticle* particle =
158  new G4PrimaryParticle(definition);
159  particle->SetKineticEnergy(pp.energy );
160  particle->SetMass( mass );
161  particle->SetMomentumDirection( pp.momentum_direction );
162  particle->SetCharge( charge );
163  particle->SetPolarization(polarization.x(),
164  polarization.y(),
165  polarization.z());
166  if (verbosityLevel > 1) {
167  G4cout << "Particle name: "
168  << definition->GetParticleName() << G4endl;
169  G4cout << " Energy: " << pp.energy << G4endl;
170  G4cout << " Position: " << pp.position << G4endl;
171  G4cout << " Direction: " << pp.momentum_direction
172  << G4endl;
173  }
174  // Set bweight equal to the multiple of all non-zero weights
175  G4double weight = eneGenerator->GetWeight()*biasRndm->GetBiasWeight();
176  // pass it to primary particle
177  particle->SetWeight(weight);
178 
179  vertex->SetPrimary(particle);
180 
181  }
182  // now pass the weight to the primary vertex. CANNOT be used here!
183  // vertex->SetWeight(particle_weight);
184  evt->AddPrimaryVertex(vertex);
185  if (verbosityLevel > 1)
186  G4cout << " Primary Vetex generated !" << G4endl;
187 }
double x() const
value_type & Get() const
Definition: G4Cache.hh:282
void AddPrimaryVertex(G4PrimaryVertex *aPrimaryVertex)
Definition: G4Event.hh:154
int G4int
Definition: G4Types.hh:78
const G4String & GetParticleName() const
double z() const
void SetKineticEnergy(G4double eKin)
G4GLOB_DLL std::ostream G4cout
G4ParticleMomentum GenerateOne()
void SetMass(G4double mas)
G4double GenerateOne(G4ParticleDefinition *)
G4double GetPDGMass() const
void SetMomentumDirection(const G4ThreeVector &p)
void SetWeight(G4double w)
void SetCharge(G4double chg)
double y() const
void SetPrimary(G4PrimaryParticle *pp)
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
void SetPolarization(const G4ThreeVector &pol)

Here is the call graph for this function:

Here is the caller graph for this function:

G4SPSAngDistribution* G4SingleParticleSource::GetAngDist ( ) const
inline

Definition at line 153 of file G4SingleParticleSource.hh.

153  {
154  return angGenerator;
155  }

Here is the caller graph for this function:

G4SPSRandomGenerator* G4SingleParticleSource::GetBiasRndm ( ) const
inline

Definition at line 161 of file G4SingleParticleSource.hh.

161  {
162  return biasRndm;
163  }

Here is the caller graph for this function:

G4SPSEneDistribution* G4SingleParticleSource::GetEneDist ( ) const
inline

Definition at line 157 of file G4SingleParticleSource.hh.

157  {
158  return eneGenerator;
159  }

Here is the caller graph for this function:

G4int G4SingleParticleSource::GetNumberOfParticles ( ) const
inline

Definition at line 206 of file G4SingleParticleSource.hh.

206  {
207  return NumberOfParticlesToBeGenerated;
208  }

Here is the caller graph for this function:

G4ParticleDefinition* G4SingleParticleSource::GetParticleDefinition ( ) const
inline

Definition at line 171 of file G4SingleParticleSource.hh.

171  {
172  return definition;
173  }

Here is the caller graph for this function:

G4double G4SingleParticleSource::GetParticleEnergy ( ) const
inline

Definition at line 218 of file G4SingleParticleSource.hh.

218  {
219  return ParticleProperties.Get().energy;
220  }
value_type & Get() const
Definition: G4Cache.hh:282

Here is the call graph for this function:

Here is the caller graph for this function:

G4ThreeVector G4SingleParticleSource::GetParticleMomentumDirection ( ) const
inline

Definition at line 214 of file G4SingleParticleSource.hh.

214  {
215  return ParticleProperties.Get().momentum_direction;
216  }
value_type & Get() const
Definition: G4Cache.hh:282

Here is the call graph for this function:

Here is the caller graph for this function:

G4ThreeVector G4SingleParticleSource::GetParticlePolarization ( ) const
inline

Definition at line 186 of file G4SingleParticleSource.hh.

186  {
187  return polarization;
188  }

Here is the caller graph for this function:

G4ThreeVector G4SingleParticleSource::GetParticlePosition ( ) const
inline

Definition at line 210 of file G4SingleParticleSource.hh.

210  {
211  return ParticleProperties.Get().position;
212  }
value_type & Get() const
Definition: G4Cache.hh:282

Here is the call graph for this function:

Here is the caller graph for this function:

G4double G4SingleParticleSource::GetParticleTime ( ) const
inline

Definition at line 196 of file G4SingleParticleSource.hh.

196  {
197  return time;
198  }

Here is the caller graph for this function:

G4SPSPosDistribution* G4SingleParticleSource::GetPosDist ( ) const
inline

Definition at line 149 of file G4SingleParticleSource.hh.

149  {
150  return posGenerator;
151  }

Here is the caller graph for this function:

void G4SingleParticleSource::SetNumberOfParticles ( G4int  i)
inline

Definition at line 201 of file G4SingleParticleSource.hh.

201  {
202  NumberOfParticlesToBeGenerated = i;
203  }

Here is the caller graph for this function:

void G4SingleParticleSource::SetParticleCharge ( G4double  aCharge)
inline

Definition at line 176 of file G4SingleParticleSource.hh.

176  {
177  charge = aCharge;
178  }

Here is the caller graph for this function:

void G4SingleParticleSource::SetParticleDefinition ( G4ParticleDefinition aParticleDefinition)

Definition at line 120 of file G4SingleParticleSource.cc.

121  {
122  definition = aParticleDefinition;
123  charge = aParticleDefinition->GetPDGCharge();
124 }
G4double GetPDGCharge() const

Here is the call graph for this function:

Here is the caller graph for this function:

void G4SingleParticleSource::SetParticlePolarization ( G4ThreeVector  aVal)
inline

Definition at line 182 of file G4SingleParticleSource.hh.

182  {
183  polarization = aVal;
184  }

Here is the caller graph for this function:

void G4SingleParticleSource::SetParticleTime ( G4double  aTime)
inline

Definition at line 192 of file G4SingleParticleSource.hh.

192  {
193  time = aTime;
194  }

Here is the caller graph for this function:

void G4SingleParticleSource::SetVerbosity ( G4int  vL)

Definition at line 111 of file G4SingleParticleSource.cc.

111  {
112  G4AutoLock l(&mutex);
113  verbosityLevel = vL;
114  posGenerator->SetVerbosity(vL);
115  angGenerator->SetVerbosity(vL);
116  eneGenerator->SetVerbosity(vL);
117  //G4cout << "Verbosity Set to: " << verbosityLevel << G4endl;
118 }

Here is the call graph for this function:


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