Belle II Software development
make_misalignment.py
1
8
9# This builds an input to the Misalignment module.
10
11import random
12from lxml import etree
13from lxml.etree import Element
14from lxml.etree import SubElement
15
16svd_layers = [3, 4, 5, 6]
17svd_nsensors = {3: 2, 4: 3, 5: 4, 6: 5}
18svd_nladders = {3: 7, 4: 10, 5: 12, 6: 16}
19
20misalignment_shifts = ['du', 'dv', 'dw']
21sigma_shifts = 2.0 # microns
22misalignment_rotations = ['dalpha', 'dbeta', 'dgamma']
23sigma_rotations = 3.0 # mrad
24
25# <SVDMisalignment/>
26svd_misalignment = Element('SVD', name='Random misalignment')
27
28
29# <SVDMisalignment><layer/>
30for i_layer in svd_layers:
31 layer_id = str(i_layer) + '.0.0'
32 layer = SubElement(svd_misalignment, 'layer', id=layer_id)
33 # <SVDMisalignment><layer><ladder/>
34 for i_ladder in range(svd_nladders[i_layer]):
35 ladder_id = str(i_layer) + '.' + str(i_ladder + 1) + '.0'
36 ladder = SubElement(layer, 'ladder', id=ladder_id)
37 # <SVDMisalignment><layer><ladder><sensor/>
38 for i_sensor in range(svd_nsensors[i_layer]):
39 sensor_id = str(i_layer) + '.' + str(i_ladder + 1) + '.' + str(i_sensor + 1)
40 sensor = SubElement(ladder, 'sensor', id=sensor_id)
41 # Add misalignment at this level
42 for param in misalignment_shifts:
43 dx = random.normalvariate(0.0, sigma_shifts)
44 p = SubElement(sensor, param, unit='um', sigma=str(sigma_shifts))
45 p.text = str(dx)
46 for param in misalignment_rotations:
47 dx = random.normalvariate(0.0, sigma_rotations)
48 p = SubElement(sensor, param, unit='mrad', sigma=str(sigma_rotations))
49 p.text = str(dx)
50
51tree = etree.ElementTree(svd_misalignment)
52
53tree.write('SVDMisalignment.xml', pretty_print=True, xml_declaration=True, encoding='utf-8', method='xml')