16 from ROOT
import Belle2
17 from ROOT.Belle2
import KLMChannelIndex, KLMElementNumbers
19 from alignment
import MillepedeCalibration
21 basf2.set_log_level(basf2.LogLevel.INFO)
23 basf2.conditions.append_testing_payloads(
'localdb/database.txt')
26 millepede = MillepedeCalibration([
'BKLMAlignment',
'EKLMAlignment',
'EKLMSegmentAlignment'])
29 index = KLMChannelIndex(KLMChannelIndex.c_IndexLevelLayer)
30 index2 = KLMChannelIndex(KLMChannelIndex.c_IndexLevelLayer)
31 while (index != index2.end()):
32 module = index.getKLMModuleNumber()
33 if (index.getSubdetector() == KLMElementNumbers.c_BKLM):
34 for ipar
in [1, 2, 3, 4, 5, 6]:
41 for ipar
in [1, 2, 6]:
49 index.setIndexLevel(KLMChannelIndex.c_IndexLevelStrip)
50 index2.setIndexLevel(KLMChannelIndex.c_IndexLevelStrip)
51 index = index2.beginEKLM()
52 index.useEKLMSegments()
53 while (index != index2.endEKLM()):
54 segment = index.getEKLMSegmentNumber()
56 millepede.fixGlobalParam(
62 input_files = sys.argv[1:]
63 calibration = millepede.create(
'klm_alignment', input_files)
64 millepede.algo.setInputFileNames(input_files)
65 millepede.algo.ignoreUndeterminedParams(
True)
66 millepede.algo.invertSign()
67 millepede.algo.execute()
68 millepede.algo.commit()
71 payloads = list(millepede.algo.getPayloads())
74 eklm_segment_alignment =
None
75 for payload
in payloads:
76 if payload.name ==
'BKLMAlignment':
77 bklm_alignment = payload.object.IsA().DynamicCast(
Belle2.BKLMAlignment().IsA(), payload.object,
False)
78 elif payload.name ==
'EKLMAlignment':
79 eklm_alignment = payload.object.IsA().DynamicCast(
Belle2.EKLMAlignment().IsA(), payload.object,
False)
80 elif payload.name ==
'EKLMAlignment':
86 "correction & errors",
87 millepede.algo.result().getNoDeterminedParameters(),
89 millepede.algo.result().getNoDeterminedParameters())
92 param = np.zeros(1, dtype=int)
93 value = np.zeros(1, dtype=np.float32)
94 correction = np.zeros(1, dtype=np.float32)
95 error = np.zeros(1, dtype=np.float32)
96 section = np.zeros(1, dtype=int)
97 sector = np.zeros(1, dtype=int)
98 layer = np.zeros(1, dtype=int)
99 sensor = np.zeros(1, dtype=int)
100 plane = np.zeros(1, dtype=int)
101 segment = np.zeros(1, dtype=int)
103 alignment_file = ROOT.TFile(
'alignment.root',
'recreate')
105 bklm_module_tree = ROOT.TTree(
'bklm_module',
'BKLM module alignment data')
106 bklm_module_tree.Branch(
'section', section,
'section/I')
107 bklm_module_tree.Branch(
'sector', sector,
'sector/I')
108 bklm_module_tree.Branch(
'layer', layer,
'layer/I')
109 bklm_module_tree.Branch(
'param', param,
'param/I')
110 bklm_module_tree.Branch(
'value', value,
'value/F')
111 bklm_module_tree.Branch(
'correction', correction,
'correction/F')
112 bklm_module_tree.Branch(
'error', error,
'error/F')
114 eklm_module_tree = ROOT.TTree(
'eklm_module',
'EKLM module alignment data')
115 eklm_module_tree.Branch(
'section', section,
'section/I')
116 eklm_module_tree.Branch(
'sector', sector,
'sector/I')
117 eklm_module_tree.Branch(
'layer', layer,
'layer/I')
118 eklm_module_tree.Branch(
'param', param,
'param/I')
119 eklm_module_tree.Branch(
'value', value,
'value/F')
120 eklm_module_tree.Branch(
'correction', correction,
'correction/F')
121 eklm_module_tree.Branch(
'error', error,
'error/F')
123 eklm_segment_tree = ROOT.TTree(
'eklm_segment',
'EKLM segment alignment data')
124 eklm_segment_tree.Branch(
'section', section,
'section/I')
125 eklm_segment_tree.Branch(
'sector', sector,
'sector/I')
126 eklm_segment_tree.Branch(
'layer', layer,
'layer/I')
127 eklm_segment_tree.Branch(
'plane', plane,
'plane/I')
128 eklm_segment_tree.Branch(
'segment', segment,
'segment/I')
129 eklm_segment_tree.Branch(
'param', param,
'param/I')
130 eklm_segment_tree.Branch(
'value', value,
'value/F')
131 eklm_segment_tree.Branch(
'correction', correction,
'correction/F')
132 eklm_segment_tree.Branch(
'error', error,
'error/F')
137 for ipar
in range(0, millepede.algo.result().getNoParameters()):
139 param[0] = label.getParameterId()
142 if millepede.algo.result().isParameterDetermined(ipar):
143 correction[0] = millepede.algo.result().getParameterCorrection(ipar)
144 error[0] = millepede.algo.result().getParameterError(ipar)
152 module = label.getElementId()
153 index.setKLMModule(module)
154 section[0] = index.getSection()
155 sector[0] = index.getSector()
156 layer[0] = index.getLayer()
157 if (index.getSubdetector() == KLMElementNumbers.c_BKLM):
158 if (bklm_alignment
is not None):
159 value[0] = bklm_alignment.getGlobalParam(module, int(param[0]))
160 bklm_module_tree.Fill()
162 if (eklm_alignment
is not None):
163 value[0] = eklm_alignment.getGlobalParam(module, int(param[0]))
164 eklm_module_tree.Fill()
167 elif (label.getUniqueId() ==
169 segment_global = label.getElementId()
170 index.setEKLMSegment(segment_global)
171 section[0] = index.getSection()
172 sector[0] = index.getSector()
173 layer[0] = index.getLayer()
174 plane[0] = index.getPlane()
175 segment[0] = index.getStrip()
176 if (eklm_segment_alignment
is not None):
177 value[0] = eklm_segment_alignment.getGlobalParam(segment, int(param[0]))
178 eklm_segment_tree.Fill()
180 if not millepede.algo.result().isParameterDetermined(ipar):
184 profile.SetBinContent(ibin, value[0])
185 profile.SetBinError(ibin, error[0])
189 bklm_module_tree.Write()
190 eklm_module_tree.Write()
191 eklm_segment_tree.Write()
192 alignment_file.Close()
Class to store BKLM alignment data in the database.
static unsigned short getGlobalUniqueID()
Get global unique identifier.
Class to store EKLM alignment data in the database.
static unsigned short getGlobalUniqueID()
Get global unique identifier.
Class to store EKLM alignment data in the database.
static unsigned short getGlobalUniqueID()
Get global unique identifier.
Class to convert to/from global labels for Millepede II to/from detector & parameter identificators.