Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4AdjointCrossSurfChecker Class Reference

#include <G4AdjointCrossSurfChecker.hh>

Public Member Functions

G4bool CrossingASphere (const G4Step *aStep, G4double sphere_radius, G4ThreeVector sphere_center, G4ThreeVector &cross_pos, G4double &cos_to_surface, G4bool &GoingIn)
 
G4bool GoingInOrOutOfaVolume (const G4Step *aStep, const G4String &volume_name, G4double &cos_to_surface, G4bool &GoingIn)
 
G4bool GoingInOrOutOfaVolumeByExtSurface (const G4Step *aStep, const G4String &volume_name, const G4String &mother_lvol_name, G4double &cos_to_surface, G4bool &GoingIn)
 
G4bool CrossingAGivenRegisteredSurface (const G4Step *aStep, const G4String &surface_name, G4ThreeVector &cross_pos, G4double &cos_to_surface, G4bool &GoingIn)
 
G4bool CrossingAGivenRegisteredSurface (const G4Step *aStep, G4int ind, G4ThreeVector &cross_pos, G4double &cos_to_surface, G4bool &GoingIn)
 
G4bool CrossingOneOfTheRegisteredSurface (const G4Step *aStep, G4String &surface_name, G4ThreeVector &cross_pos, G4double &cos_to_surface, G4bool &GoingIn)
 
G4bool CrossingAnInterfaceBetweenTwoVolumes (const G4Step *aStep, const G4String &vol1_name, const G4String &vol2_name, G4ThreeVector &cross_pos, G4double &cos_to_surface, G4bool &GoingIn)
 
G4bool AddaSphericalSurface (const G4String &SurfaceName, G4double radius, G4ThreeVector pos, G4double &area)
 
G4bool AddaSphericalSurfaceWithCenterAtTheCenterOfAVolume (const G4String &SurfaceName, G4double radius, const G4String &volume_name, G4ThreeVector &center, G4double &area)
 
G4bool AddanExtSurfaceOfAvolume (const G4String &SurfaceName, const G4String &volume_name, G4double &area)
 
G4bool AddanInterfaceBetweenTwoVolumes (const G4String &SurfaceName, const G4String &volume_name1, const G4String &volume_name2, G4double &area)
 
void ClearListOfSelectedSurface ()
 

Static Public Member Functions

static G4AdjointCrossSurfCheckerGetInstance ()
 

Detailed Description

Definition at line 50 of file G4AdjointCrossSurfChecker.hh.

Member Function Documentation

◆ AddanExtSurfaceOfAvolume()

G4bool G4AdjointCrossSurfChecker::AddanExtSurfaceOfAvolume ( const G4String SurfaceName,
const G4String volume_name,
G4double area 
)

Definition at line 386 of file G4AdjointCrossSurfChecker.cc.

389{
390 G4int ind = FindRegisteredSurface(SurfaceName);
391
392 G4VPhysicalVolume* thePhysicalVolume = nullptr;
394 thePhysicalVolume = thePhysVolStore->GetVolume(volume_name);
395 if (thePhysicalVolume == nullptr)
396 {
397 return false;
398 }
399 Area = thePhysicalVolume->GetLogicalVolume()->GetSolid()->GetSurfaceArea();
400 G4String mother_vol_name = "";
401 G4LogicalVolume* theMother = thePhysicalVolume->GetMotherLogical();
402
403 if (theMother != nullptr) mother_vol_name= theMother->GetName();
404 if (ind>=0)
405 {
406 ListOfSurfaceType[ind] = "ExternalSurfaceOfAVolume";
407 ListOfSphereRadius[ind] = 0.;
408 ListOfSphereCenter[ind] = G4ThreeVector(0.,0.,0.);
409 ListOfVol1Name[ind] = volume_name;
410 ListOfVol2Name[ind] = mother_vol_name;
411 AreaOfSurface[ind] = Area;
412 }
413 else
414 {
415 ListOfSurfaceName.push_back(SurfaceName);
416 ListOfSurfaceType.push_back("ExternalSurfaceOfAVolume");
417 ListOfSphereRadius.push_back(0.);
418 ListOfSphereCenter.push_back(G4ThreeVector(0.,0.,0.));
419 ListOfVol1Name.push_back(volume_name);
420 ListOfVol2Name.push_back(mother_vol_name);
421 AreaOfSurface.push_back(Area);
422 }
423 return true;
424}
CLHEP::Hep3Vector G4ThreeVector
int G4int
Definition: G4Types.hh:85
G4VSolid * GetSolid() const
const G4String & GetName() const
static G4PhysicalVolumeStore * GetInstance()
G4VPhysicalVolume * GetVolume(const G4String &name, G4bool verbose=true, G4bool reverseSearch=false) const
G4LogicalVolume * GetMotherLogical() const
G4LogicalVolume * GetLogicalVolume() const
virtual G4double GetSurfaceArea()
Definition: G4VSolid.cc:250

