LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
Utilities.h
Go to the documentation of this file.
1 
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 Dist2(const T& v1, const U& v2)
52  {
53  double dx = v1.X() - v2.X(), dy = v1.Y() - v2.Y(), dz = v1.Z() - v2.Z();
54  return dx * dx + dy * dy + dz * dz;
55  }
56 
57  size_t GetHitsCount(const std::vector<pma::Hit3D*>& hits, unsigned int view);
58  double GetSummedADC(const std::vector<pma::Hit3D*>& hits, unsigned int view = geo::kUnknown);
59  double GetSummedAmpl(const std::vector<pma::Hit3D*>& hits, unsigned int view = geo::kUnknown);
60 
61  double GetHitsRadius3D(const std::vector<pma::Hit3D*>& hits, bool exact = false);
62  double GetHitsRadius2D(const std::vector<pma::Hit3D*>& hits, bool exact = false);
63 
64  double GetSegmentProjVector(const TVector2& p, const TVector2& p0, const TVector2& p1);
65  double GetSegmentProjVector(const Vector2D& p, const Vector2D& p0, const Vector2D& p1);
66 
67  double GetSegmentProjVector(const TVector3& p, const TVector3& p0, const TVector3& p1);
68  double GetSegmentProjVector(const Vector3D& p, const Vector3D& p0, const Vector3D& p1);
69 
70  TVector2 GetProjectionToSegment(const TVector2& p, const TVector2& p0, const TVector2& p1);
71  TVector3 GetProjectionToSegment(const TVector3& p, const TVector3& p0, const TVector3& p1);
72 
73  double SolveLeastSquares3D(const std::vector<std::pair<TVector3, TVector3>>& lines,
74  TVector3& result);
75 
76  TVector2 GetProjectionToPlane(const TVector3& p,
77  unsigned int plane,
78  unsigned int tpc,
79  unsigned int cryo);
80  TVector2 GetVectorProjectionToPlane(const TVector3& v,
81  unsigned int plane,
82  unsigned int tpc,
83  unsigned int cryo);
84  TVector2 WireDriftToCm(detinfo::DetectorPropertiesData const& detProp,
85  unsigned int wire,
86  float drift,
87  unsigned int plane,
88  unsigned int tpc,
89  unsigned int cryo);
90  TVector2 CmToWireDrift(detinfo::DetectorPropertiesData const& detProp,
91  float xw,
92  float yd,
93  unsigned int plane,
94  unsigned int tpc,
95  unsigned int cryo);
96 }
97 
99  bool operator()(pma::Hit3D* h1, pma::Hit3D* h2) const;
100 };
101 
103  bool operator()(pma::Hit3D* h1, pma::Hit3D* h2) const;
104 };
105 
107  bool operator()(const pma::TrkCandidate& t1, const pma::TrkCandidate& t2) const;
108 };
109 
111 public:
112  bSegmentProjLess(const TVector3& s0, const TVector3& s1);
113 
114  bool operator()(TVector3* p1, TVector3* p2) const
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 
130 public:
131  bDistCenterLess2D(const TVector2& c) : center(c) {}
132 
133  bool operator()(TVector2 p1, TVector2 p2) const
134  {
135  double b1 = pma::Dist2(p1, center);
136  double b2 = pma::Dist2(p2, center);
137  return b1 < b2;
138  }
139 
140 private:
141  TVector2 center;
142 };
143 
145 public:
146  bDistCenterLess3D(const TVector3& c) : center(c) {}
147 
148  bool operator()(TVector3 p1, TVector3 p2) const
149  {
150  double b1 = pma::Dist2(p1, center);
151  double b2 = pma::Dist2(p2, center);
152  return b1 < b2;
153  }
154 
155 private:
156  TVector3 center;
157 };
158 
159 #endif
double SolveLeastSquares3D(const std::vector< std::pair< TVector3, TVector3 >> &lines, TVector3 &result)
Definition: Utilities.cxx:158
double GetSummedAmpl(const std::vector< pma::Hit3D * > &hits, unsigned int view=geo::kUnknown)
Definition: Utilities.cxx:66
TTree * t1
Definition: plottest35.C:26
double GetHitsRadius2D(const std::vector< pma::Hit3D * > &hits, bool exact=false)
Definition: Utilities.cxx:94
double Dist2(const TVector2 &v1, const TVector2 &v2)
Definition: Utilities.cxx:39
Unknown view.
Definition: geo_types.h:142
bDistCenterLess3D(const TVector3 &c)
Definition: Utilities.h:146
TVector2 WireDriftToCm(detinfo::DetectorPropertiesData const &detProp, unsigned int wire, float drift, unsigned int plane, unsigned int tpc, unsigned int cryo)
Definition: Utilities.cxx:286
double GetSegmentProjVector(const Vector3D &p, const Vector3D &p0, const Vector3D &p1)
Definition: Utilities.cxx:135
double GetHitsRadius3D(const std::vector< pma::Hit3D * > &hits, bool exact=false)
Definition: Utilities.cxx:76
recob::tracking::Vector_t Vector3D
Definition: Utilities.h:34
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:289
double Dist2(const T &v1, const U &v2)
Definition: Utilities.h:51
bool operator()(TVector3 *p1, TVector3 *p2) const
Definition: Utilities.h:114
void hits()
Definition: readHits.C:15
size_t GetHitsCount(const std::vector< pma::Hit3D * > &hits, unsigned int view)
Definition: Utilities.cxx:50
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:31
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:274
General LArSoft Utilities.
Definition of data types for geometry description.
TTree * t2
Definition: plottest35.C:36
bool operator()(TVector3 p1, TVector3 p2) const
Definition: Utilities.h:148
TH1F * h2
Definition: plot.C:44
std::map< size_t, std::vector< double > > dedx_map
Definition: Utilities.h:36
double GetSegmentProjVector(const TVector2 &p, const TVector2 &p0, const TVector2 &p1)
Definition: Utilities.cxx:112
TVector2 GetProjectionToPlane(const TVector3 &p, unsigned int plane, unsigned int tpc, unsigned int cryo)
Definition: Utilities.cxx:263
ROOT::Math::DisplacementVector2D< ROOT::Math::Cartesian2D< double > > Vector2D
Definition: Utilities.h:33
TVector3 GetProjectionToSegment(const TVector3 &p, const TVector3 &p0, const TVector3 &p1)
Definition: Utilities.cxx:151
TVector2 CmToWireDrift(detinfo::DetectorPropertiesData const &detProp, float xw, float yd, unsigned int plane, unsigned int tpc, unsigned int cryo)
Definition: Utilities.cxx:298
TH1F * h1
Definition: plot.C:41
double GetSummedADC(const std::vector< pma::Hit3D * > &hits, unsigned int view=geo::kUnknown)
Definition: Utilities.cxx:56
bool operator()(TVector2 p1, TVector2 p2) const
Definition: Utilities.h:133