11from datetime
import datetime
14import matplotlib.pyplot
as plt
17from ROOT
import Belle2
19from ROOT
import gSystem
20gSystem.Load(
'libtracking')
21gSystem.Load(
'libtracking_trackFindingCDC')
26 This Module is able to draw the content coming
from a QuadTreeImplementation
with debugOutput =
True.
31 Do not forget to set the ranges! Otherwise you will end up
with an empty plot..
33 basf2.Module.__init__(self)
54 Draw the quad tree content coming from the root file
if enabled.
64 hist = input_file.Get(
"histUsed")
66 xAxis = hist.GetXaxis()
67 yAxis = hist.GetYaxis()
69 x_edges = np.array([xAxis.GetBinLowEdge(iX)
for iX
in range(1, xAxis.GetNbins() + 2)])
70 y_edges = np.array([yAxis.GetBinLowEdge(iY)
for iY
in range(1, yAxis.GetNbins() + 2)])
72 arr_l = np.array([[hist.GetBinContent(iX, iY)
for iY
in range(1, yAxis.GetNbins() + 1)]
73 for iX
in range(1, xAxis.GetNbins() + 1)])
75 hist = input_file.Get(
"histUnused")
77 xAxis = hist.GetXaxis()
78 yAxis = hist.GetYaxis()
80 x_edges = np.array([xAxis.GetBinLowEdge(iX)
for iX
in range(1, xAxis.GetNbins() + 2)])
81 y_edges = np.array([yAxis.GetBinLowEdge(iY)
for iY
in range(1, yAxis.GetNbins() + 2)])
83 l2 = np.array([[hist.GetBinContent(iX, iY)
for iY
in range(1, yAxis.GetNbins() + 1)]
84 for iX
in range(1, xAxis.GetNbins() + 1)])
86 cmap = sb.cubehelix_palette(8, start=2, rot=0, dark=0, light=1, reverse=
False, as_cmap=
True)
88 plt.gca().pcolorfast(x_edges, y_edges, (arr_l + l2).T, cmap=cmap)
90 x_labels = [f
"{x:0.{int(not float(x).is_integer())}f}" if i % 4 == 0
else "" for i, x
in enumerate(x_edges)]
91 plt.xticks(x_edges, x_labels)
92 y_labels = [f
"{y:0.{int(not float(y).is_integer())}f}" if i % 4 == 0
else "" for i, y
in enumerate(y_edges)]
93 plt.yticks(y_edges, y_labels)
97 Save the plot to a svg and show it (maybe a png would be better?)
99 fileName = tempfile.gettempdir() + "/" + datetime.now().isoformat() +
'.svg'
100 plt.savefig(fileName)
105 Initialize the figure with the plot ranges
106 We need to implement axes labels later!
121 """Termination signal at the end of the event processing"""
128 Implementation of a quad tree plotter for SegmentQuadTrees
132 draw_segment_intersection = True and False
134 draw_segment =
True and False
136 draw_segment_averaged =
True and False
138 draw_segment_fitted =
True and False
140 draw_mc_information =
True and False
142 draw_mc_hits =
True and False
145 theta_shifted =
False
147 maximum_theta = np.pi
151 Calculate the point where the two given hits intersect
158 positionFront = first.getRecoPos2D().conformalTransformed()
159 positionBack = second.getRecoPos2D().conformalTransformed()
161 theta_cut = np.arctan2((positionBack - positionFront).x(), (positionFront - positionBack).y())
170 r_cut = positionFront.x() * np.cos(theta_cut) + positionFront.y() * np.sin(theta_cut)
172 return theta_cut, r_cut
176 Transform a given normal coordinate position to a legendre position (conformal transformed)
180 position: TrackFindingCDC.Vector2D
182 position = position.conformalTransformed()
185 r = position.x() * np.cos(theta) + position.y() * np.sin(theta)
191 Loop over all segments and execute a function
198 wrapped_vector = items.obj()
199 vector = wrapped_vector.get()
201 for quad_tree_item
in vector:
202 if quad_tree_item.getStereoType() == 0:
207 Convert given track parameters into a point in the legendre space
211 phi: phi of the track
213 charge: charge of the track
215 theta = phi + np.pi / 2
216 r = 1 / mag * 1.5 * 0.00299792458 * charge
231 Draw everything according to the given options
235 draw_segment_intersection
237 draw_segment_averaged
260 map = attributemaps.SegmentMCTrackIdColorMap()
264 plt.plot(theta, r, color=list(map(0, segment)), marker=
"o")
269 map = attributemaps.SegmentMCTrackIdColorMap()
273 plt.plot(theta, r, color=list(map(0, segment)), marker=
"", ls=
"-")
278 map = attributemaps.SegmentMCTrackIdColorMap()
281 middle_index = int(np.round(segment.size() / 2.0))
282 middle_point = list(segment.items())[middle_index]
286 plt.plot([theta_front, theta_back], [r_front, r_back], color=list(map(0, segment)), marker=
"o", ls=
"-")
291 map = attributemaps.SegmentMCTrackIdColorMap()
295 trajectory = fitter.fit(segment)
298 plt.plot(theta, r, color=list(map(0, segment)), marker=
"o")
305 wireHits = storedWireHits.obj().get()
308 cdc_hits = [cdcHits[i]
for track
in array
for i
in track.getHitIDs()]
310 for cdcHit
in cdcHits:
311 if cdcHit
in cdc_hits:
313 wireHit = wireHits.at(bisect.bisect_left(wireHits, cdcHit))
316 plt.plot(theta, r, marker=
"", color=
"black", ls=
"-", alpha=0.8)
320 wireHits = storedWireHits.obj().get()
322 map = attributemaps.listColors
327 mcTrackID = track.getMcTrackId()
329 for cdcHitID
in track.getHitIDs(Belle2.Const.CDC):
330 cdcHit = cdcHits[cdcHitID]
331 wireHit = wireHits.at(bisect.bisect_left(wireHits, cdcHit))
335 plt.plot(theta, r, marker=
"", color=map[mcTrackID % len(map)], ls=
"-", alpha=0.2)
338 map = attributemaps.listColors
342 momentum = track.getMomSeed()
346 mcTrackID = track.getMcTrackId()
348 plt.plot(theta, r, marker=
"o", color=
"black", ms=10)
349 plt.plot(theta, r, marker=
"o", color=map[mcTrackID % len(map)], ms=5)
357 Implementation of a quad tree plotter for StereoHitAssignment
363 draw_mc_tracks =
False
365 draw_track_hits =
False
367 draw_last_track =
True
369 delete_bad_hits =
False
373 Convert a genfit::TrackCand into a TrackFindingCDC.CDCTrajectory3D
377 track: genfit::TrackCand
382 position = Vector3D(track.getPosSeed())
383 momentum = Vector3D(track.getMomSeed())
384 charge = track.getChargeSeed()
386 return Trajectory3D(position, momentum, charge)
390 Use a cdc hit and a trajectory to reconstruct a CDCRecoHit3D
395 trajectory3D: TrackFindingCDC.CDCTrajectory3D
396 rlInfo: RightLeftInfo ( = short)
399 wireHits = storedWireHits.obj().get()
402 wireHit = wireHits.at(bisect.bisect_left(wireHits, cdcHit))
404 if rightLeftWireHit.getStereoType() != 0:
405 recoHit3D = CDCRecoHit3D.reconstruct(rightLeftWireHit, trajectory3D.getTrajectory2D())
412 Minim the task of the StereoQuadTree by showing the line of quadtree nodes
416 arr_l = np.array((np.array(recoHit3D.getRecoPos3D().z()) - z0) / recoHit3D.getArcLength2D())
424 if recoHit3D.getStereoType() == 0:
428 plt.plot(arr_l, z0, marker=
"", ls=
"-", alpha=0.4, color=color)
432 Draw the hit content according to the attributes
458 map = attributemaps.listColors
462 wrapped_vector = items.obj()
463 track_vector = wrapped_vector.get()
469 wireHits = storedWireHits.obj().get()
474 for track
in mc_track_cands:
475 mcTrackID = track.getMcTrackId()
478 for cdcHitID
in track.getHitIDs(Belle2.Const.CDC):
479 cdcHit = cdcHits[cdcHitID]
484 self.
plot_hit_line(leftRecoHit3D, color=map[mcTrackID % len(map)])
485 self.
plot_hit_line(rightRecoHit3D, color=map[mcTrackID % len(map)])
490 for track
in mc_track_cands:
491 mcTrackID = track.getMcTrackId()
493 z0 = trajectory.getTrajectorySZ().getZ0()
495 for cdcHitID
in track.getHitIDs(Belle2.Const.CDC):
496 cdcHit = cdcHits[cdcHitID]
497 recoHit3D = self.
create_reco_hit3D(cdcHit, trajectory, mcHitLookUp.getRLInfo(cdcHit))
500 arr_l = (recoHit3D.getRecoPos3D().z() - z0) / recoHit3D.getArcLength2D()
501 plt.plot(arr_l, z0, marker=
"o", color=map[mcTrackID % len(map)], ls=
"", alpha=0.2)
504 for id, track
in enumerate(track_vector):
505 for recoHit3D
in list(track.items()):
510 last_track = track_vector[-1]
511 trajectory = last_track.getStartTrajectory3D().getTrajectory2D()
513 for wireHit
in wireHits:
514 for rlInfo
in (-1, 1):
518 (wireHit.getRLInfo() != mcHitLookUp.getRLInfo(wireHit.getWireHit().getHit())
or
519 not recoHit3D.isInCellZBounds())):
522 if recoHit3D
in list(last_track.items()):
523 color = map[len(track_vector) % len(map)]
525 if wireHit.getRLInfo() == 1:
531 plt.xlabel(
r"$\tan \ \lambda$")
539 A wrapper around the svg drawer in the tracking package that
540 writes its output files
as a list to the queue
544 """ The same as the base class, except:
549 queue: The queue to write to
550 label: The key name in the queue
556 StereoQuadTreePlotter.__init__(self, *args, **kwargs)
562 """ Overwrite the terminate to put the list to the queue"""
563 StereoQuadTreePlotter.terminate(self)
567 """ Overwrite the function to listen for every new filename """
569 from datetime
import datetime
570 from matplotlib
import pyplot
as plt
572 fileName = tempfile.gettempdir() +
"/" + datetime.now().isoformat() +
'.svg'
573 plt.savefig(fileName)
A (simplified) python wrapper for StoreArray.
a (simplified) python wrapper for StoreObjPtr.
Interface class to the Monte Carlo information for individual hits.
Class representing an oriented hit wire including a hypotheses whether the causing track passes left ...
Class representing a three dimensional reconstructed hit.
static CDCRecoHit3D reconstruct(const CDCRecoHit2D &recoHit2D, const CDCTrajectory2D &trajectory2D)
Reconstructs the three dimensional hit from the two dimensional and the two dimensional trajectory.
static const CDCRiemannFitter & getOriginCircleFitter()
Static getter for an origin circle fitter.
Particle full three dimensional trajectory.
A two dimensional vector which is equipped with functions for correct handling of orientation relate...
A three dimensional vector.
def plot_quad_tree_content(self)
range_x_min
cached minimum x value
def save_and_show_file(self)
draw_quad_tree_content
cached flag to draw QuadTree
range_y_max
cached maximum y value
range_x_max
cached maximum x value
file_name_of_quad_tree_content
cached output filename
file_names
cached array of output filenames (one file per image)
def __init__(self, queue)
range_y_min
cached minimum y value
queue
cached value of the queue input parameter
def __init__(self, queue, label, *args, **kwargs)
label
The label for writing to the queue.
def save_and_show_file(self)
file_list
The list of created paths.
queue
The queue to handle.
bool draw_segment_averaged
by default, do not draw an averaged segment
bool draw_segment
by default, do not draw a segment
bool draw_segment_fitted
by default, do not draw a fitted segment
range_x_min
lower x bound for polar angle
bool draw_mc_hits
by default, do not draw the MC hits
bool draw_mc_information
by default, do not draw the MC information
def convertToQuadTreePicture(self, phi, mag, charge)
def calculatePositionInQuadTreePicture(self, position)
range_x_max
upper x bound for polar angle
np maximum_theta
an alias for the maximum value of the polar angle
bool draw_segment_intersection
by default, do not draw a segment intersection
def forAllAxialSegments(self, f)
bool theta_shifted
by default, polar angles and cuts are in the range (0,pi) rather than (-pi/2,+pi/2)
def calculateIntersectionInQuadTreePicture(self, first, second)
def get_plottable_line(self, recoHit3D)
def plot_hit_line(self, recoHit3D, color)
range_x_min
default lower x bound
bool draw_mc_hits
by default, do not draw the MC hits
bool delete_bad_hits
by default, do not delete the bad track hits
draw_quad_tree_content
by default, draw the QuadTree
bool draw_last_track
by default, draw the last track
range_y_max
default upper y bound
range_x_max
default upper x bound
def create_trajectory_from_track(self, track)
def create_reco_hit3D(self, cdcHit, trajectory3D, rlInfo)
bool draw_track_hits
by default, do not draw the track hits
range_y_min
default lower y bound
bool draw_mc_tracks
by default, do not draw the MC tracks