43G4AdjointPosOnPhysVolGenerator::theInstance =
nullptr;
49 if(theInstance ==
nullptr)
61 thePhysicalVolume =
nullptr;
64 for (
unsigned int i=0; i< thePhysVolStore->size(); ++i )
66 G4String vol_name =(*thePhysVolStore)[i]->GetName();
69 vol_name = (*thePhysVolStore)[i]->GetLogicalVolume()->GetName();
71 if (vol_name == aName)
73 thePhysicalVolume = (*thePhysVolStore)[i];
76 if (thePhysicalVolume !=
nullptr)
79 ComputeTransformationFromPhysVolToWorld();
83 G4cout <<
"The physical volume with name " << aName
84 <<
" does not exist!!" <<
G4endl;
85 G4cout <<
"Before generating a source on an external surface " <<
G4endl
86 <<
"of a volume you should select another physical volume."
89 return thePhysicalVolume;
135 if (ModelOfSurfaceSource ==
"OnSolid")
139 return ComputeAreaOfExtSurfaceStartingFromSphere(aSolid,NStats);
142 return ComputeAreaOfExtSurfaceStartingFromBox(aSolid,NStats);
146 if (ModelOfSurfaceSource ==
"ExternalSphere")
148 return GenerateAPositionOnASphereBoundary(aSolid, p,dir);
151 return GenerateAPositionOnABoxBoundary(aSolid, p,dir);
170 if (ModelOfSurfaceSource ==
"OnSolid")
172 GenerateAPositionOnASolidBoundary(aSolid, p,direction);
175 if (ModelOfSurfaceSource ==
"ExternalSphere")
177 GenerateAPositionOnASphereBoundary(aSolid, p, direction);
180 GenerateAPositionOnABoxBoundary(aSolid, p, direction);
195G4double G4AdjointPosOnPhysVolGenerator::
196ComputeAreaOfExtSurfaceStartingFromBox(
G4VSolid* aSolid,
G4int Nstat)
198 if ( Nstat <= 0 ) {
return 0.; }
204 area = GenerateAPositionOnABoxBoundary( aSolid,p, direction);
206 if (dist_to_in<kInfinity/2.) { ++i; }
215G4double G4AdjointPosOnPhysVolGenerator::
216ComputeAreaOfExtSurfaceStartingFromSphere(
G4VSolid* aSolid,
G4int Nstat)
218 if ( Nstat <= 0 ) {
return 0.; }
224 area = GenerateAPositionOnASphereBoundary( aSolid,p, direction);
226 if (dist_to_in<kInfinity/2.) { ++i; }
235void G4AdjointPosOnPhysVolGenerator::
244 GenerateAPositionOnASphereBoundary( aSolid,p, direction );
248 GenerateAPositionOnABoxBoundary( aSolid,p, direction);
251 if (dist_to_in<kInfinity/2.)
254 p += 0.999999*direction*dist_to_in;
261G4double G4AdjointPosOnPhysVolGenerator::
265 G4double minX,maxX,minY,maxY,minZ,maxZ;
285 G4double r=scale*std::sqrt(dX*dX+dY*dY+dZ*dZ);
288 G4double theta = std::acos(std::sqrt(cos_th2));
291 direction=-direction;
293 theta = std::acos(cos_th);
300 return 4.*CLHEP::pi*r*r;;
305G4double G4AdjointPosOnPhysVolGenerator::
310 G4double ran_var,px,py,pz,minX,maxX,minY,maxY,minZ,maxZ;
324 minX-=scale*std::abs(minX);
325 minY-=scale*std::abs(minY);
326 minZ-=scale*std::abs(minZ);
327 maxX+=scale*std::abs(maxX);
328 maxY+=scale*std::abs(maxY);
329 maxZ+=scale*std::abs(maxZ);
338 G4double area=XY_prob+YZ_prob+ZX_prob;
345 G4double sth = std::sqrt(1.-cos_th2);
351 if (ran_var <=XY_prob)
365 ranX=(ran_var1-0.5)*2.;
368 px=minX+(maxX-minX)*ranX;
369 py=minY+(maxY-minY)*ranY;
371 else if (ran_var <=(XY_prob+YZ_prob))
373 G4double ran_var1=(ran_var-XY_prob)/YZ_prob;
385 ranY=(ran_var1-0.5)*2.;
388 py=minY+(maxY-minY)*ranY;
389 pz=minZ+(maxZ-minZ)*ranZ;
393 G4double ran_var1=(ran_var-XY_prob-YZ_prob)/ZX_prob;
405 ranZ=(ran_var1-0.5)*2.;
408 px=minX+(maxX-minX)*ranX;
409 pz=minZ+(maxZ-minZ)*ranZ;
422 if (thePhysicalVolume ==
nullptr)
424 G4cout <<
"Before generating a source on an external surface" <<
G4endl
425 <<
"of volume you should select a physical volume" <<
G4endl;
430 direction = theTransformationFromPhysVolToWorld.
TransformAxis(direction);
441 costh_to_normal = CosThDirComparedToNormal;
446void G4AdjointPosOnPhysVolGenerator::ComputeTransformationFromPhysVolToWorld()
452 while (mother !=
nullptr)
454 theTransformationFromPhysVolToWorld *=
457 for (
unsigned int i=0; i<thePhysVolStore->size(); ++i )
459 if ((*thePhysVolStore)[i]->GetLogicalVolume() == mother)
461 daughter = (*thePhysVolStore)[i];
CLHEP::Hep3Vector G4ThreeVector
G4GLOB_DLL std::ostream G4cout
Hep3Vector & rotateY(double)
Hep3Vector & rotateZ(double)
void setRThetaPhi(double r, double theta, double phi)
void GenerateAPositionOnTheExtSurfaceOfTheSolid(G4ThreeVector &p, G4ThreeVector &direction)
void GenerateAPositionOnTheExtSurfaceOfThePhysicalVolume(G4ThreeVector &p, G4ThreeVector &direction)
G4VPhysicalVolume * DefinePhysicalVolume(const G4String &aName)
void DefinePhysicalVolume1(const G4String &aName)
void GenerateAPositionOnTheExtSurfaceOfASolid(G4VSolid *aSolid, G4ThreeVector &p, G4ThreeVector &direction)
G4double ComputeAreaOfExtSurface()
static G4AdjointPosOnPhysVolGenerator * GetInstance()
G4VSolid * GetSolid() const
static G4PhysicalVolumeStore * GetInstance()
G4LogicalVolume * GetMotherLogical() const
G4LogicalVolume * GetLogicalVolume() const
const G4RotationMatrix * GetFrameRotation() const
G4ThreeVector GetObjectTranslation() const
virtual G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pMin, G4double &pMax) const =0
virtual G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const =0