Belle II Software development
SetSensitiveThreshold.py
1#!/usr/bin/env python3
2
3
10
11import basf2 as b2
12
13# Import xml parser
14import xml.etree.ElementTree as xml
15
16# Load the required libraries
17
18b2.logging.log_level = b2.LogLevel.WARNING
19
20
21class SetVXDSensitiveThreshold(b2.Module):
22
23 """A utility module to manipulate the threshold on deposited energy
24 in PXD and SVD SensitiveDetector.
25 """
26
27 def __init__(self, threshold):
28 """Initialize the module"""
29
30 super().__init__()
31
32 self.threshold = threshold
33
35
37
38 self.path = 'data/{comp}/{COMP}.xml'
39
40 self.xmlpath = 'Content/SensitiveThreshold'
41
42 def set_threshold(self, component, value):
43 """ Set the threshold value in PXD or SVD file."""
44
45 filename = self.path.format(comp=component.lower(),
46 COMP=component.upper())
47 tree = xml.parse(filename)
48 for node in tree.getroot().findall(self.xmlpath):
49 if component.lower() == 'pxd':
50 self.old_pxd_threshold = float(node.text)
51 else:
52 self.old_svd_threshold = float(node.text)
53 node.text = f'{value}'
54
55 file = open(filename, 'w')
56 tree.write(file, encoding='UTF-8', xml_declaration=True)
57 file.close()
58
59 def initialize(self):
60 """ Set the required threshold value """
61
62 self.set_threshold('PXD', self.threshold)
63 self.set_threshold('SVD', self.threshold)
64
65 def beginRun(self):
66 """ Do nothing. """
67
68 def event(self):
69 """Do nothing."""
70
71 def terminate(self):
72 """ Set the previuos threshold value """
73
74 self.set_threshold('PXD', self.old_pxd_threshold)
75 self.set_threshold('SVD', self.old_svd_threshold)
76
77
78# Particle gun module
79particlegun = b2.register_module('ParticleGun')
80# Create Event information
81eventinfosetter = b2.register_module('EventInfoSetter')
82# Show progress of processing
83progress = b2.register_module('Progress')
84# Manipulate the energy threshold in VXD SensitiveDetectors.
85set_thr = SetVXDSensitiveThreshold(-0.01)
86# Load parameters
87gearbox = b2.register_module('Gearbox')
88# Create geometry
89geometry = b2.register_module('Geometry')
90# Run simulation
91simulation = b2.register_module('FullSim')
92# PXD digitization module
93pxddigi = b2.register_module('PXDDigitizer')
94# PXD clustering module
95pxdclust = b2.register_module('PXDClusterizer')
96# SVD digitization module
97svddigi = b2.register_module('SVDDigitizer')
98# SVD clustering module
99svdclust = b2.register_module('SVDClusterizer')
100# Simpleoutput
101output = b2.register_module('RootOutput')
102
103# Specify number of events to generate
104eventinfosetter.param({'evtNumList': [10], 'runList': [1]})
105
106# Set parameters for particlegun
107particlegun.param({ # Generate 5 tracks on average
108 # the number of tracks is a Poisson variate
109 # Generate pi+, pi-, e+ and e-
110 # with a normal distributed transversal momentum
111 # with a center of 5 GeV and a width of 1 GeV
112 # a normal distributed phi angle,
113 # center of 180 degree and a width of 30 degree
114 # Generate theta angles uniform in cos theta
115 # between 17 and 150 degree
116 # normal distributed vertex generation
117 # around the origin with a sigma of 2cm in the xy plane
118 # and no deviation in z
119 # all tracks sharing the same vertex per event
120 'nTracks': 1,
121 'varyNTracks': True,
122 'pdgCodes': [211, -211, 11, -11],
123 'momentumGeneration': 'normalPt',
124 'momentumParams': [5, 1],
125 'phiGeneration': 'normal',
126 'phiParams': [180, 30],
127 'thetaGeneration': 'uniformCosinus',
128 'thetaParams': [17, 150],
129 'vertexGeneration': 'normal',
130 'xVertexParams': [0, 2],
131 'yVertexParams': [0, 2],
132 'zVertexParams': [0, 0],
133 'independentVertices': False,
134 })
135
136# Select subdetectors to be built
137geometry.param('Components', ['MagneticField', 'PXD', 'SVD'])
138
139# Set the desired SensitiveDetector threshold for the VXD.
140# -1 eV means no threshold.
141# set_thr.param('threshold',-1.0)
142
143# create processing path
144main = b2.create_path()
145main.add_module(eventinfosetter)
146main.add_module(progress)
147main.add_module(particlegun)
148main.add_module(set_thr) # MUST precede gearbox!
149main.add_module(gearbox)
150main.add_module(geometry)
151main.add_module(simulation)
152main.add_module(pxddigi)
153main.add_module(pxdclust)
154main.add_module(svddigi)
155main.add_module(svdclust)
156main.add_module(output)
157
158# generate events
159b2.process(main)
160
161# show call statistics
162print(b2.statistics)
old_svd_threshold
The current svd threshold value.
old_pxd_threshold
The current pxd threshold value.