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