19 double pma::Dist2(
const TVector2 & v1,
const TVector2 & v2)
21 double dx = v1.X() - v2.X(), dy = v1.Y() - v2.Y();
22 return dx * dx + dy * dy;
26 double dx = v1.X() - v2.X(), dy = v1.Y() - v2.Y();
27 return dx * dx + dy * dy;
30 double pma::Dist2(
const TVector3 & v1,
const TVector3 & v2)
32 double dx = v1.X() - v2.X(), dy = v1.Y() - v2.Y(), dz = v1.Z() - v2.Z();
33 return dx * dx + dy * dy + dz * dz;
37 double dx = v1.X() - v2.X(), dy = v1.Y() - v2.Y(), dz = v1.Z() - v2.Z();
38 return dx * dx + dy * dy + dz * dz;
44 for (
auto const&
hit : hits)
52 for (
auto const&
hit : hits)
54 sum +=
hit->SummedADC();
61 for (
auto const&
hit : hits)
63 sum +=
hit->GetAmplitude();
69 if (!exact && (hits.size() < 5))
return 0.0;
71 if (hits.size() == 0)
return 0.0;
73 TVector3
mean(0, 0, 0);
74 for (
size_t i = 0; i < hits.size(); i++)
76 mean += hits[i]->Point3D();
78 mean *= (1.0 / hits.size());
81 for (
size_t i = 1; i < hits.size(); i++)
84 if (r2 > max_r2) max_r2 = r2;
91 if (!exact && (hits.size() < 5))
return 0.0;
93 if (hits.size() == 0)
return 0.0;
96 for (
size_t i = 0; i < hits.size(); i++)
98 mean += hits[i]->Point2D();
100 mean *= (1.0 / hits.size());
103 for (
size_t i = 1; i < hits.size(); i++)
106 if (r2 > max_r2) max_r2 = r2;
113 TVector2 v0(p); v0 -= p0;
114 TVector2 v1(p1); v1 -= p0;
116 double v0Norm = v0.Mod();
117 double v1Norm = v1.Mod();
118 double mag = v0Norm * v1Norm;
120 if (mag != 0.0) cosine = v0 * v1 / mag;
122 return v0Norm * cosine / v1Norm;
130 double v0Norm = v0.R();
131 double v1Norm = v1.R();
132 double mag = v0Norm * v1Norm;
134 if (mag != 0.0) cosine = v0.Dot(v1) / mag;
136 return v0Norm * cosine / v1Norm;
141 TVector3 v0(p); v0 -= p0;
142 TVector3 v1(p1); v1 -= p0;
144 double v0Norm = v0.Mag();
145 double v1Norm = v1.Mag();
146 double mag = v0Norm * v1Norm;
148 if (mag != 0.0) cosine = v0 * v1 / mag;
150 return v0Norm * cosine / v1Norm;
158 double v0Norm = v0.R();
159 double v1Norm = v1.R();
160 double mag = v0Norm * v1Norm;
162 if (mag != 0.0) cosine = v0.Dot(v1) / mag;
164 return v0Norm * cosine / v1Norm;
169 TVector2 v1(p1); v1 -= p0;
179 TVector3 v1(p1); v1 -= p0;
193 result.SetXYZ(0., 0., 0.);
194 if (lines.size() < 2)
196 mf::LogError(
"pma::SolveLeastSquares3D") <<
"Need min. two lines.";
201 std::vector< TVectorT<double> > U, P;
202 for (
size_t v = 0; v < lines.size(); v++)
204 TVector3 point = lines[v].first;
205 TVector3
dir = lines[v].second;
206 dir -= point; m = dir.Mag();
211 P.push_back(TVectorT<double>(3));
212 P.back()[0] = point.X(); P.back()[1] = point.Y(); P.back()[2] = point.Z();
214 U.push_back(TVectorT<double>(3));
215 U.back()[0] = dir.X(); U.back()[1] = dir.Y(); U.back()[2] = dir.Z();
217 else mf::LogWarning(
"pma::SolveLeastSquares3D") <<
"Line undefined.";
221 mf::LogError(
"pma::SolveLeastSquares3D") <<
"Need min. two lines.";
225 TVectorT<double>
x(3),
y(3),
w(3);
226 TMatrixT<double> A(3, 3);
228 double s_uc2[3], s_ur_uc[3];
229 double s_p_uc2[3], s_p_ur_uc[3];
231 w[0] = 1.0; w[1] = 1.0; w[2] = 1.0;
232 for (
size_t r = 0; r < 3; r++)
235 for (
size_t c = 0; c < 3; c++)
237 s_uc2[c] = 0.0; s_ur_uc[c] = 0.0;
238 s_p_uc2[c] = 0.0; s_p_ur_uc[c] = 0.0;
240 for (
size_t v = 0; v < P.size(); v++)
249 s_uc2[c] += w[r] * w[c] * (1 - uc * uc);
250 s_p_uc2[c] += w[r] * w[r] * pc * (1 - uc * uc);
252 s_ur_uc[c] += w[r] * w[c] * ur * uc;
253 s_p_ur_uc[c] += w[r] * w[r] * pc * ur * uc;
263 y[r] -= s_p_ur_uc[c];
264 A(r, c) = -s_ur_uc[c];
268 try {
x = A.InvertFast() *
y; }
271 result.SetXYZ(0., 0., 0.);
return 1.0e12;
274 result.SetXYZ(
x[0],
x[1],
x[2]);
277 double dx, dy, dz, mse = 0.0;
278 for (
size_t v = 0; v < lines.size(); v++)
282 dx = result.X() - pproj.X();
283 dy = result.Y() - pproj.Y();
284 dz = result.Z() - pproj.Z();
286 mse += dx * dx + dy * dy + dz * dz;
288 return mse / lines.size();
300 TVector3 v0_3d(0., 0., 0.);
304 return v1_2d - v0_2d;
307 TVector2
pma::WireDriftToCm(
unsigned int wire,
float drift,
unsigned int plane,
unsigned int tpc,
unsigned int cryo)
318 TVector2
pma::CmToWireDrift(
float xw,
float yd,
unsigned int plane,
unsigned int tpc,
unsigned int cryo)
355 segStart(s0), segStop(s1)
357 if (s0 == s1)
mf::LogError(
"pma::bSegmentProjLess") <<
"Vectors equal!";
double GetSummedAmpl(const std::vector< pma::Hit3D * > &hits, unsigned int view=geo::kUnknown)
double GetHitsRadius2D(const std::vector< pma::Hit3D * > &hits, bool exact=false)
double Dist2(const TVector2 &v1, const TVector2 &v2)
::fhicl::TupleAs< Point(::geo::Length_t,::geo::Length_t,::geo::Length_t)> Point3D
Atom object for reading a 3D point or vector (centimeters).
bool operator()(pma::Hit3D *h1, pma::Hit3D *h2)
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
double GetHitsRadius3D(const std::vector< pma::Hit3D * > &hits, bool exact=false)
recob::tracking::Vector_t Vector3D
virtual double ConvertXToTicks(double X, int p, int t, int c) const =0
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
bSegmentProjLess(const TVector3 &s0, const TVector3 &s1)
size_t GetHitsCount(const std::vector< pma::Hit3D * > &hits, unsigned int view)
TVector2 GetProjectionToSegment(const TVector2 &p, const TVector2 &p0, const TVector2 &p1)
double GetDist2ToProj(void) const
ROOT::Math::DisplacementVector2D< ROOT::Math::Cartesian2D< double > > Vector2D
TVector2 GetVectorProjectionToPlane(const TVector3 &v, unsigned int plane, unsigned int tpc, unsigned int cryo)
double SolveLeastSquares3D(const std::vector< std::pair< TVector3, TVector3 > > &lines, TVector3 &result)
Detector simulation of raw signals on wires.
Track finding helper for the Projection Matching Algorithm.
virtual double ConvertTicksToX(double ticks, int p, int t, int c) const =0
TVector3 const & Point3D(void) const
double mean(const std::vector< short > &wf, size_t start, size_t nsample)
Implementation of the Projection Matching Algorithm.
bool operator()(pma::Hit3D *h1, pma::Hit3D *h2)
double GetSegmentProjVector(const TVector2 &p, const TVector2 &p0, const TVector2 &p1)
TVector2 WireDriftToCm(unsigned int wire, float drift, unsigned int plane, unsigned int tpc, unsigned int cryo)
TVector2 GetProjectionToPlane(const TVector3 &p, unsigned int plane, unsigned int tpc, unsigned int cryo)
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
TVector2 CmToWireDrift(float xw, float yd, unsigned int plane, unsigned int tpc, unsigned int cryo)
TPCGeo const & TPC(unsigned int const tpc=0, unsigned int const cstat=0) const
Returns the specified TPC.
double GetSummedADC(const std::vector< pma::Hit3D * > &hits, unsigned int view=geo::kUnknown)
PlaneGeo const & Plane(geo::View_t view) const
Return the plane in the tpc with View_t view.
double PlaneCoordinate(geo::Point_t const &point) const
Returns the coordinate of the point on the plane.
bool operator()(const pma::TrkCandidate &t1, const pma::TrkCandidate &t2)
double WirePitch() const
Return the wire pitch (in centimeters). It is assumed constant.
pma::Track3D * Track(void) const