PmaNode3D.h
Go to the documentation of this file.
1 /**
2  * @file PmaNode3D.h
3  *
4  * @author D.Stefan and R.Sulej
5  *
6  * @brief Implementation of the Projection Matching Algorithm
7  *
8  * 3D track node. See PmaTrack3D.h file for details.
9  */
10 
11 #ifndef PmaNode3D_h
12 #define PmaNode3D_h
13 
17 namespace detinfo {
18  class DetectorPropertiesData;
19 }
20 
21 #include "TVector2.h"
22 #include "TVector3.h"
23 
24 #include <vector>
25 
26 namespace geo {
27  class TPCGeo;
28 }
29 
30 namespace pma {
31  class Node3D;
32 }
33 
34 class pma::Node3D final : public pma::Element3D, public pma::SortedBranchBase {
35 public:
36  Node3D();
38  const TVector3& p3d,
39  unsigned int tpc,
40  unsigned int cryo,
41  bool vtx = false,
42  double xshift = 0);
43 
44  TVector3 const&
45  Point3D() const
46  {
47  return fPoint3D;
48  }
49 
50  /// Returns true if the new position was accepted; returns false if the new position
51  /// was trimmed to fit insite TPC volume + fMargin.
52  bool SetPoint3D(const TVector3& p3d);
53 
54  TVector2 const&
55  Projection2D(unsigned int view) const
56  {
57  return fProj2D[view];
58  }
59 
60  double GetDistToWall() const;
61 
62  /// Check if p3d is in the same TPC as the node.
63  bool SameTPC(const TVector3& p3d, float margin = 0.0F) const;
64  bool SameTPC(const pma::Vector3D& p3d, float margin = 0.0F) const;
65 
66  /// Belongs to more than one track?
67  bool IsBranching() const;
68 
69  /// Is the first/last in this TPC?
70  bool IsTPCEdge() const;
71 
72  /// Check fIsVertex flag.
73  bool
74  IsVertex() const
75  {
76  return fIsVertex;
77  }
78  void
79  SetVertex(bool state)
80  {
81  fIsVertex = state;
82  }
83  void
84  SetVertexToBranching(bool setAllNodes)
85  {
86  if (setAllNodes || !fIsVertex) fIsVertex = IsBranching();
87  }
88 
89  std::vector<pma::Track3D*> GetBranches() const;
90 
91  /// Distance [cm] from the 3D point to the point 3D.
92  double GetDistance2To(const TVector3& p3d) const override;
93 
94  /// Distance [cm] from the 2D point to the object's 2D projection in one of
95  /// wire views.
96  double GetDistance2To(const TVector2& p2d, unsigned int view) const override;
97 
98  /// Get 3D direction cosines of the next segment, or pevious segment if this
99  /// is the last node.
100  pma::Vector3D GetDirection3D() const override;
101 
102  /// In case of a node it is simply 3D position of the node.
103  TVector3
104  GetUnconstrainedProj3D(const TVector2& p2d, unsigned int view) const override
105  {
106  return fPoint3D;
107  }
108 
109  /// Set hit 3D position and its 2D projection to the vertex.
110  void SetProjection(pma::Hit3D& h) const override;
111 
112  /// Squared sum of half-lengths of connected 3D segments
113  /// (used in the vertex position optimization).
114  double Length2() const override;
115 
116  /// Cosine of 3D angle between connected segments.
117  double SegmentCos() const;
118  /// Cosine of 2D angle (in plane parallel to wire planes) between connected
119  /// segments. Should be changed / generalized for horizontal wire planes (e.g.
120  /// 2-phase LAr).
121  double SegmentCosWirePlane() const;
122  /// Cosine of 2D angle (in horizontal plane, parallel to drift) between
123  /// connected segments. Should be changed / generalized for horizontal wire
124  /// planes (e.g. 2-phase LAr).
125  double SegmentCosTransverse() const;
126 
127  /// Objective function minimized during oprimization.
128  double GetObjFunction(float penaltyValue, float endSegWeight) const;
129 
130  /// Optimize vertex 3D position with given penalty on connected
131  /// segments angle and weight assigned to the outermost segments.
132  /// Only MSE is used in case of branching nodes.
133  void Optimize(float penaltyValue, float endSegWeight);
134 
135  void ClearAssigned(pma::Track3D* trk = 0) override;
136 
137  void
138  ApplyDriftShift(double dx)
139  {
140  fPoint3D[0] += dx;
141  fDriftOffset += dx;
142  }
143  double
145  {
146  return fDriftOffset;
147  }
148 
149  /// Set allowed node position margin around TPC.
150  static void
151  SetMargin(double m)
152  {
153  if (m >= 0.0) fMargin = m;
154  }
155 
156 private:
157  /// Returns true if node position was trimmed to its TPC volume + fMargin
158  bool LimitPoint3D();
159  void UpdateProj2D();
160 
161  double EndPtCos2Transverse() const;
162  double PiInWirePlane() const;
163  double PenaltyInWirePlane() const;
164 
165  double Pi(float endSegWeight, bool doAsymm) const;
166  double Penalty(float endSegWeight) const;
167  double Mse() const;
168 
169  double MakeGradient(float penaltyValue, float endSegWeight);
170  double StepWithGradient(float alfa, float tol, float penalty, float weight);
171 
172  double SumDist2Hits() const override;
173 
175 
176  double fMinX, fMaxX, fMinY, fMaxY, fMinZ,
177  fMaxZ; // TPC boundaries to limit the node position (+margin)
178 
179  TVector3 fPoint3D; // node position in 3D space in [cm]
180  TVector2 fProj2D[3]; // node projections to 2D views, scaled to [cm], updated
181  // on each change of 3D position
182  double fDriftOffset; // the offset due to t0
183 
184  TVector3 fGradient;
185  bool fIsVertex; // no penalty on segments angle if branching or kink detected
186 
187  static bool fGradFixed[3];
188  static double fMargin;
189 };
190 
191 #endif
void ApplyDriftShift(double dx)
Definition: PmaNode3D.h:138
TVector3 const & Point3D() const
Definition: PmaNode3D.h:45
void SetVertexToBranching(bool setAllNodes)
Definition: PmaNode3D.h:84
TVector2 const & Projection2D(unsigned int view) const
Definition: PmaNode3D.h:55
double fMinZ
Definition: PmaNode3D.h:176
auto const tol
Definition: SurfXYZTest.cc:16
double fDriftOffset
Definition: PmaNode3D.h:182
Geometry information for a single TPC.
Definition: TPCGeo.h:38
void SetVertex(bool state)
Definition: PmaNode3D.h:79
static void SetMargin(double m)
Set allowed node position margin around TPC.
Definition: PmaNode3D.h:151
recob::tracking::Vector_t Vector3D
Definition: Utilities.h:31
weight
Definition: test.py:257
def MakeGradient(nsteps, start, end)
Definition: HandyFuncs.py:138
Implementation of the Projection Matching Algorithm.
double GetDriftShift() const
Definition: PmaNode3D.h:144
bool IsVertex() const
Check fIsVertex flag.
Definition: PmaNode3D.h:74
General LArSoft Utilities.
Implementation of the Projection Matching Algorithm.
TVector3 GetUnconstrainedProj3D(const TVector2 &p2d, unsigned int view) const override
In case of a node it is simply 3D position of the node.
Definition: PmaNode3D.h:104
geo::TPCGeo const & fTpcGeo
Definition: PmaNode3D.h:174
TVector3 fPoint3D
Definition: PmaNode3D.h:179
static double fMargin
Definition: PmaNode3D.h:188
LArSoft geometry interface.
Definition: ChannelGeo.h:16
bool fIsVertex
Definition: PmaNode3D.h:185
Implementation of the Projection Matching Algorithm.
TVector3 fGradient
Definition: PmaNode3D.h:184