Belle II Software  release-08-01-10
gearbox_override.py
1 #!/usr/bin/env python3
2 
3 
10 
11 
14 
15 from basf2 import Path, process, statistics
16 
17 main = Path()
18 # EventInfoSetter - generate event meta data
19 main.add_module('EventInfoSetter', evtNumList=[1])
20 
21 gearbox = main.add_module("Gearbox")
22 gearbox.param({
23  # Set the length of the simulation volume to 9m and the width to 3m and the
24  # Material to Vacuum instead of Air (no unit for the Material though)
25  'override': [
26  ("/Global/length", "9", "m"),
27  ("/Global/width", "3", "m"),
28  # We don't need a unit so we supply an empty one
29  ("/Global/material", "Vacuum", ""),
30  # Ok, so now we change the ActiveChips parameter of the PXD to true.
31  # The // matches any number of elements in between, so the Material
32  # could be somewhere deep in the xml but we do not need to care. //foo
33  # matches /foo, /a/foo, /b/foo, /a/b/foo and so forth
34  # foo[@name='bar'] matches all elements <foo> which have an attribute
35  # name with the value bar (the @ is to specify attributes)
36  # So, this line reads "override all ActiveChips elements somewhere
37  # inside an DetectorComponent element which has the name attribute set
38  # to PXD". If more than one element matches this expression an error is
39  # produced to be on the safe side.
40  ("/DetectorComponent[@name='PXD']//ActiveChips", "true", ""),
41  ],
42  # A normal override can affect only one parameter. If one wants to override
43  # a number of parameters at once one has to use overrideMultiple to
44  # indicate that this is really the intention. So let's change the element
45  # fractions in Vacuum to all be equal to one
46  # //@fraction selects the fraction attributes which are descendents of the
47  # the Material element. Attributes cannot have a unit so we need to supply
48  # an empty unit
49  'overrideMultiple': [
50  ("//Material[@name='Vacuum']//@fraction", "1.0", "")
51  ],
52 })
53 
54 # If we would want to modify many parameters of one subdetector we could set
55 # the override prefix to have more convinient access. Beware, the override
56 # prefix is the same for all overrides so this would interfere with the
57 # examples above
58 
59 # gearbox.param({
60 # "overridePrefix": "//DetectorComponent[@name='PXD']/Content/",
61 # "override": [
62 # ("ActiveChips", "true", ""),
63 # ("SeeNeutrons", "true", ""),
64 # ("SensitiveThreshold", "0", "eV"),
65 # ],
66 # })
67 
68 # Process all events
69 process(main)
70 print(statistics(statistics.BEGIN_RUN))