Geant4 10.7.0
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 394 of file G4AdjointCrossSurfChecker.cc.

397{
398 G4int ind = FindRegisteredSurface(SurfaceName);
399
400 G4VPhysicalVolume* thePhysicalVolume = nullptr;
402 for (std::size_t i=0; i<thePhysVolStore->size(); ++i)
403 {
404 if ((*thePhysVolStore)[i]->GetName() == volume_name)
405 {
406 thePhysicalVolume = (*thePhysVolStore)[i];
407 }
408 }
409 if (thePhysicalVolume == nullptr)
410 {
411 G4cout << "The physical volume with name " << volume_name
412 << " does not exist!!" << G4endl;
413 return false;
414 }
415 Area = thePhysicalVolume->GetLogicalVolume()->GetSolid()->GetSurfaceArea();
416 G4String mother_vol_name = "";
417 G4LogicalVolume* theMother = thePhysicalVolume->GetMotherLogical();
418
419 if (theMother != nullptr) mother_vol_name= theMother->GetName();
420 if (ind>=0)
421 {
422 ListOfSurfaceType[ind] = "ExternalSurfaceOfAVolume";
423 ListOfSphereRadius[ind] = 0.;
424 ListOfSphereCenter[ind] = G4ThreeVector(0.,0.,0.);
425 ListOfVol1Name[ind] = volume_name;
426 ListOfVol2Name[ind] = mother_vol_name;
427 AreaOfSurface[ind] = Area;
428 }
429 else
430 {
431 ListOfSurfaceName.push_back(SurfaceName);
432 ListOfSurfaceType.push_back("ExternalSurfaceOfAVolume");
433 ListOfSphereRadius.push_back(0.);
434 ListOfSphereCenter.push_back(G4ThreeVector(0.,0.,0.));
435 ListOfVol1Name.push_back(volume_name);
436 ListOfVol2Name.push_back(mother_vol_name);
437 AreaOfSurface.push_back(Area);
438 }
439 return true;
440}
CLHEP::Hep3Vector G4ThreeVector
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
G4VSolid * GetSolid() const
const G4String & GetName() const
static G4PhysicalVolumeStore * GetInstance()
G4LogicalVolume * GetMotherLogical() const
G4LogicalVolume * GetLogicalVolume() const
virtual G4double GetSurfaceArea()
Definition: G4VSolid.cc:238

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 444 of file G4AdjointCrossSurfChecker.cc.

448{
449 G4int ind = FindRegisteredSurface(SurfaceName);
450 Area = -1.; // the way to compute the surface is not known yet
451 if (ind>=0)
452 {
453 ListOfSurfaceType[ind] = "BoundaryBetweenTwoVolumes";
454 ListOfSphereRadius[ind] = 0.;
455 ListOfSphereCenter[ind] = G4ThreeVector(0.,0.,0.);
456 ListOfVol1Name[ind] = volume_name1;
457 ListOfVol2Name[ind] = volume_name2;
458 AreaOfSurface[ind] = Area;
459 }
460 else
461 {
462 ListOfSurfaceName.push_back(SurfaceName);
463 ListOfSurfaceType.push_back("BoundaryBetweenTwoVolumes");
464 ListOfSphereRadius.push_back(0.);
465 ListOfSphereCenter.push_back(G4ThreeVector(0.,0.,0.));
466 ListOfVol1Name.push_back(volume_name1);
467 ListOfVol2Name.push_back(volume_name2);
468 AreaOfSurface.push_back(Area);
469 }
470 return true;
471}

◆ 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 for (std::size_t i=0; i<thePhysVolStore->size(); ++i)
353 {
354 if ((*thePhysVolStore)[i]->GetName() == volume_name)
355 {
356 thePhysicalVolume = (*thePhysVolStore)[i];
357 }
358 }
359 if (thePhysicalVolume != nullptr)
360 {
361 G4VPhysicalVolume* daughter = thePhysicalVolume;
362 G4LogicalVolume* mother = thePhysicalVolume->GetMotherLogical();
363 G4AffineTransform theTransformationFromPhysVolToWorld = G4AffineTransform();
364 while (mother != nullptr)
365 {
366 theTransformationFromPhysVolToWorld *=
368 daughter->GetObjectTranslation());
369 for ( std::size_t i=0; i<thePhysVolStore->size(); ++i)
370 {
371 if ((*thePhysVolStore)[i]->GetLogicalVolume() == mother)
372 {
373 daughter = (*thePhysVolStore)[i];
374 mother =daughter->GetMotherLogical();
375 break;
376 }
377 }
378 }
379 center = theTransformationFromPhysVolToWorld.NetTranslation();
380 G4cout << "Center of the spherical surface is at the position: "
381 << center/cm << " cm" << G4endl;
382 }
383 else
384 {
385 G4cout << "The physical volume with name " << volume_name
386 << " does not exist!! " << G4endl;
387 return false;
388 }
389 return AddaSphericalSurface(SurfaceName, radius, center, area);
390}
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 475 of file G4AdjointCrossSurfChecker.cc.

476{
477 ListOfSurfaceName.clear();
478 ListOfSurfaceType.clear();
479 ListOfSphereRadius.clear();
480 ListOfSphereCenter.clear();
481 ListOfVol1Name.clear();
482 ListOfVol2Name.clear();
483}

◆ 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:41

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: