68 if ( theInstance ==
nullptr )
76 if ( theInstance !=
nullptr )
79 theInstance =
nullptr;
85G4GeneralParticleSourceMessenger::
112 gpsDirectory->
SetGuidance(
"General Particle Source control commands.");
117 sourceDirectory->
SetGuidance(
"Multiple source control sub-directory");
120 addsourceCmd->
SetGuidance(
"Add a new source definition to the particle gun");
121 addsourceCmd->
SetGuidance(
" with the specified intensity");
123 addsourceCmd->
SetRange(
"addsource > 0.");
126 listsourceCmd->
SetGuidance(
"List the defined particle sources");
129 clearsourceCmd->
SetGuidance(
"Remove all the defined particle sources");
132 getsourceCmd->
SetGuidance(
"Show the current source index and intensity");
135 setsourceCmd->
SetGuidance(
"Set the indexed source as the current one");
136 setsourceCmd->
SetGuidance(
" so one can change its source definition");
138 setsourceCmd->
SetRange(
"setsource >= 0");
141 deletesourceCmd->
SetGuidance(
"Delete the indexed source from the list");
143 deletesourceCmd->
SetRange(
"deletesource > 0");
146 setintensityCmd->
SetGuidance(
"Reset the current source to the specified intensity");
148 setintensityCmd->
SetRange(
"setintensity > 0.");
150 multiplevertexCmd =
new G4UIcmdWithABool(
"/gps/source/multiplevertex",
this);
151 multiplevertexCmd->
SetGuidance(
"True for simultaneous generation multiple vertex");
152 multiplevertexCmd->
SetGuidance(
" Default is false");
157 flatsamplingCmd->
SetGuidance(
"True for applying flat (biased) sampling among the sources");
169 particleCmd->
SetGuidance(
"Set particle to be generated.");
170 particleCmd->
SetGuidance(
" (geantino is default)");
171 particleCmd->
SetGuidance(
" (ion can be specified for shooting ions)");
176 for(
G4int i=0; i<nPtcl; ++i)
179 candidateList +=
" ";
181 candidateList +=
"ion ";
185 directionCmd->
SetGuidance(
"Set momentum direction.");
186 directionCmd->
SetGuidance(
" Direction needs not to be a unit vector.");
187 directionCmd->
SetGuidance(
" Angular distribution type is set to planar.");
189 directionCmd->
SetRange(
"Px != 0 || Py != 0 || Pz != 0");
199 positionCmd->
SetGuidance(
"Set starting position of the particle for a Point like source.");
200 positionCmd->
SetGuidance(
" Same effect as the two /gps/pos/type Point /gps/pos/centre commands.");
207 ionCmd->
SetGuidance(
"Set properties of ion to be generated.");
211 ionCmd->
SetGuidance(
" Q:(int) Charge of Ion (in unit of e)");
212 ionCmd->
SetGuidance(
" E:(double) Excitation energy (in keV)");
229 ionLvlCmd->
SetGuidance(
"Set properties of ion to be generated.");
230 ionLvlCmd->
SetGuidance(
"[usage] /gps/ion Z A Q Lvl");
233 ionLvlCmd->
SetGuidance(
" Q:(int) Charge of Ion (in unit of e)");
234 ionLvlCmd->
SetGuidance(
" Lvl:(int) Number of metastable state excitation level (0-9)");
251 timeCmd->
SetGuidance(
"Set initial time of the particle.");
260 polCmd->
SetRange(
"Px>=-1.&&Px<=1.&&Py>=-1.&&Py<=1.&&Pz>=-1.&&Pz<=1.");
263 numberCmd->
SetGuidance(
"Set number of particles to be generated per vertex.");
270 verbosityCmd->
SetGuidance(
"Set Verbose level for GPS");
272 verbosityCmd->
SetGuidance(
" 1 : Limited information");
273 verbosityCmd->
SetGuidance(
" 2 : Detailed information");
275 verbosityCmd->
SetRange(
"level>=0 && level <=2");
281 positionDirectory->
SetGuidance(
"Positional commands sub-directory");
284 typeCmd1->
SetGuidance(
"Sets source distribution type.");
285 typeCmd1->
SetGuidance(
"Either Point, Beam, Plane, Surface or Volume");
291 shapeCmd1->
SetGuidance(
"Sets source shape for Plan, Surface or Volume type source.");
294 shapeCmd1->
SetCandidates(
"Circle Annulus Ellipse Square Rectangle Sphere Ellipsoid Cylinder EllipticCylinder Para");
297 centreCmd1->
SetGuidance(
"Set centre coordinates of source.");
303 posrot1Cmd1->
SetGuidance(
"Set the 1st vector defining the rotation matrix'.");
304 posrot1Cmd1->
SetGuidance(
"It does not need to be a unit vector.");
306 posrot1Cmd1->
SetRange(
"R1x != 0 || R1y != 0 || R1z != 0");
309 posrot2Cmd1->
SetGuidance(
"Set the 2nd vector defining the rotation matrix'.");
310 posrot2Cmd1->
SetGuidance(
"It does not need to be a unit vector.");
312 posrot2Cmd1->
SetRange(
"R2x != 0 || R2y != 0 || R2z != 0");
315 halfxCmd1->
SetGuidance(
"Set x half length of source.");
321 halfyCmd1->
SetGuidance(
"Set y half length of source.");
327 halfzCmd1->
SetGuidance(
"Set z half length of source.");
339 radius0Cmd1->
SetGuidance(
"Set inner radius of source when required.");
345 possigmarCmd1->
SetGuidance(
"Set standard deviation in radial of the beam positional profile");
346 possigmarCmd1->
SetGuidance(
" applicable to Beam type source only");
352 possigmaxCmd1->
SetGuidance(
"Set standard deviation of beam positional profile in x-dir");
353 possigmaxCmd1->
SetGuidance(
" applicable to Beam type source only");
359 possigmayCmd1->
SetGuidance(
"Set standard deviation of beam positional profile in y-dir");
360 possigmayCmd1->
SetGuidance(
" applicable to Beam type source only");
366 paralpCmd1->
SetGuidance(
"Angle from y-axis of y' in Para");
372 partheCmd1->
SetGuidance(
"Polar angle through centres of z faces");
378 parphiCmd1->
SetGuidance(
"Azimuth angle through centres of z faces");
384 confineCmd1->
SetGuidance(
"Confine source to volume (NULL to unset).");
385 confineCmd1->
SetGuidance(
" Usage: confine VolName");
392 angularDirectory->
SetGuidance(
"Angular commands sub-directory");
395 angtypeCmd1->
SetGuidance(
"Sets angular source distribution type");
396 angtypeCmd1->
SetGuidance(
" Possible variables are: iso, cos, planar, beam1d, beam2d, focused or user");
399 angtypeCmd1->
SetCandidates(
"iso cos planar beam1d beam2d focused user");
402 angrot1Cmd1->
SetGuidance(
"Sets the 1st vector for angular distribution rotation matrix");
403 angrot1Cmd1->
SetGuidance(
" Need not be a unit vector");
405 angrot1Cmd1->
SetRange(
"AR1x != 0 || AR1y != 0 || AR1z != 0");
408 angrot2Cmd1->
SetGuidance(
"Sets the 2nd vector for angular distribution rotation matrix");
409 angrot2Cmd1->
SetGuidance(
" Need not be a unit vector");
411 angrot2Cmd1->
SetRange(
"AR2x != 0 || AR2y != 0 || AR2z != 0");
442 angsigmarCmd1->
SetGuidance(
"Set standard deviation in direction for 1D beam.");
448 angsigmaxCmd1->
SetGuidance(
"Set standard deviation in direction in x-direc. for 2D beam");
454 angsigmayCmd1->
SetGuidance(
"Set standard deviation in direction in y-direc. for 2D beam");
460 angfocusCmd->
SetGuidance(
"Set the focusing point for the beam");
466 useuserangaxisCmd1->
SetGuidance(
"True for using user defined angular co-ordinates");
467 useuserangaxisCmd1->
SetGuidance(
" Default is false");
472 surfnormCmd1->
SetGuidance(
"Makes a user-defined distribution with respect to surface normals rather than x,y,z axes.");
480 energyDirectory->
SetGuidance(
"Spectral commands sub-directory");
483 energytypeCmd1->
SetGuidance(
"Sets energy distribution type");
486 energytypeCmd1->
SetCandidates(
"Mono Lin Pow Exp CPow Gauss Brem Bbody Cdg User Arb Epn LW");
501 monoenergyCmd1->
SetGuidance(
"Sets a monocromatic energy (same as gps/energy)");
507 engsigmaCmd1->
SetGuidance(
"Sets the standard deviation for Gaussian energy dist.");
513 alphaCmd1->
SetGuidance(
"Sets Alpha (index) for power-law energy dist.");
517 tempCmd1->
SetGuidance(
"Sets the temperature for Brem and BBody distributions (in Kelvin)");
521 ezeroCmd1->
SetGuidance(
"Sets E_0 for exponential distribution (in MeV)");
525 gradientCmd1->
SetGuidance(
"Sets the gradient for Lin distribution (in 1/MeV)");
529 interceptCmd1->
SetGuidance(
"Sets the intercept for Lin distributions (in MeV)");
533 arbeintCmd1->
SetGuidance(
"Sets the power-law index for the energy sampling distri. )");
537 calculateCmd1->
SetGuidance(
"Calculates the distributions for Cdg and BBody");
540 energyspecCmd1->
SetGuidance(
"True for energy and false for momentum spectra");
545 diffspecCmd1->
SetGuidance(
"True for differential and flase for integral spectra");
549 applyEnergyWeightCmd1 =
new G4UIcmdWithABool(
"/gps/ene/applyEneWeight",
this);
550 applyEnergyWeightCmd1->
SetGuidance(
"Apply energy weight.");
551 applyEnergyWeightCmd1->
SetGuidance(
"- Instead of using the Arb type histogram for sampling the energy spectrum,");
552 applyEnergyWeightCmd1->
SetGuidance(
" energy is sampled by Linear distribution, and the Arb type histogram is");
553 applyEnergyWeightCmd1->
SetGuidance(
" used for the weight of the generated particle.");
554 applyEnergyWeightCmd1->
SetGuidance(
"- \"/gps/ene/type LW\" automatically applies this command.");
555 applyEnergyWeightCmd1->
SetGuidance(
"- If this command has to be explicitly used, \"/gps/ene/type\" distribution mush be Lin.");
562 histDirectory->
SetGuidance(
"Histogram, biasing commands sub-directory");
568 histnameCmd1->
SetCandidates(
"biasx biasy biasz biast biasp biase biaspt biaspp theta phi energy arb epn");
571 resethistCmd1->
SetGuidance(
"Reset (clean) the histogram ");
574 resethistCmd1->
SetCandidates(
"biasx biasy biasz biast biasp biase biaspt biaspp theta phi energy arb epn");
577 histpointCmd1->
SetGuidance(
"Allows user to define a histogram");
580 histpointCmd1->
SetRange(
"Ehi >= 0. && Weight >= 0.");
583 histfileCmd1->
SetGuidance(
"Imports the arb energy hist in an ASCII file");
587 arbintCmd1->
SetGuidance(
"Sets the interpolation method for arbitrary distribution.");
588 arbintCmd1->
SetGuidance(
"Spline interpolation may not be applicable for some distributions.");
594G4GeneralParticleSourceMessenger::~G4GeneralParticleSourceMessenger()
596 delete positionDirectory;
607 delete possigmarCmd1;
608 delete possigmaxCmd1;
609 delete possigmayCmd1;
615 delete angularDirectory;
623 delete angsigmarCmd1;
624 delete angsigmaxCmd1;
625 delete angsigmayCmd1;
627 delete useuserangaxisCmd1;
630 delete energyDirectory;
631 delete energytypeCmd1;
634 delete monoenergyCmd1;
640 delete interceptCmd1;
642 delete calculateCmd1;
643 delete energyspecCmd1;
645 delete applyEnergyWeightCmd1;
647 delete histDirectory;
649 delete resethistCmd1;
650 delete histpointCmd1;
666 delete sourceDirectory;
668 delete listsourceCmd;
669 delete clearsourceCmd;
672 delete setintensityCmd;
673 delete deletesourceCmd;
674 delete multiplevertexCmd;
675 delete flatsamplingCmd;
678 theInstance =
nullptr;
681#define CHECKPG() { if (fParticleGun==nullptr) { \
682 G4ExceptionDescription msg; \
683 msg << "Command "<< command->GetCommandPath()<<"/";\
684 msg << command->GetCommandName(); \
685 msg << " used but no particle sources are set.";\
686 msg <<" Add at least a source with: /gps/source/add.";\
687 G4Exception("G4GeneralParticleSourceMessenger::SetNewValue","G4GPS003",\
688 FatalException,msg); return;\
1049 if( command==directionCmd )
1055 else if( command==energyCmd )
1061 else if( command==positionCmd )
1067 else if(command == verbosityCmd)
1073 else if( command==particleCmd )
1075 if (newValues ==
"ion")
1090 else if( command==timeCmd )
1095 else if( command==polCmd )
1100 else if( command==numberCmd )
1105 else if( command==ionCmd )
1107 IonCommand(newValues);
1109 else if( command==ionLvlCmd )
1111 IonLvlCommand(newValues);
1113 else if( command==listCmd )
1117 else if( command==addsourceCmd )
1121 else if( command==listsourceCmd )
1125 else if( command==clearsourceCmd )
1128 fParticleGun =
nullptr;
1130 else if( command==getsourceCmd )
1135 else if( command==setsourceCmd )
1149 <<
" source(s) are defined.";
1150 G4Exception(
"G4GeneralParticleSourceMessenger::SetNewValue",
1155 else if( command==setintensityCmd )
1159 else if( command==deletesourceCmd )
1163 else if(command == multiplevertexCmd)
1167 else if(command == flatsamplingCmd)
1174 else if(command == typeCmd1)
1179 else if(command == shapeCmd1)
1184 else if(command == centreCmd1)
1189 else if(command == posrot1Cmd1)
1194 else if(command == posrot2Cmd1)
1199 else if(command == halfxCmd1)
1204 else if(command == halfyCmd1)
1209 else if(command == halfzCmd1)
1214 else if(command == radiusCmd1)
1219 else if(command == radius0Cmd1)
1224 else if(command == possigmarCmd1)
1229 else if(command == possigmaxCmd1)
1234 else if(command == possigmayCmd1)
1239 else if(command == paralpCmd1)
1244 else if(command == partheCmd1)
1249 else if(command == parphiCmd1)
1254 else if(command == confineCmd1)
1259 else if(command == angtypeCmd1)
1264 else if(command == angrot1Cmd1)
1270 else if(command == angrot2Cmd1)
1276 else if(command == minthetaCmd1)
1281 else if(command == minphiCmd1)
1286 else if(command == maxthetaCmd1)
1291 else if(command == maxphiCmd1)
1296 else if(command == angsigmarCmd1)
1301 else if(command == angsigmaxCmd1)
1306 else if(command == angsigmayCmd1)
1311 else if(command == angfocusCmd)
1316 else if(command == useuserangaxisCmd1)
1321 else if(command == surfnormCmd1)
1326 else if(command == energytypeCmd1)
1342 else if(command == eminCmd1)
1347 else if(command == emaxCmd1)
1352 else if(command == monoenergyCmd1)
1357 else if(command == engsigmaCmd1)
1362 else if(command == alphaCmd1)
1367 else if(command == tempCmd1)
1372 else if(command == ezeroCmd1)
1377 else if(command == gradientCmd1)
1382 else if(command == interceptCmd1)
1387 else if(command == arbeintCmd1)
1392 else if(command == calculateCmd1)
1397 else if(command == energyspecCmd1)
1402 else if(command == diffspecCmd1)
1407 else if(command == applyEnergyWeightCmd1)
1411 if(eDisType !=
"Lin")
1414 ed <<
"Energy distribution is defined as " << eDisType <<
". /gps/ene/applyEneWeight is available only for Linear distribution.";
1420 else if(command == histnameCmd1)
1422 histtype = newValues;
1424 else if(command == histfileCmd1)
1430 else if(command == histpointCmd1)
1433 if(histtype ==
"biasx")
1435 if(histtype ==
"biasy")
1437 if(histtype ==
"biasz")
1439 if(histtype ==
"biast")
1441 if(histtype ==
"biasp")
1443 if(histtype ==
"biaspt")
1445 if(histtype ==
"biaspp")
1447 if(histtype ==
"biase")
1449 if(histtype ==
"theta")
1451 if(histtype ==
"phi")
1453 if(histtype ==
"energy")
1455 if(histtype ==
"arb")
1457 if(histtype ==
"epn")
1460 else if(command == resethistCmd1)
1463 if(newValues ==
"theta" || newValues ==
"phi")
1467 else if (newValues ==
"energy" || newValues ==
"arb" || newValues ==
"epn")
1476 else if(command == arbintCmd1)
1503 cv =
"Not implemented yet";
1508void G4GeneralParticleSourceMessenger::IonCommand(
G4String newValues)
1514 fAtomicNumber =
StoI(next());
1515 fAtomicMass =
StoI(next());
1519 fIonCharge = fAtomicNumber;
1523 fIonCharge =
StoI(sQ);
1527 fIonExciteEnergy = 0.0;
1531 fIonExciteEnergy =
StoD(sQ) * keV;
1535 ->
GetIon(fAtomicNumber, fAtomicMass, fIonExciteEnergy);
1539 ed <<
"Ion with Z=" << fAtomicNumber;
1540 ed <<
" A=" << fAtomicMass <<
" is not defined";
1552 ed <<
"Set /gps/particle to ion before using /gps/ion command";
1557void G4GeneralParticleSourceMessenger::IonLvlCommand(
G4String newValues)
1563 fAtomicNumberL =
StoI(next());
1564 fAtomicMassL =
StoI(next());
1568 fIonChargeL = fAtomicNumberL;
1572 fIonChargeL =
StoI(sQ);
1576 fIonEnergyLevel = 0;
1580 fIonEnergyLevel =
StoI(sQ);
1585 ->
GetIon(fAtomicNumberL, fAtomicMassL, fIonEnergyLevel);
1589 ed <<
"Ion with Z=" << fAtomicNumberL;
1590 ed <<
" A=" << fAtomicMassL <<
" is not defined";
1603 ed <<
"Set /gps/particle to ion before using /gps/ionLvl command";
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
#define G4MUTEX_INITIALIZER
G4GLOB_DLL std::ostream G4cout
static G4GeneralParticleSourceMessenger * GetInstance(G4GeneralParticleSource *)
void SetNewValue(G4UIcommand *command, G4String newValues) override
G4String GetCurrentValue(G4UIcommand *command) override
void SetFlatSampling(G4bool av)
void AddaSource(G4double)
G4int GetCurrentSourceIndex() const
G4double GetCurrentSourceIntensity() const
void SetCurrentSourceIntensity(G4double)
void SetVerbosity(G4int i)
void SetCurrentSourceto(G4int)
void DeleteaSource(G4int)
G4int GetNumberofSource()
void SetMultipleVertex(G4bool av)
G4ParticleDefinition * GetIon(G4int Z, G4int A, G4int lvl=0)
static G4IonTable * GetIonTable()
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
static G4ParticleTable * GetParticleTable()
const G4String & GetParticleName(G4int index) const
void DumpTable(const G4String &particle_name="ALL")
void SetBeamSigmaInAngX(G4double)
void SetBeamSigmaInAngR(G4double)
void UserDefAngTheta(const G4ThreeVector &)
void SetFocusPoint(const G4ThreeVector &)
void SetAngDistType(const G4String &)
void UserDefAngPhi(const G4ThreeVector &)
void SetMaxTheta(G4double)
void SetUseUserAngAxis(G4bool)
void SetMinTheta(G4double)
void SetParticleMomentumDirection(const G4ParticleMomentum &aMomDirection)
void SetBeamSigmaInAngY(G4double)
void ReSetHist(const G4String &)
void DefineAngRefAxes(const G4String &, const G4ThreeVector &)
void SetUserWRTSurface(G4bool)
void InputEnergySpectra(G4bool)
void ArbInterpolate(const G4String &)
const G4String & GetEnergyDisType()
void SetBeamSigmaInE(G4double)
void SetBiasAlpha(G4double)
void SetEnergyDisType(const G4String &)
void EpnEnergyHisto(const G4ThreeVector &)
void ArbEnergyHistoFile(const G4String &)
void SetGradient(G4double)
void ReSetHist(const G4String &)
void InputDifferentialSpectra(G4bool)
void SetMonoEnergy(G4double)
void ApplyEnergyWeight(G4bool val)
void UserEnergyHisto(const G4ThreeVector &)
void SetInterCept(G4double)
void ArbEnergyHisto(const G4ThreeVector &)
void SetParAlpha(G4double)
void SetPosRot2(const G4ThreeVector &)
void SetBeamSigmaInX(G4double)
void ConfineSourceToVolume(const G4String &)
void SetPosDisShape(const G4String &)
void SetCentreCoords(const G4ThreeVector &)
void SetBeamSigmaInR(G4double)
void SetRadius0(G4double)
void SetParTheta(G4double)
void SetPosRot1(const G4ThreeVector &)
void SetPosDisType(const G4String &)
void SetBeamSigmaInY(G4double)
void SetXBias(const G4ThreeVector &)
void SetEnergyBias(const G4ThreeVector &)
void SetPosPhiBias(const G4ThreeVector &)
void SetThetaBias(const G4ThreeVector &)
void SetYBias(const G4ThreeVector &)
void SetPosThetaBias(const G4ThreeVector &)
void SetPhiBias(const G4ThreeVector &)
void SetZBias(const G4ThreeVector &)
void ReSetHist(const G4String &)
void SetNumberOfParticles(G4int i)
void SetParticleTime(G4double aTime)
void SetParticleDefinition(G4ParticleDefinition *aParticleDefinition)
G4SPSAngDistribution * GetAngDist() const
G4SPSRandomGenerator * GetBiasRndm() const
G4SPSEneDistribution * GetEneDist() const
void SetParticlePolarization(const G4ThreeVector &aVal)
void SetParticleCharge(G4double aCharge)
G4SPSPosDistribution * GetPosDist() const
void SetDefaultUnit(const char *defUnit)
static G4ThreeVector GetNew3VectorValue(const char *paramString)
void SetParameterName(const char *theNameX, const char *theNameY, const char *theNameZ, G4bool omittable, G4bool currentAsDefault=false)
static G4ThreeVector GetNew3VectorValue(const char *paramString)
void SetParameterName(const char *theNameX, const char *theNameY, const char *theNameZ, G4bool omittable, G4bool currentAsDefault=false)
static G4bool GetNewBoolValue(const char *paramString)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetDefaultValue(G4bool defVal)
void SetDefaultValue(G4double defVal)
void SetDefaultUnit(const char *defUnit)
static G4double GetNewDoubleValue(const char *paramString)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
static G4double GetNewDoubleValue(const char *paramString)
void SetCandidates(const char *candidateList)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetDefaultValue(const char *defVal)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
static G4int GetNewIntValue(const char *paramString)
const G4String & GetCommandPath() const
void SetParameter(G4UIparameter *const newParameter)
void SetGuidance(const char *aGuidance)
void CommandFailed(G4int errCode, G4ExceptionDescription &ed)
void SetRange(const char *rs)
const G4String & GetCommandName() const
G4bool commandsShouldBeInMaster
G4double StoD(const G4String &s)
G4int StoI(const G4String &s)
void SetDefaultValue(const char *theDefaultValue)