32 #include "range/v3/algorithm.hpp" 33 #include "range/v3/numeric.hpp" 34 #include "range/v3/view.hpp" 39 double const dx = v1.X() - v2.X(), dy = v1.Y() - v2.Y();
45 double const dx = v1.X() - v2.X(), dy = v1.Y() - v2.Y();
53 return ranges::count_if(hits, [view](
auto hit) {
return view ==
hit->View2D(); });
60 auto to_summed_adc = [](
auto hit) {
return hit->SummedADC(); };
61 if (view ==
geo::kUnknown) {
return accumulate(hits | views::transform(to_summed_adc), 0.); }
62 return accumulate(hits |
views::filter([view](
auto hit) {
return view ==
hit->View2D(); }) |
63 views::transform(to_summed_adc),
71 auto to_amplitude = [](
auto hit) {
return hit->GetAmplitude(); };
72 if (view ==
geo::kUnknown) {
return accumulate(hits | views::transform(to_amplitude), 0.); }
73 return accumulate(hits |
views::filter([view](
auto hit) {
return view ==
hit->View2D(); }) |
74 views::transform(to_amplitude),
81 if (hits.empty())
return 0.0;
83 if (!exact && (hits.size() < 5))
return 0.0;
86 auto to_3d_point = [](
auto hit) -> decltype(
auto) {
return hit->Point3D(); };
87 auto const mean_point =
88 accumulate(hits | views::transform(to_3d_point), TVector3{}) * (1. / hits.size());
90 auto to_dist2_from_mean = [&mean_point](
auto hit) {
93 auto const max_r2 =
max(hits | views::transform(to_dist2_from_mean));
100 if (hits.empty())
return 0.0;
102 if (!exact && (hits.size() < 5))
return 0.0;
105 auto to_2d_point = [](
auto hit) -> decltype(
auto) {
return hit->Point2D(); };
106 auto const mean_point =
107 accumulate(hits | views::transform(to_2d_point), TVector2{}) * (1. / hits.size());
109 auto to_dist2_from_mean = [&mean_point](
auto hit) {
112 auto const max_r2 =
max(hits | views::transform(to_dist2_from_mean));
119 TVector2
const v0(p - p0);
120 TVector2
const v1(p1 - p0);
121 return v0 * v1 / v1.Mod2();
129 return v0.Dot(v1) / v1.Mag2();
135 TVector3
const v0(p - p0);
136 TVector3
const v1(p1 - p0);
137 return v0.Dot(v1) / v1.Mag2();
145 return v0.Dot(v1) / v1.Mag2();
151 TVector2
const v1(p1 - p0);
159 TVector3
const v1(p1 - p0);
171 result.SetXYZ(0., 0., 0.);
172 if (
lines.size() < 2) {
173 mf::LogError(
"pma::SolveLeastSquares3D") <<
"Need min. two lines.";
178 std::vector<TVectorT<double>> U,
P;
179 for (
size_t v = 0; v <
lines.size(); v++) {
180 TVector3 point =
lines[v].first;
187 P.push_back(TVectorT<double>(3));
188 P.back()[0] = point.X();
189 P.back()[1] = point.Y();
190 P.back()[2] = point.Z();
192 U.push_back(TVectorT<double>(3));
193 U.back()[0] = dir.X();
194 U.back()[1] = dir.Y();
195 U.back()[2] = dir.Z();
201 mf::LogError(
"pma::SolveLeastSquares3D") <<
"Need min. two lines.";
205 TVectorT<double>
x(3),
y(3),
w(3);
206 TMatrixT<double>
A(3, 3);
208 double s_uc2[3], s_ur_uc[3];
209 double s_p_uc2[3], s_p_ur_uc[3];
214 for (
size_t r = 0;
r < 3;
r++) {
216 for (
size_t c = 0;
c < 3;
c++) {
222 for (
size_t v = 0; v < P.size(); v++) {
230 s_uc2[
c] += w[
r] * w[
c] * (1 - uc * uc);
231 s_p_uc2[
c] += w[
r] * w[
r] * pc * (1 - uc * uc);
233 s_ur_uc[
c] += w[
r] * w[
c] * ur * uc;
234 s_p_ur_uc[
c] += w[
r] * w[
r] * pc * ur * uc;
242 y[
r] -= s_p_ur_uc[
c];
243 A(
r,
c) = -s_ur_uc[
c];
248 x = A.InvertFast() *
y;
251 result.SetXYZ(0., 0., 0.);
255 result.SetXYZ(
x[0],
x[1],
x[2]);
258 for (
size_t v = 0; v <
lines.size(); v++) {
261 double const dx = result.X() - pproj.X();
262 double const dy = result.Y() - pproj.Y();
263 double const dz = result.Z() - pproj.Z();
266 return mse /
lines.size();
286 TVector3 v0_3d(0., 0., 0.);
290 return v1_2d - v0_2d;
352 : segStart(s0), segStop(s1)
354 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
constexpr T sum_of_squares(T x, T y)
TVector3 const & Point3D() const
std::pair< float, std::string > P
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)
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
art framework interface to geometry description
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 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)
static int max(int a, int b)
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.
bool operator()(pma::Hit3D *h1, pma::Hit3D *h2)
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)
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)
static unsigned filter(unsigned char *out, const unsigned char *in, unsigned w, unsigned h, const LodePNG_InfoColor *info)
PlaneGeo const & Plane(geo::View_t view) const
Return the plane in the tpc with View_t view.
second_as<> second
Type of time stored in seconds, in double precision.
pma::Track3D * Track() const
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.
Encapsulate the construction of a single detector plane.