source: trunk/documents/UserDoc/DocBookUsersGuides/ForApplicationDeveloper/xml/Detector/geomOverlap.xml

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

CVS update

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