15 #include "cetlib/pow.h" 35 #include "range/v3/algorithm.hpp" 36 #include "range/v3/numeric.hpp" 37 #include "range/v3/view.hpp" 39 double pma::Dist2(
const TVector2& v1,
const TVector2& v2)
41 double const dx = v1.X() - v2.X(), dy = v1.Y() - v2.Y();
42 return cet::sum_of_squares(dx, dy);
46 double const dx = v1.X() - v2.X(), dy = v1.Y() - v2.Y();
47 return cet::sum_of_squares(dx, dy);
53 return ranges::count_if(hits, [view](
auto hit) {
return view ==
hit->View2D(); });
59 auto to_summed_adc = [](
auto hit) {
return hit->SummedADC(); };
60 if (view ==
geo::kUnknown) {
return accumulate(hits | views::transform(to_summed_adc), 0.); }
61 return accumulate(hits | views::filter([view](
auto hit) {
return view ==
hit->View2D(); }) |
62 views::transform(to_summed_adc),
69 auto to_amplitude = [](
auto hit) {
return hit->GetAmplitude(); };
70 if (view ==
geo::kUnknown) {
return accumulate(hits | views::transform(to_amplitude), 0.); }
71 return accumulate(hits | views::filter([view](
auto hit) {
return view ==
hit->View2D(); }) |
72 views::transform(to_amplitude),
78 if (hits.empty())
return 0.0;
80 if (!exact && (hits.size() < 5))
return 0.0;
83 auto to_3d_point = [](
auto hit) -> decltype(
auto) {
return hit->Point3D(); };
84 auto const mean_point =
85 accumulate(hits | views::transform(to_3d_point), TVector3{}) * (1. / hits.size());
87 auto to_dist2_from_mean = [&mean_point](
auto hit) {
90 auto const max_r2 = max(hits | views::transform(to_dist2_from_mean));
96 if (hits.empty())
return 0.0;
98 if (!exact && (hits.size() < 5))
return 0.0;
101 auto to_2d_point = [](
auto hit) -> decltype(
auto) {
return hit->Point2D(); };
102 auto const mean_point =
103 accumulate(hits | views::transform(to_2d_point), TVector2{}) * (1. / hits.size());
105 auto to_dist2_from_mean = [&mean_point](
auto hit) {
108 auto const max_r2 = max(hits | views::transform(to_dist2_from_mean));
114 TVector2
const v0(p - p0);
115 TVector2
const v1(p1 - p0);
116 return v0 * v1 / v1.Mod2();
125 return v0.Dot(v1) / v1.Mag2();
130 TVector3
const v0(p - p0);
131 TVector3
const v1(p1 - p0);
132 return v0.Dot(v1) / v1.Mag2();
141 return v0.Dot(v1) / v1.Mag2();
146 TVector2
const v1(p1 - p0);
153 TVector3
const v1(p1 - p0);
165 result.SetXYZ(0., 0., 0.);
166 if (lines.size() < 2) {
167 mf::LogError(
"pma::SolveLeastSquares3D") <<
"Need min. two lines.";
172 std::vector<TVectorT<double>> U, P;
173 for (
size_t v = 0; v < lines.size(); v++) {
174 TVector3 point = lines[v].first;
175 TVector3
dir = lines[v].second;
181 P.push_back(TVectorT<double>(3));
182 P.back()[0] = point.X();
183 P.back()[1] = point.Y();
184 P.back()[2] = point.Z();
186 U.push_back(TVectorT<double>(3));
187 U.back()[0] = dir.X();
188 U.back()[1] = dir.Y();
189 U.back()[2] = dir.Z();
195 mf::LogError(
"pma::SolveLeastSquares3D") <<
"Need min. two lines.";
199 TVectorT<double>
x(3),
y(3),
w(3);
200 TMatrixT<double> A(3, 3);
202 double s_uc2[3], s_ur_uc[3];
203 double s_p_uc2[3], s_p_ur_uc[3];
208 for (
size_t r = 0;
r < 3;
r++) {
210 for (
size_t c = 0; c < 3; c++) {
216 for (
size_t v = 0; v < P.size(); v++) {
224 s_uc2[c] += w[
r] * w[c] * (1 - uc * uc);
225 s_p_uc2[c] += w[
r] * w[
r] * pc * (1 - uc * uc);
227 s_ur_uc[c] += w[
r] * w[c] * ur * uc;
228 s_p_ur_uc[c] += w[
r] * w[
r] * pc * ur * uc;
236 y[
r] -= s_p_ur_uc[c];
237 A(
r, c) = -s_ur_uc[c];
242 x = A.InvertFast() *
y;
245 result.SetXYZ(0., 0., 0.);
249 result.SetXYZ(
x[0],
x[1],
x[2]);
252 for (
size_t v = 0; v < lines.size(); v++) {
255 double const dx = result.X() - pproj.X();
256 double const dy = result.Y() - pproj.Y();
257 double const dz = result.Z() - pproj.Z();
258 mse += cet::sum_of_squares(dx, dy, dz);
260 return mse / lines.size();
279 TVector3 v0_3d(0., 0., 0.);
283 return v1_2d - v0_2d;
335 : segStart(s0), segStop(s1)
337 if (s0 == s1)
mf::LogError(
"pma::bSegmentProjLess") <<
"Vectors equal!";
double SolveLeastSquares3D(const std::vector< std::pair< TVector3, TVector3 >> &lines, TVector3 &result)
double GetSummedAmpl(const std::vector< pma::Hit3D * > &hits, unsigned int view=geo::kUnknown)
double GetHitsRadius2D(const std::vector< pma::Hit3D * > &hits, bool exact=false)
Implementation of the Projection Matching Algorithm.
double Dist2(const TVector2 &v1, const TVector2 &v2)
pma::Hit3D const * front() const
The data type to uniquely identify a Plane.
::geo::Point_t toPoint(Point const &p)
Convert the specified point into a geo::Point_t.
TVector3 const & Point3D() const
TVector2 WireDriftToCm(detinfo::DetectorPropertiesData const &detProp, unsigned int wire, float drift, unsigned int plane, unsigned int tpc, unsigned int cryo)
bool operator()(pma::Hit3D *h1, pma::Hit3D *h2) const
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
double GetHitsRadius3D(const std::vector< pma::Hit3D * > &hits, bool exact=false)
recob::tracking::Vector_t Vector3D
double GetDist2ToProj() const
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
bSegmentProjLess(const TVector3 &s0, const TVector3 &s1)
PlaneGeo const & Plane(PlaneID const &planeid) const
Returns the specified wire.
size_t GetHitsCount(const std::vector< pma::Hit3D * > &hits, unsigned int view)
TVector2 GetProjectionToSegment(const TVector2 &p, const TVector2 &p0, const TVector2 &p1)
double ConvertXToTicks(double X, int p, int t, int c) const
Implementation of the Projection Matching Algorithm.
TVector2 GetVectorProjectionToPlane(const TVector3 &v, unsigned int plane, unsigned int tpc, unsigned int cryo)
Detector simulation of raw signals on wires.
double ConvertTicksToX(double ticks, int p, int t, int c) const
Track finding helper for the Projection Matching Algorithm.
Implementation of the Projection Matching Algorithm.
Encapsulate the construction of a single detector plane.
double GetSegmentProjVector(const TVector2 &p, const TVector2 &p0, const TVector2 &p1)
TVector2 GetProjectionToPlane(const TVector3 &p, unsigned int plane, unsigned int tpc, unsigned int cryo)
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
ROOT::Math::DisplacementVector2D< ROOT::Math::Cartesian2D< double > > Vector2D
pma::Hit3D const * back() const
TVector2 CmToWireDrift(detinfo::DetectorPropertiesData const &detProp, float xw, float yd, unsigned int plane, unsigned int tpc, unsigned int cryo)
double GetSummedADC(const std::vector< pma::Hit3D * > &hits, unsigned int view=geo::kUnknown)
second_as<> second
Type of time stored in seconds, in double precision.
bool operator()(const pma::TrkCandidate &t1, const pma::TrkCandidate &t2) const
pma::Track3D * Track() const
double PlaneCoordinate(geo::Point_t const &point) const
Returns the coordinate of the point on the plane.
art framework interface to geometry description
double WirePitch() const
Return the wire pitch (in centimeters). It is assumed constant.
Encapsulate the construction of a single detector plane.
bool operator()(pma::Hit3D *h1, pma::Hit3D *h2) const