11 from datetime
import datetime
13 import matplotlib.pyplot
as plt
16 from ROOT
import Belle2
18 from ROOT
import gSystem
19 gSystem.Load(
'libtracking')
20 gSystem.Load(
'libtracking_trackFindingCDC')
25 This Module is able to draw the content coming from a QuadTreeImplementation with debugOutput = True.
30 Do not forget to set the ranges! Otherwise you will end up with an empty plot..
32 basf2.Module.__init__(self)
53 Draw the quad tree content coming from the root file if enabled.
63 hist = input_file.Get(
"histUsed")
65 xAxis = hist.GetXaxis()
66 yAxis = hist.GetYaxis()
68 x_edges = np.array([xAxis.GetBinLowEdge(iX)
for iX
in range(1, xAxis.GetNbins() + 2)])
69 y_edges = np.array([yAxis.GetBinLowEdge(iY)
for iY
in range(1, yAxis.GetNbins() + 2)])
71 arr_l = np.array([[hist.GetBinContent(iX, iY)
for iY
in range(1, yAxis.GetNbins() + 1)]
72 for iX
in range(1, xAxis.GetNbins() + 1)])
74 hist = input_file.Get(
"histUnused")
76 xAxis = hist.GetXaxis()
77 yAxis = hist.GetYaxis()
79 x_edges = np.array([xAxis.GetBinLowEdge(iX)
for iX
in range(1, xAxis.GetNbins() + 2)])
80 y_edges = np.array([yAxis.GetBinLowEdge(iY)
for iY
in range(1, yAxis.GetNbins() + 2)])
82 l2 = np.array([[hist.GetBinContent(iX, iY)
for iY
in range(1, yAxis.GetNbins() + 1)]
83 for iX
in range(1, xAxis.GetNbins() + 1)])
85 cmap = sb.cubehelix_palette(8, start=2, rot=0, dark=0, light=1, reverse=
False, as_cmap=
True)
87 plt.gca().pcolorfast(x_edges, y_edges, (arr_l + l2).T, cmap=cmap)
89 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)]
90 plt.xticks(x_edges, x_labels)
91 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)]
92 plt.yticks(y_edges, y_labels)
96 Save the plot to a svg and show it (maybe a png would be better?)
98 fileName =
"/tmp/" + datetime.now().isoformat() +
'.svg'
104 Initialize the figure with the plot ranges
105 We need to implement axes labels later!
120 """Termination signal at the end of the event processing"""
127 Implementation of a quad tree plotter for SegmentQuadTrees
131 draw_segment_intersection =
True and False
133 draw_segment =
True and False
135 draw_segment_averaged =
True and False
137 draw_segment_fitted =
True and False
139 draw_mc_information =
True and False
141 draw_mc_hits =
True and False
144 theta_shifted =
False
146 maximum_theta = np.pi
150 Calculate the point where the two given hits intersect
157 positionFront = first.getRecoPos2D().conformalTransformed()
158 positionBack = second.getRecoPos2D().conformalTransformed()
160 theta_cut = np.arctan2((positionBack - positionFront).x(), (positionFront - positionBack).y())
169 r_cut = positionFront.x() * np.cos(theta_cut) + positionFront.y() * np.sin(theta_cut)
171 return theta_cut, r_cut
175 Transform a given normal coordinate position to a legendre position (conformal transformed)
179 position: TrackFindingCDC.Vector2D
181 position = position.conformalTransformed()
184 r = position.x() * np.cos(theta) + position.y() * np.sin(theta)
190 Loop over all segments and execute a function
197 wrapped_vector = items.obj()
198 vector = wrapped_vector.get()
200 for quad_tree_item
in vector:
201 if quad_tree_item.getStereoType() == 0:
206 Convert given track parameters into a point in the legendre space
210 phi: phi of the track
212 charge: charge of the track
214 theta = phi + np.pi / 2
215 r = 1 / mag * 1.5 * 0.00299792458 * charge
230 Draw everything according to the given options
234 draw_segment_intersection
236 draw_segment_averaged
259 map = attributemaps.SegmentMCTrackIdColorMap()
263 plt.plot(theta, r, color=list(map(0, segment)), marker=
"o")
268 map = attributemaps.SegmentMCTrackIdColorMap()
272 plt.plot(theta, r, color=list(map(0, segment)), marker=
"", ls=
"-")
277 map = attributemaps.SegmentMCTrackIdColorMap()
280 middle_index = int(np.round(segment.size() / 2.0))
281 middle_point = list(segment.items())[middle_index]
285 plt.plot([theta_front, theta_back], [r_front, r_back], color=list(map(0, segment)), marker=
"o", ls=
"-")
290 map = attributemaps.SegmentMCTrackIdColorMap()
294 trajectory = fitter.fit(segment)
296 theta, r = self.
convertToQuadTreePictureconvertToQuadTreePicture(momentum.phi(), momentum.norm(), trajectory.getChargeSign())
297 plt.plot(theta, r, color=list(map(0, segment)), marker=
"o")
304 wireHits = storedWireHits.obj().get()
307 cdc_hits = [cdcHits[i]
for track
in array
for i
in track.getHitIDs()]
309 for cdcHit
in cdcHits:
310 if cdcHit
in cdc_hits:
312 wireHit = wireHits.at(bisect.bisect_left(wireHits, cdcHit))
315 plt.plot(theta, r, marker=
"", color=
"black", ls=
"-", alpha=0.8)
319 wireHits = storedWireHits.obj().get()
321 map = attributemaps.listColors
326 mcTrackID = track.getMcTrackId()
328 for cdcHitID
in track.getHitIDs(Belle2.Const.CDC):
329 cdcHit = cdcHits[cdcHitID]
330 wireHit = wireHits.at(bisect.bisect_left(wireHits, cdcHit))
334 plt.plot(theta, r, marker=
"", color=map[mcTrackID % len(map)], ls=
"-", alpha=0.2)
337 map = attributemaps.listColors
341 momentum = track.getMomSeed()
344 theta, r = self.
convertToQuadTreePictureconvertToQuadTreePicture(momentum.Phi(), momentum.Mag(), track.getChargeSeed())
345 mcTrackID = track.getMcTrackId()
347 plt.plot(theta, r, marker=
"o", color=
"black", ms=10)
348 plt.plot(theta, r, marker=
"o", color=map[mcTrackID % len(map)], ms=5)
356 Implementation of a quad tree plotter for StereoHitAssignment
362 draw_mc_tracks =
False
364 draw_track_hits =
False
366 draw_last_track =
True
368 delete_bad_hits =
False
372 Convert a genfit::TrackCand into a TrackFindingCDC.CDCTrajectory3D
376 track: genfit::TrackCand
381 position =
Vector3D(track.getPosSeed())
382 momentum =
Vector3D(track.getMomSeed())
383 charge = track.getChargeSeed()
385 return Trajectory3D(position, momentum, charge)
389 Use a cdc hit and a trajectory to reconstruct a CDCRecoHit3D
394 trajectory3D: TrackFindingCDC.CDCTrajectory3D
395 rlInfo: RightLeftInfo ( = short)
398 wireHits = storedWireHits.obj().get()
401 wireHit = wireHits.at(bisect.bisect_left(wireHits, cdcHit))
403 if rightLeftWireHit.getStereoType() != 0:
404 recoHit3D = CDCRecoHit3D.reconstruct(rightLeftWireHit, trajectory3D.getTrajectory2D())
411 Minim the task of the StereoQuadTree by showing the line of quadtree nodes
415 arr_l = np.array((np.array(recoHit3D.getRecoPos3D().z()) - z0) / recoHit3D.getArcLength2D())
423 if recoHit3D.getStereoType() == 0:
427 plt.plot(arr_l, z0, marker=
"", ls=
"-", alpha=0.4, color=color)
431 Draw the hit content according to the attributes
457 map = attributemaps.listColors
461 wrapped_vector = items.obj()
462 track_vector = wrapped_vector.get()
468 wireHits = storedWireHits.obj().get()
473 for track
in mc_track_cands:
474 mcTrackID = track.getMcTrackId()
477 for cdcHitID
in track.getHitIDs(Belle2.Const.CDC):
478 cdcHit = cdcHits[cdcHitID]
483 self.
plot_hit_lineplot_hit_line(leftRecoHit3D, color=map[mcTrackID % len(map)])
484 self.
plot_hit_lineplot_hit_line(rightRecoHit3D, color=map[mcTrackID % len(map)])
489 for track
in mc_track_cands:
490 mcTrackID = track.getMcTrackId()
492 z0 = trajectory.getTrajectorySZ().getZ0()
494 for cdcHitID
in track.getHitIDs(Belle2.Const.CDC):
495 cdcHit = cdcHits[cdcHitID]
496 recoHit3D = self.
create_reco_hit3Dcreate_reco_hit3D(cdcHit, trajectory, mcHitLookUp.getRLInfo(cdcHit))
499 arr_l = (recoHit3D.getRecoPos3D().z() - z0) / recoHit3D.getArcLength2D()
500 plt.plot(arr_l, z0, marker=
"o", color=map[mcTrackID % len(map)], ls=
"", alpha=0.2)
503 for id, track
in enumerate(track_vector):
504 for recoHit3D
in list(track.items()):
505 self.
plot_hit_lineplot_hit_line(recoHit3D, color=map[id % len(map)])
509 last_track = track_vector[-1]
510 trajectory = last_track.getStartTrajectory3D().getTrajectory2D()
512 for wireHit
in wireHits:
513 for rlInfo
in (-1, 1):
517 (wireHit.getRLInfo() != mcHitLookUp.getRLInfo(wireHit.getWireHit().getHit())
or
518 not recoHit3D.isInCellZBounds())):
521 if recoHit3D
in list(last_track.items()):
522 color = map[len(track_vector) % len(map)]
524 if wireHit.getRLInfo() == 1:
530 plt.xlabel(
r"$\tan \ \lambda$")
538 A wrapper around the svg drawer in the tracking package that
539 writes its output files as a list to the queue
543 """ The same as the base class, except:
548 queue: The queue to write to
549 label: The key name in the queue
555 StereoQuadTreePlotter.__init__(self, *args, **kwargs)
561 """ Overwrite the terminate to put the list to the queue"""
562 StereoQuadTreePlotter.terminate(self)
566 """ Overwrite the function to listen for every new filename """
568 from datetime
import datetime
569 from matplotlib
import pyplot
as plt
571 fileName =
"/tmp/" + datetime.now().isoformat() +
'.svg'
572 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 handeling of orientation relat...
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)
maximum_theta
an alias for the maximum value of the polar angle
def calculatePositionInQuadTreePicture(self, position)
range_x_max
upper x bound for 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
HepGeom::Vector3D< double > Vector3D
3D Vector