14 #include "art/Framework/Services/Registry/ServiceHandle.h"
15 #include "cetlib/pow.h"
16 #include "messagefacility/MessageLogger/MessageLogger.h"
35 #include "range/v3/algorithm.hpp"
36 #include "range/v3/numeric.hpp"
37 #include "range/v3/view.hpp"
42 double const dx = v1.X() - v2.X(), dy = v1.Y() - v2.Y();
43 return cet::sum_of_squares(dx, dy);
48 double const dx = v1.X() - v2.X(), dy = v1.Y() - v2.Y();
49 return cet::sum_of_squares(dx, dy);
56 return ranges::count_if(hits, [view](
auto hit) {
return view ==
hit->View2D(); });
62 using namespace ranges;
63 auto to_summed_adc = [](
auto hit) {
return hit->SummedADC(); };
65 return accumulate(hits |
views::filter([view](
auto hit) {
return view ==
hit->View2D(); }) |
73 using namespace ranges;
74 auto to_amplitude = [](
auto hit) {
return hit->GetAmplitude(); };
76 return accumulate(hits |
views::filter([view](
auto hit) {
return view ==
hit->View2D(); }) |
84 if (hits.empty())
return 0.0;
86 if (!exact && (hits.size() < 5))
return 0.0;
88 using namespace ranges;
89 auto to_3d_point = [](
auto hit) -> decltype(
auto) {
return hit->Point3D(); };
90 auto const mean_point =
91 accumulate(hits |
views::transform(to_3d_point), TVector3{}) * (1. / hits.size());
93 auto to_dist2_from_mean = [&mean_point](
auto hit) {
103 if (hits.empty())
return 0.0;
105 if (!exact && (hits.size() < 5))
return 0.0;
107 using namespace ranges;
108 auto to_2d_point = [](
auto hit) -> decltype(
auto) {
return hit->Point2D(); };
109 auto const mean_point =
110 accumulate(hits |
views::transform(to_2d_point), TVector2{}) * (1. / hits.size());
112 auto to_dist2_from_mean = [&mean_point](
auto hit) {
122 TVector2
const v0(p - p0);
123 TVector2
const v1(p1 - p0);
124 return v0 * v1 / v1.Mod2();
132 return v0.Dot(v1) / v1.Mag2();
138 TVector3
const v0(p - p0);
139 TVector3
const v1(p1 - p0);
140 return v0.Dot(v1) / v1.Mag2();
148 return v0.Dot(v1) / v1.Mag2();
154 TVector2
const v1(p1 - p0);
162 TVector3
const v1(p1 - p0);
174 result.SetXYZ(0., 0., 0.);
175 if (lines.size() < 2) {
176 mf::LogError(
"pma::SolveLeastSquares3D") <<
"Need min. two lines.";
181 std::vector<TVectorT<double>> U, P;
182 for (
size_t v = 0; v < lines.size(); v++) {
183 TVector3 point = lines[v].first;
184 TVector3
dir = lines[v].second;
190 P.push_back(TVectorT<double>(3));
191 P.back()[0] = point.X();
192 P.back()[1] = point.Y();
193 P.back()[2] = point.Z();
195 U.push_back(TVectorT<double>(3));
196 U.back()[0] = dir.X();
197 U.back()[1] = dir.Y();
198 U.back()[2] = dir.Z();
201 mf::LogWarning(
"pma::SolveLeastSquares3D") <<
"Line undefined.";
204 mf::LogError(
"pma::SolveLeastSquares3D") <<
"Need min. two lines.";
208 TVectorT<double>
x(3),
y(3),
w(3);
209 TMatrixT<double>
A(3, 3);
211 double s_uc2[3], s_ur_uc[3];
212 double s_p_uc2[3], s_p_ur_uc[3];
217 for (
size_t r = 0;
r < 3;
r++) {
219 for (
size_t c = 0; c < 3; c++) {
225 for (
size_t v = 0; v < P.size(); v++) {
233 s_uc2[c] += w[
r] * w[c] * (1 - uc * uc);
234 s_p_uc2[c] += w[
r] * w[
r] * pc * (1 - uc * uc);
236 s_ur_uc[c] += w[
r] * w[c] * ur * uc;
237 s_p_ur_uc[c] += w[
r] * w[
r] * pc * ur * uc;
245 y[
r] -= s_p_ur_uc[c];
246 A(
r, c) = -s_ur_uc[c];
251 x = A.InvertFast() *
y;
254 result.SetXYZ(0., 0., 0.);
258 result.SetXYZ(
x[0],
x[1],
x[2]);
261 for (
size_t v = 0; v < lines.size(); v++) {
264 double const dx = result.X() - pproj.X();
265 double const dy = result.Y() - pproj.Y();
266 double const dz = result.Z() - pproj.Z();
267 mse += cet::sum_of_squares(dx, dy, dz);
269 return mse / lines.size();
278 art::ServiceHandle<geo::Geometry const> geom;
280 return TVector2(geom->TPC(tpc, cryo).Plane(plane).PlaneCoordinate(p), p.X());
289 TVector3 v0_3d(0., 0., 0.);
293 return v1_2d - v0_2d;
304 art::ServiceHandle<geo::Geometry const> geom;
305 return TVector2(geom->TPC(tpc, cryo).Plane(plane).WirePitch() * wire,
317 art::ServiceHandle<geo::Geometry const> geom;
318 return TVector2(xw / geom->TPC(tpc, cryo).Plane(plane).WirePitch(),
355 : segStart(s0), segStop(s1)
357 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.
process_name opflash particleana ie x
double Dist2(const TVector2 &v1, const TVector2 &v2)
pma::Hit3D const * front() const
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)
double GetHitsRadius3D(const std::vector< pma::Hit3D * > &hits, bool exact=false)
recob::tracking::Vector_t Vector3D
tuple m
now if test mode generate materials, CRT shell, world, gdml header else just generate CRT shell for u...
double GetDist2ToProj() const
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
bSegmentProjLess(const TVector3 &s0, const TVector3 &s1)
process_name opflash particleana ie ie y
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)
double ConvertTicksToX(double ticks, int p, int t, int c) const
Track finding helper for 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)
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)
pma::Track3D * Track() const
bool operator()(const pma::TrkCandidate &t1, const pma::TrkCandidate &t2)
physics associatedGroupsWithLeft p1
art framework interface to geometry description
Encapsulate the construction of a single detector plane.