Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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)
 

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

Definition at line 68 of file DMXParticleSource.cc.

68  {
69 
70  NumberOfParticlesToBeGenerated = 1;
71  particle_definition = NULL;
72  G4ThreeVector zero(0., 0., 0.);
73  particle_momentum_direction = G4ParticleMomentum(1., 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 
99  theMessenger = new DMXParticleSourceMessenger(this);
102 }
G4Navigator * GetNavigatorForTracking() const
static constexpr double twopi
Definition: G4SIunits.hh:76
static G4TransportationManager * GetTransportationManager()
static constexpr double MeV
Definition: G4SIunits.hh:214
static constexpr double pi
Definition: G4SIunits.hh:75
G4ThreeVector G4ParticleMomentum

Here is the call graph for this function:

DMXParticleSource::~DMXParticleSource ( )

Definition at line 104 of file DMXParticleSource.cc.

105 {
106  delete theMessenger;
107 }

Member Function Documentation

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
const G4String & GetName() const
bool G4bool
Definition: G4Types.hh:79
#define G4endl
Definition: G4ios.hh:61

Here is the call graph for this function:

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 
298  particle_momentum_direction.setX(px);
299  particle_momentum_direction.setY(py);
300  particle_momentum_direction.setZ(pz);
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
#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 DMXParticleSource::GenerateMonoEnergetic ( )

Definition at line 318 of file DMXParticleSource.cc.

319 {
320  particle_energy = MonoEnergy;
321 }

Here is the caller graph for this function:

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 }
tuple x
Definition: test.py:50
void setY(double)
void setZ(double)
void setX(double)
#define G4UniformRand()
Definition: Randomize.hh:97
G4GLOB_DLL std::ostream G4cout
tuple z
Definition: test.py:28
#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 DMXParticleSource::GeneratePointSource ( )

Definition at line 184 of file DMXParticleSource.cc.

185 {
186  // Generates Points given the point source.
187  if(SourcePosType == "Point")
188  particle_position = CentreCoords;
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

Here is the caller graph for this function:

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")
387  SetParticleMomentumDirection(particle_momentum_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 =
398  new G4PrimaryVertex(particle_position,particle_time);
399 
400  if(verbosityLevel >= 2)
401  G4cout << "Creating primaries and assigning to vertex" << G4endl;
402  // create new primaries and set them to the vertex
403  G4double mass = particle_definition->GetPDGMass();
404  G4double energy = particle_energy + mass;
405  G4double pmom = std::sqrt(energy*energy-mass*mass);
406  G4double px = pmom*particle_momentum_direction.x();
407  G4double py = pmom*particle_momentum_direction.y();
408  G4double pz = pmom*particle_momentum_direction.z();
409 
410  if(verbosityLevel >= 1){
411  G4cout << "Particle name: "
412  << particle_definition->GetParticleName() << G4endl;
413  G4cout << " Energy: "<<particle_energy << G4endl;
414  G4cout << " Position: "<<particle_position<< G4endl;
415  G4cout << " Direction: "<<particle_momentum_direction << G4endl;
416  G4cout << " NumberOfParticlesToBeGenerated: "
417  << NumberOfParticlesToBeGenerated << G4endl;
418  }
419 
420 
421  for( G4int i=0; i<NumberOfParticlesToBeGenerated; i++ ) {
422  G4PrimaryParticle* particle =
423  new G4PrimaryParticle(particle_definition,px,py,pz);
424  particle->SetMass( mass );
425  particle->SetCharge( particle_charge );
426  particle->SetPolarization(particle_polarization.x(),
427  particle_polarization.y(),
428  particle_polarization.z());
429  vertex->SetPrimary( particle );
430  }
431  evt->AddPrimaryVertex( vertex );
432  if(verbosityLevel > 1)
433  G4cout << " Primary Vetex generated "<< G4endl;
434 }
double x() const
void AddPrimaryVertex(G4PrimaryVertex *aPrimaryVertex)
Definition: G4Event.hh:154
int G4int
Definition: G4Types.hh:78
const G4String & GetParticleName() const
double z() const
void SetParticleMomentumDirection(G4ParticleMomentum)
G4GLOB_DLL std::ostream G4cout
bool G4bool
Definition: G4Types.hh:79
void SetMass(G4double mas)
G4double GetPDGMass() const
G4double energy(const ThreeVector &p, const G4double m)
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:

Here is the caller graph for this function:

G4double DMXParticleSource::GetParticleEnergy ( )
inline

Definition at line 87 of file DMXParticleSource.hh.

87 {return particle_energy;}

Here is the caller graph for this function:

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;
254  theVolume=gNavigator->LocateGlobalPointAndSetup(particle_position,ptr,true);
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 }
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

Here is the call graph for this function:

Here is the caller graph for this function:

void DMXParticleSource::SetAngDistType ( G4String  atype)

Definition at line 178 of file DMXParticleSource.cc.

179 {
180  AngDistType = atype;
181 }
void DMXParticleSource::SetCentreCoords ( G4ThreeVector  coordsOfCentre)

Definition at line 119 of file DMXParticleSource.cc.

120 {
121  CentreCoords = coordsOfCentre;
122 }
void DMXParticleSource::SetEnergyDisType ( G4String  DisType)

Definition at line 308 of file DMXParticleSource.cc.

309 {
310  EnergyDisType = DisType;
311 }
void DMXParticleSource::SetHalfZ ( G4double  zhalf)

Definition at line 124 of file DMXParticleSource.cc.

125 {
126  halfz = zhalf;
127 }
void DMXParticleSource::SetMonoEnergy ( G4double  menergy)

Definition at line 313 of file DMXParticleSource.cc.

314 {
315  MonoEnergy = menergy;
316 }
void DMXParticleSource::SetParticleCharge ( G4double  aCharge)
inline

Definition at line 94 of file DMXParticleSource.hh.

95  { particle_charge = aCharge; }
void DMXParticleSource::SetParticleDefinition ( G4ParticleDefinition aParticleDefinition)

Definition at line 331 of file DMXParticleSource.cc.

332 {
333  particle_definition = aParticleDefinition;
334  particle_charge = particle_definition->GetPDGCharge();
335 }
G4double GetPDGCharge() const

Here is the call graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

void DMXParticleSource::SetPosDisShape ( G4String  shapeType)

Definition at line 114 of file DMXParticleSource.cc.

115 {
116  Shape = shapeType;
117 }
void DMXParticleSource::SetPosDisType ( G4String  PosType)

Definition at line 109 of file DMXParticleSource.cc.

110 {
111  SourcePosType = PosType;
112 }
void DMXParticleSource::SetRadius ( G4double  radius)

Definition at line 129 of file DMXParticleSource.cc.

130 {
131  Radius = radius;
132 }
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

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