Belle II Software development
testbeam_utils.py
1#!/usr/bin/env python3
2
3
10
11# Geometry helpers for VXD testbeam 2017
12
13import basf2 as b2
14from testbeam.utils import add_vxdtf_v2
15
16
17def add_geometry(
18 path,
19 magnet=True,
20 field_override=None,
21 target=None,
22 geometry_xml='testbeam/vxd/2017_geometry.xml',
23 excluded_components=[],
24 geometry_version=1):
25
26 additonal_components = []
27
28 if geometry_version == 0:
29 print('WARNING: overriding the setting of parameter geometry_xml! Old value: ' + geometry_xml)
30 geometry_xml = 'testbeam/vxd/2017_geometry.xml'
31 print('New value: ' + geometry_xml)
32
33 if geometry_version == 1:
34 print('WARNING: overriding the setting of parameter geometry_xml! Old value: ' + geometry_xml)
35 geometry_xml = 'testbeam/vxd/2017_geometry_1.xml'
36 print('New value: ' + geometry_xml)
37
38 if target is not None:
39 additonal_components += [target]
40
41 if not magnet:
42 excluded_components += ['MagneticField']
43
44 if field_override is not None:
45 excluded_components += ['MagneticField']
46 additonal_components += ['MagneticFieldConstant']
47
48 # Add gearbox, additonally override field value if set
49 if field_override is not None:
50 path.add_module('Gearbox',
51 fileName=geometry_xml,
52 override=[("/DetectorComponent[@name='MagneticFieldConstant']//Z",
53 str(field_override),
54 "")])
55 else:
56 path.add_module('Gearbox', fileName=geometry_xml)
57
58 # Add geometry with additional/removed components
59 path.add_module('Geometry', excludedComponents=excluded_components, additionalComponents=additonal_components)
60
61
62def add_simulation(path, momentum=5., positrons=False, momentum_spread=0.05):
63 # momentum = 6.0 # GeV/c
64 # momentum_spread = 0.05 # %
65 theta = 90.0 # degrees
66 theta_spread = 0.005 # degrees (sigma of gaussian)
67 phi = 0.0 # degrees
68 phi_spread = 0.005 # degrees (sigma of gaussian)
69 gun_x_position = -100. # cm ... 100cm ... outside magnet + plastic shielding + Al scatterer (air equiv.)
70 # gun_x_position = -40. # cm ... 40cm ... inside magnet
71 beamspot_size_y = 0.3 # cm (sigma of gaussian)
72 beamspot_size_z = 0.3 # cm (sigma of gaussian)
73 # ParticleGun
74 particlegun = b2.register_module('ParticleGun')
75 # number of primaries per event
76 particlegun.param('nTracks', 1)
77 # DESY electrons/positrons:
78 if not positrons:
79 particlegun.param('pdgCodes', [11])
80 else:
81 particlegun.param('pdgCodes', [-11])
82
83 # momentum magnitude 2 GeV/c or something above or around.
84 # At DESY we can have up to 6 GeV/c(+-5%) electron beam.
85 # Beam divergence and spot size is adjusted similar to reality
86 # See studies of Benjamin Schwenker
87 particlegun.param('momentumGeneration', 'normal')
88 particlegun.param('momentumParams', [momentum, momentum * momentum_spread])
89 # momentum direction must be around theta=90, phi=180
90 particlegun.param('thetaGeneration', 'normal')
91 particlegun.param('thetaParams', [theta, theta_spread])
92 particlegun.param('phiGeneration', 'normal')
93 particlegun.param('phiParams', [phi, phi_spread])
94 particlegun.param('vertexGeneration', 'normal')
95 particlegun.param('xVertexParams', [gun_x_position, 0.])
96 particlegun.param('yVertexParams', [0., beamspot_size_y])
97 particlegun.param('zVertexParams', [0., beamspot_size_z])
98 particlegun.param('independentVertices', True)
99
100 path.add_module(particlegun)
101
102 path.add_module('FullSim', StoreAllSecondaries=True)
103 path.add_module('SVDDigitizer')
104
105
106def add_reconstruction(
107 path,
108 magnet=True,
109 momentum=5.,
110 vxdtf2=False,
111 mc=False,
112 geometry_version=1
113):
114
115 useThisGeometry = 'TB2017newGeo'
116 if geometry_version == 0:
117 useThisGeometry = 'TB2017'
118
119 path.add_module('SetupGenfitExtrapolation')
120 if mc:
121 path.add_module('TrackFinderMCTruthRecoTracks')
122 else:
123 if(vxdtf2):
124 add_vxdtf_v2(path,
125 magnet_on=magnet,
126 filter_overlapping=True,
127 use_segment_network_filters=True,
128 observerType=0,
129 log_level=b2.LogLevel.ERROR,
130 debug_level=1,
131 usedGeometry=useThisGeometry
132 )
133 else:
134 print("VXDTF1 not supported")
135 daf = b2.register_module('DAFRecoFitter')
136 daf.param('initializeCDCTranslators', False)
137 daf.logging.log_level = b2.LogLevel.ERROR
138 path.add_module(daf)
139 track_creator = b2.register_module('TrackCreator')
140 track_creator.param('beamSpot', [0., 0., 0.])
141 track_creator.param('pdgCodes', [11])
142 track_creator.logging.log_level = b2.LogLevel.ERROR
143 path.add_module(track_creator)