All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
pma::Segment3D Class Reference

#include <PmaSegment3D.h>

Inheritance diagram for pma::Segment3D:
pma::Element3D pma::SortedObjectBase

Public Member Functions

 Segment3D (void)
 
 Segment3D (pma::Track3D *trk, pma::Node3D *vstart, pma::Node3D *vstop)
 
Vector3D Start (void) const
 
Vector3D End (void) const
 
double GetDistance2To (const TVector3 &p3d) const override
 Distance [cm] from the 3D segment to the point 3D. More...
 
double GetDistance2To (const TVector2 &p2d, unsigned int view) const override
 Distance [cm] from the 2D point to the object's 2D projection in one of wire views. More...
 
pma::Vector3D GetDirection3D (void) const override
 Get 3D direction cosines of this segment. More...
 
TVector3 GetProjection (const TVector2 &p, unsigned int view) const
 Get 3D projection of a 2D point from the view. More...
 
TVector3 GetUnconstrainedProj3D (const TVector2 &p2d, unsigned int view) const override
 
void SetProjection (pma::Hit3D &h) const override
 Set hit 3D position and its 2D projection to the vertex. More...
 
double Length2 (void) const override
 
pma::Track3DParent (void) const
 
- Public Member Functions inherited from pma::Element3D
int TPC (void) const
 TPC index or -1 if out of any TPC. More...
 
int Cryo (void) const
 Cryostat index or -1 if out of any cryostat. More...
 
double Length (void) const
 
const std::vector< pma::Hit3D * > & Hits (void) const
 
bool HasHit (const pma::Hit3D *h) const
 
pma::Hit3DHit (size_t index)
 
void RemoveHitAt (size_t index)
 
void AddHit (pma::Hit3D *h)
 
size_t NHits (void) const
 
size_t NEnabledHits (unsigned int view=geo::kUnknown) const
 
size_t NPrecalcEnabledHits (void) const
 
TVector3 const & ReferencePoint (size_t index) const
 
size_t NPoints (void) const
 
void AddPoint (TVector3 *p)
 
virtual void ClearAssigned (pma::Track3D *trk=0)
 
void UpdateHitParams (void)
 
void UpdateProjection (void)
 
void SortHits (void)
 
double SumDist2 (void) const
 
double SumDist2 (unsigned int view) const
 
double SumHitsQ (unsigned int view) const
 
unsigned int NHits (unsigned int view) const
 
unsigned int NThisHits (unsigned int view) const
 
double HitsRadius3D (unsigned int view) const
 
bool IsFrozen (void) const
 Check if the vertex 3D position is fixed. More...
 
void SetFrozen (bool state)
 Fix / relese vertex 3D position. More...
 
bool SelectRndHits (size_t nmax_per_view)
 
bool SelectAllHits (void)
 
- Public Member Functions inherited from pma::SortedObjectBase
 SortedObjectBase (void)
 
 SortedObjectBase (pma::SortedObjectBase *prevElement, pma::SortedObjectBase *nextElement)
 
 SortedObjectBase (const pma::SortedObjectBase &src)
 Note: copy constructor does not preserve connections. More...
 
virtual ~SortedObjectBase (void)
 
virtual void Disconnect (void)
 
virtual bool AddNext (pma::SortedObjectBase *nextElement)
 
virtual int RemoveNext (pma::SortedObjectBase *nextElement)
 
virtual bool IsFirst (void) const
 
virtual bool IsLast (void) const
 
virtual pma::SortedObjectBasePrev (void) const
 
virtual pma::SortedObjectBaseNext (unsigned int index=0) const
 
virtual unsigned int NextCount (void) const
 

Private Member Functions

 Segment3D (const pma::Segment3D &src)
 
double SumDist2Hits (void) const override
 

Static Private Member Functions

static double GetDist2 (const TVector3 &psrc, const TVector3 &p0, const TVector3 &p1)
 
static double GetDist2 (const TVector2 &psrc, const TVector2 &p0, const TVector2 &p1)
 

