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

#include <G4ParticleGun.hh>

+ Inheritance diagram for G4ParticleGun:

Public Member Functions

 G4ParticleGun ()
 
 G4ParticleGun (G4int numberofparticles)
 
 G4ParticleGun (G4ParticleDefinition *particleDef, G4int numberofparticles=1)
 
virtual ~G4ParticleGun ()
 
 G4ParticleGun (const G4ParticleGun &)=delete
 
const G4ParticleGunoperator= (const G4ParticleGun &)=delete
 
G4bool operator== (const G4ParticleGun &) const =delete
 
G4bool operator!= (const G4ParticleGun &) const =delete
 
virtual void GeneratePrimaryVertex (G4Event *evt)
 
void SetParticleDefinition (G4ParticleDefinition *aParticleDefinition)
 
void SetParticleEnergy (G4double aKineticEnergy)
 
void SetParticleMomentum (G4double aMomentum)
 
void SetParticleMomentum (G4ParticleMomentum aMomentum)
 
void SetParticleMomentumDirection (G4ParticleMomentum aMomDirection)
 
void SetParticleCharge (G4double aCharge)
 
void SetParticlePolarization (G4ThreeVector aVal)
 
void SetNumberOfParticles (G4int i)
 
G4ParticleDefinitionGetParticleDefinition () const
 
G4ParticleMomentum GetParticleMomentumDirection () const
 
G4double GetParticleEnergy () const
 
G4double GetParticleMomentum () const
 
G4double GetParticleCharge () const
 
G4ThreeVector GetParticlePolarization () const
 
G4int GetNumberOfParticles () 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)
 

Protected Member Functions

virtual void SetInitialValues ()
 

Protected Attributes

G4int NumberOfParticlesToBeGenerated = 0
 
G4ParticleDefinitionparticle_definition = nullptr
 
G4ParticleMomentum particle_momentum_direction
 
G4double particle_energy = 0.0
 
G4double particle_momentum = 0.0
 
G4double particle_charge = 0.0
 
G4ThreeVector particle_polarization
 
- Protected Attributes inherited from G4VPrimaryGenerator
G4ThreeVector particle_position
 
G4double particle_time = 0.0
 

Additional Inherited Members

- Static Public Member Functions inherited from G4VPrimaryGenerator
static G4bool CheckVertexInsideWorld (const G4ThreeVector &pos)
 

Detailed Description

Definition at line 64 of file G4ParticleGun.hh.

Constructor & Destructor Documentation

◆ G4ParticleGun() [1/4]

G4ParticleGun::G4ParticleGun ( )

Definition at line 38 of file G4ParticleGun.cc.

39{
41}
virtual void SetInitialValues()

◆ G4ParticleGun() [2/4]

G4ParticleGun::G4ParticleGun ( G4int  numberofparticles)

Definition at line 43 of file G4ParticleGun.cc.

44{
46 NumberOfParticlesToBeGenerated = numberofparticles;
47}
G4int NumberOfParticlesToBeGenerated

◆ G4ParticleGun() [3/4]

G4ParticleGun::G4ParticleGun ( G4ParticleDefinition particleDef,
G4int  numberofparticles = 1 
)

Definition at line 49 of file G4ParticleGun.cc.

51{
53 NumberOfParticlesToBeGenerated = numberofparticles;
54 SetParticleDefinition( particleDef );
55}
void SetParticleDefinition(G4ParticleDefinition *aParticleDefinition)

◆ ~G4ParticleGun()

G4ParticleGun::~G4ParticleGun ( )
virtual

Definition at line 72 of file G4ParticleGun.cc.

73{
74 delete theMessenger;
75}

◆ G4ParticleGun() [4/4]

G4ParticleGun::G4ParticleGun ( const G4ParticleGun )
delete

Member Function Documentation

◆ GeneratePrimaryVertex()

void G4ParticleGun::GeneratePrimaryVertex ( G4Event evt)
virtual

Implements G4VPrimaryGenerator.

Definition at line 203 of file G4ParticleGun.cc.

204{
205 if(particle_definition == nullptr)
206 {
208 ED << "Particle definition is not defined." << G4endl;
209 ED << "G4ParticleGun::SetParticleDefinition() has to be invoked beforehand."
210 << G4endl;
211 G4Exception("G4ParticleGun::GeneratePrimaryVertex()", "Event0109",
212 FatalException, ED);
213 return;
214 }
215
216 // Create a new vertex
217 //
218 G4PrimaryVertex* vertex =
220
221 // Create new primaries and set them to the vertex
222 //
224 for( G4int i=0; i<NumberOfParticlesToBeGenerated; ++i )
225 {
226 G4PrimaryParticle* particle =
229 particle->SetMass( mass );
231 particle->SetCharge( particle_charge );
235 vertex->SetPrimary( particle );
236 }
237 evt->AddPrimaryVertex( vertex );
238}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
double G4double
Definition: G4Types.hh:83
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
double z() const
double x() const
double y() const
void AddPrimaryVertex(G4PrimaryVertex *aPrimaryVertex)
Definition: G4Event.hh:121
G4double particle_energy
G4ThreeVector particle_polarization
G4ParticleMomentum particle_momentum_direction
G4double particle_charge
G4ParticleDefinition * particle_definition
void SetCharge(G4double chg)
void SetPolarization(const G4ThreeVector &pol)
void SetKineticEnergy(G4double eKin)
void SetMomentumDirection(const G4ThreeVector &p)
void SetMass(G4double mas)
void SetPrimary(G4PrimaryParticle *pp)
G4ThreeVector particle_position

