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