Private Attributes

pma::Track3DfParent
 

Additional Inherited Members

- Static Public Member Functions inherited from pma::Element3D
static float OptFactor (unsigned int view)
 
static void SetOptFactor (unsigned int view, float value)
 
- Protected Member Functions inherited from pma::Element3D
 Element3D (void)
 
- Protected Attributes inherited from pma::Element3D
int fTPC
 
int fCryo
 
bool fFrozen
 
std::vector< pma::Hit3D * > fAssignedHits
 
std::vector< TVector3 * > fAssignedPoints
 
size_t fNThisHits [3]
 
size_t fNThisHitsEnabledAll
 
size_t fNHits [3]
 
double fSumHitsQ [3]
 
double fHitsRadius
 
- Protected Attributes inherited from pma::SortedObjectBase
pma::SortedObjectBasenext
 
pma::SortedObjectBaseprev
 
- Static Protected Attributes inherited from pma::Element3D
static float fOptFactors [3] = { 0.2F, 0.8F, 1.0F }
 

Detailed Description

Definition at line 28 of file PmaSegment3D.h.

Constructor & Destructor Documentation

pma::Segment3D::Segment3D ( void  )
inline

Definition at line 31 of file PmaSegment3D.h.

31 : fParent(0) {}
pma::Track3D * fParent
Definition: PmaSegment3D.h:75
pma::Segment3D::Segment3D ( pma::Track3D trk,
pma::Node3D vstart,
pma::Node3D vstop 
)

Definition at line 20 of file PmaSegment3D.cxx.

20  :
21  SortedObjectBase(vstart, vstop),
22  fParent(trk)
23 {
24  if (vstart->TPC() == vstop->TPC()) fTPC = vstart->TPC();
25  if (vstart->Cryo() == vstop->Cryo()) fCryo = vstart->Cryo();
26 }
pma::Track3D * fParent
Definition: PmaSegment3D.h:75
int TPC(void) const
TPC index or -1 if out of any TPC.
Definition: PmaElement3D.h:35
int Cryo(void) const
Cryostat index or -1 if out of any cryostat.
Definition: PmaElement3D.h:37
pma::Segment3D::Segment3D ( const pma::Segment3D src)
private

Member Function Documentation

Vector3D pma::Segment3D::End ( void  ) const
inline

Definition at line 39 of file PmaSegment3D.h.

40  {
41  auto const & p = static_cast< Node3D* >(Next())->Point3D();
42  return Vector3D(p.X(), p.Y(), p.Z());
43  }
::fhicl::TupleAs< Point(::geo::Length_t,::geo::Length_t,::geo::Length_t)> Point3D
Atom object for reading a 3D point or vector (centimeters).
pdgs p
Definition: selectors.fcl:22
recob::tracking::Vector_t Vector3D
virtual pma::SortedObjectBase * Next(unsigned int index=0) const
Definition: SortedObjects.h:45
pma::Vector3D pma::Segment3D::GetDirection3D ( void  ) const
overridevirtual

Get 3D direction cosines of this segment.

Implements pma::Element3D.

Definition at line 61 of file PmaSegment3D.cxx.

62 {
63  pma::Node3D* v0 = static_cast< pma::Node3D* >(prev);
64  pma::Node3D* v1 = static_cast< pma::Node3D* >(next);
66  v1->Point3D().X() - v0->Point3D().X(),
67  v1->Point3D().Y() - v0->Point3D().Y(),
68  v1->Point3D().Z() - v0->Point3D().Z());
69  return dir.Unit();
70 }
TVector3 const & Point3D() const
Definition: PmaNode3D.h:45
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
recob::tracking::Vector_t Vector3D
tuple dir
Definition: dropbox.py:28
pma::SortedObjectBase * next
Definition: SortedObjects.h:53
double pma::Segment3D::GetDist2 ( const TVector3 &  psrc,
const TVector3 &  p0,
const TVector3 &  p1 
)
staticprivate

