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

#include <G4ParticleGun.hh>

Inheritance diagram for G4ParticleGun:
Collaboration 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 ()
 
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::G4ParticleGun ( )

Definition at line 38 of file G4ParticleGun.cc.

39 {
41 }
virtual void SetInitialValues()

Here is the call graph for this function:

G4ParticleGun::G4ParticleGun ( G4int  numberofparticles)

Definition at line 43 of file G4ParticleGun.cc.

44 {
46  NumberOfParticlesToBeGenerated = numberofparticles;
47 }
virtual void SetInitialValues()
G4int NumberOfParticlesToBeGenerated

Here is the call graph for this function:

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

Definition at line 50 of file G4ParticleGun.cc.

51 {
53  NumberOfParticlesToBeGenerated = numberofparticles;
54  SetParticleDefinition( particleDef );
55 }
virtual void SetInitialValues()
G4int NumberOfParticlesToBeGenerated
void SetParticleDefinition(G4ParticleDefinition *aParticleDefinition)
G4ParticleGun::~G4ParticleGun ( )
virtual

Definition at line 72 of file G4ParticleGun.cc.

73 {
74  delete theMessenger;
75 }

Member Function Documentation

void G4ParticleGun::GeneratePrimaryVertex ( G4Event evt)
virtual

Implements G4VPrimaryGenerator.

Definition at line 212 of file G4ParticleGun.cc.

213 {
214  if(!particle_definition)
215  {
217  ED << "Particle definition is not defined." << G4endl;
218  ED << "G4ParticleGun::SetParticleDefinition() has to be invoked beforehand." << G4endl;
219  G4Exception("G4ParticleGun::GeneratePrimaryVertex()","Event0109",
220  FatalException, ED);
221  return;
222  }
223 
224  // create a new vertex
225  G4PrimaryVertex* vertex =
227 
228  // create new primaries and set them to the vertex
230  for( G4int i=0; i<NumberOfParticlesToBeGenerated; i++ ){
231  G4PrimaryParticle* particle =
233  particle->SetKineticEnergy( particle_energy );
234  particle->SetMass( mass );
236  particle->SetCharge( particle_charge );
240  vertex->SetPrimary( particle );
241  }
242 
243  evt->AddPrimaryVertex( vertex );
244 }
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
double x() const
void AddPrimaryVertex(G4PrimaryVertex *aPrimaryVertex)
Definition: G4Event.hh:154
int G4int
Definition: G4Types.hh:78
G4ParticleDefinition * particle_definition
G4ThreeVector particle_position
double z() const
void SetKineticEnergy(G4double eKin)
G4ParticleMomentum particle_momentum_direction
void SetMass(G4double mas)
G4double particle_charge
G4ThreeVector particle_polarization
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4int NumberOfParticlesToBeGenerated
G4double particle_energy
G4double GetPDGMass() const
void SetMomentumDirection(const G4ThreeVector &p)
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:

G4int G4ParticleGun::GetNumberOfParticles ( ) const
inline

Definition at line 118 of file G4ParticleGun.hh.

G4int NumberOfParticlesToBeGenerated

Here is the caller graph for this function:

G4double G4ParticleGun::GetParticleCharge ( ) const
inline

Definition at line 114 of file G4ParticleGun.hh.

115  { return particle_charge; }
G4double particle_charge
G4ParticleDefinition* G4ParticleGun::GetParticleDefinition ( ) const
inline

Definition at line 106 of file G4ParticleGun.hh.

107  { return particle_definition; }
G4ParticleDefinition * particle_definition

Here is the caller graph for this function:

G4double G4ParticleGun::GetParticleEnergy ( ) const
inline

Definition at line 110 of file G4ParticleGun.hh.

111  { return particle_energy; }
G4double particle_energy

Here is the caller graph for this function:

G4double G4ParticleGun::GetParticleMomentum ( ) const
inline

Definition at line 112 of file G4ParticleGun.hh.

113  { return particle_momentum; }
G4double particle_momentum

Here is the caller graph for this function:

G4ParticleMomentum G4ParticleGun::GetParticleMomentumDirection ( ) const
inline

Definition at line 108 of file G4ParticleGun.hh.

109  { return particle_momentum_direction; }
G4ParticleMomentum particle_momentum_direction

Here is the caller graph for this function:

G4ThreeVector G4ParticleGun::GetParticlePolarization ( ) const
inline

Definition at line 116 of file G4ParticleGun.hh.

117  { return particle_polarization; }
G4ThreeVector particle_polarization

Here is the caller graph for this function:

