Geant4  10.02.p03
DMXParticleSource Class Reference

#include <DMXParticleSource.hh>

Inheritance diagram for DMXParticleSource:
Collaboration diagram for DMXParticleSource:

Public Member Functions

 DMXParticleSource ()
 
 ~DMXParticleSource ()
 
void GeneratePrimaryVertex (G4Event *evt)
 
void SetPosDisType (G4String)
 
void SetPosDisShape (G4String)
 
void SetCentreCoords (G4ThreeVector)
 
void SetHalfZ (G4double)
 
void SetRadius (G4double)
 
void GeneratePointSource ()
 
void GeneratePointsInVolume ()
 
G4bool IsSourceConfined ()
 
void ConfineSourceToVolume (G4String)
 
void SetAngDistType (G4String)
 
void SetParticleMomentumDirection (G4ParticleMomentum)
 
void GenerateIsotropicFlux ()
 
void SetEnergyDisType (G4String)
 
void SetMonoEnergy (G4double)
 
void GenerateMonoEnergetic ()
 
G4double GetParticleEnergy ()
 
void SetVerbosity (G4int)
 
void SetParticleDefinition (G4ParticleDefinition *aParticleDefinition)
 
void SetParticleCharge (G4double aCharge)
 
- Public Member Functions inherited from G4VPrimaryGenerator
 G4VPrimaryGenerator ()
 
virtual ~G4VPrimaryGenerator ()
 
G4ThreeVector GetParticlePosition ()
 
G4double GetParticleTime ()
 
void SetParticlePosition (G4ThreeVector aPosition)
 
void SetParticleTime (G4double aTime)
 

Private Attributes

G4String SourcePosType
 
G4String Shape
 
G4double halfz
 
G4double Radius
 
G4ThreeVector CentreCoords
 
G4bool Confine
 
G4String VolName
 
G4String AngDistType
 
G4double MinTheta
 
G4double MaxTheta
 
G4double MinPhi
 
G4double MaxPhi
 
G4double Phi
 
G4String EnergyDisType
 
G4double MonoEnergy
 
G4int NumberOfParticlesToBeGenerated
 
G4ParticleDefinitionparticle_definition
 
G4ParticleMomentum particle_momentum_direction
 
G4double particle_energy
 
G4double particle_charge
 
G4ThreeVector particle_position
 
G4double particle_time
 
G4ThreeVector particle_polarization
 
G4int verbosityLevel
 
DMXParticleSourceMessengertheMessenger
 
G4NavigatorgNavigator
 

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 58 of file DMXParticleSource.hh.

Constructor & Destructor Documentation

◆ DMXParticleSource()

DMXParticleSource::DMXParticleSource ( )

Definition at line 68 of file DMXParticleSource.cc.

68  {
69 
71  particle_definition = NULL;
72  G4ThreeVector zero(0., 0., 0.);
74  particle_energy = 1.0*MeV;
75  particle_position = zero;
76  particle_time = 0.0;
77  particle_polarization = zero;
78  particle_charge = 0.0;
79 
80  SourcePosType = "Volume";
81  Shape = "NULL";
82  halfz = 0.;
83  Radius = 0.;
84  CentreCoords = zero;
85  Confine = false;
86  VolName = "NULL";
87 
88  AngDistType = "iso";
89  MinTheta = 0.;
90  MaxTheta = pi;
91  MinPhi = 0.;
92  MaxPhi = twopi;
93 
94  EnergyDisType = "Mono";
95  MonoEnergy = 1*MeV;
96 
97  verbosityLevel = 0;
98 
102 }
static const double MeV
Definition: G4SIunits.hh:211
G4Navigator * gNavigator
DMXParticleSourceMessenger * theMessenger
G4ParticleDefinition * particle_definition
static const double twopi
Definition: G4SIunits.hh:75
G4Navigator * GetNavigatorForTracking() const
G4ParticleMomentum particle_momentum_direction
G4ThreeVector particle_polarization
static G4TransportationManager * GetTransportationManager()
static const double pi
Definition: G4SIunits.hh:74
G4ThreeVector CentreCoords
G4ThreeVector G4ParticleMomentum
G4ThreeVector particle_position
Here is the call graph for this function:

◆ ~DMXParticleSource()

DMXParticleSource::~DMXParticleSource ( )

Definition at line 104 of file DMXParticleSource.cc.

105 {
106  delete theMessenger;
107 }
DMXParticleSourceMessenger * theMessenger

Member Function Documentation

◆ ConfineSourceToVolume()

void DMXParticleSource::ConfineSourceToVolume ( G4String  Vname)

