Geant4 9.6.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 ()
 
virtual void GeneratePrimaryVertex (G4Event *evt)
 
void SetParticleDefinition (G4ParticleDefinition *aParticleDefinition)
 
void SetParticleEnergy (G4double aKineticEnergy)
 
void SetParticleMomentum (G4double aMomentum)
 
void SetParticleMomentum (G4ParticleMomentum aMomentum)
 
void SetParticleMomentumDirection (G4ParticleMomentum aMomentumDirection)
 
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
 
G4ParticleDefinitionparticle_definition
 
G4ParticleMomentum particle_momentum_direction
 
G4double particle_energy
 
G4double particle_momentum
 
G4double particle_charge
 
G4ThreeVector particle_polarization
 
- Protected Attributes inherited from G4VPrimaryGenerator
G4ThreeVector particle_position
 
G4double particle_time
 

Additional Inherited Members

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

Detailed Description

Definition at line 62 of file G4ParticleGun.hh.

Constructor & Destructor Documentation

◆ G4ParticleGun() [1/3]

G4ParticleGun::G4ParticleGun ( )

Definition at line 38 of file G4ParticleGun.cc.

39{
41}
virtual void SetInitialValues()

◆ G4ParticleGun() [2/3]

G4ParticleGun::G4ParticleGun ( G4int  numberofparticles)

Definition at line 43 of file G4ParticleGun.cc.

44{
46 NumberOfParticlesToBeGenerated = numberofparticles;
47}
G4int NumberOfParticlesToBeGenerated

◆ G4ParticleGun() [3/3]

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}

Member Function Documentation

◆ GeneratePrimaryVertex()

void G4ParticleGun::GeneratePrimaryVertex ( G4Event evt)
virtual

Implements G4VPrimaryGenerator.

Definition at line 212 of file G4ParticleGun.cc.

213{
214 if(particle_definition==0) return;
215
216 // create a new vertex
217 G4PrimaryVertex* vertex =
219
220 // create new primaries and set them to the vertex
222 for( G4int i=0; i<NumberOfParticlesToBeGenerated; i++ ){
223 G4PrimaryParticle* particle =
226 particle->SetMass( mass );
228 particle->SetCharge( particle_charge );
232 vertex->SetPrimary( particle );
233 }
234
235 evt->AddPrimaryVertex( vertex );
236}
double G4double
Definition: G4Types.hh:64
int G4int
Definition: G4Types.hh:66
double z() const
double x() const
double y() const
void AddPrimaryVertex(G4PrimaryVertex *aPrimaryVertex)
Definition: G4Event.hh:142
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 118 of file G4ParticleGun.hh.

Referenced by G4ParticleGunMessenger::GetCurrentValue().

◆ GetParticleCharge()

G4double G4ParticleGun::GetParticleCharge ( ) const
inline

Definition at line 114 of file G4ParticleGun.hh.

115 { return particle_charge; }

◆ GetParticleDefinition()

G4ParticleDefinition * G4ParticleGun::GetParticleDefinition ( ) const
inline

Definition at line 106 of file G4ParticleGun.hh.

107 { return particle_definition; }

Referenced by G4ParticleGunMessenger::GetCurrentValue().

◆ GetParticleEnergy()

G4double G4ParticleGun::GetParticleEnergy ( ) const
inline

Definition at line 110 of file G4ParticleGun.hh.

111 { return particle_energy; }

Referenced by G4ParticleGunMessenger::GetCurrentValue().

◆ GetParticleMomentum()

G4double G4ParticleGun::GetParticleMomentum ( ) const
inline

Definition at line 112 of file G4ParticleGun.hh.

113 { return particle_momentum; }
G4double particle_momentum

Referenced by G4ParticleGunMessenger::GetCurrentValue().

◆ GetParticleMomentumDirection()

G4ParticleMomentum G4ParticleGun::GetParticleMomentumDirection ( ) const
inline

Definition at line 108 of file G4ParticleGun.hh.

Referenced by G4ParticleGunMessenger::GetCurrentValue().

◆ GetParticlePolarization()

G4ThreeVector G4ParticleGun::GetParticlePolarization ( ) const
inline

Definition at line 116 of file G4ParticleGun.hh.

117 { return particle_polarization; }

Referenced by G4ParticleGunMessenger::GetCurrentValue().

◆ 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 101 of file G4ParticleGun.cc.

