43G4AdjointPosOnPhysVolGenerator::theInstance =
nullptr;
49 if(theInstance ==
nullptr)
58G4AdjointPosOnPhysVolGenerator::~G4AdjointPosOnPhysVolGenerator()
64G4AdjointPosOnPhysVolGenerator::G4AdjointPosOnPhysVolGenerator()
65 : UseSphere(true), ModelOfSurfaceSource(
"OnSolid"),
66 AreaOfExtSurfaceOfThePhysicalVolume(0.), CosThDirComparedToNormal(0.)
75 thePhysicalVolume =
nullptr;
78 for (
unsigned int i=0; i< thePhysVolStore->size(); ++i )
80 G4String vol_name =(*thePhysVolStore)[i]->GetName();
83 vol_name = (*thePhysVolStore)[i]->GetLogicalVolume()->GetName();
85 if (vol_name == aName)
87 thePhysicalVolume = (*thePhysVolStore)[i];
90 if (thePhysicalVolume !=
nullptr)
93 ComputeTransformationFromPhysVolToWorld();
97 G4cout <<
"The physical volume with name " << aName
98 <<
" does not exist!!" <<
G4endl;
99 G4cout <<
"Before generating a source on an external surface " <<
G4endl
100 <<
"of a volume you should select another physical volume."
103 return thePhysicalVolume;
149 if (ModelOfSurfaceSource ==
"OnSolid")
153 return ComputeAreaOfExtSurfaceStartingFromSphere(aSolid,NStats);
157 return ComputeAreaOfExtSurfaceStartingFromBox(aSolid,NStats);
163 if (ModelOfSurfaceSource ==
"ExternalSphere")
165 return GenerateAPositionOnASphereBoundary(aSolid, p,dir);
167 return GenerateAPositionOnABoxBoundary(aSolid, p,dir);
187 if (ModelOfSurfaceSource ==
"OnSolid")
189 GenerateAPositionOnASolidBoundary(aSolid, p,direction);
192 if (ModelOfSurfaceSource ==
"ExternalSphere")
194 GenerateAPositionOnASphereBoundary(aSolid, p, direction);
197 GenerateAPositionOnABoxBoundary(aSolid, p, direction);
212G4double G4AdjointPosOnPhysVolGenerator::
213ComputeAreaOfExtSurfaceStartingFromBox(
G4VSolid* aSolid,
G4int Nstat)
215 if ( Nstat <= 0 ) {
return 0.; }
221 area = GenerateAPositionOnABoxBoundary( aSolid,p, direction);
223 if (dist_to_in<kInfinity/2.) { ++i; }
232G4double G4AdjointPosOnPhysVolGenerator::
233ComputeAreaOfExtSurfaceStartingFromSphere(
G4VSolid* aSolid,
G4int Nstat)
235 if ( Nstat <= 0 ) {
return 0.; }
241 area = GenerateAPositionOnASphereBoundary( aSolid,p, direction);
243 if (dist_to_in<kInfinity/2.) { ++i; }
252void G4AdjointPosOnPhysVolGenerator::
261 GenerateAPositionOnASphereBoundary( aSolid,p, direction );
265 GenerateAPositionOnABoxBoundary( aSolid,p, direction);
268 if (dist_to_in<kInfinity/2.)
271 p += 0.999999*direction*dist_to_in;
278G4double G4AdjointPosOnPhysVolGenerator::
282 G4double minX,maxX,minY,maxY,minZ,maxZ;
302 G4double r=scale*std::sqrt(dX*dX+dY*dY+dZ*dZ);
305 G4double theta = std::acos(std::sqrt(cos_th2));
308 direction=-direction;
310 theta = std::acos(cos_th);
317 return 4.*CLHEP::pi*r*r;;
322G4double G4AdjointPosOnPhysVolGenerator::
327 G4double ran_var,px,py,pz,minX,maxX,minY,maxY,minZ,maxZ;
341 minX-=scale*std::abs(minX);
342 minY-=scale*std::abs(minY);
343 minZ-=scale*std::abs(minZ);
344 maxX+=scale*std::abs(maxX);
345 maxY+=scale*std::abs(maxY);
346 maxZ+=scale*std::abs(maxZ);
355 G4double area=XY_prob+YZ_prob+ZX_prob;
362 G4double sth = std::sqrt(1.-cos_th2);
368 if (ran_var <=XY_prob)
382 ranX=(ran_var1-0.5)*2.;
385 px=minX+(maxX-minX)*ranX;
386 py=minY+(maxY-minY)*ranY;
388 else if (ran_var <=(XY_prob+YZ_prob))
390 G4double ran_var1=(ran_var-XY_prob)/YZ_prob;
402 ranY=(ran_var1-0.5)*2.;
405 py=minY+(maxY-minY)*ranY;
406 pz=minZ+(maxZ-minZ)*ranZ;
410 G4double ran_var1=(ran_var-XY_prob-YZ_prob)/ZX_prob;
422 ranZ=(ran_var1-0.5)*2.;
425 px=minX+(maxX-minX)*ranX;
426 pz=minZ+(maxZ-minZ)*ranZ;
439 if (thePhysicalVolume ==
nullptr)
441 G4cout <<
"Before generating a source on an external surface" <<
G4endl
442 <<
"of volume you should select a physical volume" <<
G4endl;
447 direction = theTransformationFromPhysVolToWorld.
TransformAxis(direction);
458 costh_to_normal = CosThDirComparedToNormal;
463void G4AdjointPosOnPhysVolGenerator::ComputeTransformationFromPhysVolToWorld()
469 while (mother !=
nullptr)
471 theTransformationFromPhysVolToWorld *=
474 for (
unsigned int i=0; i<thePhysVolStore->size(); ++i )
476 if ((*thePhysVolStore)[i]->GetLogicalVolume() == mother)
478 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