Definition at line 134 of file DMXParticleSource.cc.

135 {
136  VolName = Vname;
137  if(verbosityLevel == 2) G4cout << VolName << G4endl;
138 
139  // checks if selected volume exists
140  G4VPhysicalVolume *tempPV = NULL;
141  G4PhysicalVolumeStore *PVStore = 0;
142  G4String theRequiredVolumeName = VolName;
144  G4int i = 0;
145  G4bool found = false;
146  if(verbosityLevel == 2) G4cout << PVStore->size() << G4endl;
147 
148  // recasting required since PVStore->size() is actually a signed int...
149  while (!found && i<(G4int)PVStore->size())
150  {
151  tempPV = (*PVStore)[i];
152  found = tempPV->GetName() == theRequiredVolumeName;
153  if(verbosityLevel == 2)
154  G4cout << i << " " << " " << tempPV->GetName()
155  << " " << theRequiredVolumeName << " " << found << G4endl;
156  if (!found)
157  {i++;}
158  }
159 
160  // found = true then the volume exists else it doesnt.
161  if(found == true) {
162  if(verbosityLevel >= 1)
163  G4cout << "Volume " << VolName << " exists" << G4endl;
164  Confine = true;
165  }
166  else if(VolName=="NULL")
167  Confine = false;
168  else {
169  G4cout << " **** Error: Volume does not exist **** " << G4endl;
170  G4cout << " Ignoring confine condition" << G4endl;
171  VolName = "NULL";
172  Confine = false;
173  }
174 
175 }
int G4int
Definition: G4Types.hh:78
static G4PhysicalVolumeStore * GetInstance()
G4GLOB_DLL std::ostream G4cout
bool G4bool
Definition: G4Types.hh:79
const G4String & GetName() const
#define G4endl
Definition: G4ios.hh:61
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GenerateIsotropicFlux()

void DMXParticleSource::GenerateIsotropicFlux ( )

Definition at line 273 of file DMXParticleSource.cc.

274 {
275 
276  G4double rndm, rndm2;
277  G4double px, py, pz;
278 
279  G4double sintheta, sinphi, costheta, cosphi;
280  rndm = G4UniformRand();
281  costheta = std::cos(MinTheta) - rndm * (std::cos(MinTheta) - std::cos(MaxTheta));
282  sintheta = std::sqrt(1. - costheta*costheta);
283 
284  rndm2 = G4UniformRand();
285  Phi = MinPhi + (MaxPhi - MinPhi) * rndm2;
286  sinphi = std::sin(Phi);
287  cosphi = std::cos(Phi);
288 
289  px = -sintheta * cosphi;
290  py = -sintheta * sinphi;
291  pz = -costheta;
292 
293  G4double ResMag = std::sqrt((px*px) + (py*py) + (pz*pz));
294  px = px/ResMag;
295  py = py/ResMag;
296  pz = pz/ResMag;
297 
301 
302  // particle_momentum_direction now holds unit momentum vector.
303  if(verbosityLevel >= 2)
304  G4cout << "Generating isotropic vector: " << particle_momentum_direction << G4endl;
305 }
void setY(double)
void setZ(double)
void setX(double)
#define G4UniformRand()
Definition: Randomize.hh:97
G4GLOB_DLL std::ostream G4cout
G4ParticleMomentum particle_momentum_direction
#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:

◆ GenerateMonoEnergetic()

void DMXParticleSource::GenerateMonoEnergetic ( )

Definition at line 318 of file DMXParticleSource.cc.

319 {
321 }
Here is the caller graph for this function:

◆ GeneratePointsInVolume()

void DMXParticleSource::GeneratePointsInVolume ( )

Definition at line 195 of file DMXParticleSource.cc.

