62def runTracking(tracker, candidates, hits, resolution, fit_vertex=True):
63 """Find or fit tracks and, if the event qualifies, fit their vertex.
65 With ``candidates`` None, the tracker's own pattern recognition finds
66 the tracks. Otherwise ``candidates`` are dicts with ``indices`` into
67 ``hits`` (sorted by hit z in place), and each is fitted on its own.
69 Returns the fitted tracks (``SHiP::RecoTrack``, in the order of the
70 tracker's track indices), the fitted vertices (``SHiP::RecoVertex``) and,
71 per fitted track, the indices into ``hits`` that were used in the fit.
74 measurements = [tracker.AddMeasurement(h.detector_id, h.drift, resolution)
for h
in hits]
75 hit_of_measurement = {m: i
for i, m
in enumerate(measurements)
if m >= 0}
77 if candidates
is None:
80 for cand
in candidates:
81 cand[
"indices"].sort(key=
lambda i: hits[i].z)
86 for idx
in cand[
"indices"]:
87 if measurements[idx] < 0:
88 logger.warning(
"No ACTS surface for straw %d", hits[idx].detector_id)
90 if hits[idx].layer_key
not in seen_layers:
92 seen_layers.add(hits[idx].layer_key)
94 if len(used) < MIN_HITS_PER_TRACK:
95 logger.debug(
"Skipping track with too few hits: %d", len(used))
98 tracker.FitCandidate(ROOT.std.vector(
"int")([measurements[i]
for i
in used]))
100 tracks = [tracker.GetTrack(i)
for i
in range(tracker.GetNTracks())]
101 track_hit_indices = [
102 [hit_of_measurement[m]
for m
in tracker.GetTrackMeasurements(i)]
for i
in range(tracker.GetNTracks())
107 for i, track
in enumerate(tracks)
108 if track.nMeasurements() >= MIN_HITS_PER_TRACK
110 and track.chi2() / track.nDoF() <= MAX_CHI2_NDF
116 for i, j
in combinations(good, 2):
117 if tracks[i].charge() * tracks[j].charge() >= 0:
119 vertex = ROOT.SHiP.RecoVertex()
120 if tracker.FitVertex(ROOT.std.vector(
"int")([i, j]), vertex):
121 vertices.append(vertex)
123 logger.debug(
"Vertex fit failed for tracks %d and %d", i, j)
125 return tracks, vertices, track_hit_indices
129 """Match fitted tracks to SBT hits.
131 Each track is extrapolated to the plane of constant z through every SBT
132 hit. Returns one ``(hitID, distMin)`` per entry of ``selected_indices``,
133 with the distance in cm, to match the GenFit
134 ShipDigiReco.findVetoHitOnTrack; tracks with no match get
137 hits = [ROOT.TVector3(hit.GetX(), hit.GetY(), hit.GetZ())
for hit
in sbt_digis]
139 for track
in selected_indices:
140 hitID, distMin = NO_VETO_MATCH
141 for s_idx, hit
in enumerate(hits):
142 doca = tracker.DistanceToHit(int(track), hit)
143 if 0 <= doca < distMin:
144 hitID, distMin = s_idx, doca
145 veto_results.append((hitID, distMin))