All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
larreco/larreco/RecoAlg/PMAlg/Utilities.h
Go to the documentation of this file.
1 /**
2  * @file Utilities.h
3  *
4  * @author D.Stefan and R.Sulej
5  *
6  * @brief Implementation of the Projection Matching Algorithm
7  *
8  * Some geometrical functions and sorting helpers.
9  * See PmaTrack3D.h file for details.
10  */
11 
12 #ifndef Utilities_h
13 #define Utilities_h
14 
17 namespace detinfo {
18  class DetectorPropertiesData;
19 }
20 
21 #include "Math/GenVector/Cartesian2D.h"
22 #include "Math/GenVector/DisplacementVector2D.h"
23 
24 #include "TVector2.h"
25 #include "TVector3.h"
26 
27 #include <functional>
28 #include <map>
29 #include <utility>
30 #include <vector>
31 
32 namespace pma {
33  typedef ROOT::Math::DisplacementVector2D<ROOT::Math::Cartesian2D<double>> Vector2D;
35 
36  typedef std::map<size_t, std::vector<double>> dedx_map;
37 
38  class Hit3D;
39  class TrkCandidate;
40  class bSegmentProjLess;
41  class bDistCenterLess2D;
42  class bDistCenterLess3D;
44  struct bTrajectory3DDistLess;
45  struct bTrack3DLonger;
46 
47  double Dist2(const TVector2& v1, const TVector2& v2);
48  double Dist2(const Vector2D& v1, const Vector2D& v2);
49 
50  template <typename T, typename U>
51  double
52  Dist2(const T& v1, const U& v2)
53  {
54  double dx = v1.X() - v2.X(), dy = v1.Y() - v2.Y(), dz = v1.Z() - v2.Z();
55  return dx * dx + dy * dy + dz * dz;
56  }
57 
58  size_t GetHitsCount(const std::vector<pma::Hit3D*>& hits, unsigned int view);
59  double GetSummedADC(const std::vector<pma::Hit3D*>& hits, unsigned int view = geo::kUnknown);
60  double GetSummedAmpl(const std::vector<pma::Hit3D*>& hits, unsigned int view = geo::kUnknown);
61 
62  double GetHitsRadius3D(const std::vector<pma::Hit3D*>& hits, bool exact = false);
63  double GetHitsRadius2D(const std::vector<pma::Hit3D*>& hits, bool exact = false);
64 
65  double GetSegmentProjVector(const TVector2& p, const TVector2& p0, const TVector2& p1);
66  double GetSegmentProjVector(const Vector2D& p, const Vector2D& p0, const Vector2D& p1);
67 
68  double GetSegmentProjVector(const TVector3& p, const TVector3& p0, const TVector3& p1);
69  double GetSegmentProjVector(const Vector3D& p, const Vector3D& p0, const Vector3D& p1);
70 
71  TVector2 GetProjectionToSegment(const TVector2& p, const TVector2& p0, const TVector2& p1);
72  TVector3 GetProjectionToSegment(const TVector3& p, const TVector3& p0, const TVector3& p1);
73 
74  double SolveLeastSquares3D(const std::vector<std::pair<TVector3, TVector3>>& lines,
75  TVector3& result);
76 
77  TVector2 GetProjectionToPlane(const TVector3& p,
78  unsigned int plane,
79  unsigned int tpc,
80  unsigned int cryo);
81  TVector2 GetVectorProjectionToPlane(const TVector3& v,
82  unsigned int plane,
83  unsigned int tpc,
84  unsigned int cryo);
86  unsigned int wire,
87  float drift,
88  unsigned int plane,
89  unsigned int tpc,
90  unsigned int cryo);
92  float xw,
93  float yd,
94  unsigned int plane,
95  unsigned int tpc,
96  unsigned int cryo);
97 }
98 
99 struct pma::bTrajectory3DOrderLess : public std::binary_function<pma::Hit3D*, pma::Hit3D*, bool> {
100  bool operator()(pma::Hit3D* h1, pma::Hit3D* h2);
101 };
102 
103 struct pma::bTrajectory3DDistLess : public std::binary_function<pma::Hit3D*, pma::Hit3D*, bool> {
104  bool operator()(pma::Hit3D* h1, pma::Hit3D* h2);
105 };
106 
108  : public std::binary_function<const pma::TrkCandidate&, const pma::TrkCandidate&, bool> {
109  bool operator()(const pma::TrkCandidate& t1, const pma::TrkCandidate& t2);
110 };
111 
112 class pma::bSegmentProjLess : public std::binary_function<TVector3*, TVector3*, bool> {
113 public:
114  bSegmentProjLess(const TVector3& s0, const TVector3& s1);
115 
116  bool
117  operator()(TVector3* p1, TVector3* p2)
118  {
119  if (p1 && p2) {
120  double b1 = pma::GetSegmentProjVector(*p1, segStart, segStop);
121  double b2 = pma::GetSegmentProjVector(*p1, segStart, segStop);
122  return b1 < b2;
123  }
124  else
125  return false;
126  }
127 
128 private:
129  TVector3 segStart, segStop;
130 };
131 
132 class pma::bDistCenterLess2D : public std::binary_function<TVector2, TVector2, bool> {
133 public:
134  bDistCenterLess2D(const TVector2& c) : center(c) {}
135 
136  bool
137  operator()(TVector2 p1, TVector2 p2)
138  {
139  double b1 = pma::Dist2(p1, center);
140  double b2 = pma::Dist2(p2, center);
141  return b1 < b2;
142  }
143 
144 private:
145  TVector2 center;
146 };
147 
148 class pma::bDistCenterLess3D : public std::binary_function<TVector3, TVector3, bool> {
149 public:
150  bDistCenterLess3D(const TVector3& c) : center(c) {}
151 
152  bool
153  operator()(TVector3 p1, TVector3 p2)
154  {
155  double b1 = pma::Dist2(p1, center);
156  double b2 = pma::Dist2(p2, center);
157  return b1 < b2;
158  }
159 
160 private:
161  TVector3 center;
162 };
163 
164 #endif
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)
double Dist2(const TVector2 &v1, const TVector2 &v2)
Unknown view.
Definition: geo_types.h:136
bool operator()(TVector2 p1, TVector2 p2)
pdgs p
Definition: selectors.fcl:22
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
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
bSegmentProjLess(const TVector3 &s0, const TVector3 &s1)
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< Coord_t >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space. See recob::tracking::Coord_t for more details on the ...
Definition: TrackingTypes.h:29
size_t GetHitsCount(const std::vector< pma::Hit3D * > &hits, unsigned int view)
TVector2 GetProjectionToSegment(const TVector2 &p, const TVector2 &p0, const TVector2 &p1)
bool operator()(TVector3 *p1, TVector3 *p2)
bool operator()(TVector3 p1, TVector3 p2)
TVector2 GetVectorProjectionToPlane(const TVector3 &v, unsigned int plane, unsigned int tpc, unsigned int cryo)
Definition of data types for geometry description.
std::map< size_t, std::vector< double > > dedx_map
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
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)
bool operator()(const pma::TrkCandidate &t1, const pma::TrkCandidate &t2)
physics associatedGroupsWithLeft p1
auto const detProp