60 G4AdjointPosOnPhysVolGenerator::~G4AdjointPosOnPhysVolGenerator()
66 G4AdjointPosOnPhysVolGenerator::G4AdjointPosOnPhysVolGenerator()
67 : theSolid(0), thePhysicalVolume(0),
68 UseSphere(true), ModelOfSurfaceSource(
"OnSolid"),
69 AreaOfExtSurfaceOfThePhysicalVolume(0.), CosThDirComparedToNormal(0.)
77 thePhysicalVolume = 0;
80 for (
unsigned int i=0; i< thePhysVolStore->size();i++){
81 G4String vol_name =(*thePhysVolStore)[i]->GetName();
83 vol_name = (*thePhysVolStore)[i]->GetLogicalVolume()->GetName();
85 if (vol_name == aName){
86 thePhysicalVolume = (*thePhysVolStore)[i];
89 if (thePhysicalVolume){
91 ComputeTransformationFromPhysVolToWorld();
96 G4cout<<
"The physical volume with name "<<aName<<
" does not exist!!"<<std::endl;
97 G4cout<<
"Before generating a source on an external surface of a volume you should select another physical volume"<<std::endl;
99 return thePhysicalVolume;
135 if (ModelOfSurfaceSource ==
"OnSolid" ){
137 return ComputeAreaOfExtSurfaceStartingFromSphere(aSolid,NStats);
140 return ComputeAreaOfExtSurfaceStartingFromBox(aSolid,NStats);
145 if (ModelOfSurfaceSource ==
"ExternalSphere" )
return GenerateAPositionOnASphereBoundary(aSolid, p,dir);
146 return GenerateAPositionOnABoxBoundary(aSolid, p,dir);
159 if (ModelOfSurfaceSource ==
"OnSolid" ){
160 GenerateAPositionOnASolidBoundary(aSolid, p,direction);
163 if (ModelOfSurfaceSource ==
"ExternalSphere" ) {
164 GenerateAPositionOnASphereBoundary(aSolid, p, direction);
167 GenerateAPositionOnABoxBoundary(aSolid, p, direction);
177 G4double G4AdjointPosOnPhysVolGenerator::ComputeAreaOfExtSurfaceStartingFromBox(
G4VSolid* aSolid,
G4int Nstat)
179 if ( Nstat <= 0 )
return 0.;
185 area = GenerateAPositionOnABoxBoundary( aSolid,p, direction);
190 area=area*double(i)/double(j);
195 G4double G4AdjointPosOnPhysVolGenerator::ComputeAreaOfExtSurfaceStartingFromSphere(
G4VSolid* aSolid,
G4int Nstat)
197 if ( Nstat <= 0 )
return 0.;
203 area = GenerateAPositionOnASphereBoundary( aSolid,p, direction);
208 area=area*double(i)/double(j);
217 if (UseSphere) GenerateAPositionOnASphereBoundary( aSolid,p, direction);
218 else GenerateAPositionOnABoxBoundary( aSolid,p, direction);
222 p+= 0.999999*direction*dist_to_in;
230 G4double minX,maxX,minY,maxY,minZ,maxZ;
249 G4double r=scale*std::sqrt(dX*dX+dY*dY+dZ*dZ);
252 G4double theta = std::acos(std::sqrt(cos_th2));
255 direction=-direction;
257 theta = std::acos(cos_th);
264 return 4.*3.1415926*r*r;;
271 G4double ran_var,px,py,pz,minX,maxX,minY,maxY,minZ,maxZ;
285 minX-=scale*std::abs(minX);
286 minY-=scale*std::abs(minY);
287 minZ-=scale*std::abs(minZ);
288 maxX+=scale*std::abs(maxX);
289 maxY+=scale*std::abs(maxY);
290 maxZ+=scale*std::abs(maxZ);
299 G4double area=XY_prob+YZ_prob+ZX_prob;
306 G4double sth = std::sqrt(1.-cos_th2);
312 if (ran_var <=XY_prob){
323 ranX=(ran_var1-0.5)*2.;
326 px=minX+(maxX-minX)*ranX;
327 py=minY+(maxY-minY)*ranY;
329 else if (ran_var <=(XY_prob+YZ_prob)){
330 G4double ran_var1=(ran_var-XY_prob)/YZ_prob;
340 ranY=(ran_var1-0.5)*2.;
343 py=minY+(maxY-minY)*ranY;
344 pz=minZ+(maxZ-minZ)*ranZ;
348 G4double ran_var1=(ran_var-XY_prob-YZ_prob)/ZX_prob;
358 ranZ=(ran_var1-0.5)*2.;
361 px=minX+(maxX-minX)*ranX;
362 pz=minZ+(maxZ-minZ)*ranZ;
372 if (!thePhysicalVolume) {
373 G4cout<<
"Before generating a source on an external surface of volume you should select a physical volume"<<std::endl;
378 direction = theTransformationFromPhysVolToWorld.
TransformAxis(direction);
386 costh_to_normal = CosThDirComparedToNormal;
390 void G4AdjointPosOnPhysVolGenerator::ComputeTransformationFromPhysVolToWorld()
397 theTransformationFromPhysVolToWorld *=
399 for (
unsigned int i=0; i< thePhysVolStore->size();i++){
400 if ((*thePhysVolStore)[i]->GetLogicalVolume() == mother){
401 daughter = (*thePhysVolStore)[i];
virtual G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pMin, G4double &pMax) const =0
G4double ComputeAreaOfExtSurface()
static const G4double kInfinity
CLHEP::Hep3Vector G4ThreeVector
void GenerateAPositionOnTheExtSurfaceOfASolid(G4VSolid *aSolid, G4ThreeVector &p, G4ThreeVector &direction)
void GenerateAPositionOnTheExtSurfaceOfTheSolid(G4ThreeVector &p, G4ThreeVector &direction)
G4VSolid * GetSolid() const
static const G4double eps
static G4PhysicalVolumeStore * GetInstance()
G4GLOB_DLL std::ostream G4cout
Hep3Vector & rotateZ(double)
virtual G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const =0
G4LogicalVolume * GetMotherLogical() const
void setRThetaPhi(double r, double theta, double phi)
const G4RotationMatrix * GetFrameRotation() const
G4LogicalVolume * GetLogicalVolume() const
void GenerateAPositionOnTheExtSurfaceOfThePhysicalVolume(G4ThreeVector &p, G4ThreeVector &direction)
void DefinePhysicalVolume1(const G4String &aName)
Hep3Vector & rotateY(double)
static G4AdjointPosOnPhysVolGenerator * GetInstance()
G4ThreeVector GetObjectTranslation() const
G4VPhysicalVolume * DefinePhysicalVolume(const G4String &aName)