Geant4-11
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes
G4ParticleGun Class Reference

#include <G4ParticleGun.hh>

Inheritance diagram for G4ParticleGun:
G4VPrimaryGenerator

Public Member Functions

 G4ParticleGun ()
 
 G4ParticleGun (const G4ParticleGun &)=delete
 
 G4ParticleGun (G4int numberofparticles)
 
 G4ParticleGun (G4ParticleDefinition *particleDef, G4int numberofparticles=1)
 
virtual void GeneratePrimaryVertex (G4Event *evt)
 
G4int GetNumberOfParticles () const
 
G4double GetParticleCharge () const
 
G4ParticleDefinitionGetParticleDefinition () const
 
G4double GetParticleEnergy () const
 
G4double GetParticleMomentum () const
 
G4ParticleMomentum GetParticleMomentumDirection () const
 
G4ThreeVector GetParticlePolarization () const
 
G4ThreeVector GetParticlePosition ()
 
G4double GetParticleTime ()
 
G4bool operator!= (const G4ParticleGun &) const =delete
 
const G4ParticleGunoperator= (const G4ParticleGun &)=delete
 
G4bool operator== (const G4ParticleGun &) const =delete
 
void SetNumberOfParticles (G4int i)
 
void SetParticleCharge (G4double aCharge)
 
void SetParticleDefinition (G4ParticleDefinition *aParticleDefinition)
 
void SetParticleEnergy (G4double aKineticEnergy)
 
void SetParticleMomentum (G4double aMomentum)
 
void SetParticleMomentum (G4ParticleMomentum aMomentum)
 
void SetParticleMomentumDirection (G4ParticleMomentum aMomDirection)
 
void SetParticlePolarization (G4ThreeVector aVal)
 
void SetParticlePosition (G4ThreeVector aPosition)
 
void SetParticleTime (G4double aTime)
 
virtual ~G4ParticleGun ()
 

Static Public Member Functions

static G4bool CheckVertexInsideWorld (const G4ThreeVector &pos)
 

Protected Member Functions

virtual void SetInitialValues ()
 

Protected Attributes

G4int NumberOfParticlesToBeGenerated = 0
 
G4double particle_charge = 0.0
 
G4ParticleDefinitionparticle_definition = nullptr
 
G4double particle_energy = 0.0
 
G4double particle_momentum = 0.0
 
G4ParticleMomentum particle_momentum_direction
 
G4ThreeVector particle_polarization
 
G4ThreeVector particle_position
 
G4double particle_time = 0.0
 

Private Attributes

G4ParticleGunMessengertheMessenger = nullptr
 

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()

References SetInitialValues().

◆ G4ParticleGun() [2/4]

G4ParticleGun::G4ParticleGun ( G4int  numberofparticles)

Definition at line 43 of file G4ParticleGun.cc.

44{
46 NumberOfParticlesToBeGenerated = numberofparticles;
47}
G4int NumberOfParticlesToBeGenerated

References NumberOfParticlesToBeGenerated, and SetInitialValues().

◆ 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)

References NumberOfParticlesToBeGenerated, SetInitialValues(), and SetParticleDefinition().

◆ ~G4ParticleGun()

G4ParticleGun::~G4ParticleGun ( )
virtual

Definition at line 72 of file G4ParticleGun.cc.

73{
74 delete theMessenger;
75}
G4ParticleGunMessenger * theMessenger

References theMessenger.

◆ G4ParticleGun() [4/4]

G4ParticleGun::G4ParticleGun ( const G4ParticleGun right)
delete

Definition at line 46 of file pyG4ParticleGun.cc.

48{
49 *this= right;
50}

Member Function Documentation

◆ CheckVertexInsideWorld()

G4bool G4VPrimaryGenerator::CheckVertexInsideWorld ( const G4ThreeVector pos)
staticinherited

Definition at line 43 of file G4VPrimaryGenerator.cc.

44{
46 -> GetNavigatorForTracking();
47
48 G4VPhysicalVolume* world= navigator-> GetWorldVolume();
49 G4VSolid* solid = world-> GetLogicalVolume()-> GetSolid();
50 EInside qinside = solid-> Inside(pos);
51
52 return (qinside != kInside) ? false : true;
53}
static const G4double pos
static G4TransportationManager * GetTransportationManager()
EInside
Definition: geomdefs.hh:67
@ kInside
Definition: geomdefs.hh:70

References G4TransportationManager::GetTransportationManager(), kInside, write_gdml::navigator, and pos.

◆ 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

References G4Event::AddPrimaryVertex(), FatalException, G4endl, G4Exception(), G4ParticleDefinition::GetPDGMass(), NumberOfParticlesToBeGenerated, particle_charge, particle_definition, particle_energy, particle_momentum_direction, particle_polarization, G4VPrimaryGenerator::particle_position, G4VPrimaryGenerator::particle_time, G4PrimaryParticle::SetCharge(), G4PrimaryParticle::SetKineticEnergy(), G4PrimaryParticle::SetMass(), G4PrimaryParticle::SetMomentumDirection(), G4PrimaryParticle::SetPolarization(), G4PrimaryVertex::SetPrimary(), CLHEP::Hep3Vector::x(), CLHEP::Hep3Vector::y(), and CLHEP::Hep3Vector::z().

