51 if(theInstance == 0) {
53 theInstance = &manager;
60G4AdjointPosOnPhysVolGenerator::~G4AdjointPosOnPhysVolGenerator()
66G4AdjointPosOnPhysVolGenerator::G4AdjointPosOnPhysVolGenerator()
67 : theSolid(0), thePhysicalVolume(0), NStat(1000000), epsilon(0.001),
68 UseSphere(true), ModelOfSurfaceSource(
"OnSolid"),
69 ExtSourceRadius(0.), ExtSourceDx(0.), ExtSourceDy(0.), ExtSourceDz(0.),
70 AreaOfExtSurfaceOfThePhysicalVolume(0.), CosThDirComparedToNormal(0.)
78 thePhysicalVolume = 0;
81 for (
unsigned int i=0; i< thePhysVolStore->size();i++){
82 G4String vol_name =(*thePhysVolStore)[i]->GetName();
84 vol_name = (*thePhysVolStore)[i]->GetLogicalVolume()->GetName();
86 if (vol_name == aName){
87 thePhysicalVolume = (*thePhysVolStore)[i];
90 if (thePhysicalVolume){
92 ComputeTransformationFromPhysVolToWorld();
97 G4cout<<
"The physical volume with name "<<aName<<
" does not exist!!"<<std::endl;
98 G4cout<<
"Before generating a source on an external surface of a volume you should select another physical volume"<<std::endl;
100 return thePhysicalVolume;
136 if (ModelOfSurfaceSource ==
"OnSolid" ){
138 return ComputeAreaOfExtSurfaceStartingFromSphere(aSolid,NStats);
141 return ComputeAreaOfExtSurfaceStartingFromBox(aSolid,NStats);
146 if (ModelOfSurfaceSource ==
"ExternalSphere" )
return GenerateAPositionOnASphereBoundary(aSolid, p,dir);
147 return GenerateAPositionOnABoxBoundary(aSolid, p,dir);
160 if (ModelOfSurfaceSource ==
"OnSolid" ){
161 GenerateAPositionOnASolidBoundary(aSolid, p,direction);
164 if (ModelOfSurfaceSource ==
"ExternalSphere" ) {
165 GenerateAPositionOnASphereBoundary(aSolid, p, direction);
168 GenerateAPositionOnABoxBoundary(aSolid, p, direction);
178G4double G4AdjointPosOnPhysVolGenerator::ComputeAreaOfExtSurfaceStartingFromBox(
G4VSolid* aSolid,
G4int Nstat)
185 area = GenerateAPositionOnABoxBoundary( aSolid,p, direction);
187 if (dist_to_in<kInfinity/2.) i++;
190 area=area*double(i)/double(j);
195G4double G4AdjointPosOnPhysVolGenerator::ComputeAreaOfExtSurfaceStartingFromSphere(
G4VSolid* aSolid,
G4int Nstat)
202 area = GenerateAPositionOnASphereBoundary( aSolid,p, direction);
204 if (dist_to_in<kInfinity/2.) i++;
207 area=area*double(i)/double(j);
217 if (UseSphere) GenerateAPositionOnASphereBoundary( aSolid,p, direction);
218 else GenerateAPositionOnABoxBoundary( aSolid,p, direction);
220 if (dist_to_in<kInfinity/2.) {
224 p+= 0.999999*direction*dist_to_in;
225 CosThDirComparedToNormal=direction.
dot(-norm);
233 G4double minX,maxX,minY,maxY,minZ,maxZ;
252 G4double r=scale*std::sqrt(dX*dX+dY*dY+dZ*dZ);
255 G4double theta = std::acos(std::sqrt(cos_th2));
258 direction=-direction;
260 theta = std::acos(cos_th);
267 return 4.*3.1415926*r*r;;
274 G4double ran_var,px,py,pz,minX,maxX,minY,maxY,minZ,maxZ;
288 minX-=scale*std::abs(minX);
289 minY-=scale*std::abs(minY);
290 minZ-=scale*std::abs(minZ);
291 maxX+=scale*std::abs(maxX);
292 maxY+=scale*std::abs(maxY);
293 maxZ+=scale*std::abs(maxZ);
302 G4double area=XY_prob+YZ_prob+ZX_prob;
309 G4double sth = std::sqrt(1.-cos_th2);
315 if (ran_var <=XY_prob){
326 ranX=(ran_var1-0.5)*2.;
329 px=minX+(maxX-minX)*ranX;
330 py=minY+(maxY-minY)*ranY;
332 else if (ran_var <=(XY_prob+YZ_prob)){
333 G4double ran_var1=(ran_var-XY_prob)/YZ_prob;
343 ranY=(ran_var1-0.5)*2.;
346 py=minY+(maxY-minY)*ranY;
347 pz=minZ+(maxZ-minZ)*ranZ;
351 G4double ran_var1=(ran_var-XY_prob-YZ_prob)/ZX_prob;
361 ranZ=(ran_var1-0.5)*2.;
364 px=minX+(maxX-minX)*ranX;
365 pz=minZ+(maxZ-minZ)*ranZ;
375 if (!thePhysicalVolume) {
376 G4cout<<
"Before generating a source on an external surface of volume you should select a physical volume"<<std::endl;
381 direction = theTransformationFromPhysVolToWorld.
TransformAxis(direction);
389 costh_to_normal = CosThDirComparedToNormal;
393void G4AdjointPosOnPhysVolGenerator::ComputeTransformationFromPhysVolToWorld()
400 theTransformationFromPhysVolToWorld *=
402 for (
unsigned int i=0; i< thePhysVolStore->size();i++){
403 if ((*thePhysVolStore)[i]->GetLogicalVolume() == mother){
404 daughter = (*thePhysVolStore)[i];
CLHEP::Hep3Vector G4ThreeVector
G4DLLIMPORT std::ostream G4cout
Hep3Vector & rotateY(double)
Hep3Vector & rotateZ(double)
void setRThetaPhi(double r, double theta, double phi)
double dot(const Hep3Vector &) const
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 G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const =0
virtual G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const =0