Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:48:52

0001 #!/usr/bin/env python
0002 #
0003 # Copyright (c) 2019 Opticks Team. All Rights Reserved.
0004 #
0005 # This file is part of Opticks
0006 # (see https://bitbucket.org/simoncblyth/opticks).
0007 #
0008 # Licensed under the Apache License, Version 2.0 (the "License"); 
0009 # you may not use this file except in compliance with the License.  
0010 # You may obtain a copy of the License at
0011 #
0012 #   http://www.apache.org/licenses/LICENSE-2.0
0013 #
0014 # Unless required by applicable law or agreed to in writing, software 
0015 # distributed under the License is distributed on an "AS IS" BASIS, 
0016 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
0017 # See the License for the specific language governing permissions and 
0018 # limitations under the License.
0019 #
0020 
0021 """
0022 
0023 ::
0024 
0025     In [1]: run gdml.py
0026     ...
0027 
0028     In [13]: len(g.volumes)  # lv
0029     Out[13]: 249
0030 
0031     In [14]: len(g.solids)   # top level solids, ie root nodes of all the gdml solids
0032     Out[14]: 707             # comparing lv:249 so:707 -> avg  ~3 solids per lv 
0033 
0034     In [15]: len(g.materials)
0035     Out[15]: 36
0036 
0037 
0038 Hmm in scene serialization ? Preserve all the solids, or flatten into lv ?
0039 
0040 
0041 Or flatten yet more... eg for PMT there are 5 solids that natuarally go together
0042 to make an instance...
0043 
0044 * need to analyse the solid tree to look for such clusters, or defer that til later ?
0045 
0046 ::
0047 
0048     In [76]: g.volumes(47)  # eg lv:47 comprises so:131,129,127,125,126,128,130 
0049     Out[76]: 
0050     [47] Volume /dd/Geometry/PMT/lvPmtHemi0xc133740 /dd/Materials/Pyrex0xc1005e0 pmt-hemi0xc0fed90
0051        [131] Union pmt-hemi0xc0fed90  
0052          l:[129] Intersection pmt-hemi-glass-bulb0xc0feb98  
0053          l:[127] Intersection pmt-hemi-face-glass*ChildForpmt-hemi-glass-bulb0xbf1f8d0  
0054          l:[125] Sphere pmt-hemi-face-glass0xc0fde80 mm rmin 0.0 rmax 131.0  x 0.0 y 0.0 z 0.0  
0055          r:[126] Sphere pmt-hemi-top-glass0xc0fdef0 mm rmin 0.0 rmax 102.0  x 0.0 y 0.0 z 0.0  
0056          r:[128] Sphere pmt-hemi-bot-glass0xc0feac8 mm rmin 0.0 rmax 102.0  x 0.0 y 0.0 z 0.0  
0057          r:[130] Tube pmt-hemi-base0xc0fecb0 mm rmin 0.0 rmax 42.25  x 0.0 y 0.0 z 169.0  
0058        [14] Material /dd/Materials/Pyrex0xc1005e0 solid
0059        PhysVol /dd/Geometry/PMT/lvPmtHemi#pvPmtHemiVacuum0xc1340e8
0060      None None 
0061 
0062 
0063 ::
0064 
0065     In [83]: g.volumes(2).physvol   ## pv are placements: so there are loads of em, thus no need for abaolute indexing 
0066     Out[83]: 
0067     [PhysVol /dd/Geometry/RPC/lvRPCGasgap14#pvStrip14Array#pvStrip14ArrayOne:1#pvStrip14Unit0xc311da0
0068      Position mm -910.0 0.0 0.0  Rotation deg 0.0 0.0 -90.0  ,
0069      PhysVol /dd/Geometry/RPC/lvRPCGasgap14#pvStrip14Array#pvStrip14ArrayOne:2#pvStrip14Unit0xc125cf8
0070      Position mm -650.0 0.0 0.0  Rotation deg 0.0 0.0 -90.0  ,
0071      PhysVol /dd/Geometry/RPC/lvRPCGasgap14#pvStrip14Array#pvStrip14ArrayOne:3#pvStrip14Unit0xc125df0
0072      Position mm -390.0 0.0 0.0  Rotation deg 0.0 0.0 -90.0  ,
0073      PhysVol /dd/Geometry/RPC/lvRPCGasgap14#pvStrip14Array#pvStrip14ArrayOne:4#pvStrip14Unit0xc125ee8
0074      Position mm -130.0 0.0 0.0  Rotation deg 0.0 0.0 -90.0  ,
0075      PhysVol /dd/Geometry/RPC/lvRPCGasgap14#pvStrip14Array#pvStrip14ArrayOne:5#pvStrip14Unit0xc125fe0
0076      Position mm 130.0 0.0 0.0  Rotation deg 0.0 0.0 -90.0  ,
0077      PhysVol /dd/Geometry/RPC/lvRPCGasgap14#pvStrip14Array#pvStrip14ArrayOne:6#pvStrip14Unit0xc1260d8
0078      Position mm 390.0 0.0 0.0  Rotation deg 0.0 0.0 -90.0  ,
0079      PhysVol /dd/Geometry/RPC/lvRPCGasgap14#pvStrip14Array#pvStrip14ArrayOne:7#pvStrip14Unit0xc1261d0
0080      Position mm 650.0 0.0 0.0  Rotation deg 0.0 0.0 -90.0  ,
0081      PhysVol /dd/Geometry/RPC/lvRPCGasgap14#pvStrip14Array#pvStrip14ArrayOne:8#pvStrip14Unit0xc1262c8
0082      Position mm 910.0 0.0 0.0  Rotation deg 0.0 0.0 -90.0  ]
0083 
0084 
0085 
0086 Absolute gidx volume(lv), solid and material indexing done via odict:: 
0087 
0088     In [75]: g.volumes.keys()
0089     Out[75]: 
0090     ['/dd/Geometry/PoolDetails/lvNearTopCover0xc137060',
0091      '/dd/Geometry/RPC/lvRPCStrip0xc2213c0',
0092      '/dd/Geometry/RPC/lvRPCGasgap140xbf98ae0',
0093      ...
0094 
0095 
0096 
0097     In [59]: g.volumes(100)
0098     Out[59]: 
0099     [100] Volume /dd/Geometry/CalibrationSources/lvLedSourceShell0xc3066b0 /dd/Materials/Acrylic0xc02ab98 led-source-shell0xc3068f0
0100        [320] Union led-source-shell0xc3068f0  
0101          l:[318] Union led-acryliccylinder+ChildForled-source-shell0xc306188  
0102          l:[316] Tube led-acryliccylinder0xc306f40 mm rmin 0.0 rmax 10.035  x 0.0 y 0.0 z 29.73  
0103          r:[317] Sphere led-acrylicendtop0xc306fe8 mm rmin 0.0 rmax 10.035  x 0.0 y 0.0 z 0.0  
0104          r:[319] Sphere led-acrylicendbot0xc307120 mm rmin 0.0 rmax 10.035  x 0.0 y 0.0 z 0.0  
0105        [8] Material /dd/Materials/Acrylic0xc02ab98 solid
0106        PhysVol /dd/Geometry/CalibrationSources/lvLedSourceShell#pvDiffuserBall0xc0d3488
0107      None None 
0108 
0109     In [60]: g.solids(320)
0110     Out[60]: 
0111     [320] Union led-source-shell0xc3068f0  
0112          l:[318] Union led-acryliccylinder+ChildForled-source-shell0xc306188  
0113          l:[316] Tube led-acryliccylinder0xc306f40 mm rmin 0.0 rmax 10.035  x 0.0 y 0.0 z 29.73  
0114          r:[317] Sphere led-acrylicendtop0xc306fe8 mm rmin 0.0 rmax 10.035  x 0.0 y 0.0 z 0.0  
0115          r:[319] Sphere led-acrylicendbot0xc307120 mm rmin 0.0 rmax 10.035  x 0.0 y 0.0 z 0.0  
0116 
0117     In [61]: g.solids(319)
0118     Out[61]: [319] Sphere led-acrylicendbot0xc307120 mm rmin 0.0 rmax 10.035  x 0.0 y 0.0 z 0.0  
0119 
0120     In [62]: g.materials(8)
0121     Out[62]: [8] Material /dd/Materials/Acrylic0xc02ab98 solid
0122 
0123 
0124 
0125     In [72]: print g.solids(2).xml
0126     <subtraction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="near_top_cover-ChildFornear_top_cover_box0xc241498">
0127           <first ref="near_top_cover0xc5843d8"/>
0128           <second ref="near_top_cover_sub00xc584418"/>
0129           <position name="near_top_cover-ChildFornear_top_cover_box0xc241498_pos" unit="mm" x="8000" y="5000" z="0"/>
0130           <rotation name="near_top_cover-ChildFornear_top_cover_box0xc241498_rot" unit="deg" x="0" y="0" z="45"/>
0131         </subtraction>
0132         
0133 
0134 
0135 
0136     In [55]: g.volumes(100).solid
0137     Out[55]: 
0138     Union led-source-shell0xc3068f0  
0139          l:Union led-acryliccylinder+ChildForled-source-shell0xc306188  
0140          l:Tube led-acryliccylinder0xc306f40 mm rmin 0.0 rmax 10.035  x 0.0 y 0.0 z 29.73  
0141          r:Sphere led-acrylicendtop0xc306fe8 mm rmin 0.0 rmax 10.035  x 0.0 y 0.0 z 0.0  
0142          r:Sphere led-acrylicendbot0xc307120 mm rmin 0.0 rmax 10.035  x 0.0 y 0.0 z 0.0  
0143 
0144     In [56]: g.volumes(100).solid.idx
0145     Out[56]: 320
0146 
0147     In [57]: g.solids(320)
0148     Out[57]: 
0149     Union led-source-shell0xc3068f0  
0150          l:Union led-acryliccylinder+ChildForled-source-shell0xc306188  
0151          l:Tube led-acryliccylinder0xc306f40 mm rmin 0.0 rmax 10.035  x 0.0 y 0.0 z 29.73  
0152          r:Sphere led-acrylicendtop0xc306fe8 mm rmin 0.0 rmax 10.035  x 0.0 y 0.0 z 0.0  
0153          r:Sphere led-acrylicendbot0xc307120 mm rmin 0.0 rmax 10.035  x 0.0 y 0.0 z 0.0  
0154 
0155 
0156 
0157 
0158 
0159     In [19]: len(gdml.elem.findall("solids/*"))
0160     Out[19]: 707
0161 
0162     In [20]: len(gdml.elem.findall("solids//*"))
0163     Out[20]: 1526
0164 
0165     In [21]: set([e.tag for e in gdml.elem.findall("solids//*")])
0166     Out[21]: 
0167     {
0168      'position',
0169      'rotation',
0170 
0171      'first',
0172      'second',
0173      'intersection',
0174      'subtraction',
0175      'union',
0176 
0177      'box',     
0178      'sphere',
0179      'tube',
0180      'cone',
0181      'polycone', 'zplane'
0182      'trd',                 # trapezoid
0183 
0184    }
0185 
0186 
0187     In [26]: for e in gdml.elem.findall("solids//tube"):print tostring_(e)
0188 
0189     In [26]: for e in gdml.elem.findall("solids//trd"):print tostring_(e)
0190     <trd xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" lunit="mm" name="SstTopRadiusRibBase0xc271078" x1="160" x2="691.02" y1="20" y2="20" z="2228.5"/>
0191     <trd xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" lunit="mm" name="SstInnVerRibCut0xbf31118" x1="100" x2="237.2" y1="27" y2="27" z="50.02"/>
0192 
0193 
0194 """
0195 
0196 
0197 if __name__ == '__main__':
0198     pass
0199 
0200 
0201