Geant4 11.2.2
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 51 of file G4AdjointCrossSurfChecker.hh.

Member Function Documentation

◆ AddanExtSurfaceOfAvolume()

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

Definition at line 309 of file G4AdjointCrossSurfChecker.cc.

311{
312 G4int ind = FindRegisteredSurface(SurfaceName);
313
314 G4VPhysicalVolume* thePhysicalVolume = nullptr;
316 thePhysicalVolume = thePhysVolStore->GetVolume(volume_name);
317 if (thePhysicalVolume == nullptr) {
318 return false;
319 }
320 Area = thePhysicalVolume->GetLogicalVolume()->GetSolid()->GetSurfaceArea();
321 G4String mother_vol_name = "";
322 G4LogicalVolume* theMother = thePhysicalVolume->GetMotherLogical();
323
324 if (theMother != nullptr) mother_vol_name = theMother->GetName();
325 if (ind >= 0) {
326 ListOfSurfaceType[ind] = "ExternalSurfaceOfAVolume";
327 ListOfSphereRadius[ind] = 0.;
328 ListOfSphereCenter[ind] = G4ThreeVector(0., 0., 0.);
329 ListOfVol1Name[ind] = volume_name;
330 ListOfVol2Name[ind] = mother_vol_name;
331 AreaOfSurface[ind] = Area;
332 }
333 else {
334 ListOfSurfaceName.push_back(SurfaceName);
335 ListOfSurfaceType.emplace_back("ExternalSurfaceOfAVolume");
336 ListOfSphereRadius.push_back(0.);
337 ListOfSphereCenter.emplace_back(0., 0., 0.);
338 ListOfVol1Name.push_back(volume_name);
339 ListOfVol2Name.push_back(mother_vol_name);
340 AreaOfSurface.push_back(Area);
341 }
342 return true;
343}
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 347 of file G4AdjointCrossSurfChecker.cc.

349{
350 G4int ind = FindRegisteredSurface(SurfaceName);
351 Area = -1.; // the way to compute the surface is not known yet
352 if (ind >= 0) {
353 ListOfSurfaceType[ind] = "BoundaryBetweenTwoVolumes";
354 ListOfSphereRadius[ind] = 0.;
355 ListOfSphereCenter[ind] = G4ThreeVector(0., 0., 0.);
356 ListOfVol1Name[ind] = volume_name1;
357 ListOfVol2Name[ind] = volume_name2;
358 AreaOfSurface[ind] = Area;
359 }
360 else {
361 ListOfSurfaceName.push_back(SurfaceName);
362 ListOfSurfaceType.emplace_back("BoundaryBetweenTwoVolumes");
363 ListOfSphereRadius.push_back(0.);
364 ListOfSphereCenter.emplace_back(0., 0., 0.);
365 ListOfVol1Name.push_back(volume_name1);
366 ListOfVol2Name.push_back(volume_name2);
367 AreaOfSurface.push_back(Area);
368 }
369 return true;
370}

◆ AddaSphericalSurface()

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

Definition at line 248 of file G4AdjointCrossSurfChecker.cc.

250{
251 G4int ind = FindRegisteredSurface(SurfaceName);
252 Area = 4. * pi * radius * radius;
253 if (ind >= 0) {
254 ListOfSurfaceType[ind] = "Sphere";
255 ListOfSphereRadius[ind] = radius;
256 ListOfSphereCenter[ind] = pos;
257 ListOfVol1Name[ind] = "";
258 ListOfVol2Name[ind] = "";
259 AreaOfSurface[ind] = Area;
260 }
261 else {
262 ListOfSurfaceName.push_back(SurfaceName);
263 ListOfSurfaceType.emplace_back("Sphere");
264 ListOfSphereRadius.push_back(radius);
265 ListOfSphereCenter.push_back(pos);
266 ListOfVol1Name.emplace_back("");
267 ListOfVol2Name.emplace_back("");
268 AreaOfSurface.push_back(Area);
269 }
270 return true;
271}

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

278{
279 G4VPhysicalVolume* thePhysicalVolume = nullptr;
281 thePhysicalVolume = thePhysVolStore->GetVolume(volume_name);
282 if (thePhysicalVolume != nullptr) {
283 G4VPhysicalVolume* daughter = thePhysicalVolume;
284 G4LogicalVolume* mother = thePhysicalVolume->GetMotherLogical();
285 G4AffineTransform theTransformationFromPhysVolToWorld = G4AffineTransform();
286 while (mother != nullptr) {
287 theTransformationFromPhysVolToWorld *=
289 for (std::size_t i = 0; i < thePhysVolStore->size(); ++i) {
290 if ((*thePhysVolStore)[i]->GetLogicalVolume() == mother) {
291 daughter = (*thePhysVolStore)[i];
292 mother = daughter->GetMotherLogical();
293 break;
294 }
295 }
296 }
297 center = theTransformationFromPhysVolToWorld.NetTranslation();
298 G4cout << "Center of the spherical surface is at the position: " << center / cm << " cm"
299 << G4endl;
300 }
301 else {
302 return false;
303 }
304 return AddaSphericalSurface(SurfaceName, radius, center, area);
305}
#define G4endl
Definition G4ios.hh:67
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 374 of file G4AdjointCrossSurfChecker.cc.

375{
376 ListOfSurfaceName.clear();
377 ListOfSurfaceType.clear();
378 ListOfSphereRadius.clear();
379 ListOfSphereCenter.clear();
380 ListOfVol1Name.clear();
381 ListOfVol2Name.clear();
382}

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

165{
166 G4int ind = FindRegisteredSurface(surface_name);
167 G4bool did_cross = false;
168 if (ind >= 0) {
169 did_cross = CrossingAGivenRegisteredSurface(aStep, ind, crossing_pos, cos_to_surface, GoingIn);
170 }
171 return did_cross;
172}
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 176 of file G4AdjointCrossSurfChecker.cc.

178{
179 G4String surf_type = ListOfSurfaceType[ind];
180 G4double radius = ListOfSphereRadius[ind];
181 G4ThreeVector center = ListOfSphereCenter[ind];
182 G4String vol1 = ListOfVol1Name[ind];
183 G4String vol2 = ListOfVol2Name[ind];
184
185 G4bool did_cross = false;
186 if (surf_type == "Sphere") {
187 did_cross = CrossingASphere(aStep, radius, center, crossing_pos, cos_to_surface, GoingIn);
188 }
189 else if (surf_type == "ExternalSurfaceOfAVolume") {
190 did_cross = GoingInOrOutOfaVolumeByExtSurface(aStep, vol1, vol2, cos_to_surface, GoingIn);
191 crossing_pos = aStep->GetPostStepPoint()->GetPosition();
192 }
193 else if (surf_type == "BoundaryBetweenTwoVolumes") {
195 aStep, vol1, vol2, crossing_pos, cos_to_surface, GoingIn);
196 }
197 return did_cross;
198}
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 216 of file G4AdjointCrossSurfChecker.cc.

218{
219 G4bool step_at_boundary = (aStep->GetPostStepPoint()->GetStepStatus() == fGeomBoundary);
220 G4bool did_cross = false;
221 if (step_at_boundary) {
222 const G4VTouchable* postStepTouchable = aStep->GetPostStepPoint()->GetTouchable();
223 const G4VTouchable* preStepTouchable = aStep->GetPreStepPoint()->GetTouchable();
224 if ((preStepTouchable != nullptr) && (postStepTouchable != nullptr)) {
225 G4String post_vol_name = postStepTouchable->GetVolume()->GetName();
226 if (post_vol_name.empty()) {
227 post_vol_name = postStepTouchable->GetVolume()->GetLogicalVolume()->GetName();
228 }
229 G4String pre_vol_name = preStepTouchable->GetVolume()->GetName();
230 if (pre_vol_name.empty()) {
231 pre_vol_name = preStepTouchable->GetVolume()->GetLogicalVolume()->GetName();
232 }
233 if (pre_vol_name == vol1_name && post_vol_name == vol2_name) {
234 GoingIn = true;
235 did_cross = true;
236 }
237 else if (pre_vol_name == vol2_name && post_vol_name == vol1_name) {
238 GoingIn = false;
239 did_cross = true;
240 }
241 }
242 }
243 return did_cross; // still need to compute the cosine of the direction
244}
@ fGeomBoundary
const G4VTouchable * GetTouchable() const
G4StepPoint * GetPreStepPoint() const
virtual G4VPhysicalVolume * GetVolume(G4int depth=0) const
const G4String & GetName() const

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

63{
64 G4ThreeVector pos1 = aStep->GetPreStepPoint()->GetPosition() - sphere_center;
65 G4ThreeVector pos2 = aStep->GetPostStepPoint()->GetPosition() - sphere_center;
66 G4double r1 = pos1.mag();
67 G4double r2 = pos2.mag();
68 G4bool did_cross = false;
69
70 if (r1 <= sphere_radius && r2 > sphere_radius) {
71 did_cross = true;
72 GoingIn = false;
73 }
74 else if (r2 <= sphere_radius && r1 > sphere_radius) {
75 did_cross = true;
76 GoingIn = true;
77 }
78
79 if (did_cross) {
80 G4ThreeVector dr = pos2 - pos1;
81 G4double r12 = r1 * r1;
82 G4double rdr = dr.mag();
83 G4double a, b, c, d;
84 a = rdr * rdr;
85 b = 2. * pos1.dot(dr);
86 c = r12 - sphere_radius * sphere_radius;
87 d = std::sqrt(b * b - 4. * a * c);
88 G4double l = (-b + d) / 2. / a;
89 if (l > 1.) l = (-b - d) / 2. / a;
90 crossing_pos = pos1 + l * dr;
91 cos_th = std::abs(dr.cosTheta(crossing_pos));
92 }
93 return did_cross;
94}
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 202 of file G4AdjointCrossSurfChecker.cc.

204{
205 for (std::size_t i = 0; i < ListOfSurfaceName.size(); ++i) {
206 if (CrossingAGivenRegisteredSurface(aStep, G4int(i), crossing_pos, cos_to_surface, GoingIn)) {
207 surface_name = ListOfSurfaceName[i];
208 return true;
209 }
210 }
211 return false;
212}

Referenced by G4AdjointSteppingAction::UserSteppingAction().

◆ GetInstance()

◆ GoingInOrOutOfaVolume()

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

Definition at line 98 of file G4AdjointCrossSurfChecker.cc.

100{
101 G4bool step_at_boundary = (aStep->GetPostStepPoint()->GetStepStatus() == fGeomBoundary);
102 G4bool did_cross = false;
103 if (step_at_boundary) {
104 const G4VTouchable* postStepTouchable = aStep->GetPostStepPoint()->GetTouchable();
105 const G4VTouchable* preStepTouchable = aStep->GetPreStepPoint()->GetTouchable();
106 if ((preStepTouchable != nullptr) && (postStepTouchable != nullptr) &&
107 (postStepTouchable->GetVolume() != nullptr) && (preStepTouchable->GetVolume() != nullptr))
108 {
109 G4String post_vol_name = postStepTouchable->GetVolume()->GetName();
110 G4String pre_vol_name = preStepTouchable->GetVolume()->GetName();
111
112 if (post_vol_name == volume_name) {
113 GoingIn = true;
114 did_cross = true;
115 }
116 else if (pre_vol_name == volume_name) {
117 GoingIn = false;
118 did_cross = true;
119 }
120 }
121 }
122 return did_cross; // still need to compute the cosine of the direction
123}

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

130{
131 G4bool step_at_boundary = (aStep->GetPostStepPoint()->GetStepStatus() == fGeomBoundary);
132 G4bool did_cross = false;
133 if (step_at_boundary) {
134 const G4VTouchable* postStepTouchable = aStep->GetPostStepPoint()->GetTouchable();
135 const G4VTouchable* preStepTouchable = aStep->GetPreStepPoint()->GetTouchable();
136 const G4VPhysicalVolume* postVol =
137 (postStepTouchable != nullptr) ? postStepTouchable->GetVolume() : nullptr;
138 const G4VPhysicalVolume* preVol =
139 (preStepTouchable != nullptr) ? preStepTouchable->GetVolume() : nullptr;
140 if (preStepTouchable != nullptr && postStepTouchable != nullptr && postVol != nullptr &&
141 preVol != nullptr)
142 {
143 G4String post_vol_name = postVol->GetName();
144 G4String post_log_vol_name = postVol->GetLogicalVolume()->GetName();
145 G4String pre_vol_name = preVol->GetName();
146 G4String pre_log_vol_name = preVol->GetLogicalVolume()->GetName();
147 if (post_vol_name == volume_name && pre_log_vol_name == mother_logical_vol_name) {
148 GoingIn = true;
149 did_cross = true;
150 }
151 else if (pre_vol_name == volume_name && post_log_vol_name == mother_logical_vol_name) {
152 GoingIn = false;
153 did_cross = true;
154 }
155 }
156 }
157 return did_cross; // still need to compute the cosine of the direction
158}

Referenced by CrossingAGivenRegisteredSurface().


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