Referenced by G4AdjointSimManager::DefineAdjointSourceOnTheExtSurfaceOfAVolume(), and G4AdjointSimManager::DefineExtSourceOnTheExtSurfaceOfAVolume().

◆ AddanInterfaceBetweenTwoVolumes()

G4bool G4AdjointCrossSurfChecker::AddanInterfaceBetweenTwoVolumes ( const G4String SurfaceName,
const G4String volume_name1,
const G4String volume_name2,
G4double area 
)

Definition at line 428 of file G4AdjointCrossSurfChecker.cc.

432{
433 G4int ind = FindRegisteredSurface(SurfaceName);
434 Area = -1.; // the way to compute the surface is not known yet
435 if (ind>=0)
436 {
437 ListOfSurfaceType[ind] = "BoundaryBetweenTwoVolumes";
438 ListOfSphereRadius[ind] = 0.;
439 ListOfSphereCenter[ind] = G4ThreeVector(0.,0.,0.);
440 ListOfVol1Name[ind] = volume_name1;
441 ListOfVol2Name[ind] = volume_name2;
442 AreaOfSurface[ind] = Area;
443 }
444 else
445 {
446 ListOfSurfaceName.push_back(SurfaceName);
447 ListOfSurfaceType.push_back("BoundaryBetweenTwoVolumes");
448 ListOfSphereRadius.push_back(0.);
449 ListOfSphereCenter.push_back(G4ThreeVector(0.,0.,0.));
450 ListOfVol1Name.push_back(volume_name1);
451 ListOfVol2Name.push_back(volume_name2);
452 AreaOfSurface.push_back(Area);
453 }
454 return true;
455}

◆ AddaSphericalSurface()

G4bool G4AdjointCrossSurfChecker::AddaSphericalSurface ( const G4String SurfaceName,
G4double  radius,
G4ThreeVector  pos,
G4double area 
)

Definition at line 313 of file G4AdjointCrossSurfChecker.cc.

316{
317 G4int ind = FindRegisteredSurface(SurfaceName);
318 Area = 4.*pi*radius*radius;
319 if (ind>=0)
320 {
321 ListOfSurfaceType[ind] = "Sphere";
322 ListOfSphereRadius[ind] = radius;
323 ListOfSphereCenter[ind] = pos;
324 ListOfVol1Name[ind] = "";
325 ListOfVol2Name[ind] = "";
326 AreaOfSurface[ind] = Area;
327 }
328 else
329 {
330 ListOfSurfaceName.push_back(SurfaceName);
331 ListOfSurfaceType.push_back("Sphere");
332 ListOfSphereRadius.push_back(radius);
333 ListOfSphereCenter.push_back(pos);
334 ListOfVol1Name.push_back("");
335 ListOfVol2Name.push_back("");
336 AreaOfSurface.push_back(Area);
337 }
338 return true;
339}
const G4double pi

Referenced by AddaSphericalSurfaceWithCenterAtTheCenterOfAVolume(), G4AdjointSimManager::DefineSphericalAdjointSource(), and G4AdjointSimManager::DefineSphericalExtSource().

◆ AddaSphericalSurfaceWithCenterAtTheCenterOfAVolume()

G4bool G4AdjointCrossSurfChecker::AddaSphericalSurfaceWithCenterAtTheCenterOfAVolume ( const G4String SurfaceName,
G4double  radius,
const G4String volume_name,
G4ThreeVector center,
G4double area 
)

Definition at line 343 of file G4AdjointCrossSurfChecker.cc.

349{
350 G4VPhysicalVolume* thePhysicalVolume = nullptr;
352 thePhysicalVolume = thePhysVolStore->GetVolume(volume_name);
353 if (thePhysicalVolume != nullptr)
354 {
355 G4VPhysicalVolume* daughter = thePhysicalVolume;
356 G4LogicalVolume* mother = thePhysicalVolume->GetMotherLogical();
357 G4AffineTransform theTransformationFromPhysVolToWorld = G4AffineTransform();
358 while (mother != nullptr)
359 {
360 theTransformationFromPhysVolToWorld *=
362 daughter->GetObjectTranslation());
363 for ( std::size_t i=0; i<thePhysVolStore->size(); ++i)
364 {
365 if ((*thePhysVolStore)[i]->GetLogicalVolume() == mother)
366 {
367 daughter = (*thePhysVolStore)[i];
368 mother =daughter->GetMotherLogical();
369 break;
370 }
371 }
372 }
373 center = theTransformationFromPhysVolToWorld.NetTranslation();
374 G4cout << "Center of the spherical surface is at the position: "
375 << center/cm << " cm" << G4endl;
376 }
377 else
378 {
379 return false;
380 }
381 return AddaSphericalSurface(SurfaceName, radius, center, area);
382}
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
G4bool AddaSphericalSurface(const G4String &SurfaceName, G4double radius, G4ThreeVector pos, G4double &area)
G4ThreeVector NetTranslation() const
const G4RotationMatrix * GetFrameRotation() const
G4ThreeVector GetObjectTranslation() const

Referenced by G4AdjointSimManager::DefineSphericalAdjointSourceWithCentreAtTheCentreOfAVolume(), and G4AdjointSimManager::DefineSphericalExtSourceWithCentreAtTheCentreOfAVolume().

◆ ClearListOfSelectedSurface()

void G4AdjointCrossSurfChecker::ClearListOfSelectedSurface ( )

Definition at line 459 of file G4AdjointCrossSurfChecker.cc.

460{
461 ListOfSurfaceName.clear();
462 ListOfSurfaceType.clear();
463 ListOfSphereRadius.clear();
464 ListOfSphereCenter.clear();
465 ListOfVol1Name.clear();
466 ListOfVol2Name.clear();
467}

◆ CrossingAGivenRegisteredSurface() [1/2]

G4bool G4AdjointCrossSurfChecker::CrossingAGivenRegisteredSurface ( const G4Step aStep,
const G4String surface_name,
G4ThreeVector cross_pos,
G4double cos_to_surface,
G4bool GoingIn 
)

Definition at line 194 of file G4AdjointCrossSurfChecker.cc.

199{
200 G4int ind = FindRegisteredSurface(surface_name);
201 G4bool did_cross = false;
202 if (ind >=0)
203 {
204 did_cross = CrossingAGivenRegisteredSurface(aStep, ind, crossing_pos,
205 cos_to_surface, GoingIn);
206 }
207 return did_cross;
208}
bool G4bool
Definition: G4Types.hh:86
G4bool CrossingAGivenRegisteredSurface(const G4Step *aStep, const G4String &surface_name, G4ThreeVector &cross_pos, G4double &cos_to_surface, G4bool &GoingIn)

Referenced by CrossingAGivenRegisteredSurface(), and CrossingOneOfTheRegisteredSurface().

◆ CrossingAGivenRegisteredSurface() [2/2]

G4bool G4AdjointCrossSurfChecker::CrossingAGivenRegisteredSurface ( const G4Step aStep,
G4int  ind,
G4ThreeVector cross_pos,
G4double cos_to_surface,
G4bool GoingIn 
)

Definition at line 212 of file G4AdjointCrossSurfChecker.cc.

216{
217 G4String surf_type = ListOfSurfaceType[ind];
218 G4double radius = ListOfSphereRadius[ind];
219 G4ThreeVector center = ListOfSphereCenter[ind];
220 G4String vol1 = ListOfVol1Name[ind];
221 G4String vol2 = ListOfVol2Name[ind];
222
223 G4bool did_cross = false;
224 if (surf_type == "Sphere")
225 {
226 did_cross = CrossingASphere(aStep, radius, center,crossing_pos,
227 cos_to_surface, GoingIn);
228 }
229 else if (surf_type == "ExternalSurfaceOfAVolume")
230 {
231 did_cross = GoingInOrOutOfaVolumeByExtSurface(aStep, vol1, vol2,
232 cos_to_surface, GoingIn);
233 crossing_pos= aStep->GetPostStepPoint()->GetPosition();
234 }
235 else if (surf_type == "BoundaryBetweenTwoVolumes")
236 {
237 did_cross = CrossingAnInterfaceBetweenTwoVolumes(aStep, vol1, vol2,
238 crossing_pos,
239 cos_to_surface, GoingIn);
240 }
241 return did_cross;
242}
double G4double
Definition: G4Types.hh:83
G4bool CrossingAnInterfaceBetweenTwoVolumes(const G4Step *aStep, const G4String &vol1_name, const G4String &vol2_name, G4ThreeVector &cross_pos, G4double &cos_to_surface, G4bool &GoingIn)
G4bool GoingInOrOutOfaVolumeByExtSurface(const G4Step *aStep, const G4String &volume_name, const G4String &mother_lvol_name, G4double &cos_to_surface, G4bool &GoingIn)
G4bool CrossingASphere(const G4Step *aStep, G4double sphere_radius, G4ThreeVector sphere_center, G4ThreeVector &cross_pos, G4double &cos_to_surface, G4bool &GoingIn)
const G4ThreeVector & GetPosition() const
G4StepPoint * GetPostStepPoint() const

