Belle II Software development
runIPVXD_noCAF.py
1#!/usr/bin/env python3
2
3
10
11import basf2
12import ROOT
13from ROOT import Belle2
14import numpy as np
15
16from runIPVXD_CAF import get_calibration
17import millepede_calibration as mpc
18
19cal = get_calibration(dict(), [tag for tag in basf2.conditions.globaltags])
20collector_file = 'CollectorOutput.root'
21collector_file = mpc.collect(cal,
22 'dimuon_skim',
23 [f for f in Belle2.Environment.Instance().getInputFilesOverride()],
24 collector_file)
25mpc.calibrate(cal, [collector_file])
26
27algo = cal.algorithms[0].algorithm
28
29
30# Get the payloads into handy variables
31payloads = list(algo.getPayloads())
32vxd = None
33for payload in payloads:
34 if payload.name == 'VXDAlignment':
35 vxd = payload.object.IsA().DynamicCast(Belle2.VXDAlignment().IsA(), payload.object, False)
36
37
38# Profile plot for all determined parameters
39profile = ROOT.TH1F(
40 "profile",
41 "correction & errors",
42 algo.result().getNoDeterminedParameters(),
43 1,
44 algo.result().getNoDeterminedParameters())
45
46# Define some branch variables
47param = np.zeros(1, dtype=int)
48value = np.zeros(1, dtype=float)
49correction = np.zeros(1, dtype=float)
50error = np.zeros(1, dtype=float)
51layer = np.zeros(1, dtype=int)
52ladder = np.zeros(1, dtype=int)
53sensor = np.zeros(1, dtype=int)
54segment = np.zeros(1, dtype=int)
55x = np.zeros(1, dtype=float)
56y = np.zeros(1, dtype=float)
57z = np.zeros(1, dtype=float)
58eigenweight = np.zeros(1, dtype=float)
59
60# Tree with VXD data
61vxdtree = ROOT.TTree('vxd', 'VXD data')
62vxdtree.Branch('layer', layer, 'layer/I')
63vxdtree.Branch('ladder', ladder, 'ladder/I')
64vxdtree.Branch('sensor', sensor, 'sensor/I')
65vxdtree.Branch('segment', segment, 'segment/I')
66vxdtree.Branch('param', param, 'param/I')
67vxdtree.Branch('value', value, 'value/D')
68vxdtree.Branch('correction', correction, 'correction/D')
69vxdtree.Branch('error', error, 'error/D')
70vxdtree.Branch('x', x, 'x/D')
71vxdtree.Branch('y', y, 'y/D')
72vxdtree.Branch('z', z, 'z/D')
73vxdtree.Branch('eigenweight', eigenweight, 'eigenweight/D')
74
75corrections = Belle2.VXDAlignment()
76errors = Belle2.VXDAlignment()
77eigenweights = Belle2.VXDAlignment()
78
79# Index of determined param
80ibin = 0
81for ipar in range(0, algo.result().getNoParameters()):
82 if not algo.result().isParameterDetermined(ipar):
83 continue
84
85 ibin = ibin + 1
86
87 label = Belle2.GlobalLabel(algo.result().getParameterLabel(ipar))
88 param[0] = label.getParameterId()
89 correction[0] = algo.result().getParameterCorrection(ipar)
90 error[0] = algo.result().getParameterError(ipar)
91
92 if (label.getUniqueId() == Belle2.VXDAlignment.getGlobalUniqueID()):
93 sid = label.getElementId()
94 pid = label.getParameterId()
95 ew = algo.result().getEigenVectorElement(0, ipar) # + algo.result().getEigenVectorElement(1, ipar)
96
97 if vxd:
98 value[0] = vxd.get(sid, pid)
99 else:
100 value[0] = 0.
101 corrections.set(sid, pid, correction[0])
102 errors.set(sid, pid, error[0])
103 eigenweights.set(sid, pid, ew)
104
105 layer[0] = Belle2.VxdID(sid).getLayerNumber()
106 ladder[0] = Belle2.VxdID(sid).getLadderNumber()
107 sensor[0] = Belle2.VxdID(sid).getSensorNumber()
108 segment[0] = Belle2.VxdID(sid).getSegmentNumber()
109
110 x[0] = 0.
111 y[0] = 0.
112 z[0] = 0.
113 eigenweight[0] = ew
114 vxdtree.Fill()
115
116 profile.SetBinContent(ibin, value[0])
117 profile.SetBinError(ibin, error[0])
118
119condition = 0
120
121if algo.result().getNoEigenPairs():
122 maxEigenValue = algo.result().getEigenNumber(algo.result().getNoEigenPairs() - 1)
123 minEigenValue = algo.result().getEigenNumber(0)
124 condition = maxEigenValue / minEigenValue
125
126if condition:
127 print("Condition number of the matrix: ", condition)
128
129diagfile = ROOT.TFile('MillepedeJobDiagnostics.root', 'recreate')
130diagfile.cd()
131if vxd:
132 vxd.Write('values')
133corrections.Write('corrections')
134errors.Write('errors')
135eigenweights.Write('eigenweights')
136vxdtree.Write('vxdtree')
137profile.Write('profile')
138diagfile.Close()
static Environment & Instance()
Static method to get a reference to the Environment instance.
Definition: Environment.cc:28
Class to convert to/from global labels for Millepede II to/from detector & parameter identificators.
Definition: GlobalLabel.h:41
VXD alignment (and maybe some calibration) parameters.
Definition: VXDAlignment.h:19
static unsigned short getGlobalUniqueID()
Get global unique id.
Definition: VXDAlignment.h:47
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33