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