◆ GetNumberOfParticles()

G4int G4ParticleGun::GetNumberOfParticles ( ) const
inline

Definition at line 117 of file G4ParticleGun.hh.

Referenced by G4ParticleGunMessenger::GetCurrentValue().

◆ GetParticleCharge()

G4double G4ParticleGun::GetParticleCharge ( ) const
inline

Definition at line 113 of file G4ParticleGun.hh.

114 { return particle_charge; }

◆ GetParticleDefinition()

G4ParticleDefinition * G4ParticleGun::GetParticleDefinition ( ) const
inline

Definition at line 105 of file G4ParticleGun.hh.

106 { return particle_definition; }

Referenced by G4ParticleGunMessenger::GetCurrentValue().

◆ GetParticleEnergy()

G4double G4ParticleGun::GetParticleEnergy ( ) const
inline

Definition at line 109 of file G4ParticleGun.hh.

110 { return particle_energy; }

Referenced by G4ParticleGunMessenger::GetCurrentValue().

◆ GetParticleMomentum()

G4double G4ParticleGun::GetParticleMomentum ( ) const
inline

Definition at line 111 of file G4ParticleGun.hh.

112 { return particle_momentum; }
G4double particle_momentum

Referenced by G4ParticleGunMessenger::GetCurrentValue().

◆ GetParticleMomentumDirection()

G4ParticleMomentum G4ParticleGun::GetParticleMomentumDirection ( ) const
inline

Definition at line 107 of file G4ParticleGun.hh.

Referenced by G4ParticleGunMessenger::GetCurrentValue().

◆ GetParticlePolarization()

G4ThreeVector G4ParticleGun::GetParticlePolarization ( ) const
inline

Definition at line 115 of file G4ParticleGun.hh.

116 { return particle_polarization; }

Referenced by G4ParticleGunMessenger::GetCurrentValue().

◆ operator!=()

G4bool G4ParticleGun::operator!= ( const G4ParticleGun ) const
delete

◆ operator=()

const G4ParticleGun & G4ParticleGun::operator= ( const G4ParticleGun )
delete

◆ operator==()

G4bool G4ParticleGun::operator== ( const G4ParticleGun ) const
delete

◆ SetInitialValues()

void G4ParticleGun::SetInitialValues ( )
protectedvirtual

Definition at line 57 of file G4ParticleGun.cc.

Referenced by G4ParticleGun().

◆ SetNumberOfParticles()

void G4ParticleGun::SetNumberOfParticles ( G4int  i)
inline

Definition at line 102 of file G4ParticleGun.hh.

Referenced by G4ParticleGunMessenger::SetNewValue().

◆ SetParticleCharge()

void G4ParticleGun::SetParticleCharge ( G4double  aCharge)
inline

Definition at line 98 of file G4ParticleGun.hh.

99 { particle_charge = aCharge; }

◆ SetParticleDefinition()

void G4ParticleGun::SetParticleDefinition ( G4ParticleDefinition aParticleDefinition)

Definition at line 77 of file G4ParticleGun.cc.

79{
80 if(aParticleDefinition == nullptr)
81 {
82 G4Exception("G4ParticleGun::SetParticleDefinition()", "Event0101",
83 FatalException, "Null pointer is given.");
84 }
85 if(aParticleDefinition->IsShortLived())
86 {
87 if(aParticleDefinition->GetDecayTable() == nullptr)
88 {
90 ED << "G4ParticleGun does not support shooting a short-lived "
91 << "particle without a valid decay table." << G4endl;
92 ED << "G4ParticleGun::SetParticleDefinition for "
93 << aParticleDefinition->GetParticleName() << " is ignored." << G4endl;
94 G4Exception("G4ParticleGun::SetParticleDefinition()", "Event0102",
95 JustWarning, ED);
96 return;
97 }
98 }
99 particle_definition = aParticleDefinition;
101 if(particle_momentum>0.0)
102 {
105 std::sqrt(particle_momentum*particle_momentum+mass*mass)-mass;
106 }
107}
@ JustWarning
G4double GetPDGCharge() const
G4DecayTable * GetDecayTable() const
const G4String & GetParticleName() const

Referenced by G4ParticleGun(), G4ParticleGunMessenger::G4ParticleGunMessenger(), and G4ParticleGunMessenger::SetNewValue().

◆ SetParticleEnergy()