196 {
197  G4ThreeVector RandPos;
198  G4double x=0., y=0., z=0.;
199 
200  if(SourcePosType != "Volume" && verbosityLevel >= 1)
201  G4cout << "Error SourcePosType not Volume" << G4endl;
202 
203  if(Shape == "Sphere") {
204  x = Radius*2.;
205  y = Radius*2.;
206  z = Radius*2.;
207  while(((x*x)+(y*y)+(z*z)) > (Radius*Radius)) {
208  x = G4UniformRand();
209  y = G4UniformRand();
210  z = G4UniformRand();
211 
212  x = (x*2.*Radius) - Radius;
213  y = (y*2.*Radius) - Radius;
214  z = (z*2.*Radius) - Radius;
215  }
216  }
217 
218  else if(Shape == "Cylinder") {
219  x = Radius*2.;
220  y = Radius*2.;
221  while(((x*x)+(y*y)) > (Radius*Radius)) {
222  x = G4UniformRand();
223  y = G4UniformRand();
224  z = G4UniformRand();
225  x = (x*2.*Radius) - Radius;
226  y = (y*2.*Radius) - Radius;
227  z = (z*2.*halfz) - halfz;
228  }
229  }
230 
231  else
232  G4cout << "Error: Volume Shape Does Not Exist" << G4endl;
233 
234  RandPos.setX(x);
235  RandPos.setY(y);
236  RandPos.setZ(z);
237  particle_position = CentreCoords + RandPos;
238 
239 }
void setY(double)
void setZ(double)
void setX(double)
Double_t y
#define G4UniformRand()
Definition: Randomize.hh:97
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
G4ThreeVector CentreCoords
double G4double
Definition: G4Types.hh:76
G4ThreeVector particle_position
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GeneratePointSource()

void DMXParticleSource::GeneratePointSource ( )

Definition at line 184 of file DMXParticleSource.cc.

185 {
186  // Generates Points given the point source.
187  if(SourcePosType == "Point")
189  else
190  if(verbosityLevel >= 1)
191  G4cout << "Error SourcePosType is not set to Point" << G4endl;
192 }
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
G4ThreeVector CentreCoords
G4ThreeVector particle_position
Here is the caller graph for this function:

◆ GeneratePrimaryVertex()

void DMXParticleSource::GeneratePrimaryVertex ( G4Event evt)
virtual

Implements G4VPrimaryGenerator.

Definition at line 338 of file DMXParticleSource.cc.

339 {
340 
341  if(particle_definition==NULL) {
342  G4cout << "No particle has been defined!" << G4endl;
343  return;
344  }
345 
346  // Position
347  G4bool srcconf = false;
348  G4int LoopCount = 0;
349 
350  while(srcconf == false) {
351  if(SourcePosType == "Point")
353  else if(SourcePosType == "Volume")
355  else {
356  G4cout << "Error: SourcePosType undefined" << G4endl;
357  G4cout << "Generating point source" << G4endl;
359  }
360  if(Confine == true) {
361  srcconf = IsSourceConfined();
362  // if source in confined srcconf = true terminating the loop
363  // if source isnt confined srcconf = false and loop continues
364  }
365  else if(Confine == false)
366  srcconf = true; // terminate loop
367 
368  LoopCount++;
369  if(LoopCount == 100000) {
370  G4cout << "*************************************" << G4endl;
371  G4cout << "LoopCount = 100000" << G4endl;
372  G4cout << "Either the source distribution >> confinement" << G4endl;
373  G4cout << "or any confining volume may not overlap with" << G4endl;
374  G4cout << "the source distribution or any confining volumes" << G4endl;
375  G4cout << "may not exist"<< G4endl;
376  G4cout << "If you have set confine then this will be ignored" <<G4endl;
377  G4cout << "for this event." << G4endl;
378  G4cout << "*************************************" << G4endl;
379  srcconf = true; //Avoids an infinite loop
380  }
381  }
382 
383  // Angular stuff
384  if(AngDistType == "iso")
386  else if(AngDistType == "direction")
388  else
389  G4cout << "Error: AngDistType has unusual value" << G4endl;
390  // Energy stuff
391  if(EnergyDisType == "Mono")
393  else
394  G4cout << "Error: EnergyDisType has unusual value" << G4endl;
395 
396  // create a new vertex
397  G4PrimaryVertex* vertex =
399 
400  if(verbosityLevel >= 2)
401  G4cout << "Creating primaries and assigning to vertex" << G4endl;
402  // create new primaries and set them to the vertex
405  G4double pmom = std::sqrt(energy*energy-mass*mass);
409 
410  if(verbosityLevel >= 1){
411  G4cout << "Particle name: "
413  G4cout << " Energy: "<<particle_energy << G4endl;
414  G4cout << " Position: "<<particle_position<< G4endl;
415  G4cout << " Direction: "<<particle_momentum_direction << G4endl;
416  G4cout << " NumberOfParticlesToBeGenerated: "
418  }
419 
420 
421  for( G4int i=0; i<NumberOfParticlesToBeGenerated; i++ ) {
422  G4PrimaryParticle* particle =
424  particle->SetMass( mass );
425  particle->SetCharge( particle_charge );
429  vertex->SetPrimary( particle );
430  }
431  evt->AddPrimaryVertex( vertex );
432  if(verbosityLevel > 1)
433  G4cout << " Primary Vetex generated "<< G4endl;
434 }
void AddPrimaryVertex(G4PrimaryVertex *aPrimaryVertex)
Definition: G4Event.hh:154
int G4int
Definition: G4Types.hh:78
void SetParticleMomentumDirection(G4ParticleMomentum)
const G4String & GetParticleName() const
G4GLOB_DLL std::ostream G4cout
double energy
Definition: plottest35.C:25
bool G4bool
Definition: G4Types.hh:79
G4ParticleDefinition * particle_definition
void SetMass(G4double mas)
G4ParticleMomentum particle_momentum_direction
G4ThreeVector particle_polarization
double x() const
double y() const
void SetCharge(G4double chg)
double z() const
void SetPrimary(G4PrimaryParticle *pp)
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
void SetPolarization(const G4ThreeVector &pol)
G4ThreeVector particle_position
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetParticleEnergy()