Definition at line 221 of file PmaSegment3D.cxx.

222 {
223  pma::Vector3D v0(psrc.X() - p0.X(), psrc.Y() - p0.Y(), psrc.Z() - p0.Z());
224  pma::Vector3D v1(p1.X() - p0.X(), p1.Y() - p0.Y(), p1.Z() - p0.Z());
225  pma::Vector3D v2(psrc.X() - p1.X(), psrc.Y() - p1.Y(), psrc.Z() - p1.Z());
226 
227  double v1Norm2 = v1.Mag2();
228  if (v1Norm2 >= 1.0E-6) // >= 0.01mm
229  {
230  double v0v1 = v0.Dot(v1);
231  double v2v1 = v2.Dot(v1);
232  double v0Norm2 = v0.Mag2();
233  double v2Norm2 = v2.Mag2();
234 
235  double result = 0.0;
236  if ((v0v1 > 0.0) && (v2v1 < 0.0))
237  {
238  double cosine01_square = 0.0;
239  double mag01_square = v0Norm2 * v1Norm2;
240  if (mag01_square != 0.0) cosine01_square = v0v1 * v0v1 / mag01_square;
241 
242  result = (1.0 - cosine01_square) * v0Norm2;
243  }
244  else // increase distance to prefer hit assigned to the vertex, not segment
245  {
246  if (v0v1 <= 0.0) result = 1.0001 * v0Norm2;
247  else result = 1.0001 * v2Norm2;
248  }
249 
250  if (result >= 0.0) return result;
251  else return 0.0;
252  }
253  else // short segment or its projection
254  {
255  double dx = 0.5 * (p0.X() + p1.X()) - psrc.X();
256  double dy = 0.5 * (p0.Y() + p1.Y()) - psrc.Y();
257  double dz = 0.5 * (p0.Z() + p1.Z()) - psrc.Z();
258  return dx * dx + dy * dy + dz * dz;
259  }
260 }
process_name E
recob::tracking::Vector_t Vector3D
physics associatedGroupsWithLeft p1
double pma::Segment3D::GetDist2 ( const TVector2 &  psrc,
const TVector2 &  p0,
const TVector2 &  p1 
)
staticprivate

Definition at line 262 of file PmaSegment3D.cxx.

263 {
264  pma::Vector2D v0(psrc.X() - p0.X(), psrc.Y() - p0.Y());
265  pma::Vector2D v1(p1.X() - p0.X(), p1.Y() - p0.Y());
266  pma::Vector2D v2(psrc.X() - p1.X(), psrc.Y() - p1.Y());
267 
268  double v1Norm2 = v1.Mag2();
269  if (v1Norm2 >= 1.0E-6) // >= 0.01mm
270  {
271  double v0v1 = v0.Dot(v1);
272  double v2v1 = v2.Dot(v1);
273  double v0Norm2 = v0.Mag2();
274  double v2Norm2 = v2.Mag2();
275 
276  double result = 0.0;
277  if ((v0v1 > 0.0) && (v2v1 < 0.0))
278  {
279  double cosine01_square = 0.0;
280  double mag01_square = v0Norm2 * v1Norm2;
281  if (mag01_square != 0.0) cosine01_square = v0v1 * v0v1 / mag01_square;
282 
283  result = (1.0 - cosine01_square) * v0Norm2;
284  }
285  else // increase distance to prefer hit assigned to the vertex, not segment
286  {
287  if (v0v1 <= 0.0) result = 1.0001 * v0Norm2;
288  else result = 1.0001 * v2Norm2;
289  }
290  if (result >= 0.0) return result;
291  else return 0.0;
292  }
293  else // short segment or its projection
294  {
295  double dx = 0.5 * (p0.X() + p1.X()) - psrc.X();
296  double dy = 0.5 * (p0.Y() + p1.Y()) - psrc.Y();
297  return dx * dx + dy * dy;
298  }
299 }
process_name E
ROOT::Math::DisplacementVector2D< ROOT::Math::Cartesian2D< double > > Vector2D
physics associatedGroupsWithLeft p1
double pma::Segment3D::GetDistance2To ( const TVector3 &  p3d) const
overridevirtual

