260 G4cout <<
"The new axes, x', y', z' "
273 {
G4cout <<
"Volume confinement is set off." <<
G4endl; }
286 if (tempPV !=
nullptr)
297 <<
"> does not exist **** " <<
G4endl;
316 G4cerr <<
"Error SourcePosType is not set to Point" <<
G4endl;
331 if(
Shape ==
"Circle")
335 while(std::sqrt((x*x) + (y*y)) >
Radius)
363 G4cout <<
"Raw position " << x <<
"," << y <<
"," << z <<
G4endl;
397 G4cerr <<
"Error: SourcePosType is not Plane" <<
G4endl;
402 if(
Shape ==
"Circle")
406 while(std::sqrt((x*x) + (y*y)) >
Radius)
415 else if(
Shape ==
"Annulus")
419 while(std::sqrt((x*x) + (y*y)) >
Radius
420 || std::sqrt((x*x) + (y*y)) <
Radius0 )
429 else if(
Shape ==
"Ellipse")
432 while(expression > 1.)
443 else if(
Shape ==
"Square")
450 else if(
Shape ==
"Rectangle")
467 G4cout <<
"Raw position " << x <<
"," << y <<
"," << z <<
G4endl;
513 G4cout <<
"Reference vectors for cosine-law "
535 if(
Shape ==
"Sphere")
539 theta = std::acos(1. - 2.*theta);
542 x =
Radius * std::sin(theta) * std::cos(phi);
543 y =
Radius * std::sin(theta) * std::sin(phi);
544 z =
Radius * std::cos(theta);
553 zdash = zdash.
unit();
560 else if(
Shape ==
"Ellipsoid")
572 theta = std::acos(1. - 2.*theta);
575 while(maxphi-minphi > 0.)
577 middlephi = (maxphi+minphi)/2.;
578 answer = (1./(
halfx*
halfx))*(middlephi/2. + std::sin(2*middlephi)/4.)
579 + (1./(
halfy*
halfy))*(middlephi/2. - std::sin(2*middlephi)/4.)
581 answer = answer/constant;
582 if(answer > phi) maxphi = middlephi;
583 if(answer < phi) minphi = middlephi;
584 if(std::fabs(answer-phi) <= 0.00001)
593 x = std::sin(theta)*std::cos(phi);
594 y = std::sin(theta)*std::sin(phi);
606 tempxvar = 1./tempxvar;
607 G4double coordx = std::sqrt(tempxvar);
616 tempyvar = 1./tempyvar;
617 G4double coordy = std::sqrt(tempyvar);
626 tempzvar = 1./tempzvar;
627 G4double coordz = std::sqrt(tempzvar);
629 lhs = std::sqrt((coordx*coordx)/(
halfx*
halfx) +
635 G4cout <<
"Error: theta, phi not really on ellipsoid" <<
G4endl;
641 if(TestRandVar > 0.5)
646 if(TestRandVar > 0.5)
651 if(TestRandVar > 0.5)
656 RandPos.
setX(coordx);
657 RandPos.
setY(coordy);
658 RandPos.
setZ(coordz);
663 zdash = zdash.
unit();
670 else if(
Shape ==
"Cylinder")
673 G4double AreaTotal, prob1, prob2, prob3;
683 AreaTotal = AreaTop + AreaBot + AreaLat;
685 prob1 = AreaTop / AreaTotal;
686 prob2 = AreaBot / AreaTotal;
687 prob3 = 1.00 - prob1 - prob2;
688 if(std::fabs(prob3 - (AreaLat/AreaTotal)) >= 0.001)
700 if(testrand <= prob1)
721 else if((testrand > prob1) && (testrand <= (prob1 + prob2)))
742 else if(testrand > (prob1+prob2))
747 rand = rand * 2. *
pi;
749 x =
Radius * std::cos(rand);
750 y =
Radius * std::sin(rand);
760 zdash = zdash.
unit();
776 else if(
Shape ==
"EllipticCylinder")
778 G4double AreaTop, AreaBot, AreaLat, AreaTotal;
797 * (1 + (3*h)/(10 + std::sqrt(4 - 3*h)));
798 AreaTotal = AreaTop + AreaBot + AreaLat;
800 prob1 = AreaTop / AreaTotal;
801 prob2 = AreaBot / AreaTotal;
802 prob3 = 1.00 - prob1 - prob2;
803 if(std::fabs(prob3 - (AreaLat/AreaTotal)) >= 0.001)
815 if(testrand <= prob1)
819 while(expression > 1.)
830 else if((testrand > prob1) && (testrand <= (prob1 + prob2)))
834 while(expression > 1.)
845 else if(testrand > (prob1+prob2))
850 rand = rand * 2. *
pi;
852 x =
halfx * std::cos(rand);
853 y =
halfy * std::sin(rand);
871 zdash = zdash.
unit();
878 else if(
Shape ==
"Para")
890 G4double AreaTotal = 2*(AreaX + AreaY + AreaZ);
892 Probs[0] = AreaX/AreaTotal;
893 Probs[1] = Probs[0] + AreaX/AreaTotal;
894 Probs[2] = Probs[1] + AreaY/AreaTotal;
895 Probs[3] = Probs[2] + AreaY/AreaTotal;
896 Probs[4] = Probs[3] + AreaZ/AreaTotal;
897 Probs[5] = Probs[4] + AreaZ/AreaTotal;
912 if(testrand < Probs[0])
926 xdash = xdash.
unit();
927 ydash = ydash.
unit();
933 else if(testrand >= Probs[0] && testrand < Probs[1])
947 xdash = xdash.
unit();
948 ydash = ydash.
unit();
954 else if(testrand >= Probs[1] && testrand < Probs[2])
967 ydash = ydash.
unit();
974 else if(testrand >= Probs[2] && testrand < Probs[3])
987 ydash = ydash.
unit();
994 else if(testrand >= Probs[3] && testrand < Probs[4])
1008 else if(testrand >= Probs[4] && testrand < Probs[5])
1027 G4cout <<
"testrand=" << testrand <<
" Probs[5]=" << Probs[5] <<
G4endl;
1085 if(
Shape ==
"Sphere")
1101 else if(
Shape ==
"Ellipsoid")
1118 else if(
Shape ==
"Cylinder")
1133 else if(
Shape ==
"EllipticCylinder")
1136 while(expression > 1.)
1149 else if(
Shape ==
"Para")
1163 G4cout <<
"Error: Volume Shape does not exist" <<
G4endl;
1177 RandPos.
setX(tempx);
1178 RandPos.
setY(tempy);
1179 RandPos.
setZ(tempz);
1187 G4cout <<
"Raw position " << x <<
"," << y <<
"," << z <<
G4endl;
1198 zdash = zdash.
unit();
1229 if(theVolume ==
nullptr) {
return false; }
1250 G4int LoopCount = 0;
1251 while(srcconf ==
false)
1266 msg <<
"Error: SourcePosType undefined\n";
1267 msg <<
"Generating point source\n";
1268 G4Exception(
"G4SPSPosDistribution::GenerateOne()",
1283 if(LoopCount == 100000)
1286 msg <<
"LoopCount = 100000\n";
1287 msg <<
"Either the source distribution >> confinement\n";
1288 msg <<
"or any confining volume may not overlap with\n";
1289 msg <<
"the source distribution or any confining volumes\n";
1290 msg <<
"may not exist\n"<<
G4endl;
1291 msg <<
"If you have set confine then this will be ignored\n";
1292 msg <<
"for this event.\n" <<
G4endl;
1293 G4Exception(
"G4SPSPosDistribution::GenerateOne()",
static const G4double pos
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
static constexpr double twopi
static constexpr double pi
#define G4MUTEXDESTROY(mutex)
#define G4MUTEXINIT(mutex)
CLHEP::Hep3Vector G4ThreeVector
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
Hep3Vector cross(const Hep3Vector &) const
virtual G4VPhysicalVolume * LocateGlobalPointAndSetup(const G4ThreeVector &point, const G4ThreeVector *direction=nullptr, const G4bool pRelativeSearch=true, const G4bool ignoreDirection=true)
static G4PhysicalVolumeStore * GetInstance()
G4VPhysicalVolume * GetVolume(const G4String &name, G4bool verbose=true, G4bool reverseSearch=false) const
G4double GetRadius() const
const G4ThreeVector & GetCentreCoords() const
G4double GetHalfZ() const
void SetParAlpha(G4double)
void GeneratePointSource(G4ThreeVector &outoutPos)
void GeneratePointsInVolume(G4ThreeVector &outputPos)
void SetPosRot2(const G4ThreeVector &)
void GeneratePointsOnSurface(G4ThreeVector &outputPos)
void SetBeamSigmaInX(G4double)
void ConfineSourceToVolume(const G4String &)
void GeneratePointsInBeam(G4ThreeVector &outoutPos)
void SetBiasRndm(G4SPSRandomGenerator *a)
void GenerateRotationMatrices()
const G4String & GetPosDisType() const
void SetPosDisShape(const G4String &)
void SetVerbosity(G4int a)
const G4ThreeVector & GetParticlePos() const
void SetCentreCoords(const G4ThreeVector &)
G4ThreeVector GenerateOne()
void SetBeamSigmaInR(G4double)
G4ThreeVector CentreCoords
const G4String & GetSourcePosType() const
void SetRadius0(G4double)
const G4ThreeVector & GetSideRefVec2() const
G4double GetHalfX() const
void SetParTheta(G4double)
G4SPSRandomGenerator * PosRndm
G4Cache< thread_data_t > ThreadData
const G4String & GetPosDisShape() const
const G4ThreeVector & GetSideRefVec3() const
G4bool IsSourceConfined(G4ThreeVector &outputPos)
const G4ThreeVector & GetSideRefVec1() const
void SetPosRot1(const G4ThreeVector &)
void GeneratePointsInPlane(G4ThreeVector &outoutPos)
G4double GetHalfY() const
void SetPosDisType(const G4String &)
void SetBeamSigmaInY(G4double)
G4double GenRandPosTheta()
static G4TransportationManager * GetTransportationManager()
G4Navigator * GetNavigatorForTracking() const
const G4String & GetName() const
DLL_API const Hep3Vector HepZHat
DLL_API const Hep3Vector HepXHat
DLL_API const Hep3Vector HepYHat
ThreeVector shoot(const G4int Ap, const G4int Af)
G4ThreeVector CParticlePos
G4ThreeVector CSideRefVec1
G4ThreeVector CSideRefVec2
G4ThreeVector CSideRefVec3