51 if(theInstance == 0) {
53 theInstance = &manager;
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)
184 area = GenerateAPositionOnABoxBoundary( aSolid,p, direction);
186 if (dist_to_in<kInfinity/2.) i++;
189 area=area*double(i)/double(j);
194 G4double G4AdjointPosOnPhysVolGenerator::ComputeAreaOfExtSurfaceStartingFromSphere(
G4VSolid* aSolid,
G4int Nstat)
201 area = GenerateAPositionOnASphereBoundary( aSolid,p, direction);
203 if (dist_to_in<kInfinity/2.) i++;
206 area=area*double(i)/double(j);
216 if (UseSphere) GenerateAPositionOnASphereBoundary( aSolid,p, direction);
217 else GenerateAPositionOnABoxBoundary( aSolid,p, direction);
219 if (dist_to_in<kInfinity/2.) {
223 p+= 0.999999*direction*dist_to_in;
224 CosThDirComparedToNormal=direction.
dot(-norm);
232 G4double minX,maxX,minY,maxY,minZ,maxZ;
251 G4double r=scale*std::sqrt(dX*dX+dY*dY+dZ*dZ);
254 G4double theta = std::acos(std::sqrt(cos_th2));
257 direction=-direction;
259 theta = std::acos(cos_th);
266 return 4.*3.1415926*r*
r;;
273 G4double ran_var,px,py,pz,minX,maxX,minY,maxY,minZ,maxZ;
287 minX-=scale*std::abs(minX);
288 minY-=scale*std::abs(minY);
289 minZ-=scale*std::abs(minZ);
290 maxX+=scale*std::abs(maxX);
291 maxY+=scale*std::abs(maxY);
292 maxZ+=scale*std::abs(maxZ);
301 G4double area=XY_prob+YZ_prob+ZX_prob;
308 G4double sth = std::sqrt(1.-cos_th2);
314 if (ran_var <=XY_prob){
325 ranX=(ran_var1-0.5)*2.;
328 px=minX+(maxX-minX)*ranX;
329 py=minY+(maxY-minY)*ranY;
331 else if (ran_var <=(XY_prob+YZ_prob)){
332 G4double ran_var1=(ran_var-XY_prob)/YZ_prob;
342 ranY=(ran_var1-0.5)*2.;
345 py=minY+(maxY-minY)*ranY;
346 pz=minZ+(maxZ-minZ)*ranZ;
350 G4double ran_var1=(ran_var-XY_prob-YZ_prob)/ZX_prob;
360 ranZ=(ran_var1-0.5)*2.;
363 px=minX+(maxX-minX)*ranX;
364 pz=minZ+(maxZ-minZ)*ranZ;
374 if (!thePhysicalVolume) {
375 G4cout<<
"Before generating a source on an external surface of volume you should select a physical volume"<<std::endl;
380 direction = theTransformationFromPhysVolToWorld.
TransformAxis(direction);
388 costh_to_normal = CosThDirComparedToNormal;
392 void G4AdjointPosOnPhysVolGenerator::ComputeTransformationFromPhysVolToWorld()
399 theTransformationFromPhysVolToWorld *=
401 for (
unsigned int i=0; i< thePhysVolStore->size();i++){
402 if ((*thePhysVolStore)[i]->GetLogicalVolume() == mother){
403 daughter = (*thePhysVolStore)[i];