source: trunk/documents/UserDoc/UsersGuides/ForApplicationDeveloper/html/Detector/geomOverlap.html @ 1208

Last change on this file since 1208 was 1208, checked in by garnier, 15 years ago

CVS update

File size: 16.9 KB
Line 
1<html>
2<head>
3<title>ADG: Geometry</title>
4</head>
5
6<!-- Changed by: Gabriele Cosmo, 18-Apr-2005 -->
7<!-- $Id: geomOverlap.html,v 1.4 2006/06/09 13:58:38 gcosmo Exp $ -->
8<!-- $Name:  $ -->
9<body>
10<table WIDTH="100%"><TR>
11<td>
12<a href="../../../../Overview/html/index.html">
13<IMG SRC="../../../../resources/html/IconsGIF/Overview.gif" ALT="Overview"></a>
14<a href="geometry.html">
15<IMG SRC="../../../../resources/html/IconsGIF/Contents.gif" ALT="Contents"></a>
16<a href="geomG3toG4.html">
17<IMG SRC="../../../../resources/html/IconsGIF/Previous.gif" ALT="Previous"></a>
18<a href="geomDynamic.html">
19<IMG SRC="../../../../resources/html/IconsGIF/Next.gif" ALT="Next"></a>
20</td>
21<td ALIGN="Right">
22<font SIZE="-1" COLOR="#238E23">
23<b>Geant4 User's Guide</b>
24<br>
25<b>For Application Developers</b>
26<br>
27<b>Geometry</b>
28</font>
29</td>
30</tr></table>
31<br><br>
32
33<a name="4.1.11">
34<h2>4.1.11 Detecting Overlapping Volumes</h2></a>
35
36<b>The problem of overlapping volumes</b>
37<p>
38Volumes are often positioned within other volumes with the intent that
39one is fully contained within the other.  If, however, a volume extends
40beyond the boundaries of its mother volume, it is defined as overlapping.
41It may also be intended that volumes are positioned within the same mother
42volume such that they do not intersect one another.  When such volumes do
43intersect, they are also defined as overlapping.
44</p>
45 
46<p>
47The problem of detecting overlaps between volumes is bounded by the
48complexity of the solid model description. Hence it requires the same
49mathematical sophistication which is needed to describe the most complex
50solid topology, in general. However, a tunable accuracy can be obtained
51by approximating the solids via first and/or second order surfaces and
52checking their intersections.
53</p>
54 
55<P> </P>
56 
57<b>Detecting overlaps: built-in kernel commands</b>
58 
59<p>
60In general, the most powerful clash detection algorithms are provided by
61CAD systems, treating the intersection between the solids in their topological
62form.
63</p>
64 
65<p>
66Geant4 provides some built-in run-time commands to activate
67verification tests for the user-defined geometry:
68 <PRE>
69     geometry/test/grid_test [recursion_flag]
70     --&gt; to start verification of geometry for overlapping regions
71         based on standard lines grid setup. If the "recursion_flag" is
72         set to 'false' (the default), the check is limited to the first
73         depth level of the geometry tree; otherwise it visits recursively
74         the whole geometry tree. In the latter case, it may take a long
75         time, depending on the complexity of the geometry.
76     geometry/test/cylinder_test [recursion_flag]
77     --&gt; shoots lines according to a cylindrical pattern. If the
78         "recursion_flag" is set to 'false' (the default), the check is
79         limited to the first depth level of the geometry tree; otherwise
80         it visits recursively the whole geometry tree. In the latter case,
81         it may take a long time, depending on the complexity of the geometry.
82     geometry/test/line_test [recursion_flag]
83     --&gt; shoots a line according to a specified direction and position
84         defined by the user. If the "recursion_flag" is set to 'false'
85         (the default), the check is limited to the first depth level of the
86         geometry tree; otherwise it visits recursively the whole geometry
87         tree.
88     geometry/test/position
89     --&gt; to specify position for the line_test.
90     geometry/test/direction
91     --&gt; to specify direction for the line_test.
92     geometry/test/grid_cells
93     --&gt; to define the resolution of the lines in the grid test as number
94         of cells, specifying them for each dimension, X, Y and Z.
95         The new settings will be applied to the grid_test command.
96     geometry/test/cylinder_geometry
97     --&gt; to define the details of the cylinder geometry, by specifying:
98             nPhi - number of lines per Phi
99             nZ   - number of Z points
100             nRho - number of Rho points
101         The new settings will be applied to the cylinder_test command.
102     geometry/test/cylinder_scaleZ
103     --&gt; to define the resolution of the cylinder geometry, by specifying
104         the fraction scale for points along Z.
105         The new settings will be applied to the cylinder_test command.
106     geometry/test/cylinder_scaleRho
107     --&gt; to define the resolution of the cylinder geometry, by specifying
108         the fraction scale for points along Rho.
109         The new settings will be applied to the cylinder_test command.
110     geometry/test/recursion_start
111     --&gt; to set the initial level in the geometry tree for starting the
112         recursion (default value being zero, i.e. the world volume).
113         The new settings will then be applied to any recursive test.
114     geometry/test/recursion_depth
115     --&gt; to set the depth in the geometry tree for recursion, so that
116         recursion will stop after having reached the specified depth (the
117         default being the full depth of the geometry tree).
118         The new settings will then be applied to any recursive test.
119 </PRE>
120</P>
121 
122 To detect overlapping volumes, the built-in test uses the intersection
123 of solids with linear trajectories. For example, consider figure 4.1.4:</P>
124 
125 <center>
126  <table BORDER=1 CELLPADDING=8>
127  <tr><td>
128  <IMG SRC="geometry.src/geomtest.gif" ALT="|Geometry Test|" HEIGHT=162 WIDTH=402>
129  </td></tr>
130  <tr>
131  <td ALIGN=center>
132  Figure 4.1.4<BR>
133  Different cases of placed volumes overlapping each other.
134  </td></tr>
135  </table>
136 </center>
137 
138<p>
139Here we have a line intersecting some physical volume (large, black rectangle).
140Belonging to the volume are four daughters: A, B, C, and D.
141Indicated by the dots are the intersections of the line with the
142mother volume and the four daughters.
143</p>
144 
145<p>
146This example has two geometry errors. First, volume A sticks outside its
147mother volume (this practice, sometimes used in GEANT3.21, is not allowed
148in Geant4). This can be noticed because the intersection point (leftmost
149magenta dot) lies outside the mother volume, as defined by the space
150between the two black dots.
151</p>
152 
153<p>
154The second error is that daughter volumes A and B overlap. This is noticeable
155because one of the intersections with A (rightmost magenta dot) is
156inside the volume B, as defined as the space between the red dots.
157Alternatively, one of the intersections with B (leftmost red dot) is
158inside the volume A, as defined as the space between the magenta dots.
159</p>
160           
161<p>
162Each of these two types of errors is represented by a line segment,
163 which has a start point, an end point, and, a length.
164 Depending on the type of error, the points are most clearly recognized in
165 either the coordinate system of the volume, the global coordinate
166 system, or the coordinate system of the daughters involved.</P>
167 
168<P>
169Also notice that certain errors will be missed unless a line
170 is supplied in precisely the correct path. Unfortunately, it is hard to
171 predict which lines are best at uncovering potential geometry errors.
172 Instead, the geometry testing code uses a grid of lines, in the hope of
173 at least uncovering gross geometry errors.
174 More subtle errors could easily be missed.</P>
175 
176<P>
177Another difficult issue is roundoff error. For example, daughters C and D
178 lie precisely next to each other. It is possible, due to roundoff,
179 that one of the intersections points will lie just slightly inside the
180 space of the other. In addition, a volume that lies tightly up against
181 the outside of its mother may have an intersection point that just slightly
182 lies outside the mother.</P>
183 
184<P>
185To avoid spurious errors caused by roundoff, a rather generous tolerance
186 of 0.1 micron is used by default. This tolerance can be adjusted as
187 needed by the application through the run-time command:
188<PRE>
189   geometry/test/tolerance &lt;new-value&gt;
190</PRE>
191</P>
192 
193<P>
194Finally, notice that no mention is made of the possible daughter volumes
195 of A, B, C, and D. To keep the code simple, only the immediate daughters
196 of a volume are checked at one pass. To test these "granddaughter" volumes,
197 the daughters A, B, C, and D each have to be tested themselves in turn.
198 To make this more automatic, an optional recursive algorithm is included;
199 it first tests a target volume, then it loops over all
200 daughter volumes and calls itself.</P>
201 
202<P>Pay attention! For a complex geometry, checking the entire volume
203 hierarchy can be extremely time consuming.</P>
204 
205<P> </P>
206 
207<b>Detecting overlaps at construction</b>
208 
209<P>
210Since release 8.0, the Geant4 geometry modeler provides the ability to
211detect overlaps of placed volumes (normal placements or parameterised)
212at the time of construction. This check is optional and can be activated
213when instantiating a placement (see <tt>G4PVPlacement</tt> constructor in
214<a href="geomPhysical.html#4.1.4.1">Section 4.1.4.1</a>) or a parameterised
215volume (see <tt>G4PVParameterised</tt> constructor in
216<a href="geomPhysical.html#4.1.4.2">Section 4.1.4.2</a>).<br>
217The positioning of that specific volume will be checked against all volumes
218in the same hierarchy level and its mother volume.
219Depending on the complexity of the geometry being checked, the check may
220require considerable CPU time; it is therefore suggested to use it only
221for debugging the geometry setup and to apply it only to the part of the
222geometry setup which requires debugging.</P>
223<P>
224The classes <tt>G4PVPlacement</tt> and <tt>G4PVParameterised</tt> also
225provide a method:
226<pre>
227   G4bool CheckOverlaps(G4int res=1000)
228</pre>
229which will force the check for the specified volume. The check verifies
230if each placed or parameterised instance is overlapping with other instances
231or with its mother volume. A default resolution for the number of points to
232be generated and verified is provided. The method returns <tt>true</tt> if
233an overlap occurs.</P>
234
235<P> </P>
236
237<B>Using the visualization driver: DAVID</B>
238 
239<p>
240The Geant4 visualization offers a powerful debugging tool for detecting
241potential intersections of physical volumes. The Geant4 DAVID visualization
242tool <a href="#DAVID">[2]</a> can infact automatically detect the overlaps
243between the volumes defined in Geant4 and converted to a graphical
244representation for visualization purposes. The accuracy of the graphical
245representation can be tuned onto the exact geometrical description. In the
246debugging, physical-volume surfaces are automatically decomposed into 3D
247polygons, and intersections of the generated polygons are investigated. If a
248polygon intersects with another one, physical volumes which these polygons
249belong to are visualized in color (red is the default). The figure 4.1.5 below
250is a sample visualization of a detector geometry with intersecting physical
251volumes highlighted:
252</p>
253 
254 <center>
255  <table BORDER=1 CELLPADDING=8>
256  <tr><td>
257  <IMG SRC="geometry.src/DAVID_SAMPLE.gif" ALT="|DAVID Geometry Test|" HEIGHT=567 WIDTH=322></P>
258  </td></tr>
259  <tr>
260  <td ALIGN=center>
261  Figure 4.1.5<BR>
262  A geometry with overlapping volumes highlighted by DAVID.
263  </td></tr>
264  </table>
265 </center>
266 
267<p>
268At present physical volumes made of the following solids are able to
269be debugged: <tt>G4Box</tt>, <tt>G4Cons</tt>, <tt>G4Para</tt>,
270<tt>G4Sphere</tt>, <tt>G4Trd</tt>, <tt>G4Trap</tt>, <tt>G4Tubs</tt>.
271(Existence of other solids is harmless.)
272</p>
273 
274<p>
275Visual debugging of physical-volume surfaces is performed with the DAWNFILE
276driver defined in the visualization category and with the two application
277packages, i.e. Fukui Renderer &quot;DAWN&quot; and a visual intersection
278debugger &quot;DAVID&quot;. DAWN <a href="#DAWN">[1]</a> and
279DAVID <a href="#DAVID">[2]</a> can be downloaded from the Web.
280</p>
281 
282<p>
283How to compile Geant4 with the DAWNFILE driver incorporated is described
284in <A HREF="../Visualization/visdrivers.html"> Section 8.3</A>.
285</p>
286 
287<p>
288 If the DAWNFILE driver, DAWN and DAVID are all working well in your
289 host machine, the visual intersection debugging of physical-volume surfaces
290 can be performed as follows:</P>
291 
292<P>
293 Run your Geant4 executable, invoke the DAWNFILE driver, and execute
294 visualization commands to visualize your detector geometry:
295 
296<PRE>
297     Idle> /vis/open DAWNFILE
298     .....(setting camera etc)...
299     Idle> /vis/drawVolume
300     Idle> /vis/viewer/update
301</PRE></P>
302 
303<P>
304 Then a file &quot;g4.prim&quot;, which describes the detector geometry,
305 is generated in the current directory and DAVID is invoked to read it.
306 (The description of the format of the file g4.prim can be found from the
307 <a href="http://geant4.kek.jp/GEANT4/vis/DAWN/G4PRIM_FORMAT_24/">DAWN web
308 site documentation</a>.)</P>
309 
310<P>
311 If DAVID detects intersection of physical-volume surfaces, it automatically
312 invokes DAWN to visualize the detector geometry with the intersected physical
313 volumes highlighted (See the above sample visualization).</P>
314 
315<P>
316 If no intersection is detected, visualization is skipped and the following
317 message is displayed on the console:
318 
319<PRE>
320     ------------------------------------------------------
321     !!! Number of intersected volumes : 0 !!!
322     !!! Congratulations ! \(^o^)/         !!!
323     ------------------------------------------------------
324</PRE></P>
325 
326<P>
327 If you always want to skip visualization, set an environmental variable
328 as follows beforehand:
329 
330<PRE>
331     %  setenv DAVID_NO_VIEW  1
332</PRE></P>
333                                           
334<P>
335 To control the precision associated to computation of intersections (default
336 precision is set to 9), it is possible to use the environmental variable for
337 the DAWNFILE graphics driver, as follows:
338 
339<PRE>
340     %  setenv G4DAWNFILE_PRECISION  10
341</PRE></P>
342 
343<P>
344 If necessary, re-visualize the detector geometry with intersected parts
345 highlighted. The data are saved in a file &quot;g4david.prim&quot; in the
346 current directory. This file can be re-visualized with DAWN as follows:
347 
348<PRE>
349     % dawn g4david.prim
350</PRE></P>
351 
352<P>
353It is also helpful to convert the generated file g4david.prim into a
354VRML-formatted file and perform interactive visualization of it with your
355WWW browser. The file conversion tool <tt>prim2wrml</tt> can be downloaded
356from the <A HREF="http://geant4.kek.jp/GEANT4/vis/DAWN/About_prim2vrml1.html">DAWN
357web site download pages</A>.</P>
358</OL>
359 
360<P>
361 For more details, see the <A HREF="http://geant4.kek.jp/GEANT4/vis/DAWN/About_DAVID.html">document
362 of DAVID</A> mentioned above.</P>
363 
364<P> </P>
365                                 
366<b>Using the geometry debugging tool OLAP</b>
367 
368<p>
369<b>OLAP</b> is a tool developed in the CMS experiment at CERN to help in
370identifying ovelapping volumes in a detector geometry. It is placed in the
371area for specific tools/examples, in
372<tt>geant4/examples/extended/geometry</tt>.  The technique consists in
373shooting <tt>geantinos</tt> particles in one direction and the opposite one,
374and verifying that the boundary crossings are the same.
375<br>
376The tool can be used for any Geant4 geometry, provided that the user
377geometry to be debugged is available as a subclass of
378<tt>G4VUserDetectorConstruction</tt> and is used to construct the
379<tt>OlapDetConstr</tt> class of the tool. A dummy class
380<tt>RandomDetector</tt> is provided for this purpose in the tool itself.<BR>
381Run-time commands are provided by the tool to navigate in the geometry tree.
382UNIX like navigation of the logical volume hierarchy is provided by the
383<tt>/olap/cd</tt> command. The root of the logical volume tree can be accessed
384by the character '/'.  Any node in the volume tree can be accessed by a '/'
385separated string of regular expressions. If '/' is at the beginning of the
386string, the tree hierarchy is transversed from the root, otherwise from the
387currently chosen logical volume. Further the command
388<tt>/olap/goto [regexp]</tt> can be used to jump to the first logical volume
389matching the expression <tt>[regexp]</tt>.
390Every successful navigation command (<tt>/olap/cd</tt>, <tt>olap/goto</tt>)
391results in the construction of a <tt>NewWorld</tt>, the mother volume being
392the argument of the command and the daughter volumes being the direct
393daughters of the mother volume.<BR>
394<tt>/olap/pwd</tt> always shows where in the full geometrical hierarchy the
395current <tt>NewWorld</tt> and mother volume are located.<BR>
396For more detailed information, view the <tt>README</tt> file provided with
397the tool.
398</p>
399<br>
400<hr>
401<p>
402<table>
403<tr><td valign=top><a name="DAWN">[1]</a>
404    <td><a href="http://geant4.kek.jp/GEANT4/vis/DAWN/About_DAWN.html">http://geant4.kek.jp/GEANT4/vis/DAWN/About_DAWN.html</a>
405<tr><td valign=top><a name="DAVID">[2]</a>
406    <td><a href="http://geant4.kek.jp/GEANT4/vis/DAWN/About_DAVID.html">http://geant4.kek.jp/GEANT4/vis/DAWN/About_DAVID.html</a>
407</table>
408</p>
409
410<hr><a href="../../../../Authors/html/subjectsToAuthors.html">
411<i>About the authors</a></i> </P>
412
413</body>
414</html>
Note: See TracBrowser for help on using the repository browser.