20from ROOT
import Belle2
23b2.set_random_seed(10346)
28 Histogram the difference position residuals and pulls between clusters
and truehits.
33 Create histograms for pulls
and residuals
45 self.
rfile = ROOT.TFile(
"PXDPositionEstimation.root",
"RECREATE")
60 f
'Particle momentum kind={kind:d}', 5000, 0.0, 10.0)
62 f
'Particle angle thetaU kind={kind:d}', 180, -90, +90)
64 f
'Particle angle thetaV kind={kind:d}', 180, -90, +90)
66 f
'Cluster charge kind={kind:d}', 255, 0.0, 255.0)
81 self.
hist_map_residual_u[(kind, mode)] = ROOT.TH1F(f
'hist_map_residual_u_kind_{kind:d}_mode_{mode:d}',
82 f
'PXD residual U kind={kind:d} mode={mode:d}',
84 self.
hist_map_residual_v[(kind, mode)] = ROOT.TH1F(f
'hist_map_residual_v_kind_{kind:d}_mode_{mode:d}',
85 f
'PXD residual V kind={kind:d} mode={mode:d}',
88 f
'PXD residual pull U kind={kind:d} mode={mode:d}',
91 f
'PXD residual pull V kind={kind:d} mode={mode:d}',
101 name = f
'hist_map_residual_v_kind_{kind:d}_mode_{mode:d}_special_{bin:d}'
102 title = f
'PXD residual V kind={kind:d} mode={mode:d} {self.binlimits[bin][0]:.0f}' + \
103 f
'<thetaV<{self.binlimits[bin][1]:.0f}'
107 """Fill the residual and pull histograms"""
112 for truehit
in truehits:
115 clusters = truehit.getRelationsFrom(
"PXDClusters")
118 for j, cls
in enumerate(clusters):
121 if clusters.weight(j) < 100:
124 mom = truehit.getMomentum()
127 thetaU = math.atan(tu) * 180 / math.pi
128 thetaV = math.atan(tv) * 180 / math.pi
137 clusterkind = cls.getKind()
142 if clusterkind <= 3
and mom.Mag() > 0.02:
160 pull_u = (truehit.getU() - cls.getU()) / cls.getUSigma()
161 pull_v = (truehit.getV() - cls.getV()) / cls.getVSigma()
175 shape_likelyhood = PositionEstimator.getShapeLikelyhood(cls, tu, tv)
176 if shape_likelyhood > 0:
179 offset = PositionEstimator.getClusterOffset(cls, tu, tv)
186 shiftU = sensor_info.getUCellPosition(cls.getUStart())
187 shiftV = sensor_info.getVCellPosition(cls.getVStart())
191 pull_u = (truehit.getU() - shiftU - offset.getU()) / (math.sqrt(offset.getUSigma2()))
192 pull_v = (truehit.getV() - shiftV - offset.getV()) / (math.sqrt(offset.getVSigma2()))
194 self.
hist_map_residual_u[(clusterkind, mode)].Fill(truehit.getU() - shiftU - offset.getU())
195 self.
hist_map_residual_v[(clusterkind, mode)].Fill(truehit.getV() - shiftV - offset.getV())
201 truehit.getV() - shiftV - offset.getV())
204 truehit.getV() - shiftV - offset.getV())
207 truehit.getV() - shiftV - offset.getV())
211 self.
hist_map_residual_u[(clusterkind, mode)].Fill(truehit.getU() - shiftU - offset.getU())
212 self.
hist_map_residual_v[(clusterkind, mode)].Fill(truehit.getV() - shiftV - offset.getV())
218 truehit.getV() - shiftV - offset.getV())
221 truehit.getV() - shiftV - offset.getV())
224 truehit.getV() - shiftV - offset.getV())
230 pull_u = (truehit.getU() - cls.getU()) / cls.getUSigma()
231 pull_v = (truehit.getV() - cls.getV()) / cls.getVSigma()
247 Format and write all histograms
and plot them
250 for kind
in range(5):
267 for kind
in range(4):
268 for mode
in range(3):
290 hcoverage = ROOT.TH1F(
"hist_coverage",
'Coverage of corrections', 2, 1, 2)
293 hcoverage.SetLineWidth(2)
294 hcoverage.SetYTitle(
'coverage / %')
295 hcoverage.SetTitle(
'Coverage of cluster shape corrections')
297 print(f
"Coverage of cluster shape corrections is {100.0 * float(self.nfound_offset / self.nclusters):.2f}% ")
298 print(f
"Coverage of cluster shape likelyhoods is {100.0 * float(self.nfound_shapes / self.nclusters):.2f}% ")
304if __name__ ==
"__main__":
310 parser = argparse.ArgumentParser(description=
"Test cluster shape corrections on generic BBbar events")
314 default=
'/home/benjamin/prerelease-01-00-00b-validation/samples',
316 help=
'Location of bg overlay files')
317 parser.add_argument(
'--bkgOverlay', dest=
'bkgOverlay', action=
"store_true", help=
'Perform background overlay')
318 args = parser.parse_args()
321 bkgfiles = glob.glob(args.bglocation +
'/*.root')
322 if len(bkgfiles) == 0:
323 print(
'No BG overlay files found')
327 main = b2.create_path()
328 main.add_module(
"EventInfoSetter", evtNumList=[10000])
329 main.add_module(
"Gearbox")
331 main.add_module(
"Geometry", components=[
'MagneticField',
'BeamPipe',
'PXD'], useDB=
False)
334 main.add_module(
"EvtGenInput")
339 bkginput = b2.register_module(
'BGOverlayInput')
340 bkginput.param(
'inputFileNames', bkgfiles)
341 main.add_module(bkginput)
343 main.add_module(
"FullSim")
344 main.add_module(
"PXDDigitizer")
349 main.add_module(
'BGOverlayExecutor', PXDDigitsName=
'')
350 main.add_module(
"PXDDigitSorter", digits=
'')
352 main.add_module(
"ActivatePXDClusterPositionEstimator")
353 main.add_module(
"PXDClusterizer")
356 main.add_module(positionestimation)
357 main.add_module(
"Progress")
Class PXDTrueHit - Records of tracks that either enter or leave the sensitive volume.
static PXDClusterPositionEstimator & getInstance()
Main (and only) way to access the PXDClusterPositionEstimator.
A (simplified) python wrapper for StoreArray.
static GeoCache & getInstance()
Return a reference to the singleton instance.
hist_map_clustercharge
Histograms for cluster charge related to particle.
hist_map_theta_u
Histograms for true particle angle thetaU.
rfile
Output file to store all plots.
hist_map_residual_pull_v
Histograms for v residual pulls.
nfound_offset
Counter for clusters where position correction was found in payload.
hist_map_residual_v_special
Histograms for v residuals for smaller thetaV range.
binlimits
ThetaV angle ranges for v residuals.
nclusters
Counter for all clusters.
hist_map_residual_pull_u
Histograms for u residual pulls.
nfound_shapes
Counter for cluster where shape likelyhood was found in payload.
hist_map_momentum
Histograms for true particle momenta.
hist_map_residual_u
Histograms for u residuals.
hist_map_theta_v
Histograms for true particle angle thetaV.
hist_map_residual_v
Histograms for v residuals.