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