PmaElement3D.h
Go to the documentation of this file.
1 /**
2  * @file PmaElement3D.h
3  *
4  * @author D.Stefan and R.Sulej
5  *
6  * @brief Implementation of the Projection Matching Algorithm
7  *
8  * Base for 3D segments and track nodes. See PmaTrack3D.h file for details.
9  * See PmaTrack3D.h file for details.
10  */
11 
12 #ifndef PmaElement3D_h
13 #define PmaElement3D_h
14 
15 #include <math.h>
16 
19 
20 #include "TVector2.h"
21 #include "TVector3.h"
22 
23 namespace pma
24 {
25  class Element3D;
26  class Hit3D;
27  class Track3D;
28 }
29 
31 {
32 public:
33  /// TPC index or -1 if out of any TPC.
34  int TPC(void) const { return fTPC; }
35  /// Cryostat index or -1 if out of any cryostat.
36  int Cryo(void) const { return fCryo; }
37 
38  /// Distance [cm] from the 3D point to the object 3D.
39  virtual double GetDistance2To(const TVector3& p3d) const = 0;
40 
41  /// Distance [cm] from the 2D point to the object's 2D projection in one of wire views.
42  virtual double GetDistance2To(const TVector2& p2d, unsigned int view) const = 0;
43 
44  /// Get 3D direction cosines corresponding to this element.
45  virtual pma::Vector3D GetDirection3D(void) const = 0;
46 
47  virtual TVector3 GetUnconstrainedProj3D(const TVector2& p2d, unsigned int view) const = 0;
48 
49  virtual void SetProjection(pma::Hit3D& h) const = 0;
50 
51  virtual double Length2(void) const = 0;
52  double Length(void) const { return sqrt(Length2()); }
53 
54  const std::vector< pma::Hit3D* > & Hits(void) const { return fAssignedHits; }
55 
56  bool HasHit(const pma::Hit3D* h) const
57  {
58  for (const auto a : fAssignedHits) { if (h == a) return true; }
59  return false;
60  }
61 
62  pma::Hit3D& Hit(size_t index) { return *(fAssignedHits[index]); }
63  void RemoveHitAt(size_t index)
64  {
65  if (index < fAssignedHits.size())
66  fAssignedHits.erase(fAssignedHits.begin() + index);
67  }
68  void AddHit(pma::Hit3D* h)
69  {
70  fAssignedHits.push_back(h);
71  SetProjection(*h);
72  }
73 
74  size_t NHits(void) const { return fAssignedHits.size(); }
75  size_t NEnabledHits(unsigned int view = geo::kUnknown) const;
76  size_t NPrecalcEnabledHits(void) const { return fNThisHitsEnabledAll; }
77 
78  TVector3 const & ReferencePoint(size_t index) const { return *(fAssignedPoints[index]); }
79  size_t NPoints(void) const { return fAssignedPoints.size(); }
80  void AddPoint(TVector3* p) { fAssignedPoints.push_back(p); }
81 
82  /// Clear hits/points vectors of this element, optionally only
83  /// those which are owned by given track.
84  virtual void ClearAssigned(pma::Track3D* trk = 0);
85 
86  void UpdateHitParams(void);
87  void UpdateProjection(void) { for (auto h : fAssignedHits) SetProjection(*h); }
88  void SortHits(void);
89 
90  double SumDist2(void) const;
91  double SumDist2(unsigned int view) const;
92  double SumHitsQ(unsigned int view) const { return fSumHitsQ[view]; }
93  unsigned int NHits(unsigned int view) const { return fNHits[view]; }
94  unsigned int NThisHits(unsigned int view) const { return fNThisHits[view]; }
95 
96  double HitsRadius3D(unsigned int view) const;
97 
98  /// Check if the vertex 3D position is fixed.
99  bool IsFrozen(void) const { return fFrozen; }
100  /// Fix / relese vertex 3D position.
101  void SetFrozen(bool state) { fFrozen = state; }
102 
103  bool SelectRndHits(size_t nmax_per_view);
104  bool SelectAllHits(void);
105 
106  static float OptFactor(unsigned int view) { return fOptFactors[view]; }
107  static void SetOptFactor(unsigned int view, float value) { fOptFactors[view] = value; }
108 
109 protected:
110  Element3D(void); // Element3D is only a common base for nodes and segments
111  int fTPC, fCryo; // -1 if out of any TPC or cryostat
112 
113  virtual double SumDist2Hits(void) const = 0;
114 
115  bool fFrozen;
116  std::vector< pma::Hit3D* > fAssignedHits; // 2D hits
117  std::vector< TVector3* > fAssignedPoints; // 3D peculiar points reconstructed elsewhere
118  size_t fNThisHits[3];
120  size_t fNHits[3];
121  double fSumHitsQ[3];
122  double fHitsRadius;
123 
124  static float fOptFactors[3]; // impact factors of data from various 2D views
125 };
126 
127 #endif
size_t NPrecalcEnabledHits(void) const
Definition: PmaElement3D.h:76
unsigned int NHits(unsigned int view) const
Definition: PmaElement3D.h:93
double fSumHitsQ[3]
Definition: PmaElement3D.h:121
bool HasHit(const pma::Hit3D *h) const
Definition: PmaElement3D.h:56
void RemoveHitAt(size_t index)
Definition: PmaElement3D.h:63
static void SetOptFactor(unsigned int view, float value)
Definition: PmaElement3D.h:107
Unknown view.
Definition: geo_types.h:136
virtual TVector3 GetUnconstrainedProj3D(const TVector2 &p2d, unsigned int view) const =0
void AddPoint(TVector3 *p)
Definition: PmaElement3D.h:80
size_t fNThisHits[3]
Definition: PmaElement3D.h:118
virtual void SetProjection(pma::Hit3D &h) const =0
double SumHitsQ(unsigned int view) const
Definition: PmaElement3D.h:92
recob::tracking::Vector_t Vector3D
Definition: Utilities.h:31
double HitsRadius3D(unsigned int view) const
virtual double Length2(void) const =0
virtual void ClearAssigned(pma::Track3D *trk=0)
virtual pma::Vector3D GetDirection3D(void) const =0
Get 3D direction cosines corresponding to this element.
int TPC(void) const
TPC index or -1 if out of any TPC.
Definition: PmaElement3D.h:34
size_t NPoints(void) const
Definition: PmaElement3D.h:79
size_t fNHits[3]
Definition: PmaElement3D.h:120
const std::vector< pma::Hit3D * > & Hits(void) const
Definition: PmaElement3D.h:54
std::vector< TVector3 * > fAssignedPoints
Definition: PmaElement3D.h:117
const double a
void SetFrozen(bool state)
Fix / relese vertex 3D position.
Definition: PmaElement3D.h:101
p
Definition: test.py:223
std::vector< pma::Hit3D * > fAssignedHits
Definition: PmaElement3D.h:116
pma::Hit3D & Hit(size_t index)
Definition: PmaElement3D.h:62
static float fOptFactors[3]
Definition: PmaElement3D.h:124
Definition of data types for geometry description.
double SumDist2(void) const
unsigned int NThisHits(unsigned int view) const
Definition: PmaElement3D.h:94
int Cryo(void) const
Cryostat index or -1 if out of any cryostat.
Definition: PmaElement3D.h:36
Implementation of the Projection Matching Algorithm.
void UpdateProjection(void)
Definition: PmaElement3D.h:87
void SortHits(void)
bool SelectRndHits(size_t nmax_per_view)
bool IsFrozen(void) const
Check if the vertex 3D position is fixed.
Definition: PmaElement3D.h:99
size_t fNThisHitsEnabledAll
Definition: PmaElement3D.h:119
TVector3 const & ReferencePoint(size_t index) const
Definition: PmaElement3D.h:78
double fHitsRadius
Definition: PmaElement3D.h:122
virtual double GetDistance2To(const TVector3 &p3d) const =0
Distance [cm] from the 3D point to the object 3D.
void AddHit(pma::Hit3D *h)
Definition: PmaElement3D.h:68
void UpdateHitParams(void)
bool SelectAllHits(void)
virtual double SumDist2Hits(void) const =0
size_t NHits(void) const
Definition: PmaElement3D.h:74
double Length(void) const
Definition: PmaElement3D.h:52
size_t NEnabledHits(unsigned int view=geo::kUnknown) const
static float OptFactor(unsigned int view)
Definition: PmaElement3D.h:106