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

#include <G4SingleParticleSource.hh>

+ Inheritance 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 (const G4ThreeVector &aVal)
 
const G4ThreeVectorGetParticlePolarization () 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 ()
 
virtual void GeneratePrimaryVertex (G4Event *evt)=0
 
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 70 of file G4SingleParticleSource.hh.

Constructor & Destructor Documentation

◆ G4SingleParticleSource()

G4SingleParticleSource::G4SingleParticleSource ( )

Definition at line 57 of file G4SingleParticleSource.cc.

58{
59 // Initialise all variables
60 // Position distribution Variables
61
62 NumberOfParticlesToBeGenerated = 1;
63 definition = G4Geantino::GeantinoDefinition();
64
65 charge = 0.0;
66 time = 0;
67 polarization = G4ThreeVector();
68
69 biasRndm = new G4SPSRandomGenerator();
70 posGenerator = new G4SPSPosDistribution();
71 posGenerator->SetBiasRndm(biasRndm);
72 angGenerator = new G4SPSAngDistribution();
73 angGenerator->SetPosDistribution(posGenerator);
74 angGenerator->SetBiasRndm(biasRndm);
75 eneGenerator = new G4SPSEneDistribution();
76 eneGenerator->SetBiasRndm(biasRndm);
77
78 verbosityLevel = 0;
79
81}
#define G4MUTEXINIT(mutex)
Definition: G4Threading.hh:87
CLHEP::Hep3Vector G4ThreeVector
static G4Geantino * GeantinoDefinition()
Definition: G4Geantino.cc:81
void SetPosDistribution(G4SPSPosDistribution *a)
void SetBiasRndm(G4SPSRandomGenerator *a)
void SetBiasRndm(G4SPSRandomGenerator *a)
void SetBiasRndm(G4SPSRandomGenerator *a)

◆ ~G4SingleParticleSource()

G4SingleParticleSource::~G4SingleParticleSource ( )

Definition at line 83 of file G4SingleParticleSource.cc.

84{
85 delete biasRndm;
86 delete posGenerator;
87 delete angGenerator;
88 delete eneGenerator;
89
91}
#define G4MUTEXDESTROY(mutex)
Definition: G4Threading.hh:90

Member Function Documentation

◆ GeneratePrimaryVertex()

void G4SingleParticleSource::GeneratePrimaryVertex ( G4Event evt)
virtual

Implements G4VPrimaryGenerator.

Definition at line 109 of file G4SingleParticleSource.cc.

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

Referenced by G4AdjointPrimaryGenerator::GenerateAdjointPrimaryVertex(), G4AdjointPrimaryGenerator::GenerateFwdPrimaryVertex(), and G4GeneralParticleSource::GeneratePrimaryVertex().

◆ GetAngDist()

◆ GetBiasRndm()

G4SPSRandomGenerator * G4SingleParticleSource::GetBiasRndm ( ) const
inline

◆ GetEneDist()

◆ GetNumberOfParticles()

G4int G4SingleParticleSource::GetNumberOfParticles ( ) const
inline

Definition at line 119 of file G4SingleParticleSource.hh.

120 { return NumberOfParticlesToBeGenerated; }

Referenced by G4GeneralParticleSource::GetNumberOfParticles(), and G4GeneralParticleSource::ListSource().

◆ GetParticleDefinition()

G4ParticleDefinition * G4SingleParticleSource::GetParticleDefinition ( ) const
inline

Definition at line 100 of file G4SingleParticleSource.hh.

101 { return definition; }

Referenced by G4GeneralParticleSource::GetParticleDefinition(), and G4GeneralParticleSource::ListSource().

◆ GetParticleEnergy()

G4double G4SingleParticleSource::GetParticleEnergy ( ) const
inline

Definition at line 127 of file G4SingleParticleSource.hh.

128 { return ParticleProperties.Get().energy; }

Referenced by G4GeneralParticleSource::GetParticleEnergy(), and G4GeneralParticleSource::ListSource().

◆ GetParticleMomentumDirection()

G4ThreeVector G4SingleParticleSource::GetParticleMomentumDirection ( ) const
inline

Definition at line 125 of file G4SingleParticleSource.hh.

126 { return ParticleProperties.Get().momentum_direction; }

Referenced by G4GeneralParticleSource::GetParticleMomentumDirection().

◆ GetParticlePolarization()

const G4ThreeVector & G4SingleParticleSource::GetParticlePolarization ( ) const
inline

Definition at line 109 of file G4SingleParticleSource.hh.

110 { return polarization; }

Referenced by G4GeneralParticleSource::GetParticlePolarization().

◆ GetParticlePosition()

G4ThreeVector G4SingleParticleSource::GetParticlePosition ( ) const
inline

Definition at line 123 of file G4SingleParticleSource.hh.

124 { return ParticleProperties.Get().position; }

Referenced by G4GeneralParticleSource::GetParticlePosition().

◆ GetParticleTime()

G4double G4SingleParticleSource::GetParticleTime ( ) const
inline

Definition at line 114 of file G4SingleParticleSource.hh.

114{ return time; }

Referenced by G4GeneralParticleSource::GetParticleTime().

◆ GetPosDist()

◆ SetNumberOfParticles()

void G4SingleParticleSource::SetNumberOfParticles ( G4int  i)
inline

Definition at line 117 of file G4SingleParticleSource.hh.

118 { NumberOfParticlesToBeGenerated = i; }

Referenced by G4GeneralParticleSourceMessenger::SetNewValue(), and G4GeneralParticleSource::SetNumberOfParticles().

◆ SetParticleCharge()

void G4SingleParticleSource::SetParticleCharge ( G4double  aCharge)
inline

Definition at line 104 of file G4SingleParticleSource.hh.

104{ charge = aCharge; }

Referenced by G4GeneralParticleSource::SetParticleCharge().

◆ SetParticleDefinition()

void G4SingleParticleSource::SetParticleDefinition ( G4ParticleDefinition aParticleDefinition)

◆ SetParticlePolarization()

void G4SingleParticleSource::SetParticlePolarization ( const G4ThreeVector aVal)
inline

◆ SetParticleTime()

void G4SingleParticleSource::SetParticleTime ( G4double  aTime)
inline

◆ SetVerbosity()

void G4SingleParticleSource::SetVerbosity ( G4int  vL)

Definition at line 93 of file G4SingleParticleSource.cc.

94{
95 G4AutoLock l(&mutex);
96 verbosityLevel = vL;
97 posGenerator->SetVerbosity(vL);
98 angGenerator->SetVerbosity(vL);
99 eneGenerator->SetVerbosity(vL);
100}

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