Distance [cm] from the 3D segment to the point 3D.

Implements pma::Element3D.

Definition at line 28 of file PmaSegment3D.cxx.

29 {
30  pma::Node3D* v0 = static_cast< pma::Node3D* >(prev);
31  pma::Node3D* v1 = static_cast< pma::Node3D* >(next);
32  return GetDist2(p3d, v0->Point3D(), v1->Point3D());
33 }
TVector3 const & Point3D() const
Definition: PmaNode3D.h:45
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
pma::SortedObjectBase * next
Definition: SortedObjects.h:53
static double GetDist2(const TVector3 &psrc, const TVector3 &p0, const TVector3 &p1)
double pma::Segment3D::GetDistance2To ( const TVector2 &  p2d,
unsigned int  view 
) const
overridevirtual

Distance [cm] from the 2D point to the object's 2D projection in one of wire views.

Implements pma::Element3D.

Definition at line 35 of file PmaSegment3D.cxx.

36 {
37  pma::Node3D* v0 = static_cast< pma::Node3D* >(prev);
38  pma::Node3D* v1 = static_cast< pma::Node3D* >(next);
39  return GetDist2(p2d, v0->Projection2D(view), v1->Projection2D(view));
40 }
TVector2 const & Projection2D(unsigned int view) const
Definition: PmaNode3D.h:55
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
pma::SortedObjectBase * next
Definition: SortedObjects.h:53
static double GetDist2(const TVector3 &psrc, const TVector3 &p0, const TVector3 &p1)
TVector3 pma::Segment3D::GetProjection ( const TVector2 &  p,
unsigned int  view 
) const

Get 3D projection of a 2D point from the view.

Definition at line 72 of file PmaSegment3D.cxx.

73 {
74  pma::Node3D* vStart = static_cast< pma::Node3D* >(prev);
75  pma::Node3D* vStop = static_cast< pma::Node3D* >(next);
76 
77  TVector2 v0(p);
78  v0 -= vStart->Projection2D(view);
79 
80  TVector2 v1(vStop->Projection2D(view));
81  v1 -= vStart->Projection2D(view);
82 
83  TVector3 v3d(vStop->Point3D());
84  v3d -= vStart->Point3D();
85 
86  TVector3 v3dStart(vStart->Point3D());
87  TVector3 v3dStop(vStop->Point3D());
88 
89  double v0Norm = v0.Mod();
90  double v1Norm = v1.Mod();
91 
92  TVector3 result(0, 0, 0);
93  if (v1Norm > 1.0E-6)// 0.01mm
94  {
95  double mag = v0Norm * v1Norm;
96  double cosine = 0.0;
97  if (mag != 0.0) cosine = v0 * v1 / mag;
98  double b = v0Norm * cosine / v1Norm;
99 
100  if (b < 1.0)
101  {
102  result = v3dStart;
103  if (b > 0.0) result += (v3d * b);
104  }
105  else result = v3dStop;
106  }
107  else // segment 2D projection is almost a point
108  {
109  mf::LogWarning("pma::Segment3D") << "Short segment projection.";
110 
111  result = v3dStart;
112  result += v3dStop;
113  result *= 0.5;
114  }
115  return result;
116 }
TVector3 const & Point3D() const
Definition: PmaNode3D.h:45
TVector2 const & Projection2D(unsigned int view) const
Definition: PmaNode3D.h:55
pdgs p
Definition: selectors.fcl:22
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
process_name E
pma::SortedObjectBase * next
Definition: SortedObjects.h:53
TVector3 pma::Segment3D::GetUnconstrainedProj3D ( const TVector2 &  p2d,
unsigned int  view 
) const
overridevirtual

Get 3D projection of a 2D point from the view, no limitations if it falls beyond the segment endpoints.

Implements pma::Element3D.

