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 <map>
28 
29 namespace pma {
30  typedef ROOT::Math::DisplacementVector2D<ROOT::Math::Cartesian2D<double>> Vector2D;
32 
33  typedef std::map<size_t, std::vector<double>> dedx_map;
34 
35  class Hit3D;
36  class TrkCandidate;
37  class bSegmentProjLess;
38  class bDistCenterLess2D;
39  class bDistCenterLess3D;
41  struct bTrajectory3DDistLess;
42  struct bTrack3DLonger;
43 
44  double Dist2(const TVector2& v1, const TVector2& v2);
45  double Dist2(const Vector2D& v1, const Vector2D& v2);
46 
47  template <typename T, typename U>
48  double
49  Dist2(const T& v1, const U& v2)
50  {
51  double dx = v1.X() - v2.X(), dy = v1.Y() - v2.Y(), dz = v1.Z() - v2.Z();
52  return dx * dx + dy * dy + dz * dz;
53  }
54 
55  size_t GetHitsCount(const std::vector<pma::Hit3D*>& hits, unsigned int view);
56  double GetSummedADC(const std::vector<pma::Hit3D*>& hits, unsigned int view = geo::kUnknown);
57  double GetSummedAmpl(const std::vector<pma::Hit3D*>& hits, unsigned int view = geo::kUnknown);
58 
59  double GetHitsRadius3D(const std::vector<pma::Hit3D*>& hits, bool exact = false);
60  double GetHitsRadius2D(const std::vector<pma::Hit3D*>& hits, bool exact = false);
61 
62  double GetSegmentProjVector(const TVector2& p, const TVector2& p0, const TVector2& p1);
63  double GetSegmentProjVector(const Vector2D& p, const Vector2D& p0, const Vector2D& p1);
64 
65  double GetSegmentProjVector(const TVector3& p, const TVector3& p0, const TVector3& p1);
66  double GetSegmentProjVector(const Vector3D& p, const Vector3D& p0, const Vector3D& p1);
67 
68  TVector2 GetProjectionToSegment(const TVector2& p, const TVector2& p0, const TVector2& p1);
69  TVector3 GetProjectionToSegment(const TVector3& p, const TVector3& p0, const TVector3& p1);
70 
71  double SolveLeastSquares3D(const std::vector<std::pair<TVector3, TVector3>>& lines,
72  TVector3& result);
73 
74  TVector2 GetProjectionToPlane(const TVector3& p,
75  unsigned int plane,
76  unsigned int tpc,
77  unsigned int cryo);
78  TVector2 GetVectorProjectionToPlane(const TVector3& v,
79  unsigned int plane,
80  unsigned int tpc,
81  unsigned int cryo);
82  TVector2 WireDriftToCm(detinfo::DetectorPropertiesData const& detProp,
83  unsigned int wire,
84  float drift,
85  unsigned int plane,
86  unsigned int tpc,
87  unsigned int cryo);
88  TVector2 CmToWireDrift(detinfo::DetectorPropertiesData const& detProp,
89  float xw,
90  float yd,
91  unsigned int plane,
92  unsigned int tpc,
93  unsigned int cryo);
94 }
95 
96 struct pma::bTrajectory3DOrderLess : public std::binary_function<pma::Hit3D*, pma::Hit3D*, bool> {
97  bool operator()(pma::Hit3D* h1, pma::Hit3D* h2);
98 };
99 
100 struct pma::bTrajectory3DDistLess : public std::binary_function<pma::Hit3D*, pma::Hit3D*, bool> {
101  bool operator()(pma::Hit3D* h1, pma::Hit3D* h2);
102 };
103 
105  : public std::binary_function<const pma::TrkCandidate&, const pma::TrkCandidate&, bool> {
106  bool operator()(const pma::TrkCandidate& t1, const pma::TrkCandidate& t2);
107 };
108 
109 class pma::bSegmentProjLess : public std::binary_function<TVector3*, TVector3*, bool> {
110 public:
111  bSegmentProjLess(const TVector3& s0, const TVector3& s1);
112 
113  bool
114  operator()(TVector3* p1, TVector3* p2)
115  {
116  if (p1 && p2) {
117  double b1 = pma::GetSegmentProjVector(*p1, segStart, segStop);
118  double b2 = pma::GetSegmentProjVector(*p1, segStart, segStop);
119  return b1 < b2;
120  }
121  else
122  return false;
123  }
124 
125 private:
126  TVector3 segStart, segStop;
127 };
128 
129 class pma::bDistCenterLess2D : public std::binary_function<TVector2, TVector2, bool> {
130 public:
131  bDistCenterLess2D(const TVector2& c) : center(c) {}
132 
133  bool
134  operator()(TVector2 p1, TVector2 p2)
135  {
136  double b1 = pma::Dist2(p1, center);
137  double b2 = pma::Dist2(p2, center);
138  return b1 < b2;
139  }
140 
141 private:
142  TVector2 center;
143 };
144 
145 class pma::bDistCenterLess3D : public std::binary_function<TVector3, TVector3, bool> {
146 public:
147  bDistCenterLess3D(const TVector3& c) : center(c) {}
148 
149  bool
150  operator()(TVector3 p1, TVector3 p2)
151  {
152  double b1 = pma::Dist2(p1, center);
153  double b2 = pma::Dist2(p2, center);
154  return b1 < b2;
155  }
156 
157 private:
158  TVector3 center;
159 };
160 
161 #endif
double SolveLeastSquares3D(const std::vector< std::pair< TVector3, TVector3 >> &lines, TVector3 &result)
Definition: Utilities.cxx:165
double GetSummedAmpl(const std::vector< pma::Hit3D * > &hits, unsigned int view=geo::kUnknown)
Definition: Utilities.cxx:68
double GetHitsRadius2D(const std::vector< pma::Hit3D * > &hits, bool exact=false)
Definition: Utilities.cxx:98
static QCString result
double Dist2(const TVector2 &v1, const TVector2 &v2)
Definition: Utilities.cxx:37
Unknown view.
Definition: geo_types.h:136
bool operator()(TVector2 p1, TVector2 p2)
Definition: Utilities.h:134
struct vector vector
bDistCenterLess3D(const TVector3 &c)
Definition: Utilities.h:147
TVector2 WireDriftToCm(detinfo::DetectorPropertiesData const &detProp, unsigned int wire, float drift, unsigned int plane, unsigned int tpc, unsigned int cryo)
Definition: Utilities.cxx:294
double GetSegmentProjVector(const Vector3D &p, const Vector3D &p0, const Vector3D &p1)
Definition: Utilities.cxx:141
double GetHitsRadius3D(const std::vector< pma::Hit3D * > &hits, bool exact=false)
Definition: Utilities.cxx:79
recob::tracking::Vector_t Vector3D
Definition: Utilities.h:31
double Dist2(const T &v1, const U &v2)
Definition: Utilities.h:49
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)
Definition: Utilities.cxx:50
bool operator()(TVector3 *p1, TVector3 *p2)
Definition: Utilities.h:114
bool operator()(TVector3 p1, TVector3 p2)
Definition: Utilities.h:150
p
Definition: test.py:223
bDistCenterLess2D(const TVector2 &c)
Definition: Utilities.h:131
TVector2 GetVectorProjectionToPlane(const TVector3 &v, unsigned int plane, unsigned int tpc, unsigned int cryo)
Definition: Utilities.cxx:281
General LArSoft Utilities.
Definition of data types for geometry description.
std::map< size_t, std::vector< double > > dedx_map
Definition: Utilities.h:33
double GetSegmentProjVector(const TVector2 &p, const TVector2 &p0, const TVector2 &p1)
Definition: Utilities.cxx:117
TVector2 GetProjectionToPlane(const TVector3 &p, unsigned int plane, unsigned int tpc, unsigned int cryo)
Definition: Utilities.cxx:270
def center(depos, point)
Definition: depos.py:117
ROOT::Math::DisplacementVector2D< ROOT::Math::Cartesian2D< double > > Vector2D
Definition: Utilities.h:30
TVector3 GetProjectionToSegment(const TVector3 &p, const TVector3 &p0, const TVector3 &p1)
Definition: Utilities.cxx:157
TVector2 CmToWireDrift(detinfo::DetectorPropertiesData const &detProp, float xw, float yd, unsigned int plane, unsigned int tpc, unsigned int cryo)
Definition: Utilities.cxx:307
double GetSummedADC(const std::vector< pma::Hit3D * > &hits, unsigned int view=geo::kUnknown)
Definition: Utilities.cxx:57