3 from ROOT
import Belle2
5 from ROOT
import gSystem
6 gSystem.Load(
'libtracking')
7 gSystem.Load(
'libtracking_trackFindingCDC')
9 import matplotlib.pyplot
as plt
10 import matplotlib.patches
as patches
11 import matplotlib.colors
as colors
12 import matplotlib.cm
as cmx
15 from datetime
import datetime
23 This Module is able to draw the content coming from a QuadTreeImplementation with debugOutput = True.
28 Do not forget to set the ranges! Otherwise you will end up with an empty plot..
30 basf2.Module.__init__(self)
51 Draw the quad tree content coming from the root file if enabled.
61 hist = input_file.Get(
"histUsed")
63 xAxis = hist.GetXaxis()
64 yAxis = hist.GetYaxis()
66 x_edges = np.array([xAxis.GetBinLowEdge(iX)
for iX
in range(1, xAxis.GetNbins() + 2)])
67 y_edges = np.array([yAxis.GetBinLowEdge(iY)
for iY
in range(1, yAxis.GetNbins() + 2)])
69 l = np.array([[hist.GetBinContent(iX, iY)
for iY
in range(1, yAxis.GetNbins() + 1)]
70 for iX
in range(1, xAxis.GetNbins() + 1)])
72 hist = input_file.Get(
"histUnused")
74 xAxis = hist.GetXaxis()
75 yAxis = hist.GetYaxis()
77 x_edges = np.array([xAxis.GetBinLowEdge(iX)
for iX
in xrange(1, xAxis.GetNbins() + 2)])
78 y_edges = np.array([yAxis.GetBinLowEdge(iY)
for iY
in xrange(1, yAxis.GetNbins() + 2)])
80 l2 = np.array([[hist.GetBinContent(iX, iY)
for iY
in xrange(1, yAxis.GetNbins() + 1)]
81 for iX
in xrange(1, xAxis.GetNbins() + 1)])
83 cmap = sb.cubehelix_palette(8, start=2, rot=0, dark=0, light=1, reverse=
False, as_cmap=
True)
85 plt.gca().pcolorfast(x_edges, y_edges, (l + l2).T, cmap=cmap)
87 x_labels = [
"{1:0.{0}f}".format(int(
not float(x).is_integer()), x)
if i % 4 == 0
else "" for i, x
in enumerate(x_edges)]
88 plt.xticks(x_edges, x_labels)
89 y_labels = [
"{1:0.{0}f}".format(int(
not float(y).is_integer()), y)
if i % 4 == 0
else "" for i, y
in enumerate(y_edges)]
90 plt.yticks(y_edges, y_labels)
94 Save the plot to a svg and show it (maybe a png would be better?)
96 fileName =
"/tmp/" + datetime.now().isoformat() +
'.svg'
102 Initialize the figure with the plot ranges
103 We need to implement axes labels later!
118 """Termination signal at the end of the event processing"""
125 Implementation of a quad tree plotter for SegmentQuadTrees
129 draw_segment_intersection =
True and False
131 draw_segment =
True and False
133 draw_segment_averaged =
True and False
135 draw_segment_fitted =
True and False
137 draw_mc_information =
True and False
139 draw_mc_hits =
True and False
142 theta_shifted =
False
144 maximum_theta = np.pi
148 Calculate the point where the two given hits intersect
155 positionFront = first.getRecoPos2D().conformalTransformed()
156 positionBack = second.getRecoPos2D().conformalTransformed()
158 theta_cut = np.arctan2((positionBack - positionFront).x(), (positionFront - positionBack).y())
167 r_cut = positionFront.x() * np.cos(theta_cut) + positionFront.y() * np.sin(theta_cut)
169 return theta_cut, r_cut
173 Transform a given normal coordinate position to a legendre position (conformal transformed)
177 position: TrackFindingCDC.Vector2D
179 position = position.conformalTransformed()
182 r = position.x() * np.cos(theta) + position.y() * np.sin(theta)
188 Loop over all segments and execute a function
195 wrapped_vector = items.obj()
196 vector = wrapped_vector.get()
198 for quad_tree_item
in vector:
199 if quad_tree_item.getStereoType() == 0:
204 Convert given track parameters into a point in the legendre space
208 phi: phi of the track
210 charge: charge of the track
212 theta = phi + np.pi / 2
213 r = 1 / mag * 1.5 * 0.00299792458 * charge
228 Draw everything according to the given options
232 draw_segment_intersection
234 draw_segment_averaged
257 map = attributemaps.SegmentMCTrackIdColorMap()
261 plt.plot(theta, r, color=list(map(0, segment)), marker=
"o")
266 map = attributemaps.SegmentMCTrackIdColorMap()
270 plt.plot(theta, r, color=list(map(0, segment)), marker=
"", ls=
"-")
275 map = attributemaps.SegmentMCTrackIdColorMap()
278 middle_index = int(np.round(segment.size() / 2.0))
279 middle_point = list(segment.items())[middle_index]
283 plt.plot([theta_front, theta_back], [r_front, r_back], color=list(map(0, segment)), marker=
"o", ls=
"-")
288 map = attributemaps.SegmentMCTrackIdColorMap()
292 trajectory = fitter.fit(segment)
295 plt.plot(theta, r, color=list(map(0, segment)), marker=
"o")
302 wireHits = storedWireHits.obj().get()
305 cdc_hits = [cdcHits[i]
for track
in array
for i
in track.getHitIDs()]
307 for cdcHit
in cdcHits:
308 if cdcHit
in cdc_hits:
310 wireHit = wireHits.at(bisect.bisect_left(wireHits, cdcHit))
313 plt.plot(theta, r, marker=
"", color=
"black", ls=
"-", alpha=0.8)
317 wireHits = storedWireHits.obj().get()
319 map = attributemaps.listColors
324 mcTrackID = track.getMcTrackId()
326 for cdcHitID
in track.getHitIDs(Belle2.Const.CDC):
327 cdcHit = cdcHits[cdcHitID]
328 wireHit = wireHits.at(bisect.bisect_left(wireHits, cdcHit))
332 plt.plot(theta, r, marker=
"", color=map[mcTrackID % len(map)], ls=
"-", alpha=0.2)
335 map = attributemaps.listColors
339 momentum = track.getMomSeed()
343 mcTrackID = track.getMcTrackId()
345 plt.plot(theta, r, marker=
"o", color=
"black", ms=10)
346 plt.plot(theta, r, marker=
"o", color=map[mcTrackID % len(map)], ms=5)
354 Implementation of a quad tree plotter for StereoHitAssignment
360 draw_mc_tracks =
False
362 draw_track_hits =
False
364 draw_last_track =
True
366 delete_bad_hits =
False
370 Convert a genfit::TrackCand into a TrackFindingCDC.CDCTrajectory3D
374 track: genfit::TrackCand
379 position =
Vector3D(track.getPosSeed())
380 momentum =
Vector3D(track.getMomSeed())
381 charge = track.getChargeSeed()
383 return Trajectory3D(position, momentum, charge)
387 Use a cdc hit and a trajectory to reconstruct a CDCRecoHit3D
392 trajectory3D: TrackFindingCDC.CDCTrajectory3D
393 rlInfo: RightLeftInfo ( = short)
396 wireHits = storedWireHits.obj().get()
399 wireHit = wireHits.at(bisect.bisect_left(wireHits, cdcHit))
401 if rightLeftWireHit.getStereoType() != 0:
402 recoHit3D = CDCRecoHit3D.reconstruct(rightLeftWireHit, trajectory3D.getTrajectory2D())
409 Minim the task of the StereoQuadTree by showing the line of quadtree nodes
413 l = np.array((np.array(recoHit3D.getRecoPos3D().z()) - z0) / recoHit3D.getArcLength2D())
421 if recoHit3D.getStereoType() == 0:
425 plt.plot(l, z0, marker=
"", ls=
"-", alpha=0.4, color=color)
429 Draw the hit content according to the attributes
455 map = attributemaps.listColors
459 wrapped_vector = items.obj()
460 track_vector = wrapped_vector.get()
466 wireHits = storedWireHits.obj().get()
471 for track
in mc_track_cands:
472 mcTrackID = track.getMcTrackId()
475 for cdcHitID
in track.getHitIDs(Belle2.Const.CDC):
476 cdcHit = cdcHits[cdcHitID]
481 self.
plot_hit_line(leftRecoHit3D, color=map[mcTrackID % len(map)])
482 self.
plot_hit_line(rightRecoHit3D, color=map[mcTrackID % len(map)])
487 for track
in mc_track_cands:
488 mcTrackID = track.getMcTrackId()
490 z0 = trajectory.getTrajectorySZ().getZ0()
492 for cdcHitID
in track.getHitIDs(Belle2.Const.CDC):
493 cdcHit = cdcHits[cdcHitID]
494 recoHit3D = self.
create_reco_hit3D(cdcHit, trajectory, mcHitLookUp.getRLInfo(cdcHit))
497 l = (recoHit3D.getRecoPos3D().z() - z0) / recoHit3D.getArcLength2D()
498 plt.plot(l, z0, marker=
"o", color=map[mcTrackID % len(map)], ls=
"", alpha=0.2)
501 for id, track
in enumerate(track_vector):
502 for recoHit3D
in list(track.items()):
507 last_track = track_vector[-1]
508 trajectory = last_track.getStartTrajectory3D().getTrajectory2D()
510 for wireHit
in wireHits:
511 for rlInfo
in (-1, 1):
515 (rlWireHit.getRLInfo() != mcHitLookUp.getRLInfo(rlWireHit.getWireHit().getHit())
or
516 not recoHit3D.isInCellZBounds())):
519 if recoHit3D
in list(last_track.items()):
520 color = map[len(track_vector) % len(map)]
522 if rlWireHit.getRLInfo() == 1:
528 plt.xlabel(
r"$\tan \ \lambda$")
536 A wrapper around the svg drawer in the tracking package that
537 writes its output files as a list to the queue
541 """ The same as the base class, except:
546 queue: The queue to write to
547 label: The key name in the queue
553 StereoQuadTreePlotter.__init__(self, *args, **kwargs)
559 """ Overwrite the terminate to put the list to the queue"""
560 StereoQuadTreePlotter.terminate(self)
564 """ Overwrite the function to listen for every new filename """
566 from datetime
import datetime
567 from matplotlib
import pyplot
as plt
569 fileName =
"/tmp/" + datetime.now().isoformat() +
'.svg'
570 plt.savefig(fileName)