void G4ParticleGun::SetParticleEnergy ( G4double  aKineticEnergy)

Definition at line 109 of file G4ParticleGun.cc.

110{
111 particle_energy = aKineticEnergy;
112 if(particle_momentum>0.0)
113 {
114 if(particle_definition != nullptr)
115 {
116 G4cout << "G4ParticleGun::" << particle_definition->GetParticleName()
117 << G4endl;
118 }
119 else
120 {
121 G4cout << "G4ParticleGun::" << " " << G4endl;
122 }
123 G4cout << " was defined in terms of Momentum: "
124 << particle_momentum/GeV << "GeV/c" << G4endl;
125 G4cout << " is now defined in terms of KineticEnergy: "
126 << particle_energy/GeV << "GeV" << G4endl;
127 particle_momentum = 0.0;
128 }
129}
G4GLOB_DLL std::ostream G4cout

Referenced by G4ParticleGunMessenger::G4ParticleGunMessenger(), and G4ParticleGunMessenger::SetNewValue().

◆ SetParticleMomentum() [1/2]

void G4ParticleGun::SetParticleMomentum ( G4double  aMomentum)

Definition at line 131 of file G4ParticleGun.cc.

132{
133 if(particle_energy>0.0)
134 {
135 if(particle_definition != nullptr)
136 {
137 G4cout << "G4ParticleGun::" << particle_definition->GetParticleName()
138 << G4endl;
139 }
140 else
141 {
142 G4cout << "G4ParticleGun::" << " " << G4endl;
143 }
144 G4cout << " was defined in terms of KineticEnergy: "
145 << particle_energy/GeV << "GeV" << G4endl;
146 G4cout << " is now defined in terms Momentum: "
147 << aMomentum/GeV << "GeV/c" << G4endl;
148 }
149 if(particle_definition == nullptr)
150 {
151 G4cout << "Particle Definition not defined yet for G4ParticleGun"
152 << G4endl;
153 G4cout << "Zero Mass is assumed" << G4endl;
154 particle_momentum = aMomentum;
155 particle_energy = aMomentum;
156 }
157 else
158 {
160 particle_momentum = aMomentum;
162 std::sqrt(particle_momentum*particle_momentum+mass*mass)-mass;
163 }
164}

Referenced by G4ParticleGunMessenger::SetNewValue().

◆ SetParticleMomentum() [2/2]

void G4ParticleGun::SetParticleMomentum ( G4ParticleMomentum  aMomentum)

Definition at line 166 of file G4ParticleGun.cc.

167{
168 if(particle_energy>0.0)
169 {
170 if(particle_definition != nullptr)
171 {
172 G4cout << "G4ParticleGun::" << particle_definition->GetParticleName()
173 << G4endl;
174 }
175 else
176 {
177 G4cout << "G4ParticleGun::" << " " << G4endl;
178 }
179 G4cout << " was defined in terms of KineticEnergy: "
180 << particle_energy/GeV << "GeV" << G4endl;
181 G4cout << " is now defined in terms Momentum: "
182 << aMomentum.mag()/GeV << "GeV/c" << G4endl;
183 }
184 if(particle_definition == nullptr)
185 {
186 G4cout << "Particle Definition not defined yet for G4ParticleGun"
187 << G4endl;
188 G4cout << "Zero Mass is assumed" << G4endl;
189 particle_momentum_direction = aMomentum.unit();
190 particle_momentum = aMomentum.mag();
191 particle_energy = aMomentum.mag();
192 }
193 else
194 {
196 particle_momentum = aMomentum.mag();
197 particle_momentum_direction = aMomentum.unit();
199 std::sqrt(particle_momentum*particle_momentum+mass*mass)-mass;
200 }
201}
Hep3Vector unit() const
double mag() const

◆ SetParticleMomentumDirection()

void G4ParticleGun::SetParticleMomentumDirection ( G4ParticleMomentum  aMomDirection)
inline

◆ SetParticlePolarization()

void G4ParticleGun::SetParticlePolarization ( G4ThreeVector  aVal)
inline

Definition at line 100 of file G4ParticleGun.hh.

101 { particle_polarization = aVal; }

Referenced by G4ParticleGunMessenger::SetNewValue().

Member Data Documentation

◆ NumberOfParticlesToBeGenerated

G4int G4ParticleGun::NumberOfParticlesToBeGenerated = 0
protected

◆ particle_charge

G4double G4ParticleGun::particle_charge = 0.0
protected

◆ particle_definition

G4ParticleDefinition* G4ParticleGun::particle_definition = nullptr
protected

◆ particle_energy

G4double G4ParticleGun::particle_energy = 0.0
protected

◆ particle_momentum

G4double G4ParticleGun::particle_momentum = 0.0
protected

◆ particle_momentum_direction

G4ParticleMomentum G4ParticleGun::particle_momentum_direction
protected

◆ particle_polarization

G4ThreeVector G4ParticleGun::particle_polarization
protected

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