Belle II Software  release-08-01-10
prepare_extract.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 # ----------------------------------------------------------------
13 # Create a geometry extract (needed for R-Phi and R-Z projections)
14 # ----------------------------------------------------------------
15 #
16 # PLEASE READ COMMENTS IN THIS SCRIPT
17 #
18 # Geometry extract is a simplified and small version of the geometry
19 # stored in a ROOT file and loaded by default (from display/data/geometry_extract.root)
20 # It is needed for R-Phi and R-Z projection (empty for full geometry).
21 # It is faster to display and manipulate (zoom, rotation) than full geometry
22 #
23 # This script will open Display, where one can:
24 # 1) Remove volumes to have reasonably-sized extract
25 # - Go to Eve panel -> Scenes -> Geometry scene
26 # - Select volumes to be removed completely from the extract by right-clicking
27 # on them and selecting 'Destroy' from the pop-up menu
28 # 2) Hide volumes for better visibility (just un-check their check-box).
29 # These can be later re-enabled in the Display.
30 # 3) Change volume colors, transparency etc. (only in the Display UI)
31 # 4) Save the extract from window menu by clicking on Scene -> Save geometry extract
32 # It will be saved in current directory with name 'geometry_extract.root'
33 #
34 # NOTE: 1) and 2) can be done also automatically from the script (read below)
35 # NOTE: You are supposed to review / slightly modify the visual appearance in
36 # the Display UI. But using the parameters in this script can save you from
37 # lot of tedious work of destroying hundreds of volumes by hand
38 
39 
40 import basf2 as b2
41 
42 # Change between Phase3 (phase2=False) and Phase2 geometry (phase2=True)
43 phase2 = False
44 # create paths
45 main = b2.create_path()
46 
47 # Use RootInput instead EventInfoSetter (not both!) if you want
48 # to load some event data from a ROOT file
49 main.add_module('EventInfoSetter')
50 # main.add_module('RootInput')
51 
52 # You can specify different geometry here, e.g. Phase2
53 # Select only sub-detectors you want to show (e.g. no BeamPipe) in components
54 # WARNING: ECL cannot be displayed (will crash due to unsupported volumes)
55 if phase2:
56  main.add_module('Gearbox', fileName='/geometry/Beast2_phase2.xml')
57  main.add_module('Geometry', components=['FANGS', 'CLAWS', 'PLUME', 'PXD', 'SVD', 'CDC', 'TOP', 'ARICH', 'KLM'], useDB=False)
58 else:
59  main.add_module('Gearbox')
60  main.add_module('Geometry', components=['PXD', 'SVD', 'CDC', 'TOP', 'ARICH', 'KLM'], useDB=False)
61 
62 display = b2.register_module('Display')
63 
64 # Has to be True to show the full TGeo geometry instead of simplified extract
65 # which you want to prepare with this script
66 display.param('fullGeometry', True)
67 
68 # List of volumes to be hidden (can be re-enabled in Eve panel / Geometry scene)
69 # The volumes and all their daughters will be hidden.
70 # NOTE: Volume names in the Eve panel have usually a suffix ('_1' etc. which you have to omit here)
71 # For example 'BKLM.EnvelopeLogical' is named 'BKLM.EnvelopeLogical_1' but here you need to specify
72 # them without the suffix (their visualisation is changed directly in geometry in memory - which
73 # has no effect to e.g. simulation - but many volumes have the same name)
74 # For example 'PXD.Switcher_refl' will hide all 'PXD.Switcher_refl_#' you could see in the Eve panel.
75 display.param('hideVolumes', ['logicalCDC',
76  'ARICH.masterVolume',
77  'BKLM.EnvelopeLogical',
78  'Endcap_1',
79  'Endcap_2'])
80 
81 # List of volumes to be deleted. This time the suffix is needed.
82 # NOTE: These are REGULAR EXPRESSIONS from ROOT, see:
83 # https://root.cern.ch/root/html534/TPRegexp.html
84 #
85 # NOTE: If the expression starts with '#', only children of this
86 # element are deleted (sometimes useful), the leading '#'
87 # is removed before making regular expression.
88 # WARNING: For some reason one can still expand this in the Eve panel, which
89 # will cause the children elements to re-appear (strange, why?!) -
90 # so do not click (expand) it if you do not want it in the extract
91 #
92 # Some usefull examples:
93 #
94 # - You need to escape special characters like '.' (dot) by '\\'
95 # For example to select all volumes which contain 'PXD.ReadoutChips', use:
96 # 'PXD\\.ReadoutChips'
97 #
98 # - To select exactly the volume with given name, e.g. 'logicalCDC_0', use:
99 # '^logicalCDC_0$'
100 #
101 # - To select any volume which contains some string, e.g. 'Encap_1'. 'LayerEndcap_2' etc., use simply:
102 # 'Endcap'
103 #
104 # - To select volumes starting with some string, e.g. 'Endcap_1', 'Endcap_2' etc., use:
105 # '^Endcap'
106 #
107 # - '.*' means any or no characters, so e.g. to remove volumes which contain
108 # 'PXD.Switcher', 'PXD.SwitcherChip', 'Switcher' etc., you could use:
109 # 'Switcher.*'
110 #
111 # A B2INFO message is issued for every volume deleted. Please check the output is what you expect.
112 #
113 # Follows a default list used to create Phase 3(2) extract:
114 # NOTE: One can do much more efficiently with regular expressions...
115 # I keep this list if someone would like to re-enable some parts without
116 # all the work of going through the geometry scene.
117 display.param('deleteVolumes', [
118  # 'BKLM\\.EnvelopeLogical',
119  # '^Endcap_1.*',
120  # '^Endcap_2.*',
121 
122  # --- BKLM ---------------------------------------------------
123  '#BKLM\\.F', # Note the leading # (only delete children)
124  '#BKLM\\.B', # Note the leading # (only delete children)
125  # --- EKLM ---------------------------------------------------
126  '#^Layer_.*', # Note the leading # (only delete children)
127  '#^ShieldLayer.*', # Note the leading # (only delete children)
128  # --- CDC ----------------------------------------------------
129  '#^logicalCDC_0$', # delete children + hide this (see above)
130  # --- TOP ----------------------------------------------------
131  '#^TOPEnvelopeModule.*',
132  # --- ARICH --------------------------------------------------
133  '#ARICH.*', # delete children + hide this (see above)
134  # --- PXD ----------------------------------------------------
135  'PXD\\.Switcher.*',
136  'PXD\\.Balcony.*',
137  'PXD\\.Cap.*',
138  'PXD\\.ReadoutChips.*',
139  'PXD\\.Reinforcement.*',
140  'PXD\\.ThinningLayer.*',
141  'PXD\\.Border.*',
142  'CarbonTube.*',
143  '^backward_.*',
144  '^forward_.*',
145  # --- SVD ----------------------------------------------------
146  'SVD\\. Forward.*',
147  'SVD\\. Backward.*',
148  'SVD\\. Outer',
149  'SVD\\.Kapton.*',
150  'SVD\\.Layer.*',
151  'SVD\\.Barrel.*',
152  'SVD\\.Origami.*',
153  'SVD\\.Slanted.*',
154  'SVD\\.APV.*'
155 ])
156 
157 # To use custom extract afterwards in Display, you need to set
158 # fullGeometry=False (default) and change the path to the extract used (in your own display script):
159 #
160 # display.param('customGeometryExtractPath', 'geometry_extract.root')
161 
162 main.add_module(display)
163 
164 b2.process(main)
165 # print(statistics(statistics.INIT))