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

Last change on this file since 905 was 904, checked in by garnier, 16 years ago

ajout de la doc

File size: 17.8 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.gif" 
127               format="GIF" contentwidth="10.0cm" align="center" />
128  </imageobject>
129  <imageobject role="html">
130    <imagedata fileref="./AllResources/Detector/geometry.src/geomtest.gif" 
131               format="GIF" 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. The check
258verifies if each placed or parameterised instance is overlapping
259with other instances or with its mother volume. A default
260resolution for the number of points to be generated and verified is
261provided. The method returns <literal>true</literal> if an overlap
262occurs. It is also possible to specify a "tolerance" by which overlaps
263not exceeding such quantity will not be reported; by default, all
264overlaps are reported.
265</para>
266
267<para>
268<emphasis role="bold">Using the visualization driver: DAVID</emphasis>
269</para>
270<para>
271The Geant4 visualization offers a powerful debugging tool for
272detecting potential intersections of physical volumes. The Geant4
273<ulink url="http://geant4.kek.jp/GEANT4/vis/DAWN/About_DAVID.html">
274DAVID</ulink> visualization tool  can infact
275automatically detect the overlaps between the volumes defined in
276Geant4 and converted to a graphical representation for
277visualization purposes. The accuracy of the graphical
278representation can be tuned onto the exact geometrical description.
279In the debugging, physical-volume surfaces are automatically
280decomposed into 3D polygons, and intersections of the generated
281polygons are investigated. If a polygon intersects with another
282one, physical volumes which these polygons belong to are visualized
283in color (red is the default). The <xref linkend="fig.Geom.Overlap_2" /> 
284below is a sample visualization of a detector geometry with intersecting
285physical volumes highlighted:
286
287<figure id="fig.Geom.Overlap_2">
288<title>
289  A geometry with overlapping volumes highlighted by DAVID.
290</title>
291<mediaobject>
292  <imageobject role="fo">
293    <imagedata fileref="./AllResources/Detector/geometry.src/DAVID_SAMPLE.gif" 
294               format="GIF" contentwidth="3.0cm" align="center" />
295  </imageobject>
296  <imageobject role="html">
297    <imagedata fileref="./AllResources/Detector/geometry.src/DAVID_SAMPLE.gif"
298               format="GIF" align="center" />
299  </imageobject>
300</mediaobject>
301</figure>
302</para>
303
304<para>
305At present physical volumes made of the following solids are
306able to be debugged: <literal>G4Box</literal>, <literal>G4Cons</literal>,
307<literal>G4Para</literal>, <literal>G4Sphere</literal>, <literal>G4Trd</literal>,
308<literal>G4Trap</literal>, <literal>G4Tubs</literal>. (Existence of other solids is
309harmless.)
310</para>
311
312<para>
313Visual debugging of physical-volume surfaces is performed with
314the DAWNFILE driver defined in the visualization category and with
315the two application packages, i.e. Fukui Renderer "DAWN" and a
316visual intersection debugger "DAVID".
317<ulink url="http://geant4.kek.jp/GEANT4/vis/DAWN/About_DAWN.html">
318DAWN</ulink> and
319<ulink url="http://geant4.kek.jp/GEANT4/vis/DAWN/About_DAVID.html">
320DAVID</ulink> can be downloaded from the Web.
321</para>
322
323<para>
324How to compile Geant4 with the DAWNFILE driver incorporated is
325described in <xref linkend="sect.VisDrv" />.
326</para>
327
328<para>
329If the DAWNFILE driver, DAWN and DAVID are all working well in
330your host machine, the visual intersection debugging of
331physical-volume surfaces can be performed as follows:
332</para>
333
334<para>
335Run your Geant4 executable, invoke the DAWNFILE driver, and
336execute visualization commands to visualize your detector
337geometry:
338
339<informalexample>
340<programlisting>
341     Idle&gt; /vis/open DAWNFILE
342     .....(setting camera etc)...
343     Idle&gt; /vis/drawVolume
344     Idle&gt; /vis/viewer/update
345</programlisting>
346</informalexample>
347</para>
348
349<para>
350Then a file "g4.prim", which describes the detector geometry, is
351generated in the current directory and DAVID is invoked to read it.
352(The description of the format of the file g4.prim can be found
353from the
354<ulink url="http://geant4.kek.jp/GEANT4/vis/DAWN/G4PRIM_FORMAT_24/">
355DAWN web site documentation</ulink>.)
356</para>
357
358<para>
359If DAVID detects intersection of physical-volume surfaces, it
360automatically invokes DAWN to visualize the detector geometry with
361the intersected physical volumes highlighted (See the above sample
362visualization).
363</para>
364
365<para>
366If no intersection is detected, visualization is skipped and the
367following message is displayed on the console:
368
369<informalexample>
370<programlisting>
371     ------------------------------------------------------
372     !!! Number of intersected volumes : 0 !!!
373     !!! Congratulations ! \(^o^)/         !!!
374     ------------------------------------------------------
375</programlisting>
376</informalexample>
377</para>
378
379<para>
380If you always want to skip visualization, set an environmental
381variable as follows beforehand:
382
383<informalexample>
384<programlisting>
385     %  setenv DAVID_NO_VIEW  1
386</programlisting>
387</informalexample>
388</para>
389
390<para>
391To control the precision associated to computation of
392intersections (default precision is set to 9), it is possible to
393use the environmental variable for the DAWNFILE graphics driver, as
394follows:
395
396<informalexample>
397<programlisting>
398     %  setenv G4DAWNFILE_PRECISION  10
399</programlisting>
400</informalexample>
401</para>
402
403<para>
404If necessary, re-visualize the detector geometry with
405intersected parts highlighted. The data are saved in a file
406"g4david.prim" in the current directory. This file can be
407re-visualized with DAWN as follows:
408
409<informalexample>
410<programlisting>
411     % dawn g4david.prim
412</programlisting>
413</informalexample>
414</para>
415
416<para>
417It is also helpful to convert the generated file g4david.prim
418into a VRML-formatted file and perform interactive visualization of
419it with your WWW browser. The file conversion tool
420<literal>prim2wrml</literal> can be downloaded from the
421<ulink url="http://geant4.kek.jp/GEANT4/vis/DAWN/About_prim2vrml1.html">
422DAWN web site download pages</ulink>.
423</para>
424
425<para>
426For more details, see the
427<ulink url="http://geant4.kek.jp/GEANT4/vis/DAWN/About_DAVID.html">
428document of DAVID</ulink> mentioned above.
429</para>
430
431</sect3>
432
433<!-- ******************* Section (Level#3) ****************** -->
434<sect3 id="sect.Geom.Overlap.OLAP">
435<title>
436Using the geometry debugging tool OLAP
437</title>
438
439<para>
440<emphasis role="bold">OLAP</emphasis> is a tool developed in the CMS experiment
441at CERN to help in identifying ovelapping volumes in a detector geometry. It
442is placed in the area for specific tools/examples, in
443<literal>geant4/examples/extended/geometry</literal>. The technique consists
444in shooting <literal>geantinos</literal> particles in one direction and the
445opposite one, and verifying that the boundary crossings are the
446same.
447</para>
448
449<para>
450The tool can be used for any Geant4 geometry, provided that the
451user geometry to be debugged is available as a subclass of
452<literal>G4VUserDetectorConstruction</literal> and is used to construct the
453<literal>OlapDetConstr</literal> class of the tool. A dummy class
454<literal>RandomDetector</literal> is provided for this purpose in the tool
455itself.
456</para>
457
458<para>
459Run-time commands are provided by the tool to navigate in the
460geometry tree. UNIX like navigation of the logical volume hierarchy
461is provided by the <literal>/olap/cd</literal> command. The root of the
462logical volume tree can be accessed by the character '/'. Any node
463in the volume tree can be accessed by a '/' separated string of
464regular expressions. If '/' is at the beginning of the string, the
465tree hierarchy is transversed from the root, otherwise from the
466currently chosen logical volume. Further the command <literal>/olap/goto
467[regexp]</literal> can be used to jump to the first logical volume
468matching the expression <literal>[regexp]</literal>. Every successful
469navigation command (<literal>/olap/cd</literal>, <literal>olap/goto</literal>) results
470in the construction of a <literal>NewWorld</literal>, the mother volume being
471the argument of the command and the daughter volumes being the
472direct daughters of the mother volume.
473</para>
474
475<para>
476<literal>/olap/pwd</literal> always shows where in the full geometrical
477hierarchy the current <literal>NewWorld</literal> and mother volume are
478located.
479</para>
480
481<para>
482For more detailed information, view the <literal>README</literal> file
483provided with the tool.
484</para>
485
486
487</sect3>
488</sect2>
Note: See TracBrowser for help on using the repository browser.