G4double DMXParticleSource::GetParticleEnergy ( )
inline

Definition at line 87 of file DMXParticleSource.hh.

87 {return particle_energy;}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsSourceConfined()

G4bool DMXParticleSource::IsSourceConfined ( )

Definition at line 242 of file DMXParticleSource.cc.

243 {
244 
245  // Method to check point is within the volume specified
246  if(Confine == false)
247  G4cout << "Error: Confine is false" << G4endl;
248  G4ThreeVector null(0.,0.,0.);
249  G4ThreeVector *ptr;
250  ptr = &null;
251 
252  // Check particle_position is within VolName
253  G4VPhysicalVolume *theVolume;
255  G4String theVolName = theVolume->GetName();
256  if(theVolName == VolName) {
257  if(verbosityLevel >= 1)
258  G4cout << "Particle is in volume " << VolName << G4endl;
259  return(true);
260  }
261  else
262  return(false);
263 }
G4Navigator * gNavigator
G4GLOB_DLL std::ostream G4cout
const G4String & GetName() const
virtual G4VPhysicalVolume * LocateGlobalPointAndSetup(const G4ThreeVector &point, const G4ThreeVector *direction=0, const G4bool pRelativeSearch=true, const G4bool ignoreDirection=true)
Definition: G4Navigator.cc:125
#define G4endl
Definition: G4ios.hh:61
G4ThreeVector particle_position
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetAngDistType()

void DMXParticleSource::SetAngDistType ( G4String  atype)

Definition at line 178 of file DMXParticleSource.cc.

179 {
180  AngDistType = atype;
181 }
Here is the caller graph for this function:

◆ SetCentreCoords()

void DMXParticleSource::SetCentreCoords ( G4ThreeVector  coordsOfCentre)

Definition at line 119 of file DMXParticleSource.cc.

120 {
121  CentreCoords = coordsOfCentre;
122 }
G4ThreeVector CentreCoords
Here is the caller graph for this function:

◆ SetEnergyDisType()

void DMXParticleSource::SetEnergyDisType ( G4String  DisType)

Definition at line 308 of file DMXParticleSource.cc.

309 {
310  EnergyDisType = DisType;
311 }
Here is the caller graph for this function:

◆ SetHalfZ()

void DMXParticleSource::SetHalfZ ( G4double  zhalf)

Definition at line 124 of file DMXParticleSource.cc.

125 {
126  halfz = zhalf;
127 }
Here is the caller graph for this function:

◆ SetMonoEnergy()

void DMXParticleSource::SetMonoEnergy ( G4double  menergy)

Definition at line 313 of file DMXParticleSource.cc.

314 {
315  MonoEnergy = menergy;
316 }
Here is the caller graph for this function:

◆ SetParticleCharge()

void DMXParticleSource::SetParticleCharge ( G4double  aCharge)
inline

Definition at line 94 of file DMXParticleSource.hh.

95  { particle_charge = aCharge; }
Here is the caller graph for this function:

◆ SetParticleDefinition()

void DMXParticleSource::SetParticleDefinition ( G4ParticleDefinition aParticleDefinition)

Definition at line 331 of file DMXParticleSource.cc.

332 {
333  particle_definition = aParticleDefinition;
335 }
G4ParticleDefinition * particle_definition
G4double GetPDGCharge() const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetParticleMomentumDirection()

void DMXParticleSource::SetParticleMomentumDirection ( G4ParticleMomentum  aDirection)

Definition at line 267 of file DMXParticleSource.cc.

267  {
268 
269  particle_momentum_direction = aDirection.unit();
270 }
Hep3Vector unit() const
G4ParticleMomentum particle_momentum_direction
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetPosDisShape()

