Geant4 9.6.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 ()
 
G4SPSAngDistributionGetAngDist ()
 
G4SPSEneDistributionGetEneDist ()
 
G4SPSRandomGeneratorGetBiasRndm ()
 
void SetVerbosity (G4int)
 
void SetParticleDefinition (G4ParticleDefinition *aParticleDefinition)
 
G4ParticleDefinitionGetParticleDefinition ()
 
void SetParticleCharge (G4double aCharge)
 
void SetParticlePolarization (G4ThreeVector aVal)
 
G4ThreeVector GetParticlePolarization ()
 
void SetParticleTime (G4double aTime)
 
G4double GetParticleTime ()
 
void SetNumberOfParticles (G4int i)
 
G4int GetNumberOfParticles ()
 
G4ThreeVector GetParticlePosition ()
 
G4ThreeVector GetParticleMomentumDirection ()
 
G4double GetParticleEnergy ()
 
- 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
 

Detailed Description

Definition at line 123 of file G4SingleParticleSource.hh.

Constructor & Destructor Documentation

◆ G4SingleParticleSource()

G4SingleParticleSource::G4SingleParticleSource ( )

Definition at line 63 of file G4SingleParticleSource.cc.

63 {
64 // Initialise all variables
65 // Position distribution Variables
66
67 NumberOfParticlesToBeGenerated = 1;
68 particle_definition = G4Geantino::GeantinoDefinition();
69 G4ThreeVector zero;
70 particle_momentum_direction = G4ParticleMomentum(1, 0, 0);
71 particle_energy = 1.0 * MeV;
72 particle_position = zero;
73 particle_time = 0.0;
74 particle_polarization = zero;
75 particle_charge = 0.0;
76 particle_weight = 1.0;
77
78 biasRndm = new G4SPSRandomGenerator();
79 posGenerator = new G4SPSPosDistribution();
80 posGenerator->SetBiasRndm(biasRndm);
81 angGenerator = new G4SPSAngDistribution();
82 angGenerator->SetPosDistribution(posGenerator);
83 angGenerator->SetBiasRndm(biasRndm);
84 eneGenerator = new G4SPSEneDistribution();
85 eneGenerator->SetBiasRndm(biasRndm);
86
87 // verbosity
88 verbosityLevel = 0;
89
90}
G4ThreeVector G4ParticleMomentum
static G4Geantino * GeantinoDefinition()
Definition: G4Geantino.cc:82
void SetPosDistribution(G4SPSPosDistribution *a)
void SetBiasRndm(G4SPSRandomGenerator *a)
void SetBiasRndm(G4SPSRandomGenerator *a)
void SetBiasRndm(G4SPSRandomGenerator *a)

◆ ~G4SingleParticleSource()

G4SingleParticleSource::~G4SingleParticleSource ( )

Definition at line 92 of file G4SingleParticleSource.cc.

92 {
93 delete biasRndm;
94 delete posGenerator;
95 delete angGenerator;
96 delete eneGenerator;
97}

Member Function Documentation

◆ GeneratePrimaryVertex()

void G4SingleParticleSource::GeneratePrimaryVertex ( G4Event evt)
virtual

Implements G4VPrimaryGenerator.

Definition at line 113 of file G4SingleParticleSource.cc.

113 {
114 if (particle_definition == NULL)
115 return;
116
117 if (verbosityLevel > 1)
118 G4cout << " NumberOfParticlesToBeGenerated: "
119 << NumberOfParticlesToBeGenerated << G4endl;
120
121 // Position stuff
122 particle_position = posGenerator->GenerateOne();
123
124 // create a new vertex
125 G4PrimaryVertex* vertex = new G4PrimaryVertex(particle_position,
126 particle_time);
127
128 for (G4int i = 0; i < NumberOfParticlesToBeGenerated; i++) {
129 // Angular stuff
130 particle_momentum_direction = angGenerator->GenerateOne();
131 // Energy stuff
132 particle_energy = eneGenerator->GenerateOne(particle_definition);
133
134 if (verbosityLevel >= 2)
135 G4cout << "Creating primaries and assigning to vertex" << G4endl;
136 // create new primaries and set them to the vertex
137 G4double mass = particle_definition->GetPDGMass();
138 G4PrimaryParticle* particle =
139 new G4PrimaryParticle(particle_definition);
140 particle->SetKineticEnergy( particle_energy );
141 particle->SetMass( mass );
142 particle->SetMomentumDirection( particle_momentum_direction );
143 particle->SetCharge( particle_charge );
144 particle->SetPolarization(particle_polarization.x(),
145 particle_polarization.y(),
146 particle_polarization.z());
147 if (verbosityLevel > 1) {
148 G4cout << "Particle name: "
149 << particle_definition->GetParticleName() << G4endl;
150 G4cout << " Energy: " << particle_energy << G4endl;
151 G4cout << " Position: " << particle_position << G4endl;
152 G4cout << " Direction: " << particle_momentum_direction
153 << G4endl;
154 }
155 // Set bweight equal to the multiple of all non-zero weights
156 particle_weight = eneGenerator->GetWeight()*biasRndm->GetBiasWeight();
157 // pass it to primary particle
158 particle->SetWeight(particle_weight);
159
160 vertex->SetPrimary(particle);
161
162 }
163 // now pass the weight to the primary vertex. CANNOT be used here!
164 // vertex->SetWeight(particle_weight);
165 evt->AddPrimaryVertex(vertex);
166 if (verbosityLevel > 1)
167 G4cout << " Primary Vetex generated !" << G4endl;
168}
double G4double
Definition: G4Types.hh:64
int G4int
Definition: G4Types.hh:66
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cout
double z() const
double x() const
double y() const
void AddPrimaryVertex(G4PrimaryVertex *aPrimaryVertex)
Definition: G4Event.hh:142
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 GenerateOne(G4ParticleDefinition *)

