16from ROOT
import Belle2
17from ROOT.Belle2
import KLMChannelIndex, KLMElementNumbers
19from alignment
import MillepedeCalibration
21basf2.set_log_level(basf2.LogLevel.INFO)
23basf2.conditions.append_testing_payloads(
'localdb/database.txt')
26millepede = MillepedeCalibration([
'BKLMAlignment',
'EKLMAlignment',
'EKLMSegmentAlignment'])
29index = KLMChannelIndex(KLMChannelIndex.c_IndexLevelLayer)
30index2 = KLMChannelIndex(KLMChannelIndex.c_IndexLevelLayer)
31while (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]:
49index.setIndexLevel(KLMChannelIndex.c_IndexLevelStrip)
50index2.setIndexLevel(KLMChannelIndex.c_IndexLevelStrip)
51index = index2.beginEKLM()
52index.useEKLMSegments()
53while (index != index2.endEKLM()):
54 segment = index.getEKLMSegmentNumber()
56 millepede.fixGlobalParam(
62input_files = sys.argv[1:]
63calibration = millepede.create(
'klm_alignment', input_files)
64millepede.algo.setInputFileNames(input_files)
65millepede.algo.ignoreUndeterminedParams(
True)
66millepede.algo.invertSign()
67millepede.algo.execute()
68millepede.algo.commit()
71payloads = list(millepede.algo.getPayloads())
74eklm_segment_alignment =
None
75for 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())
92param = np.zeros(1, dtype=int)
93value = np.zeros(1, dtype=np.float32)
94correction = np.zeros(1, dtype=np.float32)
95error = np.zeros(1, dtype=np.float32)
96section = np.zeros(1, dtype=int)
97sector = np.zeros(1, dtype=int)
98layer = np.zeros(1, dtype=int)
99sensor = np.zeros(1, dtype=int)
100plane = np.zeros(1, dtype=int)
101segment = np.zeros(1, dtype=int)
103alignment_file = ROOT.TFile(
'alignment.root',
'recreate')
105bklm_module_tree = ROOT.TTree(
'bklm_module',
'BKLM module alignment data')
106bklm_module_tree.Branch(
'section', section,
'section/I')
107bklm_module_tree.Branch(
'sector', sector,
'sector/I')
108bklm_module_tree.Branch(
'layer', layer,
'layer/I')
109bklm_module_tree.Branch(
'param', param,
'param/I')
110bklm_module_tree.Branch(
'value', value,
'value/F')
111bklm_module_tree.Branch(
'correction', correction,
'correction/F')
112bklm_module_tree.Branch(
'error', error,
'error/F')
114eklm_module_tree = ROOT.TTree(
'eklm_module',
'EKLM module alignment data')
115eklm_module_tree.Branch(
'section', section,
'section/I')
116eklm_module_tree.Branch(
'sector', sector,
'sector/I')
117eklm_module_tree.Branch(
'layer', layer,
'layer/I')
118eklm_module_tree.Branch(
'param', param,
'param/I')
119eklm_module_tree.Branch(
'value', value,
'value/F')
120eklm_module_tree.Branch(
'correction', correction,
'correction/F')
121eklm_module_tree.Branch(
'error', error,
'error/F')
123eklm_segment_tree = ROOT.TTree(
'eklm_segment',
'EKLM segment alignment data')
124eklm_segment_tree.Branch(
'section', section,
'section/I')
125eklm_segment_tree.Branch(
'sector', sector,
'sector/I')
126eklm_segment_tree.Branch(
'layer', layer,
'layer/I')
127eklm_segment_tree.Branch(
'plane', plane,
'plane/I')
128eklm_segment_tree.Branch(
'segment', segment,
'segment/I')
129eklm_segment_tree.Branch(
'param', param,
'param/I')
130eklm_segment_tree.Branch(
'value', value,
'value/F')
131eklm_segment_tree.Branch(
'correction', correction,
'correction/F')
132eklm_segment_tree.Branch(
'error', error,
'error/F')
137for 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])
189bklm_module_tree.Write()
190eklm_module_tree.Write()
191eklm_segment_tree.Write()
192alignment_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.