void DMXParticleSource::SetPosDisShape ( G4String  shapeType)

Definition at line 114 of file DMXParticleSource.cc.

115 {
116  Shape = shapeType;
117 }
Here is the caller graph for this function:

◆ SetPosDisType()

void DMXParticleSource::SetPosDisType ( G4String  PosType)

Definition at line 109 of file DMXParticleSource.cc.

110 {
111  SourcePosType = PosType;
112 }
Here is the caller graph for this function:

◆ SetRadius()

void DMXParticleSource::SetRadius ( G4double  radius)

Definition at line 129 of file DMXParticleSource.cc.

130 {
131  Radius = radius;
132 }
Here is the caller graph for this function:

◆ SetVerbosity()

void DMXParticleSource::SetVerbosity ( G4int  vL)

Definition at line 324 of file DMXParticleSource.cc.

325 {
326  verbosityLevel = vL;
327  G4cout << "Verbosity Set to: " << verbosityLevel << G4endl;
328 }
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ AngDistType

G4String DMXParticleSource::AngDistType
private

Definition at line 107 of file DMXParticleSource.hh.

◆ CentreCoords

G4ThreeVector DMXParticleSource::CentreCoords
private

Definition at line 104 of file DMXParticleSource.hh.

◆ Confine

G4bool DMXParticleSource::Confine
private

Definition at line 105 of file DMXParticleSource.hh.

◆ EnergyDisType

G4String DMXParticleSource::EnergyDisType
private

Definition at line 110 of file DMXParticleSource.hh.

◆ gNavigator

G4Navigator* DMXParticleSource::gNavigator
private

Definition at line 129 of file DMXParticleSource.hh.

◆ halfz

G4double DMXParticleSource::halfz
private

Definition at line 102 of file DMXParticleSource.hh.

◆ MaxPhi

G4double DMXParticleSource::MaxPhi
private

Definition at line 108 of file DMXParticleSource.hh.

◆ MaxTheta

G4double DMXParticleSource::MaxTheta
private

Definition at line 108 of file DMXParticleSource.hh.

◆ MinPhi

G4double DMXParticleSource::MinPhi
private

Definition at line 108 of file DMXParticleSource.hh.

◆ MinTheta

G4double DMXParticleSource::MinTheta
private

Definition at line 108 of file DMXParticleSource.hh.

◆ MonoEnergy

G4double DMXParticleSource::MonoEnergy
private

Definition at line 111 of file DMXParticleSource.hh.

◆ NumberOfParticlesToBeGenerated

G4int DMXParticleSource::NumberOfParticlesToBeGenerated
private

Definition at line 114 of file DMXParticleSource.hh.

◆ particle_charge

G4double DMXParticleSource::particle_charge
private

Definition at line 118 of file DMXParticleSource.hh.

◆ particle_definition

G4ParticleDefinition* DMXParticleSource::particle_definition
private

Definition at line 115 of file DMXParticleSource.hh.

◆ particle_energy

G4double DMXParticleSource::particle_energy
private

Definition at line 117 of file DMXParticleSource.hh.

◆ particle_momentum_direction

G4ParticleMomentum DMXParticleSource::particle_momentum_direction
private

Definition at line 116 of file DMXParticleSource.hh.

◆ particle_polarization

G4ThreeVector DMXParticleSource::particle_polarization
private

Definition at line 121 of file DMXParticleSource.hh.

◆ particle_position

G4ThreeVector DMXParticleSource::particle_position
private

Definition at line 119 of file DMXParticleSource.hh.

◆ particle_time

G4double DMXParticleSource::particle_time
private

Definition at line 120 of file DMXParticleSource.hh.

◆ Phi

G4double DMXParticleSource::Phi
private

Definition at line 109 of file DMXParticleSource.hh.

◆ Radius

G4double DMXParticleSource::Radius
private

Definition at line 103 of file DMXParticleSource.hh.

◆ Shape

G4String DMXParticleSource::Shape
private

Definition at line 101 of file DMXParticleSource.hh.

◆ SourcePosType

G4String DMXParticleSource::SourcePosType
private

Definition at line 100 of file DMXParticleSource.hh.

◆ theMessenger

DMXParticleSourceMessenger* DMXParticleSource::theMessenger
private

Definition at line 128 of file DMXParticleSource.hh.

◆ verbosityLevel

G4int DMXParticleSource::verbosityLevel
private

Definition at line 124 of file DMXParticleSource.hh.

◆ VolName

G4String DMXParticleSource::VolName
private

Definition at line 106 of file DMXParticleSource.hh.


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