56 : Theta(0.), Phi(0.), posDist(0),angRndm(0)
62 AngDistType =
"planar";
74 UserDistType =
"NULL";
75 UserWRTSurface =
true;
77 IPDFThetaExist =
false;
93 if(atype !=
"iso" && atype !=
"cos" && atype !=
"user" && atype !=
"planar"
94 && atype !=
"beam1d" && atype !=
"beam2d" && atype !=
"focused")
95 G4cout <<
"Error, distribution must be iso, cos, planar, beam1d, beam2d, focused or user" <<
G4endl;
98 if (AngDistType ==
"cos") MaxTheta =
pi/2. ;
99 if (AngDistType ==
"user") {
100 UDefThetaH = IPDFThetaH = ZeroPhysVector ;
101 IPDFThetaExist = false ;
102 UDefPhiH = IPDFPhiH = ZeroPhysVector ;
103 IPDFPhiExist = false ;
110 if(refname ==
"angref1")
111 AngRef1 = ref.
unit();
112 else if(refname ==
"angref2")
113 AngRef2 = ref.
unit();
120 AngRef3 = AngRef1.
cross(AngRef2);
121 AngRef2 = AngRef3.
cross(AngRef1);
123 if(verbosityLevel == 2)
125 G4cout <<
"Angular distribution rotation axes " << AngRef1 <<
" " << AngRef2 <<
" " << AngRef3 <<
G4endl;
174 particle_momentum_direction = aMomentumDirection.
unit();
200 if(UserDistType ==
"NULL") UserDistType =
"theta";
201 if(UserDistType ==
"phi") UserDistType =
"both";
205 if(verbosityLevel >= 1)
220 if(UserDistType ==
"NULL") UserDistType =
"phi";
221 if(UserDistType ==
"theta") UserDistType =
"both";
225 if(verbosityLevel >= 1)
244 UserWRTSurface = wrtSurf;
252 UserAngRef = userang;
259 if (AngDistType ==
"beam1d")
268 theta = std::sqrt (px*px + py*py);
270 phi = std::acos(px/theta);
271 if ( py < 0.) phi = -phi;
276 px = -std::sin(theta) * std::cos(phi);
277 py = -std::sin(theta) * std::sin(phi);
278 pz = -std::cos(theta);
280 finx = px, finy =py, finz =pz;
284 finx = (px * AngRef1.
x()) + (py * AngRef2.
x()) + (pz * AngRef3.
x());
285 finy = (px * AngRef1.
y()) + (py * AngRef2.
y()) + (pz * AngRef3.
y());
286 finz = (px * AngRef1.
z()) + (py * AngRef2.
z()) + (pz * AngRef3.
z());
287 G4double ResMag = std::sqrt((finx*finx) + (finy*finy) + (finz*finz));
297 if(verbosityLevel >= 1)
306 if(verbosityLevel >= 1)
307 G4cout <<
"Generating focused vector: " << mom <<
G4endl;
318 G4double sintheta, sinphi,costheta,cosphi;
320 costheta = std::cos(MinTheta) - rndm * (std::cos(MinTheta) - std::cos(MaxTheta));
321 sintheta = std::sqrt(1. - costheta*costheta);
324 Phi = MinPhi + (MaxPhi - MinPhi) * rndm2;
325 sinphi = std::sin(Phi);
326 cosphi = std::cos(Phi);
328 px = -sintheta * cosphi;
329 py = -sintheta * sinphi;
340 finx = (px * AngRef1.
x()) + (py * AngRef2.
x()) + (pz * AngRef3.
x());
341 finy = (px * AngRef1.
y()) + (py * AngRef2.
y()) + (pz * AngRef3.
y());
342 finz = (px * AngRef1.
z()) + (py * AngRef2.
z()) + (pz * AngRef3.
z());
352 finx = (px * AngRef1.
x()) + (py * AngRef2.
x()) + (pz * AngRef3.
x());
353 finy = (px * AngRef1.
y()) + (py * AngRef2.
y()) + (pz * AngRef3.
y());
354 finz = (px * AngRef1.
z()) + (py * AngRef2.
z()) + (pz * AngRef3.
z());
361 G4double ResMag = std::sqrt((finx*finx) + (finy*finy) + (finz*finz));
371 if(verbosityLevel >= 1)
372 G4cout <<
"Generating isotropic vector: " << mom <<
G4endl;
381 G4double sintheta, sinphi,costheta,cosphi;
383 sintheta = std::sqrt( rndm * (std::sin(MaxTheta)*std::sin(MaxTheta) - std::sin(MinTheta)*std::sin(MinTheta) )
384 +std::sin(MinTheta)*std::sin(MinTheta) );
385 costheta = std::sqrt(1. -sintheta*sintheta);
388 Phi = MinPhi + (MaxPhi - MinPhi) * rndm2;
389 sinphi = std::sin(Phi);
390 cosphi = std::cos(Phi);
392 px = -sintheta * cosphi;
393 py = -sintheta * sinphi;
403 finx = (px * AngRef1.
x()) + (py * AngRef2.
x()) + (pz * AngRef3.
x());
404 finy = (px * AngRef1.
y()) + (py * AngRef2.
y()) + (pz * AngRef3.
y());
405 finz = (px * AngRef1.
z()) + (py * AngRef2.
z()) + (pz * AngRef3.
z());
414 finx = (px * AngRef1.
x()) + (py * AngRef2.
x()) + (pz * AngRef3.
x());
415 finy = (px * AngRef1.
y()) + (py * AngRef2.
y()) + (pz * AngRef3.
y());
416 finz = (px * AngRef1.
z()) + (py * AngRef2.
z()) + (pz * AngRef3.
z());
423 G4double ResMag = std::sqrt((finx*finx) + (finy*finy) + (finz*finz));
433 if(verbosityLevel >= 1)
435 G4cout <<
"Resultant cosine-law unit momentum vector " << mom <<
G4endl;
444 if(verbosityLevel >= 1)
446 G4cout <<
"Resultant Planar wave momentum vector " << mom <<
G4endl;
454 if(UserDistType ==
"NULL")
456 else if(UserDistType ==
"theta") {
458 while(Theta > MaxTheta || Theta < MinTheta)
459 Theta = GenerateUserDefTheta();
461 while(Phi > MaxPhi || Phi < MinPhi) {
466 else if(UserDistType ==
"phi") {
468 while(Theta > MaxTheta || Theta < MinTheta)
471 Theta = std::acos(1. - (2. * rndm));
474 while(Phi > MaxPhi || Phi < MinPhi)
475 Phi = GenerateUserDefPhi();
477 else if(UserDistType ==
"both")
480 while(Theta > MaxTheta || Theta < MinTheta)
481 Theta = GenerateUserDefTheta();
483 while(Phi > MaxPhi || Phi < MinPhi)
484 Phi = GenerateUserDefPhi();
486 px = -std::sin(Theta) * std::cos(Phi);
487 py = -std::sin(Theta) * std::sin(Phi);
488 pz = -std::cos(Theta);
490 pmag = std::sqrt((px*px) + (py*py) + (pz*pz));
492 if(!UserWRTSurface) {
497 finx = (px * AngRef1.
x()) + (py * AngRef2.
x()) + (pz * AngRef3.
x());
498 finy = (px * AngRef1.
y()) + (py * AngRef2.
y()) + (pz * AngRef3.
y());
499 finz = (px * AngRef1.
z()) + (py * AngRef2.
z()) + (pz * AngRef3.
z());
505 G4double ResMag = std::sqrt((finx*finx) + (finy*finy) + (finz*finz));
518 if(verbosityLevel > 1) {
520 G4cout <<
"Raw Unit vector "<<pxh<<
","<<pyh<<
","<<pzh<<
G4endl;
531 G4double ResMag = std::sqrt((resultx*resultx) + (resulty*resulty) + (resultz*resultz));
532 resultx = resultx/ResMag;
533 resulty = resulty/ResMag;
534 resultz = resultz/ResMag;
542 if(verbosityLevel > 0 )
544 G4cout <<
"Final User Defined momentum vector " << particle_momentum_direction <<
G4endl;
548 G4double G4SPSAngDistribution::GenerateUserDefTheta()
552 if(UserDistType ==
"NULL" || UserDistType ==
"phi")
564 if(IPDFThetaExist ==
false)
567 G4double bins[1024],vals[1024], sum;
571 vals[0] = UDefThetaH(
size_t(0));
573 for(ii=1;ii<maxbin;ii++)
576 vals[ii] = UDefThetaH(
size_t(ii)) + vals[ii-1];
577 sum = sum + UDefThetaH(
size_t(ii));
579 for(ii=0;ii<maxbin;ii++)
581 vals[ii] = vals[ii]/sum;
585 IPDFThetaExist =
true;
594 G4double G4SPSAngDistribution::GenerateUserDefPhi()
599 if(UserDistType ==
"NULL" || UserDistType ==
"theta")
611 if(IPDFPhiExist ==
false)
614 G4double bins[1024],vals[1024], sum;
618 vals[0] = UDefPhiH(
size_t(0));
620 for(ii=1;ii<maxbin;ii++)
623 vals[ii] = UDefPhiH(
size_t(ii)) + vals[ii-1];
624 sum = sum + UDefPhiH(
size_t(ii));
626 for(ii=0;ii<maxbin;ii++)
628 vals[ii] = vals[ii]/sum;
644 if (atype ==
"theta") {
645 UDefThetaH = IPDFThetaH = ZeroPhysVector ;
646 IPDFThetaExist = false ;}
647 else if (atype ==
"phi"){
648 UDefPhiH = IPDFPhiH = ZeroPhysVector ;
649 IPDFPhiExist = false ;}
661 if(AngDistType ==
"iso")
662 GenerateIsotropicFlux(localM);
663 else if(AngDistType ==
"cos")
664 GenerateCosineLawFlux(localM);
665 else if(AngDistType ==
"planar")
666 GeneratePlanarFlux(localM);
667 else if(AngDistType ==
"beam1d" || AngDistType ==
"beam2d" )
668 GenerateBeamFlux(localM);
669 else if(AngDistType ==
"user")
670 GenerateUserDefFlux(localM);
671 else if(AngDistType ==
"focused")
672 GenerateFocusedFlux(localM);
674 G4cout <<
"Error: AngDistType has unusual value" <<
G4endl;
ThreeVector shoot(const G4int Ap, const G4int Af)
DLL_API const Hep3Vector HepZHat
G4ThreeVector GetSideRefVec2() const
CLHEP::Hep3Vector G4ThreeVector
void SetBeamSigmaInAngR(G4double)
#define G4MUTEXINIT(mutex)
void SetBeamSigmaInAngY(G4double)
void InsertValues(G4double energy, G4double value)
void SetMinTheta(G4double)
void SetUseUserAngAxis(G4bool)
size_t GetVectorLength() const
G4double GetLowEdgeEnergy(size_t binNumber) const
static constexpr double twopi
G4ThreeVector GetDirection()
void UserDefAngPhi(G4ThreeVector)
void UserDefAngTheta(G4ThreeVector)
G4GLOB_DLL std::ostream G4cout
G4ParticleMomentum GenerateOne()
void SetBiasRndm(G4SPSRandomGenerator *a)
void DefineAngRefAxes(G4String, G4ThreeVector)
DLL_API const Hep3Vector HepYHat
G4double GetEnergy(G4double aValue)
G4ThreeVector GetSideRefVec3() const
void SetAngDistType(G4String)
void SetPosDistribution(G4SPSPosDistribution *a)
DLL_API const Hep3Vector HepXHat
void SetFocusPoint(G4ThreeVector)
void SetParticleMomentumDirection(G4ParticleMomentum aMomentumDirection)
G4ThreeVector GetSideRefVec1() const
G4ThreeVector GetParticlePos() const
static constexpr double pi
Hep3Vector cross(const Hep3Vector &) const
void SetUserWRTSurface(G4bool)
void SetVerbosity(G4int a)
void SetMaxTheta(G4double)
G4String GetSourcePosType() const
G4ThreeVector G4ParticleMomentum
#define G4MUTEXDESTROY(mutex)
void SetBeamSigmaInAngX(G4double)