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