Referenced by export_G4ParticleGun(), and PrimaryGeneratorAction::GeneratePrimaries().

◆ GetNumberOfParticles()

G4int G4ParticleGun::GetNumberOfParticles ( ) const
inline

◆ GetParticleCharge()

G4double G4ParticleGun::GetParticleCharge ( ) const
inline

Definition at line 113 of file G4ParticleGun.hh.

114 { return particle_charge; }

References particle_charge.

Referenced by export_G4ParticleGun().

◆ GetParticleDefinition()

G4ParticleDefinition * G4ParticleGun::GetParticleDefinition ( ) const
inline

◆ GetParticleEnergy()

G4double G4ParticleGun::GetParticleEnergy ( ) const
inline

◆ GetParticleMomentum()

G4double G4ParticleGun::GetParticleMomentum ( ) const
inline

Definition at line 111 of file G4ParticleGun.hh.

112 { return particle_momentum; }
G4double particle_momentum

References particle_momentum.

Referenced by G4ParticleGunMessenger::GetCurrentValue().

◆ GetParticleMomentumDirection()

G4ParticleMomentum G4ParticleGun::GetParticleMomentumDirection ( ) const
inline

◆ GetParticlePolarization()

G4ThreeVector G4ParticleGun::GetParticlePolarization ( ) const
inline

Definition at line 115 of file G4ParticleGun.hh.

116 { return particle_polarization; }

References particle_polarization.

Referenced by export_G4ParticleGun(), and G4ParticleGunMessenger::GetCurrentValue().

◆ GetParticlePosition()

G4ThreeVector G4VPrimaryGenerator::GetParticlePosition ( )
inlineinherited

◆ GetParticleTime()

G4double G4VPrimaryGenerator::GetParticleTime ( )
inlineinherited

◆ operator!=()

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

Definition at line 74 of file pyG4ParticleGun.cc.

76{
77 return false;
78}

◆ operator=()

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

◆ operator==()

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

Definition at line 67 of file pyG4ParticleGun.cc.

69{
70 return false;
71}

◆ SetInitialValues()

void G4ParticleGun::SetInitialValues ( )
protectedvirtual

◆ SetNumberOfParticles()

void G4ParticleGun::SetNumberOfParticles ( G4int  i)
inline

◆ SetParticleCharge()

void G4ParticleGun::SetParticleCharge ( G4double  aCharge)
inline

◆ 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

References FatalException, G4endl, G4Exception(), G4ParticleDefinition::GetDecayTable(), G4ParticleDefinition::GetParticleName(), G4ParticleDefinition::GetPDGCharge(), G4ParticleDefinition::GetPDGMass(), G4ParticleDefinition::IsShortLived(), JustWarning, particle_charge, particle_definition, particle_energy, and particle_momentum.

Referenced by export_G4ParticleGun(), G4ParticleGun(), G4ParticleGunMessenger::G4ParticleGunMessenger(), G4ParticleGunMessenger::IonCommand(), G4ParticleGunMessenger::IonLevelCommand(), PrimaryGeneratorAction::SetDefaultKinematic(), 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}
static constexpr double GeV
Definition: G4SIunits.hh:203
G4GLOB_DLL std::ostream G4cout

References G4cout, G4endl, G4ParticleDefinition::GetParticleName(), GeV, particle_definition, particle_energy, and particle_momentum.

Referenced by export_G4ParticleGun(), G4ParticleGunMessenger::G4ParticleGunMessenger(), PrimaryGeneratorAction::SetDefaultKinematic(), 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}

References G4cout, G4endl, G4ParticleDefinition::GetParticleName(), G4ParticleDefinition::GetPDGMass(), GeV, particle_definition, particle_energy, and particle_momentum.

Referenced by export_G4ParticleGun(), and 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

References G4cout, G4endl, G4ParticleDefinition::GetParticleName(), G4ParticleDefinition::GetPDGMass(), GeV, CLHEP::Hep3Vector::mag(), particle_definition, particle_energy, particle_momentum, particle_momentum_direction, and CLHEP::Hep3Vector::unit().

◆ 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; }

References particle_polarization.

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

◆ SetParticlePosition()

void G4VPrimaryGenerator::SetParticlePosition ( G4ThreeVector  aPosition)
inlineinherited

◆ SetParticleTime()

void G4VPrimaryGenerator::SetParticleTime ( G4double  aTime)
inlineinherited

Field 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

◆ particle_position

G4ThreeVector G4VPrimaryGenerator::particle_position
protectedinherited

◆ particle_time

G4double G4VPrimaryGenerator::particle_time = 0.0
protectedinherited

◆ theMessenger

G4ParticleGunMessenger* G4ParticleGun::theMessenger = nullptr
private

Definition at line 134 of file G4ParticleGun.hh.

Referenced by SetInitialValues(), and ~G4ParticleGun().


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