13 #include "Math/GenVector/DisplacementVector2D.h"
18 #include "messagefacility/MessageLogger/MessageLogger.h"
48 for (
auto h : fAssignedHits)
52 unsigned int view =
h->View2D();
54 sum += OptFactor(view) *
h->GetSigmaFactor()
86 TVector3 v3dStart(vStart->
Point3D());
87 TVector3 v3dStop(vStop->
Point3D());
89 double v0Norm = v0.Mod();
90 double v1Norm = v1.Mod();
92 TVector3 result(0, 0, 0);
95 double mag = v0Norm * v1Norm;
97 if (mag != 0.0) cosine = v0 * v1 / mag;
98 double b = v0Norm * cosine / v1Norm;
103 if (b > 0.0) result += (v3d * b);
105 else result = v3dStop;
109 mf::LogWarning(
"pma::Segment3D") <<
"Short segment projection.";
129 TVector3 v3d(vStop->
Point3D());
132 double v0Norm = v0.Mod();
133 double v1Norm = v1.Mod();
136 double mag = v0Norm * v1Norm;
138 if (mag != 0.0) cosine = v0 * v1 / mag;
139 double b = v0Norm * cosine / v1Norm;
141 return vStart->
Point3D() + (v3d * b);
158 auto const & pointStart = vStart->
Point3D();
159 auto const & pointStop = vStop->
Point3D();
165 h.
Point2D().X() - projStart.X(),
166 h.
Point2D().Y() - projStart.Y());
169 projStop.X() - projStart.X(),
170 projStop.Y() - projStart.Y());
173 pointStop.X() - pointStart.X(),
174 pointStop.Y() - pointStart.Y(),
175 pointStop.Z() - pointStart.Z());
177 double v0Norm = sqrt(v0.Mag2());
178 double v1Norm = sqrt(v1.Mag2());
181 double mag = v0Norm * v1Norm;
183 if (mag != 0.0) cosine = v0.Dot(v1) / mag;
184 double b = v0Norm * cosine / v1Norm;
192 pointStart.X() + v3d.X(),
193 pointStart.Y() + v3d.Y(),
194 pointStart.Z() + v3d.Z());
199 0.5 * (projStart.X() + projStop.X()),
200 0.5 * (projStart.Y() + projStop.Y()), 0.0
F);
203 0.5 * (pointStart.X() + pointStop.X()),
204 0.5 * (pointStart.Y() + pointStop.Y()),
205 0.5 * (pointStart.Z() + pointStop.Z()));
215 mf::LogError(
"pma::Segment3D") <<
"Segment endpoints not set.";
223 pma::Vector3D v0(psrc.X() - p0.X(), psrc.Y() - p0.Y(), psrc.Z() - p0.Z());
224 pma::Vector3D v1(p1.X() - p0.X(), p1.Y() - p0.Y(), p1.Z() - p0.Z());
225 pma::Vector3D v2(psrc.X() - p1.X(), psrc.Y() - p1.Y(), psrc.Z() - p1.Z());
227 double v1Norm2 = v1.Mag2();
228 if (v1Norm2 >= 1.0
E-6)
230 double v0v1 = v0.Dot(v1);
231 double v2v1 = v2.Dot(v1);
232 double v0Norm2 = v0.Mag2();
233 double v2Norm2 = v2.Mag2();
236 if ((v0v1 > 0.0) && (v2v1 < 0.0))
238 double cosine01_square = 0.0;
239 double mag01_square = v0Norm2 * v1Norm2;
240 if (mag01_square != 0.0) cosine01_square = v0v1 * v0v1 / mag01_square;
242 result = (1.0 - cosine01_square) * v0Norm2;
246 if (v0v1 <= 0.0) result = 1.0001 * v0Norm2;
247 else result = 1.0001 * v2Norm2;
250 if (result >= 0.0)
return result;
255 double dx = 0.5 * (p0.X() + p1.X()) - psrc.X();
256 double dy = 0.5 * (p0.Y() + p1.Y()) - psrc.Y();
257 double dz = 0.5 * (p0.Z() + p1.Z()) - psrc.Z();
258 return dx * dx + dy * dy + dz * dz;
268 double v1Norm2 = v1.Mag2();
269 if (v1Norm2 >= 1.0
E-6)
271 double v0v1 = v0.Dot(v1);
272 double v2v1 = v2.Dot(v1);
273 double v0Norm2 = v0.Mag2();
274 double v2Norm2 = v2.Mag2();
277 if ((v0v1 > 0.0) && (v2v1 < 0.0))
279 double cosine01_square = 0.0;
280 double mag01_square = v0Norm2 * v1Norm2;
281 if (mag01_square != 0.0) cosine01_square = v0v1 * v0v1 / mag01_square;
283 result = (1.0 - cosine01_square) * v0Norm2;
287 if (v0v1 <= 0.0) result = 1.0001 * v0Norm2;
288 else result = 1.0001 * v2Norm2;
290 if (result >= 0.0)
return result;
295 double dx = 0.5 * (p0.X() + p1.X()) - psrc.X();
296 double dy = 0.5 * (p0.Y() + p1.Y()) - psrc.Y();
297 return dx * dx + dy * dy;
TVector3 const & Point3D() const
TVector2 const & Projection2D(unsigned int view) const
double Dist2(const TVector2 &v1, const TVector2 &v2)
double GetDistance2To(const TVector3 &p3d) const override
Distance [cm] from the 3D segment to the point 3D.
Implementation of the Projection Matching Algorithm.
::fhicl::TupleAs< Point(::geo::Length_t,::geo::Length_t,::geo::Length_t)> Point3D
Atom object for reading a 3D point or vector (centimeters).
double SumDist2Hits(void) const override
recob::tracking::Vector_t Vector3D
int TPC(void) const
TPC index or -1 if out of any TPC.
double Length2(void) const override
TVector3 GetProjection(const TVector2 &p, unsigned int view) const
Get 3D projection of a 2D point from the view.
unsigned int View2D() const noexcept
void SetProjection(pma::Hit3D &h) const override
Set hit 3D position and its 2D projection to the vertex.
Implementation of the Projection Matching Algorithm.
void SetProjection(const TVector2 &p, float b)
TVector3 GetUnconstrainedProj3D(const TVector2 &p2d, unsigned int view) const override
TVector2 const & Point2D() const noexcept
int Cryo(void) const
Cryostat index or -1 if out of any cryostat.
void SetPoint3D(const TVector3 &p3d)
ROOT::Math::DisplacementVector2D< ROOT::Math::Cartesian2D< double > > Vector2D
physics associatedGroupsWithLeft p1
pma::Vector3D GetDirection3D(void) const override
Get 3D direction cosines of this segment.
static double GetDist2(const TVector3 &psrc, const TVector3 &p0, const TVector3 &p1)