103{
104 if(!aParticleDefinition)
105 {
106 G4Exception("G4ParticleGun::SetParticleDefinition()","Event0101",
107 FatalException,"Null pointer is given.");
108 }
109 if(aParticleDefinition->IsShortLived())
110 {
111 if(!(aParticleDefinition->GetDecayTable()))
112 {
114 ED << "G4ParticleGun does not support shooting a short-lived particle without a valid decay table." << G4endl;
115 ED << "G4ParticleGun::SetParticleDefinition for "
116 << aParticleDefinition->GetParticleName() << " is ignored." << G4endl;
117 G4Exception("G4ParticleGun::SetParticleDefinition()","Event0102",
118 JustWarning,ED);
119 return;
120 }
121 }
122 particle_definition = aParticleDefinition;
124 if(particle_momentum>0.0)
125 {
128 std::sqrt(particle_momentum*particle_momentum+mass*mass)-mass;
129 }
130}
@ JustWarning
@ FatalException
#define G4endl
Definition: G4ios.hh:52
G4double GetPDGCharge() const
G4DecayTable * GetDecayTable() const
const G4String & GetParticleName() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76

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

◆ SetParticleEnergy()

void G4ParticleGun::SetParticleEnergy ( G4double  aKineticEnergy)

Definition at line 132 of file G4ParticleGun.cc.

133{
134 particle_energy = aKineticEnergy;
135 if(particle_momentum>0.0){
137 G4cout << "G4ParticleGun::" << particle_definition->GetParticleName()
138 << G4endl;
139 }else{
140 G4cout << "G4ParticleGun::" << " " << G4endl;
141 }
142 G4cout << " was defined in terms of Momentum: "
143 << particle_momentum/GeV << "GeV/c" << G4endl;
144 G4cout << " is now defined in terms of KineticEnergy: "
145 << particle_energy/GeV << "GeV" << G4endl;
146 particle_momentum = 0.0;
147 }
148}
G4DLLIMPORT std::ostream G4cout

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

◆ SetParticleMomentum() [1/2]

void G4ParticleGun::SetParticleMomentum ( G4double  aMomentum)

Definition at line 150 of file G4ParticleGun.cc.

151{
152 if(particle_energy>0.0){
154 G4cout << "G4ParticleGun::" << particle_definition->GetParticleName()
155 << G4endl;
156 }else{
157 G4cout << "G4ParticleGun::" << " " << G4endl;
158 }
159 G4cout << " was defined in terms of KineticEnergy: "
160 << particle_energy/GeV << "GeV" << G4endl;
161 G4cout << " is now defined in terms Momentum: "
162 << aMomentum/GeV << "GeV/c" << G4endl;
163 }
165 {
166 G4cout <<"Particle Definition not defined yet for G4ParticleGun"<< G4endl;
167 G4cout <<"Zero Mass is assumed"<<G4endl;
168 particle_momentum = aMomentum;
169 particle_energy = aMomentum;
170 }
171 else
172 {
174 particle_momentum = aMomentum;
176 std::sqrt(particle_momentum*particle_momentum+mass*mass)-mass;
177 }
178}

Referenced by G4ParticleGunMessenger::SetNewValue().

◆ SetParticleMomentum() [2/2]

void G4ParticleGun::SetParticleMomentum ( G4ParticleMomentum  aMomentum)

Definition at line 180 of file G4ParticleGun.cc.

181{
182 if(particle_energy>0.0){
184 G4cout << "G4ParticleGun::" << particle_definition->GetParticleName()
185 << G4endl;
186 }else{
187 G4cout << "G4ParticleGun::" << " " << G4endl;
188 }
189 G4cout << " was defined in terms of KineticEnergy: "
190 << particle_energy/GeV << "GeV" << G4endl;
191 G4cout << " is now defined in terms Momentum: "
192 << aMomentum.mag()/GeV << "GeV/c" << G4endl;
193 }
195 {
196 G4cout <<"Particle Definition not defined yet for G4ParticleGun"<< G4endl;
197 G4cout <<"Zero Mass is assumed"<<G4endl;
198 particle_momentum_direction = aMomentum.unit();
199 particle_momentum = aMomentum.mag();
200 particle_energy = aMomentum.mag();
201 }
202 else
203 {
205 particle_momentum = aMomentum.mag();
206 particle_momentum_direction = aMomentum.unit();
208 std::sqrt(particle_momentum*particle_momentum+mass*mass)-mass;
209 }
210}
Hep3Vector unit() const
double mag() const

◆ SetParticleMomentumDirection()

void G4ParticleGun::SetParticleMomentumDirection ( G4ParticleMomentum  aMomentumDirection)
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
protected

◆ particle_charge

G4double G4ParticleGun::particle_charge
protected

◆ particle_definition

◆ particle_energy

G4double G4ParticleGun::particle_energy
protected

◆ particle_momentum

G4double G4ParticleGun::particle_momentum
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: