515 if(
Shape ==
"Sphere")
520 theta = std::acos(1. - 2.*theta);
524 x =
Radius * std::sin(theta) * std::cos(phi);
525 y =
Radius * std::sin(theta) * std::sin(phi);
526 z =
Radius * std::cos(theta);
534 zdash = zdash.unit();
537 td.CSideRefVec1 = xdash.
unit();
538 td.CSideRefVec2 = ydash.
unit();
539 td.CSideRefVec3 = zdash.
unit();
542 else if(
Shape ==
"Ellipsoid")
554 theta = std::acos(1. - 2.*theta);
557 while(maxphi-minphi > 0.)
559 middlephi = (maxphi+minphi)/2.;
560 answer = (1./(
halfx*
halfx))*(middlephi/2. + std::sin(2*middlephi)/4.)
561 + (1./(halfy*
halfy))*(middlephi/2. - std::sin(2*middlephi)/4.)
563 answer = answer/constant;
564 if(answer > phi) maxphi = middlephi;
565 if(answer < phi) minphi = middlephi;
566 if(std::fabs(answer-phi) <= 0.00001)
573 x = std::sin(theta)*std::cos(phi);
574 y = std::sin(theta)*std::sin(phi);
585 tempxvar = 1./tempxvar;
586 G4double coordx = std::sqrt(tempxvar);
594 tempyvar = 1./tempyvar;
595 G4double coordy = std::sqrt(tempyvar);
601 tempzvar=(numXinZ*numXinZ)/(halfx*halfx)
602 +(numYinZ*numYinZ)/(halfy*halfy)+1./(
halfz*
halfz);
603 tempzvar = 1./tempzvar;
604 G4double coordz = std::sqrt(tempzvar);
606 lhs = std::sqrt((coordx*coordx)/(halfx*halfx) +
607 (coordy*coordy)/(halfy*halfy) +
611 G4cout <<
"Error: theta, phi not really on ellipsoid" <<
G4endl;
615 if(TestRandVar > 0.5)
620 if(TestRandVar > 0.5)
625 if(TestRandVar > 0.5)
630 RandPos.
setX(coordx);
631 RandPos.
setY(coordy);
632 RandPos.
setZ(coordz);
636 zdash = zdash.unit();
639 td.CSideRefVec1 = xdash.
unit();
640 td.CSideRefVec2 = ydash.
unit();
641 td.CSideRefVec3 = zdash.
unit();
643 else if(
Shape ==
"Cylinder")
646 G4double AreaTotal, prob1, prob2, prob3;
655 AreaLat = 2. *
pi * Radius * 2. *
halfz;
656 AreaTotal = AreaTop + AreaBot + AreaLat;
658 prob1 = AreaTop / AreaTotal;
659 prob2 = AreaBot / AreaTotal;
660 prob3 = 1.00 - prob1 - prob2;
661 if(std::fabs(prob3 - (AreaLat/AreaTotal)) >= 0.001)
671 if(testrand <= prob1)
677 while(((x*x)+(y*y)) > (Radius*Radius))
688 td.CSideRefVec1 =
Rotx;
689 td.CSideRefVec2 =
Roty;
690 td.CSideRefVec3 =
Rotz;
692 else if((testrand > prob1) && (testrand <= (prob1 + prob2)))
698 while(((x*x)+(y*y)) > (Radius*Radius))
709 td.CSideRefVec1 =
Rotx;
710 td.CSideRefVec2 = -
Roty;
711 td.CSideRefVec3 = -
Rotz;
713 else if(testrand > (prob1+prob2))
719 rand = rand * 2. *
pi;
721 x = Radius * std::cos(rand);
722 y = Radius * std::sin(rand);
731 zdash = zdash.unit();
734 td.CSideRefVec1 = xdash.
unit();
735 td.CSideRefVec2 = ydash.
unit();
736 td.CSideRefVec3 = zdash.
unit();
746 else if(
Shape ==
"Para")
755 G4double AreaX = halfy * halfz * 4.;
756 G4double AreaY = halfx * halfz * 4.;
757 G4double AreaZ = halfx * halfy * 4.;
758 G4double AreaTotal = 2*(AreaX + AreaY + AreaZ);
760 Probs[0] = AreaX/AreaTotal;
761 Probs[1] = Probs[0] + AreaX/AreaTotal;
762 Probs[2] = Probs[1] + AreaY/AreaTotal;
763 Probs[3] = Probs[2] + AreaY/AreaTotal;
764 Probs[4] = Probs[3] + AreaZ/AreaTotal;
765 Probs[5] = Probs[4] + AreaZ/AreaTotal;
778 if(testrand < Probs[0])
789 xdash = xdash.
unit();
790 ydash = ydash.
unit();
792 td.CSideRefVec1 = xdash.
unit();
793 td.CSideRefVec2 = ydash.
unit();
794 td.CSideRefVec3 = zdash.
unit();
796 else if(testrand >= Probs[0] && testrand < Probs[1])
807 xdash = xdash.
unit();
808 ydash = ydash.
unit();
810 td.CSideRefVec1 = xdash.
unit();
811 td.CSideRefVec2 = ydash.
unit();
812 td.CSideRefVec3 = zdash.
unit();
814 else if(testrand >= Probs[1] && testrand < Probs[2])
824 ydash = ydash.
unit();
827 td.CSideRefVec1 = xdash.
unit();
828 td.CSideRefVec2 = -ydash.
unit();
829 td.CSideRefVec3 = -zdash.
unit();
831 else if(testrand >= Probs[2] && testrand < Probs[3])
841 ydash = ydash.
unit();
844 td.CSideRefVec1 = xdash.
unit();
845 td.CSideRefVec2 = ydash.
unit();
846 td.CSideRefVec3 = zdash.
unit();
848 else if(testrand >= Probs[3] && testrand < Probs[4])
855 td.CSideRefVec1 =
Rotx;
856 td.CSideRefVec2 =
Roty;
857 td.CSideRefVec3 =
Rotz;
859 else if(testrand >= Probs[4] && testrand < Probs[5])
866 td.CSideRefVec1 =
Rotx;
867 td.CSideRefVec2 = -
Roty;
868 td.CSideRefVec3 = -
Rotz;
874 G4cout <<
"testrand=" << testrand <<
" Probs[5]=" << Probs[5] <<
G4endl;
906 G4cout <<
"Reference vectors for cosine-law " << td.CSideRefVec1 <<
" " << td.CSideRefVec2 <<
" " << td.CSideRefVec3 <<
G4endl;
G4Cache< thread_data_t > ThreadData
G4GLOB_DLL std::ostream G4cout
Hep3Vector cross(const Hep3Vector &) const
static const double twopi
G4SPSRandomGenerator * PosRndm
G4ThreeVector CentreCoords
G4double GenRandPosTheta()
static const G4double pos