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;
33 for (
auto const&
hit : hits)
41 for (
auto const&
hit : hits)
43 sum +=
hit->SummedADC();
50 for (
auto const&
hit : hits)
52 sum +=
hit->GetAmplitude();
58 if (!exact && (hits.size() < 5))
return 0.0;
60 if (hits.size() == 0)
return 0.0;
62 TVector3
mean(0, 0, 0);
63 for (
size_t i = 0; i < hits.size(); i++)
65 mean += hits[i]->Point3D();
67 mean *= (1.0 / hits.size());
70 for (
size_t i = 1; i < hits.size(); i++)
73 if (r2 > max_r2) max_r2 = r2;
80 if (!exact && (hits.size() < 5))
return 0.0;
82 if (hits.size() == 0)
return 0.0;
85 for (
size_t i = 0; i < hits.size(); i++)
87 mean += hits[i]->Point2D();
89 mean *= (1.0 / hits.size());
92 for (
size_t i = 1; i < hits.size(); i++)
95 if (r2 > max_r2) max_r2 = r2;
102 TVector2 v0(p); v0 -= p0;
103 TVector2 v1(p1); v1 -= p0;
105 double v0Norm = v0.Mod();
106 double v1Norm = v1.Mod();
107 double mag = v0Norm * v1Norm;
109 if (mag != 0.0) cosine = v0 * v1 / mag;
111 return v0Norm * cosine / v1Norm;
119 double v0Norm = v0.R();
120 double v1Norm = v1.R();
121 double mag = v0Norm * v1Norm;
123 if (mag != 0.0) cosine = v0.Dot(v1) / mag;
125 return v0Norm * cosine / v1Norm;
130 TVector3 v0(p); v0 -= p0;
131 TVector3 v1(p1); v1 -= p0;
133 double v0Norm = v0.Mag();
134 double v1Norm = v1.Mag();
135 double mag = v0Norm * v1Norm;
137 if (mag != 0.0) cosine = v0 * v1 / mag;
139 return v0Norm * cosine / v1Norm;
147 double v0Norm = v0.R();
148 double v1Norm = v1.R();
149 double mag = v0Norm * v1Norm;
151 if (mag != 0.0) cosine = v0.Dot(v1) / mag;
153 return v0Norm * cosine / v1Norm;
158 TVector2 v1(p1); v1 -= p0;
168 TVector3 v1(p1); v1 -= p0;
182 result.SetXYZ(0., 0., 0.);
183 if (lines.size() < 2)
185 mf::LogError(
"pma::SolveLeastSquares3D") <<
"Need min. two lines.";
190 std::vector< TVectorT<double> > U, P;
191 for (
size_t v = 0; v < lines.size(); v++)
193 TVector3 point = lines[v].first;
194 TVector3
dir = lines[v].second;
195 dir -= point; m = dir.Mag();
200 P.push_back(TVectorT<double>(3));
201 P.back()[0] = point.X(); P.back()[1] = point.Y(); P.back()[2] = point.Z();
203 U.push_back(TVectorT<double>(3));
204 U.back()[0] = dir.X(); U.back()[1] = dir.Y(); U.back()[2] = dir.Z();
206 else mf::LogWarning(
"pma::SolveLeastSquares3D") <<
"Line undefined.";
210 mf::LogError(
"pma::SolveLeastSquares3D") <<
"Need min. two lines.";
214 TVectorT<double>
x(3),
y(3),
w(3);
215 TMatrixT<double> A(3, 3);
217 double s_uc2[3], s_ur_uc[3];
218 double s_p_uc2[3], s_p_ur_uc[3];
220 w[0] = 1.0; w[1] = 1.0; w[2] = 1.0;
221 for (
size_t r = 0; r < 3; r++)
224 for (
size_t c = 0; c < 3; c++)
226 s_uc2[c] = 0.0; s_ur_uc[c] = 0.0;
227 s_p_uc2[c] = 0.0; s_p_ur_uc[c] = 0.0;
229 for (
size_t v = 0; v < P.size(); v++)
238 s_uc2[c] += w[r] * w[c] * (1 - uc * uc);
239 s_p_uc2[c] += w[r] * w[r] * pc * (1 - uc * uc);
241 s_ur_uc[c] += w[r] * w[c] * ur * uc;
242 s_p_ur_uc[c] += w[r] * w[r] * pc * ur * uc;
252 y[r] -= s_p_ur_uc[c];
253 A(r, c) = -s_ur_uc[c];
257 try {
x = A.InvertFast() *
y; }
260 result.SetXYZ(0., 0., 0.);
return 1.0e12;
263 result.SetXYZ(
x[0],
x[1],
x[2]);
266 double dx, dy, dz, mse = 0.0;
267 for (
size_t v = 0; v < lines.size(); v++)
271 dx = result.X() - pproj.X();
272 dy = result.Y() - pproj.Y();
273 dz = result.Z() - pproj.Z();
275 mse += dx * dx + dy * dy + dz * dz;
277 return mse / lines.size();
289 TVector3 v0_3d(0., 0., 0.);
293 return v1_2d - v0_2d;
296 TVector2
pma::WireDriftToCm(
unsigned int wire,
float drift,
unsigned int plane,
unsigned int tpc,
unsigned int cryo)
307 TVector2
pma::CmToWireDrift(
float xw,
float yd,
unsigned int plane,
unsigned int tpc,
unsigned int cryo)
344 segStart(s0), segStop(s1)
346 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