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> |
---|
13 | Detecting Overlapping Volumes |
---|
14 | </title> |
---|
15 | |
---|
16 | <!-- ******************* Section (Level#3) ****************** --> |
---|
17 | <sect3 id="sect.Geom.Overlap.Prob"> |
---|
18 | <title> |
---|
19 | The problem of overlapping volumes |
---|
20 | </title> |
---|
21 | |
---|
22 | <para> |
---|
23 | Volumes are often positioned within other volumes with the |
---|
24 | intent that one is fully contained within the other. If, however, a |
---|
25 | volume extends beyond the boundaries of its mother volume, it is |
---|
26 | defined as overlapping. It may also be intended that volumes are |
---|
27 | positioned within the same mother volume such that they do not |
---|
28 | intersect one another. When such volumes do intersect, they are |
---|
29 | also defined as overlapping. |
---|
30 | </para> |
---|
31 | |
---|
32 | <para> |
---|
33 | The problem of detecting overlaps between volumes is bounded by |
---|
34 | the complexity of the solid model description. Hence it requires |
---|
35 | the same mathematical sophistication which is needed to describe |
---|
36 | the most complex solid topology, in general. However, a tunable |
---|
37 | accuracy can be obtained by approximating the solids via first |
---|
38 | and/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> |
---|
46 | Detecting overlaps: built-in kernel commands |
---|
47 | </title> |
---|
48 | |
---|
49 | <para> |
---|
50 | In general, the most powerful clash detection algorithms are |
---|
51 | provided by CAD systems, treating the intersection between the |
---|
52 | solids in their topological form. |
---|
53 | </para> |
---|
54 | |
---|
55 | <para> |
---|
56 | Geant4 provides some built-in run-time commands to activate |
---|
57 | verification tests for the user-defined geometry: |
---|
58 | |
---|
59 | <informalexample> |
---|
60 | <programlisting> |
---|
61 | geometry/test/grid_test [recursion_flag] |
---|
62 | --> 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 | --> 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 | --> 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 | --> to specify position for the line_test. |
---|
82 | geometry/test/direction |
---|
83 | --> to specify direction for the line_test. |
---|
84 | geometry/test/grid_cells |
---|
85 | --> 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 | --> 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 | --> 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 | --> 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 | --> 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 | --> 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> |
---|
116 | To detect overlapping volumes, the built-in test uses the |
---|
117 | intersection of solids with linear trajectories. For example, |
---|
118 | consider <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> |
---|
138 | Here we have a line intersecting some physical volume (large, |
---|
139 | black rectangle). Belonging to the volume are four daughters: A, B, |
---|
140 | C, and D. Indicated by the dots are the intersections of the line |
---|
141 | with the mother volume and the four daughters. |
---|
142 | </para> |
---|
143 | |
---|
144 | <para> |
---|
145 | This example has two geometry errors. First, volume A sticks |
---|
146 | outside its mother volume (this practice, sometimes used in |
---|
147 | GEANT3.21, is not allowed in Geant4). This can be noticed because |
---|
148 | the intersection point (leftmost magenta dot) lies outside the |
---|
149 | mother volume, as defined by the space between the two black |
---|
150 | dots. |
---|
151 | </para> |
---|
152 | |
---|
153 | <para> |
---|
154 | The second error is that daughter volumes A and B overlap. This |
---|
155 | is noticeable because one of the intersections with A (rightmost |
---|
156 | magenta dot) is inside the volume B, as defined as the space |
---|
157 | between the red dots. Alternatively, one of the intersections with |
---|
158 | B (leftmost red dot) is inside the volume A, as defined as the |
---|
159 | space between the magenta dots. |
---|
160 | </para> |
---|
161 | |
---|
162 | <para> |
---|
163 | Each of these two types of errors is represented by a line |
---|
164 | segment, which has a start point, an end point, and, a length. |
---|
165 | Depending on the type of error, the points are most clearly |
---|
166 | recognized in either the coordinate system of the volume, the |
---|
167 | global coordinate system, or the coordinate system of the daughters |
---|
168 | involved. |
---|
169 | </para> |
---|
170 | |
---|
171 | <para> |
---|
172 | Also notice that certain errors will be missed unless a line is |
---|
173 | supplied in precisely the correct path. Unfortunately, it is hard |
---|
174 | to predict which lines are best at uncovering potential geometry |
---|
175 | errors. Instead, the geometry testing code uses a grid of lines, in |
---|
176 | the hope of at least uncovering gross geometry errors. More subtle |
---|
177 | errors could easily be missed. |
---|
178 | </para> |
---|
179 | |
---|
180 | <para> |
---|
181 | Another difficult issue is roundoff error. For example, |
---|
182 | daughters C and D lie precisely next to each other. It is possible, |
---|
183 | due to roundoff, that one of the intersections points will lie just |
---|
184 | slightly inside the space of the other. In addition, a volume that |
---|
185 | lies tightly up against the outside of its mother may have an |
---|
186 | intersection point that just slightly lies outside the mother. |
---|
187 | </para> |
---|
188 | |
---|
189 | <para> |
---|
190 | To avoid spurious errors caused by roundoff, a rather generous |
---|
191 | tolerance of 0.1 micron is used by default. This tolerance can be |
---|
192 | adjusted as needed by the application through the run-time |
---|
193 | command: |
---|
194 | |
---|
195 | <informalexample> |
---|
196 | <programlisting> |
---|
197 | geometry/test/tolerance <new-value> |
---|
198 | </programlisting> |
---|
199 | </informalexample> |
---|
200 | </para> |
---|
201 | |
---|
202 | <para> |
---|
203 | Finally, notice that no mention is made of the possible daughter |
---|
204 | volumes of A, B, C, and D. To keep the code simple, only the |
---|
205 | immediate daughters of a volume are checked at one pass. To test |
---|
206 | these "granddaughter" volumes, the daughters A, B, C, and D each |
---|
207 | have to be tested themselves in turn. To make this more automatic, |
---|
208 | an optional recursive algorithm is included; it first tests a |
---|
209 | target volume, then it loops over all daughter volumes and calls |
---|
210 | itself. |
---|
211 | </para> |
---|
212 | |
---|
213 | <para> |
---|
214 | Pay attention! For a complex geometry, checking the entire |
---|
215 | volume 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> |
---|
223 | Detecting overlaps at construction |
---|
224 | </title> |
---|
225 | |
---|
226 | <para> |
---|
227 | Since release 8.0, the Geant4 geometry modeler provides the |
---|
228 | ability to detect overlaps of placed volumes (normal placements or |
---|
229 | parameterised) at the time of construction. This check is optional |
---|
230 | and can be activated when instantiating a placement (see |
---|
231 | <literal>G4PVPlacement</literal> constructor in |
---|
232 | <xref linkend="sect.Geom.PhysVol.PlaceSingle" />) or a parameterised |
---|
233 | volume (see <literal>G4PVParameterised</literal> constructor in |
---|
234 | <xref linkend="sect.Geom.PhysVol.RepeatVol" />). |
---|
235 | </para> |
---|
236 | |
---|
237 | <para> |
---|
238 | The positioning of that specific volume will be checked against all |
---|
239 | volumes in the same hierarchy level and its mother volume. |
---|
240 | Depending on the complexity of the geometry being checked, the |
---|
241 | check may require considerable CPU time; it is therefore suggested |
---|
242 | to use it only for debugging the geometry setup and to apply it |
---|
243 | only to the part of the geometry setup which requires |
---|
244 | debugging. |
---|
245 | </para> |
---|
246 | |
---|
247 | <para> |
---|
248 | The 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 | |
---|
257 | which will force the check for the specified volume. The check |
---|
258 | verifies if each placed or parameterised instance is overlapping |
---|
259 | with other instances or with its mother volume. A default |
---|
260 | resolution for the number of points to be generated and verified is |
---|
261 | provided. The method returns <literal>true</literal> if an overlap |
---|
262 | occurs. It is also possible to specify a "tolerance" by which overlaps |
---|
263 | not exceeding such quantity will not be reported; by default, all |
---|
264 | overlaps are reported. |
---|
265 | </para> |
---|
266 | |
---|
267 | <para> |
---|
268 | <emphasis role="bold">Using the visualization driver: DAVID</emphasis> |
---|
269 | </para> |
---|
270 | <para> |
---|
271 | The Geant4 visualization offers a powerful debugging tool for |
---|
272 | detecting potential intersections of physical volumes. The Geant4 |
---|
273 | <ulink url="http://geant4.kek.jp/GEANT4/vis/DAWN/About_DAVID.html"> |
---|
274 | DAVID</ulink> visualization tool can infact |
---|
275 | automatically detect the overlaps between the volumes defined in |
---|
276 | Geant4 and converted to a graphical representation for |
---|
277 | visualization purposes. The accuracy of the graphical |
---|
278 | representation can be tuned onto the exact geometrical description. |
---|
279 | In the debugging, physical-volume surfaces are automatically |
---|
280 | decomposed into 3D polygons, and intersections of the generated |
---|
281 | polygons are investigated. If a polygon intersects with another |
---|
282 | one, physical volumes which these polygons belong to are visualized |
---|
283 | in color (red is the default). The <xref linkend="fig.Geom.Overlap_2" /> |
---|
284 | below is a sample visualization of a detector geometry with intersecting |
---|
285 | physical 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> |
---|
305 | At present physical volumes made of the following solids are |
---|
306 | able 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 |
---|
309 | harmless.) |
---|
310 | </para> |
---|
311 | |
---|
312 | <para> |
---|
313 | Visual debugging of physical-volume surfaces is performed with |
---|
314 | the DAWNFILE driver defined in the visualization category and with |
---|
315 | the two application packages, i.e. Fukui Renderer "DAWN" and a |
---|
316 | visual intersection debugger "DAVID". |
---|
317 | <ulink url="http://geant4.kek.jp/GEANT4/vis/DAWN/About_DAWN.html"> |
---|
318 | DAWN</ulink> and |
---|
319 | <ulink url="http://geant4.kek.jp/GEANT4/vis/DAWN/About_DAVID.html"> |
---|
320 | DAVID</ulink> can be downloaded from the Web. |
---|
321 | </para> |
---|
322 | |
---|
323 | <para> |
---|
324 | How to compile Geant4 with the DAWNFILE driver incorporated is |
---|
325 | described in <xref linkend="sect.VisDrv" />. |
---|
326 | </para> |
---|
327 | |
---|
328 | <para> |
---|
329 | If the DAWNFILE driver, DAWN and DAVID are all working well in |
---|
330 | your host machine, the visual intersection debugging of |
---|
331 | physical-volume surfaces can be performed as follows: |
---|
332 | </para> |
---|
333 | |
---|
334 | <para> |
---|
335 | Run your Geant4 executable, invoke the DAWNFILE driver, and |
---|
336 | execute visualization commands to visualize your detector |
---|
337 | geometry: |
---|
338 | |
---|
339 | <informalexample> |
---|
340 | <programlisting> |
---|
341 | Idle> /vis/open DAWNFILE |
---|
342 | .....(setting camera etc)... |
---|
343 | Idle> /vis/drawVolume |
---|
344 | Idle> /vis/viewer/update |
---|
345 | </programlisting> |
---|
346 | </informalexample> |
---|
347 | </para> |
---|
348 | |
---|
349 | <para> |
---|
350 | Then a file "g4.prim", which describes the detector geometry, is |
---|
351 | generated 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 |
---|
353 | from the |
---|
354 | <ulink url="http://geant4.kek.jp/GEANT4/vis/DAWN/G4PRIM_FORMAT_24/"> |
---|
355 | DAWN web site documentation</ulink>.) |
---|
356 | </para> |
---|
357 | |
---|
358 | <para> |
---|
359 | If DAVID detects intersection of physical-volume surfaces, it |
---|
360 | automatically invokes DAWN to visualize the detector geometry with |
---|
361 | the intersected physical volumes highlighted (See the above sample |
---|
362 | visualization). |
---|
363 | </para> |
---|
364 | |
---|
365 | <para> |
---|
366 | If no intersection is detected, visualization is skipped and the |
---|
367 | following 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> |
---|
380 | If you always want to skip visualization, set an environmental |
---|
381 | variable as follows beforehand: |
---|
382 | |
---|
383 | <informalexample> |
---|
384 | <programlisting> |
---|
385 | % setenv DAVID_NO_VIEW 1 |
---|
386 | </programlisting> |
---|
387 | </informalexample> |
---|
388 | </para> |
---|
389 | |
---|
390 | <para> |
---|
391 | To control the precision associated to computation of |
---|
392 | intersections (default precision is set to 9), it is possible to |
---|
393 | use the environmental variable for the DAWNFILE graphics driver, as |
---|
394 | follows: |
---|
395 | |
---|
396 | <informalexample> |
---|
397 | <programlisting> |
---|
398 | % setenv G4DAWNFILE_PRECISION 10 |
---|
399 | </programlisting> |
---|
400 | </informalexample> |
---|
401 | </para> |
---|
402 | |
---|
403 | <para> |
---|
404 | If necessary, re-visualize the detector geometry with |
---|
405 | intersected parts highlighted. The data are saved in a file |
---|
406 | "g4david.prim" in the current directory. This file can be |
---|
407 | re-visualized with DAWN as follows: |
---|
408 | |
---|
409 | <informalexample> |
---|
410 | <programlisting> |
---|
411 | % dawn g4david.prim |
---|
412 | </programlisting> |
---|
413 | </informalexample> |
---|
414 | </para> |
---|
415 | |
---|
416 | <para> |
---|
417 | It is also helpful to convert the generated file g4david.prim |
---|
418 | into a VRML-formatted file and perform interactive visualization of |
---|
419 | it 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"> |
---|
422 | DAWN web site download pages</ulink>. |
---|
423 | </para> |
---|
424 | |
---|
425 | <para> |
---|
426 | For more details, see the |
---|
427 | <ulink url="http://geant4.kek.jp/GEANT4/vis/DAWN/About_DAVID.html"> |
---|
428 | document of DAVID</ulink> mentioned above. |
---|
429 | </para> |
---|
430 | |
---|
431 | </sect3> |
---|
432 | |
---|
433 | <!-- ******************* Section (Level#3) ****************** --> |
---|
434 | <sect3 id="sect.Geom.Overlap.OLAP"> |
---|
435 | <title> |
---|
436 | Using the geometry debugging tool OLAP |
---|
437 | </title> |
---|
438 | |
---|
439 | <para> |
---|
440 | <emphasis role="bold">OLAP</emphasis> is a tool developed in the CMS experiment |
---|
441 | at CERN to help in identifying ovelapping volumes in a detector geometry. It |
---|
442 | is placed in the area for specific tools/examples, in |
---|
443 | <literal>geant4/examples/extended/geometry</literal>. The technique consists |
---|
444 | in shooting <literal>geantinos</literal> particles in one direction and the |
---|
445 | opposite one, and verifying that the boundary crossings are the |
---|
446 | same. |
---|
447 | </para> |
---|
448 | |
---|
449 | <para> |
---|
450 | The tool can be used for any Geant4 geometry, provided that the |
---|
451 | user 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 |
---|
455 | itself. |
---|
456 | </para> |
---|
457 | |
---|
458 | <para> |
---|
459 | Run-time commands are provided by the tool to navigate in the |
---|
460 | geometry tree. UNIX like navigation of the logical volume hierarchy |
---|
461 | is provided by the <literal>/olap/cd</literal> command. The root of the |
---|
462 | logical volume tree can be accessed by the character '/'. Any node |
---|
463 | in the volume tree can be accessed by a '/' separated string of |
---|
464 | regular expressions. If '/' is at the beginning of the string, the |
---|
465 | tree hierarchy is transversed from the root, otherwise from the |
---|
466 | currently chosen logical volume. Further the command <literal>/olap/goto |
---|
467 | [regexp]</literal> can be used to jump to the first logical volume |
---|
468 | matching the expression <literal>[regexp]</literal>. Every successful |
---|
469 | navigation command (<literal>/olap/cd</literal>, <literal>olap/goto</literal>) results |
---|
470 | in the construction of a <literal>NewWorld</literal>, the mother volume being |
---|
471 | the argument of the command and the daughter volumes being the |
---|
472 | direct daughters of the mother volume. |
---|
473 | </para> |
---|
474 | |
---|
475 | <para> |
---|
476 | <literal>/olap/pwd</literal> always shows where in the full geometrical |
---|
477 | hierarchy the current <literal>NewWorld</literal> and mother volume are |
---|
478 | located. |
---|
479 | </para> |
---|
480 | |
---|
481 | <para> |
---|
482 | For more detailed information, view the <literal>README</literal> file |
---|
483 | provided with the tool. |
---|
484 | </para> |
---|
485 | |
---|
486 | |
---|
487 | </sect3> |
---|
488 | </sect2> |
---|