◆ CrossingAnInterfaceBetweenTwoVolumes()

G4bool G4AdjointCrossSurfChecker::CrossingAnInterfaceBetweenTwoVolumes ( const G4Step aStep,
const G4String vol1_name,
const G4String vol2_name,
G4ThreeVector cross_pos,
G4double cos_to_surface,
G4bool GoingIn 
)

Definition at line 266 of file G4AdjointCrossSurfChecker.cc.

272{
273 G4bool step_at_boundary =
275 G4bool did_cross = false;
276 if (step_at_boundary)
277 {
278 const G4VTouchable* postStepTouchable =
279 aStep->GetPostStepPoint()->GetTouchable();
280 const G4VTouchable* preStepTouchable =
281 aStep->GetPreStepPoint()->GetTouchable();
282 if (preStepTouchable && postStepTouchable)
283 {
284 G4String post_vol_name = postStepTouchable->GetVolume()->GetName();
285 if (post_vol_name == "")
286 {
287 post_vol_name = postStepTouchable->GetVolume()->GetLogicalVolume()
288 ->GetName();
289 }
290 G4String pre_vol_name = preStepTouchable->GetVolume()->GetName();
291 if (pre_vol_name == "")
292 {
293 pre_vol_name = preStepTouchable->GetVolume()->GetLogicalVolume()
294 ->GetName();
295 }
296 if (pre_vol_name == vol1_name && post_vol_name == vol2_name)
297 {
298 GoingIn=true;
299 did_cross=true;
300 }
301 else if (pre_vol_name == vol2_name && post_vol_name == vol1_name)
302 {
303 GoingIn=false;
304 did_cross=true;
305 }
306 }
307 }
308 return did_cross; // still need to compute the cosine of the direction
309}
@ fGeomBoundary
Definition: G4StepStatus.hh:43
G4StepStatus GetStepStatus() const
const G4VTouchable * GetTouchable() const
G4StepPoint * GetPreStepPoint() const
const G4String & GetName() const
virtual G4VPhysicalVolume * GetVolume(G4int depth=0) const
Definition: G4VTouchable.cc:34

Referenced by CrossingAGivenRegisteredSurface().

◆ CrossingASphere()

G4bool G4AdjointCrossSurfChecker::CrossingASphere ( const G4Step aStep,
G4double  sphere_radius,
G4ThreeVector  sphere_center,
G4ThreeVector cross_pos,
G4double cos_to_surface,
G4bool GoingIn 
)

Definition at line 70 of file G4AdjointCrossSurfChecker.cc.

74{
75 G4ThreeVector pos1 = aStep->GetPreStepPoint()->GetPosition() - sphere_center;
76 G4ThreeVector pos2 = aStep->GetPostStepPoint()->GetPosition() - sphere_center;
77 G4double r1 = pos1.mag();
78 G4double r2 = pos2.mag();
79 G4bool did_cross = false;
80
81 if (r1<=sphere_radius && r2>sphere_radius)
82 {
83 did_cross = true;
84 GoingIn = false;
85 }
86 else if (r2<=sphere_radius && r1>sphere_radius)
87 {
88 did_cross = true;
89 GoingIn = true;
90 }
91
92 if (did_cross)
93 {
94 G4ThreeVector dr = pos2-pos1;
95 G4double r12 = r1*r1;
96 G4double rdr = dr.mag();
97 G4double a,b,c,d;
98 a = rdr*rdr;
99 b = 2.*pos1.dot(dr);
100 c = r12-sphere_radius*sphere_radius;
101 d = std::sqrt(b*b-4.*a*c);
102 G4double l = (-b+d)/2./a;
103 if (l > 1.) l=(-b-d)/2./a;
104 crossing_pos = pos1+l*dr;
105 cos_th = std::abs(dr.cosTheta(crossing_pos));
106 }
107 return did_cross;
108}
double mag() const

