Belle II Software  release-08-01-10
runIPVXD_noCAF.py
1 #!/usr/bin/env python3
2 
3 
10 
11 import basf2
12 import ROOT
13 from ROOT import Belle2
14 import numpy as np
15 
16 from runIPVXD_CAF import get_calibration
17 import millepede_calibration as mpc
18 
19 cal = get_calibration(dict(), [tag for tag in basf2.conditions.globaltags])
20 collector_file = 'CollectorOutput.root'
21 collector_file = mpc.collect(cal,
22  'dimuon_skim',
23  [f for f in Belle2.Environment.Instance().getInputFilesOverride()],
24  collector_file)
25 mpc.calibrate(cal, [collector_file])
26 
27 algo = cal.algorithms[0].algorithm
28 
29 
30 # Get the payloads into handy variables
31 payloads = list(algo.getPayloads())
32 vxd = None
33 for 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
39 profile = ROOT.TH1F(
40  "profile",
41  "correction & errors",
42  algo.result().getNoDeterminedParameters(),
43  1,
44  algo.result().getNoDeterminedParameters())
45 
46 # Define some branch variables
47 param = np.zeros(1, dtype=int)
48 value = np.zeros(1, dtype=float)
49 correction = np.zeros(1, dtype=float)
50 error = np.zeros(1, dtype=float)
51 layer = np.zeros(1, dtype=int)
52 ladder = np.zeros(1, dtype=int)
53 sensor = np.zeros(1, dtype=int)
54 segment = np.zeros(1, dtype=int)
55 x = np.zeros(1, dtype=float)
56 y = np.zeros(1, dtype=float)
57 z = np.zeros(1, dtype=float)
58 eigenweight = np.zeros(1, dtype=float)
59 
60 # Tree with VXD data
61 vxdtree = ROOT.TTree('vxd', 'VXD data')
62 vxdtree.Branch('layer', layer, 'layer/I')
63 vxdtree.Branch('ladder', ladder, 'ladder/I')
64 vxdtree.Branch('sensor', sensor, 'sensor/I')
65 vxdtree.Branch('segment', segment, 'segment/I')
66 vxdtree.Branch('param', param, 'param/I')
67 vxdtree.Branch('value', value, 'value/D')
68 vxdtree.Branch('correction', correction, 'correction/D')
69 vxdtree.Branch('error', error, 'error/D')
70 vxdtree.Branch('x', x, 'x/D')
71 vxdtree.Branch('y', y, 'y/D')
72 vxdtree.Branch('z', z, 'z/D')
73 vxdtree.Branch('eigenweight', eigenweight, 'eigenweight/D')
74 
75 corrections = Belle2.VXDAlignment()
76 errors = Belle2.VXDAlignment()
77 eigenweights = Belle2.VXDAlignment()
78 
79 # Index of determined param
80 ibin = 0
81 for 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 
119 condition = 0
120 
121 if algo.result().getNoEigenPairs():
122  maxEigenValue = algo.result().getEigenNumber(algo.result().getNoEigenPairs() - 1)
123  minEigenValue = algo.result().getEigenNumber(0)
124  condition = maxEigenValue / minEigenValue
125 
126 if condition:
127  print("Condition number of the matrix: ", condition)
128 
129 diagfile = ROOT.TFile('MillepedeJobDiagnostics.root', 'recreate')
130 diagfile.cd()
131 if vxd:
132  vxd.Write('values')
133 corrections.Write('corrections')
134 errors.Write('errors')
135 eigenweights.Write('eigenweights')
136 vxdtree.Write('vxdtree')
137 profile.Write('profile')
138 diagfile.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