Definition at line 118 of file PmaSegment3D.cxx.

119 {
120  pma::Node3D* vStart = static_cast< pma::Node3D* >(prev);
121  pma::Node3D* vStop = static_cast< pma::Node3D* >(next);
122 
123  TVector2 v0(p2d);
124  v0 -= vStart->Projection2D(view);
125 
126  TVector2 v1(vStop->Projection2D(view));
127  v1 -= vStart->Projection2D(view);
128 
129  TVector3 v3d(vStop->Point3D());
130  v3d -= vStart->Point3D();
131 
132  double v0Norm = v0.Mod();
133  double v1Norm = v1.Mod();
134  if (v1Norm > 1.0E-6) // 0.01mm
135  {
136  double mag = v0Norm * v1Norm;
137  double cosine = 0.0;
138  if (mag != 0.0) cosine = v0 * v1 / mag;
139  double b = v0Norm * cosine / v1Norm;
140 
141  return vStart->Point3D() + (v3d * b);
142  }
143  else // segment 2D projection is almost a point
144  {
145  v3d = vStart->Point3D();
146  v3d += vStop->Point3D();
147  v3d *= 0.5;
148 
149  return v3d;
150  }
151 }
TVector3 const & Point3D() const
Definition: PmaNode3D.h:45
TVector2 const & Projection2D(unsigned int view) const
Definition: PmaNode3D.h:55
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
process_name E
pma::SortedObjectBase * next
Definition: SortedObjects.h:53
double pma::Segment3D::Length2 ( void  ) const
overridevirtual

Squared sum of half-lengths of connected 3D segments (used in the vertex position optimization).

Implements pma::Element3D.

Definition at line 209 of file PmaSegment3D.cxx.

210 {
211  if (prev && next)
212  return pma::Dist2( ((pma::Node3D*)prev)->Point3D(), ((pma::Node3D*)next)->Point3D() );
213  else
214  {
215  mf::LogError("pma::Segment3D") << "Segment endpoints not set.";
216  return 0.0;
217  }
218 }
double Dist2(const TVector2 &v1, const TVector2 &v2)
::fhicl::TupleAs< Point(::geo::Length_t,::geo::Length_t,::geo::Length_t)> Point3D
Atom object for reading a 3D point or vector (centimeters).
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
pma::SortedObjectBase * next
Definition: SortedObjects.h:53
pma::Track3D* pma::Segment3D::Parent ( void  ) const
inline

Definition at line 68 of file PmaSegment3D.h.

68 { return fParent; }
pma::Track3D * fParent
Definition: PmaSegment3D.h:75
void pma::Segment3D::SetProjection ( pma::Hit3D h) const
overridevirtual

Set hit 3D position and its 2D projection to the vertex.

Implements pma::Element3D.

Definition at line 153 of file PmaSegment3D.cxx.