Referenced by G4AdjointPrimaryGenerator::GenerateAdjointPrimaryVertex().

◆ GetAngDist()

◆ GetBiasRndm()

G4SPSRandomGenerator * G4SingleParticleSource::GetBiasRndm ( )
inline

Definition at line 141 of file G4SingleParticleSource.hh.

141 {
142 return biasRndm;
143 }

Referenced by G4GeneralParticleSourceMessenger::SetNewValue().

◆ GetEneDist()

G4SPSEneDistribution * G4SingleParticleSource::GetEneDist ( )
inline

◆ GetNumberOfParticles()

G4int G4SingleParticleSource::GetNumberOfParticles ( )
inline

Definition at line 186 of file G4SingleParticleSource.hh.

186 {
187 return NumberOfParticlesToBeGenerated;
188 }

Referenced by G4GeneralParticleSource::GetNumberOfParticles().

◆ GetParticleDefinition()

G4ParticleDefinition * G4SingleParticleSource::GetParticleDefinition ( )
inline

Definition at line 151 of file G4SingleParticleSource.hh.

151 {
152 return particle_definition;
153 }

Referenced by G4GeneralParticleSource::GetParticleDefinition().

◆ GetParticleEnergy()

G4double G4SingleParticleSource::GetParticleEnergy ( )
inline

Definition at line 198 of file G4SingleParticleSource.hh.

198 {
199 return particle_energy;
200 }

Referenced by G4GeneralParticleSource::GetParticleEnergy().

◆ GetParticleMomentumDirection()

G4ThreeVector G4SingleParticleSource::GetParticleMomentumDirection ( )
inline

Definition at line 194 of file G4SingleParticleSource.hh.

194 {
195 return particle_momentum_direction;
196 }

Referenced by G4GeneralParticleSource::GetParticleMomentumDirection().

◆ GetParticlePolarization()

G4ThreeVector G4SingleParticleSource::GetParticlePolarization ( )
inline

Definition at line 166 of file G4SingleParticleSource.hh.

166 {
167 return particle_polarization;
168 }

Referenced by G4GeneralParticleSource::GetParticlePolarization().

◆ GetParticlePosition()

G4ThreeVector G4SingleParticleSource::GetParticlePosition ( )
inline

Definition at line 190 of file G4SingleParticleSource.hh.

190 {
191 return particle_position;
192 }

Referenced by G4GeneralParticleSource::GetParticlePosition().

◆ GetParticleTime()

G4double G4SingleParticleSource::GetParticleTime ( )
inline

Definition at line 176 of file G4SingleParticleSource.hh.

176 {
177 return particle_time;
178 }

Referenced by G4GeneralParticleSource::GetParticleTime().

◆ GetPosDist()

◆ SetNumberOfParticles()

void G4SingleParticleSource::SetNumberOfParticles ( G4int  i)
inline

Definition at line 181 of file G4SingleParticleSource.hh.

181 {
182 NumberOfParticlesToBeGenerated = i;
183 }

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

◆ SetParticleCharge()

void G4SingleParticleSource::SetParticleCharge ( G4double  aCharge)
inline

Definition at line 156 of file G4SingleParticleSource.hh.

156 {
157 particle_charge = aCharge;
158 }

Referenced by G4GeneralParticleSource::SetParticleCharge().

◆ SetParticleDefinition()

void G4SingleParticleSource::SetParticleDefinition ( G4ParticleDefinition aParticleDefinition)

Definition at line 107 of file G4SingleParticleSource.cc.

108 {
109 particle_definition = aParticleDefinition;
110 particle_charge = particle_definition->GetPDGCharge();
111}
G4double GetPDGCharge() const

Referenced by G4AdjointPrimaryGenerator::GenerateAdjointPrimaryVertex(), G4GeneralParticleSourceMessenger::SetNewValue(), and G4GeneralParticleSource::SetParticleDefinition().

◆ SetParticlePolarization()

void G4SingleParticleSource::SetParticlePolarization ( G4ThreeVector  aVal)
inline

Definition at line 162 of file G4SingleParticleSource.hh.

162 {
163 particle_polarization = aVal;
164 }

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

◆ SetParticleTime()

void G4SingleParticleSource::SetParticleTime ( G4double  aTime)
inline

Definition at line 172 of file G4SingleParticleSource.hh.

172 {
173 particle_time = aTime;
174 }

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

◆ SetVerbosity()

void G4SingleParticleSource::SetVerbosity ( G4int  vL)

Definition at line 99 of file G4SingleParticleSource.cc.

99 {
100 verbosityLevel = vL;
101 posGenerator->SetVerbosity(vL);
102 angGenerator->SetVerbosity(vL);
103 eneGenerator->SetVerbosity(vL);
104 G4cout << "Verbosity Set to: " << verbosityLevel << G4endl;
105}

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


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