13For SectorMaps running on data it significantly improves performance if the SectorMap is trained
14on the Geometry as it is in data. This script reads alignment data from a GT and compares the aligned
15Geometry with the not aligned Geomtry. The differences are written are written out in xml file
16format which can be directly used to create new Geometry payloads for SVD and PXD.
17Note you need to provide one or more global tags (or local DB) which contain the default geometry
18and alignement payloads to be used. Be careful that the IOVs do need to match (e.g. by editing the DB
19txt file for a local DB). See for example svd/scripts/dbImporters/create_SVDGeometryPar_payload.py
23from ROOT
import Belle2
29parser = argparse.ArgumentParser(description=
'Script that produces a xml file with \
30 sensor displacements to be used to create a DB payload. ')
38 help=
"The txt file defining a local DB (optional)."
46 help=
"List of global tag names separated by space (optional)."
54 help=
"The experiment number needed to pick correct IOV. (optional)."
62 help=
"The run number needed to pick correct IOV. (optional)"
65args = parser.parse_args()
68if not args.localDB ==
'':
69 basf2.B2INFO(
'Prepending local DB: ' + args.localDB)
70 basf2.conditions.prepend_testing_payloads(args.localDB)
73for aGT
in args.listOfGT:
74 basf2.B2INFO(
'Prepending global tag: ' + aGT)
75 basf2.conditions.prepend_globaltag(aGT)
79 """ Module to create misalignment (first reads real sensor positions, then applies misalignment and creates a xml file
80 suited for creating a DB payload). The DB payload itself
is created by using the Geometry module by setting the
81 createPayloads to
True.
93 ''' event function '''
100 center = ROOT.TVector3(0., 0., 0.)
102 centerN = info.pointToGlobal(center,
False)
103 centerA = info.pointToGlobal(center,
True)
105 centerDiff = centerA - centerN
107 centerDiff = info.vectorToLocal(centerDiff, reco=
False)
111 if (maxDiff < centerDiff.R()):
112 maxDiff = centerDiff.R()
119 self.
sensors[f
"{sensor.getLayerNumber()}.{sensor.getLadderNumber()}.{sensor.getSensorNumber()}"] = [
120 centerDiff.X(), centerDiff.Y(), centerDiff.Z(), phi, theta, psi]
123 basf2.B2ERROR(f
"Max occured displacements are smaller then 1e-9! Are you sure alignments constants \
124 are loaded correctly? max={maxDiff} cm")
130path = basf2.create_path()
131path.add_module(
"EventInfoSetter", expList=[args.expNum], runList=[args.runNum], evtNumList=[1])
132path.add_module(
"Gearbox")
133path.add_module(
"Geometry")
134path.add_module(reader)
137sensors = reader.sensors
140allladders = [8, 12, 7, 10, 12, 16]
141allsensors = [2, 2, 2, 3, 4, 5]
145 ''' Writes a single line into the xml file
146 @param xml the opened xml file to be written to
147 @param txt the line to be written
149 xml.writelines([txt + "\n"])
152def c(xml, name, alig=None):
154 Creates displacement information in the correct format to be written to the xml file.
155 @param the open xml file to be written to
156 @param name The name of the sensor which information
is written
160 alig = [0., 0., 0., 0., 0., 0.]
161 a(xml,
"<Align component=\"" + name +
"\">")
162 a(xml, f
"<du unit=\"cm\" >{alig[0]}</du> <dv unit=\"cm\" > {alig[1]}</dv> <dw unit=\"cm\" >{alig[2]}</dw>")
163 a(xml, f
"<alpha unit=\"rad\">{alig[3]}</alpha> <beta unit=\"rad\">{alig[4]}</beta> <gamma unit=\"rad\">{alig[5]}</gamma>")
168with open(
"PXD-Alignment.xml",
"w")
as xml:
171 a(xml,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
172 a(xml,
"<Alignment>")
182 for ladder
in range(1, allladders[layer - 1] + 1):
183 c(xml, f
"{layer}.{ladder}")
184 for sensor
in range(1, allsensors[layer - 1] + 1):
185 if f
"{layer}.{ladder}.{sensor}" in sensors:
186 c(xml, f
"{layer}.{ladder}.{sensor}", [v
for v
in sensors[f
"{layer}.{ladder}.{sensor}"]])
189 a(xml,
"</Alignment>")
193with open(
"SVD-Alignment.xml",
"w")
as xml:
196 a(xml,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
197 a(xml,
"<Alignment>")
205 for layer
in [3, 4, 5, 6]:
207 for ladder
in range(1, allladders[layer - 1] + 1):
208 c(xml, f
"{layer}.{ladder}")
209 for sensor
in range(1, allsensors[layer - 1] + 1):
210 if f
"{layer}.{ladder}.{sensor}" in sensors:
211 c(xml, f
"{layer}.{ladder}.{sensor}", [v
for v
in sensors[f
"{layer}.{ladder}.{sensor}"]])
214 a(xml,
"</Alignment>")
static GeoCache & getInstance()
Return a reference to the singleton instance.
sensors
dictionary to map the displacements for each sensor