154 {
155  pma::Node3D* vStart = static_cast< pma::Node3D* >(prev);
156  pma::Node3D* vStop = static_cast< pma::Node3D* >(next);
157 
158  auto const & pointStart = vStart->Point3D();
159  auto const & pointStop = vStop->Point3D();
160 
161  auto const & projStart = vStart->Projection2D(h.View2D());
162  auto const & projStop = vStop->Projection2D(h.View2D());
163 
164  pma::Vector2D v0(
165  h.Point2D().X() - projStart.X(),
166  h.Point2D().Y() - projStart.Y());
167 
168  pma::Vector2D v1(
169  projStop.X() - projStart.X(),
170  projStop.Y() - projStart.Y());
171 
172  pma::Vector3D v3d(
173  pointStop.X() - pointStart.X(),
174  pointStop.Y() - pointStart.Y(),
175  pointStop.Z() - pointStart.Z());
176 
177  double v0Norm = sqrt(v0.Mag2());
178  double v1Norm = sqrt(v1.Mag2());
179  if (v1Norm > 1.0E-6) // 0.01mm
180  {
181  double mag = v0Norm * v1Norm;
182  double cosine = 0.0;
183  if (mag != 0.0) cosine = v0.Dot(v1) / mag;
184  double b = v0Norm * cosine / v1Norm;
185 
186  pma::Vector2D p(projStart.X(), projStart.Y());
187  p += (v1 * b);
188  v3d *= b;
189 
190  h.SetProjection(p.X(), p.Y(), (float)b);
191  h.SetPoint3D(
192  pointStart.X() + v3d.X(),
193  pointStart.Y() + v3d.Y(),
194  pointStart.Z() + v3d.Z());
195  }
196  else // segment 2D projection is almost a point
197  {
198  h.SetProjection(
199  0.5 * (projStart.X() + projStop.X()),
200  0.5 * (projStart.Y() + projStop.Y()), 0.0F);
201 
202  h.SetPoint3D(
203  0.5 * (pointStart.X() + pointStop.X()),
204  0.5 * (pointStart.Y() + pointStop.Y()),
205  0.5 * (pointStart.Z() + pointStop.Z()));
206  }
207 }
TVector3 const & Point3D() const
Definition: PmaNode3D.h:45
TVector2 const & Projection2D(unsigned int view) const
Definition: PmaNode3D.h:55
pdgs p
Definition: selectors.fcl:22
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
process_name E
recob::tracking::Vector_t Vector3D
unsigned int View2D() const noexcept
Definition: PmaHit3D.h:93
void SetProjection(const TVector2 &p, float b)
Definition: PmaHit3D.h:148
TVector2 const & Point2D() const noexcept
Definition: PmaHit3D.h:72
void SetPoint3D(const TVector3 &p3d)
Definition: PmaHit3D.h:61
ROOT::Math::DisplacementVector2D< ROOT::Math::Cartesian2D< double > > Vector2D
pma::SortedObjectBase * next
Definition: SortedObjects.h:53
Vector3D pma::Segment3D::Start ( void  ) const
inline

Definition at line 34 of file PmaSegment3D.h.

35  {
36  auto const & p = static_cast< Node3D* >(Prev())->Point3D();
37  return Vector3D(p.X(), p.Y(), p.Z());
38  }
::fhicl::TupleAs< Point(::geo::Length_t,::geo::Length_t,::geo::Length_t)> Point3D
Atom object for reading a 3D point or vector (centimeters).
pdgs p
Definition: selectors.fcl:22
recob::tracking::Vector_t Vector3D
virtual pma::SortedObjectBase * Prev(void) const
Definition: SortedObjects.h:44
double pma::Segment3D::SumDist2Hits ( void  ) const
overrideprivatevirtual

Implements pma::Element3D.

Definition at line 42 of file PmaSegment3D.cxx.

43 {
44  pma::Node3D* v0 = static_cast< pma::Node3D* >(prev);
45  pma::Node3D* v1 = static_cast< pma::Node3D* >(next);
46 
47  double sum = 0.0F;
48  for (auto h : fAssignedHits)
49  {
50  if (h->IsEnabled())
51  {
52  unsigned int view = h->View2D();
53 
54  sum += OptFactor(view) * h->GetSigmaFactor() // alpha_i * (hit_amp / hit_max_amp)
55  * GetDist2(h->Point2D(), v0->Projection2D(view), v1->Projection2D(view));
56  }
57  }
58  return sum;
59 }
TVector2 const & Projection2D(unsigned int view) const
Definition: PmaNode3D.h:55
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
while getopts h
std::vector< pma::Hit3D * > fAssignedHits
Definition: PmaElement3D.h:117
pma::SortedObjectBase * next
Definition: SortedObjects.h:53
static float OptFactor(unsigned int view)
Definition: PmaElement3D.h:107
static double GetDist2(const TVector3 &psrc, const TVector3 &p0, const TVector3 &p1)

Member Data Documentation

pma::Track3D* pma::Segment3D::fParent
private

Definition at line 75 of file PmaSegment3D.h.


The documentation for this class was generated from the following files: