38 """Calculate time associated with the candidate decay vertex using strawtubes MCPoint info."""
39 t0 = self.
tree.ShipEventHeader.GetEventTime()
40 candidate_pos = ROOT.TVector3()
41 candidate.GetVertex(candidate_pos)
43 d1, d2 = candidate.GetDaughter(0), candidate.GetDaughter(1)
44 d1_mc, d2_mc = self.
tree.fitTrack2MC[d1], self.
tree.fitTrack2MC[d2]
46 time_vtx_from_strawhits = []
48 for hit
in self.
tree.strawtubesPoint:
49 if not (int(str(hit.GetDetectorID())[:1]) == 1
or int(str(hit.GetDetectorID())[:1]) == 2):
52 if not (hit.GetTrackID() == d1_mc
or hit.GetTrackID() == d2_mc):
55 t_straw = hit.GetTime()
58 (candidate_pos.X() - hit.GetX()) ** 2
59 + (candidate_pos.Y() - hit.GetY()) ** 2
60 + (candidate_pos.Z() - hit.GetZ()) ** 2
63 d_mom = self.
tree.MCTrack[hit.GetTrackID()].GetP() / u.GeV
64 mass = self.
tree.MCTrack[hit.GetTrackID()].GetMass()
65 v = u.c_light * d_mom / np.sqrt(d_mom**2 + (mass) ** 2)
67 t_vertex = t_straw - (dist / v)
69 time_vtx_from_strawhits.append(t_vertex)
71 if not time_vtx_from_strawhits:
74 t_vtx = np.average(time_vtx_from_strawhits) + t0
79 """Calculate the impact parameter of the candidate relative to (0,0,target.z0)."""
80 candidate_pos = ROOT.TVector3()
81 candidate.GetVertex(candidate_pos)
83 candidate_mom = ROOT.TLorentzVector()
84 candidate.Momentum(candidate_mom)
85 target_point = ROOT.TVector3(0, 0, self.
ship_geo.target.z0)
88 if hasattr(candidate_mom,
"P"):
91 P = candidate_mom.Mag()
93 projection_factor += candidate_mom(i) / P * (target_point(i) - candidate_pos(i))
97 dist += (target_point(i) - candidate_pos(i) - projection_factor * candidate_mom(i) / P) ** 2
98 dist = ROOT.TMath.Sqrt(dist)
103 """Calculate the minimum distance(in XY plane) of the candidate decay vertex to the inner wall of the decay vessel. If outside the decay volume, return 0."""
104 candidate_pos = ROOT.TVector3()
105 candidate.GetVertex(candidate_pos)
106 position = (candidate_pos.X(), candidate_pos.Y(), candidate_pos.Z())
109 dalpha = 2 * ROOT.TMath.Pi() / nsteps
110 min_distance = float(
"inf")
117 for n
in range(nsteps):
120 ROOT.TMath.Sin(alpha),
121 ROOT.TMath.Cos(alpha),
129 min_distance = min(min_distance, distance)
151 """Return the momentum(Mag) of the particle's daughter tracks.
153 Tracks without a usable fit yield -1, which fails the preselection
157 t1, t2 = candidate.GetDaughter(0), candidate.GetDaughter(1)
158 tracks = get_tracks(self.
tree)
161 if not info.converged
or info.mom
is None or info.ndf <= 0:
162 daughter_mom.append(-1.0)
164 daughter_mom.append(info.mom.Mag())
166 return np.array(daughter_mom)
177 """Check if the candidate decay vertex is within the Fiducial Volume."""
178 candidate_pos = ROOT.TVector3()
179 candidate.GetVertex(candidate_pos)
181 if candidate_pos.Z() > self.
ship_geo.TrackStation1.z:
188 vertex_node = ROOT.gGeoManager.FindNode(candidate_pos.X(), candidate_pos.Y(), candidate_pos.Z())
189 vertex_elem = vertex_node.GetVolume().GetName()
190 return vertex_elem.startswith(
"decay_medium")
193 """Return the reduced chi^2 of the particle's daughter tracks.
195 Tracks without a usable fit yield infinity, which fails the
196 preselection chi^2 cut.
198 t1, t2 = candidate.GetDaughter(0), candidate.GetDaughter(1)
201 tracks = get_tracks(self.
tree)
204 if not info.converged
or info.ndf <= 0:
205 chi2ndf.append(float(
"inf"))
207 chi2ndf.append(info.chi2 / info.ndf)
209 return np.array(chi2ndf)
211 def preselection_cut(self, candidate, IP_cut: float = 250, show_table: bool =
False) -> bool:
213 Umbrella method to apply the pre-selection cuts on the candidate.
215 show_table=True tabulates the pre-selection parameters.
219 if len(self.
tree.Particles) != 1:
229 if self.
DOCA(candidate) >= 1 * u.cm:
231 if np.any(self.
nDOF(candidate) <= 25):
233 if np.any(self.
chi2nDOF(candidate) >= 5):
241 "Number of candidates in event",
242 len(self.
tree.Particles),
244 len(self.
tree.Particles) == 1,
247 "Time @ decay vertex (ns)",
253 "Impact Parameter (cm)",
255 f
"IP < {IP_cut * u.cm} cm",
260 self.
DOCA(candidate),
262 self.
DOCA(candidate) < 1 * u.cm,
265 "Is within Fiducial Volume?",
271 "Dist2InnerWall (cm)",
277 "Dist2VesselEntrance (cm)",
284 "Daughter Momentum [d1, d2] (GeV)",
290 "Degrees of Freedom [d1, d2]",
291 self.
nDOF(candidate),
293 np.all(self.
nDOF(candidate) > 25),
296 "Reduced Chi^2 [d1, d2]",
299 np.all(self.
chi2nDOF(candidate) < 5),
301 [
"\033[1mPre-selection passed:\033[0m",
"",
"", flag],
306 f
"\033[1;32m{row[3]}\033[0m" if row[3]
else f
"\033[1;31m{row[3]}\033[0m"
316 "Pre-selection Check",