Referenced by CrossingAGivenRegisteredSurface().

◆ CrossingOneOfTheRegisteredSurface()

G4bool G4AdjointCrossSurfChecker::CrossingOneOfTheRegisteredSurface ( const G4Step aStep,
G4String surface_name,
G4ThreeVector cross_pos,
G4double cos_to_surface,
G4bool GoingIn 
)

Definition at line 246 of file G4AdjointCrossSurfChecker.cc.

251{
252 for (std::size_t i=0; i<ListOfSurfaceName.size(); ++i)
253 {
254 if (CrossingAGivenRegisteredSurface(aStep, G4int(i), crossing_pos,
255 cos_to_surface, GoingIn))
256 {
257 surface_name = ListOfSurfaceName[i];
258 return true;
259 }
260 }
261 return false;
262}

◆ GetInstance()

◆ GoingInOrOutOfaVolume()

G4bool G4AdjointCrossSurfChecker::GoingInOrOutOfaVolume ( const G4Step aStep,
const G4String volume_name,
G4double cos_to_surface,
G4bool GoingIn 
)

Definition at line 112 of file G4AdjointCrossSurfChecker.cc.

115{
116 G4bool step_at_boundary =
118 G4bool did_cross = false;
119 if (step_at_boundary)
120 {
121 const G4VTouchable* postStepTouchable =
122 aStep->GetPostStepPoint()->GetTouchable();
123 const G4VTouchable* preStepTouchable =
124 aStep->GetPreStepPoint()->GetTouchable();
125 if (preStepTouchable && postStepTouchable
126 && postStepTouchable->GetVolume() && preStepTouchable->GetVolume())
127 {
128 G4String post_vol_name = postStepTouchable->GetVolume()->GetName();
129 G4String pre_vol_name = preStepTouchable->GetVolume()->GetName();
130
131 if (post_vol_name == volume_name )
132 {
133 GoingIn = true;
134 did_cross = true;
135 }
136 else if (pre_vol_name == volume_name)
137 {
138 GoingIn = false;
139 did_cross = true;
140 }
141 }
142 }
143 return did_cross; // still need to compute the cosine of the direction
144}

◆ GoingInOrOutOfaVolumeByExtSurface()

G4bool G4AdjointCrossSurfChecker::GoingInOrOutOfaVolumeByExtSurface ( const G4Step aStep,
const G4String volume_name,
const G4String mother_lvol_name,
G4double cos_to_surface,
G4bool GoingIn 
)

Definition at line 148 of file G4AdjointCrossSurfChecker.cc.

154{
155 G4bool step_at_boundary =
157 G4bool did_cross = false;
158 if (step_at_boundary)
159 {
160 const G4VTouchable* postStepTouchable =
161 aStep->GetPostStepPoint()->GetTouchable();
162 const G4VTouchable* preStepTouchable =
163 aStep->GetPreStepPoint()->GetTouchable();
164 const G4VPhysicalVolume* postVol = (postStepTouchable != nullptr)
165 ? postStepTouchable->GetVolume() : nullptr;
166 const G4VPhysicalVolume* preVol = (preStepTouchable != nullptr)
167 ? preStepTouchable->GetVolume() : nullptr;
168 if (preStepTouchable != nullptr && postStepTouchable != nullptr
169 && postVol != nullptr && preVol != nullptr)
170 {
171 G4String post_vol_name = postVol->GetName();
172 G4String post_log_vol_name = postVol->GetLogicalVolume()->GetName();
173 G4String pre_vol_name = preVol->GetName();
174 G4String pre_log_vol_name = preVol->GetLogicalVolume()->GetName();
175 if (post_vol_name == volume_name
176 && pre_log_vol_name == mother_logical_vol_name)
177 {
178 GoingIn = true;
179 did_cross = true;
180 }
181 else if (pre_vol_name == volume_name
182 && post_log_vol_name == mother_logical_vol_name )
183 {
184 GoingIn = false;
185 did_cross = true;
186 }
187 }
188 }
189 return did_cross; // still need to compute the cosine of the direction
190}

Referenced by CrossingAGivenRegisteredSurface().


The documentation for this class was generated from the following files: