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

G4GeomTestVolume allows to check for inconsistencies in the geometric boundaries of a physical volume and the boundaries of all its immediate daughters. More...

#include <G4GeomTestVolume.hh>

Public Member Functions

 G4GeomTestVolume (G4VPhysicalVolume *theTarget, G4double theTolerance=0.0, G4int numberOfPoints=10000, G4bool theVerbosity=true)
 ~G4GeomTestVolume ()
G4double GetTolerance () const
void SetTolerance (G4double tolerance)
G4int GetResolution () const
void SetResolution (G4int points)
G4bool GetVerbosity () const
void SetVerbosity (G4bool verbosity)
G4int GetErrorsThreshold () const
void SetErrorsThreshold (G4int max)
void TestOverlapInTree () const
void TestRecursiveOverlap (G4int sLevel=0, G4int depth=-1)

Detailed Description

G4GeomTestVolume allows to check for inconsistencies in the geometric boundaries of a physical volume and the boundaries of all its immediate daughters.

Definition at line 49 of file G4GeomTestVolume.hh.

Constructor & Destructor Documentation

◆ G4GeomTestVolume()

G4GeomTestVolume::G4GeomTestVolume ( G4VPhysicalVolume * theTarget,
G4double theTolerance = 0.0,
G4int numberOfPoints = 10000,
G4bool theVerbosity = true )

Constructor and Destructor.

Definition at line 43 of file G4GeomTestVolume.cc.

47 : target(theTarget), tolerance(theTolerance),
48 resolution(numberOfPoints), verbosity(theVerbosity)
49{;}

Referenced by TestRecursiveOverlap().

◆ ~G4GeomTestVolume()

G4GeomTestVolume::~G4GeomTestVolume ( )

Definition at line 54 of file G4GeomTestVolume.cc.

54{;}

Member Function Documentation

◆ GetErrorsThreshold()

G4int G4GeomTestVolume::GetErrorsThreshold ( ) const

Get/Set maximum number of errors to report (default set to 1).

Definition at line 107 of file G4GeomTestVolume.cc.

108{
109 return maxErr;
110}

◆ GetResolution()

G4int G4GeomTestVolume::GetResolution ( ) const

Gets/Sets number of points to check (default set to 10000).

Definition at line 75 of file G4GeomTestVolume.cc.

76{
77 return resolution;
78}

◆ GetTolerance()

G4double G4GeomTestVolume::GetTolerance ( ) const

Gets/Sets error tolerance (default set to 0*mm).

Definition at line 59 of file G4GeomTestVolume.cc.

60{
61 return tolerance;
62}

◆ GetVerbosity()

G4bool G4GeomTestVolume::GetVerbosity ( ) const

Gets/Sets verbosity mode (default set to true).

Definition at line 91 of file G4GeomTestVolume.cc.

92{
93 return verbosity;
94}

◆ SetErrorsThreshold()

void G4GeomTestVolume::SetErrorsThreshold ( G4int max)

Definition at line 115 of file G4GeomTestVolume.cc.

116{
117 maxErr = max;
118}
T max(const T t1, const T t2)
brief Return the largest of the two arguments

Referenced by TestRecursiveOverlap().

◆ SetResolution()

void G4GeomTestVolume::SetResolution ( G4int points)

Definition at line 83 of file G4GeomTestVolume.cc.

84{
85 resolution = np;
86}

◆ SetTolerance()

void G4GeomTestVolume::SetTolerance ( G4double tolerance)

Definition at line 67 of file G4GeomTestVolume.cc.

68{
69 tolerance = tol;
70}

◆ SetVerbosity()

void G4GeomTestVolume::SetVerbosity ( G4bool verbosity)

Definition at line 99 of file G4GeomTestVolume.cc.

100{
101 verbosity = verb;
102}

◆ TestOverlapInTree()

void G4GeomTestVolume::TestOverlapInTree ( ) const

Checks for overlaps in the volume tree without duplication in identical logical volumes.

Definition at line 123 of file G4GeomTestVolume.cc.

124{
125 std::queue<G4VPhysicalVolume*> volumes;
126 std::set<G4LogicalVolume*> checked;
127
128 volumes.push(target);
129 while (!volumes.empty())
130 {
131 G4VPhysicalVolume* current = volumes.front();
132 volumes.pop();
133
134 // check overlaps for daughters
135 G4LogicalVolume* logical = current->GetLogicalVolume();
136 std::size_t ndaughters = logical->GetNoDaughters();
137 for (std::size_t i=0; i<ndaughters; ++i)
138 {
139 G4VPhysicalVolume* daughter = logical->GetDaughter(i);
140 daughter->CheckOverlaps(resolution, tolerance, verbosity, maxErr);
141 }
142
143 // append the queue of volumes
144 G4LogicalVolume* previousLogical = nullptr;
145 for (std::size_t i=0; i<ndaughters; ++i)
146 {
147 G4VPhysicalVolume* daughter = logical->GetDaughter(i);
148 G4LogicalVolume* daughterLogical = daughter->GetLogicalVolume();
149 if (daughterLogical->GetNoDaughters() == 0) { continue; }
150 G4bool found = (daughterLogical == previousLogical);
151 if (!found) { found = (checked.find(daughterLogical) != checked.cend()); }
152 if (!found)
153 {
154 checked.emplace(daughterLogical);
155 previousLogical = daughterLogical;
156 volumes.push(daughter);
157 }
158 else
159 {
160 if (verbosity)
161 {
162 G4cout << "Checking overlaps in tree of volume " << daughter->GetName()
163 << " (" << daughterLogical->GetSolid()->GetEntityType() << ")"
164 << " is omitted, to avoid duplication" << G4endl;
165 }
166 }
167 }
168 }
169}
bool G4bool
Definition G4Types.hh:86
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
G4VSolid * GetSolid() const
std::size_t GetNoDaughters() const
G4VPhysicalVolume * GetDaughter(const std::size_t i) const
virtual G4bool CheckOverlaps(G4int res=1000, G4double tol=0., G4bool verbose=true, G4int errMax=1)
G4LogicalVolume * GetLogicalVolume() const
const G4String & GetName() const
virtual G4GeometryType GetEntityType() const =0

◆ TestRecursiveOverlap()

void G4GeomTestVolume::TestRecursiveOverlap ( G4int sLevel = 0,
G4int depth = -1 )

Activates overlaps check, propagating recursively to the daughters, with possibility of specifying the initial level in the volume tree and the depth (default is the whole tree).

Note
Depending on the complexity of the geometry, this may require long computational time.

Definition at line 174 of file G4GeomTestVolume.cc.

175{
176 // If reached requested level of depth (i.e. set to 0), exit.
177 // If not depth specified (i.e. set to -1), visit the whole tree.
178 // If requested initial level of depth is not zero, visit from beginning
179 //
180 if (depth == 0) { return; }
181 if (depth != -1) { depth--; }
182 if (slevel != 0) { slevel--; }
183
184 //
185 // As long as we reached the requested
186 // initial level of depth, test ourselves
187 //
188 if ( slevel==0 )
189 {
190 target->CheckOverlaps(resolution, tolerance, verbosity, maxErr);
191 }
192
193 //
194 // Loop over unique daughters
195 //
196 std::set<const G4LogicalVolume *> tested;
197
198 const G4LogicalVolume *logical = target->GetLogicalVolume();
199 auto nDaughter = (G4int)logical->GetNoDaughters();
200 for( auto iDaughter=0; iDaughter<nDaughter; ++iDaughter )
201 {
202 G4VPhysicalVolume *daughter = logical->GetDaughter(iDaughter);
203
204 // Tested already?
205 //
206 // const G4LogicalVolume *daughterLogical =
207 // daughter->GetLogicalVolume();
208 // std::pair<std::set<const G4LogicalVolume *>::iterator, G4bool>
209 // there = tested.insert(daughterLogical);
210 // if (!there.second) continue;
211
212 //
213 // Recurse
214 //
215 G4GeomTestVolume vTest( daughter, tolerance, resolution, verbosity );
216 vTest.SetErrorsThreshold(maxErr);
217 vTest.TestRecursiveOverlap( slevel,depth );
218 }
219}
int G4int
Definition G4Types.hh:85
G4GeomTestVolume(G4VPhysicalVolume *theTarget, G4double theTolerance=0.0, G4int numberOfPoints=10000, G4bool theVerbosity=true)

Referenced by TestRecursiveOverlap().


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