void G4ParticleGun::SetInitialValues ( )
protectedvirtual

Definition at line 57 of file G4ParticleGun.cc.

58 {
60  particle_definition = nullptr;
61  G4ThreeVector zero;
63  particle_energy = 0.0;
64  particle_momentum = 0.0;
65  particle_position = zero;
66  particle_time = 0.0;
67  particle_polarization = zero;
68  particle_charge = 0.0;
69  theMessenger = new G4ParticleGunMessenger(this);
70 }
G4double particle_momentum
G4ParticleDefinition * particle_definition
G4ThreeVector particle_position
G4ParticleMomentum particle_momentum_direction
G4double particle_charge
G4ThreeVector particle_polarization
G4int NumberOfParticlesToBeGenerated
G4double particle_energy
G4ThreeVector G4ParticleMomentum

Here is the caller graph for this function:

void G4ParticleGun::SetNumberOfParticles ( G4int  i)
inline

Definition at line 102 of file G4ParticleGun.hh.

G4int NumberOfParticlesToBeGenerated

Here is the caller graph for this function:

void G4ParticleGun::SetParticleCharge ( G4double  aCharge)
inline

Definition at line 98 of file G4ParticleGun.hh.

99  { particle_charge = aCharge; }
G4double particle_charge
void G4ParticleGun::SetParticleDefinition ( G4ParticleDefinition aParticleDefinition)

Definition at line 102 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 }
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
G4double particle_momentum
G4ParticleDefinition * particle_definition
const G4String & GetParticleName() const
G4DecayTable * GetDecayTable() const
G4double particle_charge
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4double particle_energy
G4double GetPDGMass() const
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
G4double GetPDGCharge() const

Here is the call graph for this function:

Here is the caller graph for this function:

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 }
G4double particle_momentum
G4ParticleDefinition * particle_definition
const G4String & GetParticleName() const
G4GLOB_DLL std::ostream G4cout
G4double particle_energy
static constexpr double GeV
Definition: G4SIunits.hh:217
#define G4endl
Definition: G4ios.hh:61

Here is the call graph for this function:

Here is the caller graph for this function:

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 }
G4double particle_momentum
G4ParticleDefinition * particle_definition
const G4String & GetParticleName() const
G4GLOB_DLL std::ostream G4cout
G4double particle_energy
G4double GetPDGMass() const
static constexpr double GeV
Definition: G4SIunits.hh:217
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76

Here is the call graph for this function:

Here is the caller graph for this function:

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();
207  particle_energy =
208  std::sqrt(particle_momentum*particle_momentum+mass*mass)-mass;
209  }
210 }
G4double particle_momentum
G4ParticleDefinition * particle_definition
const G4String & GetParticleName() const
G4ParticleMomentum particle_momentum_direction
G4GLOB_DLL std::ostream G4cout
G4double particle_energy
G4double GetPDGMass() const
Hep3Vector unit() const
static constexpr double GeV
Definition: G4SIunits.hh:217
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
double mag() const

Here is the call graph for this function:

void G4ParticleGun::SetParticleMomentumDirection ( G4ParticleMomentum  aMomentumDirection)
inline

Definition at line 96 of file G4ParticleGun.hh.

97  { particle_momentum_direction = aMomentumDirection.unit(); }
G4ParticleMomentum particle_momentum_direction
Hep3Vector unit() const

Here is the call graph for this function:

Here is the caller graph for this function:

void G4ParticleGun::SetParticlePolarization ( G4ThreeVector  aVal)
inline

Definition at line 100 of file G4ParticleGun.hh.

101  { particle_polarization = aVal; }
G4ThreeVector particle_polarization

Here is the caller graph for this function:

Member Data Documentation

G4int G4ParticleGun::NumberOfParticlesToBeGenerated
protected

Definition at line 124 of file G4ParticleGun.hh.

G4double G4ParticleGun::particle_charge
protected

Definition at line 129 of file G4ParticleGun.hh.

G4ParticleDefinition* G4ParticleGun::particle_definition
protected

Definition at line 125 of file G4ParticleGun.hh.

G4double G4ParticleGun::particle_energy
protected

Definition at line 127 of file G4ParticleGun.hh.

G4double G4ParticleGun::particle_momentum
protected

Definition at line 128 of file G4ParticleGun.hh.

G4ParticleMomentum G4ParticleGun::particle_momentum_direction
protected

Definition at line 126 of file G4ParticleGun.hh.

G4ThreeVector G4ParticleGun::particle_polarization
protected

Definition at line 130 of file G4ParticleGun.hh.


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