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