LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
pma::Node3D Class Reference

#include "PmaNode3D.h"

Inheritance diagram for pma::Node3D:
pma::Element3D pma::SortedBranchBase pma::SortedObjectBase

Public Member Functions

 Node3D (void)
 
 Node3D (const TVector3 &p3d, unsigned int tpc, unsigned int cryo, bool vtx=false, double xshift=0)
 
TVector3 const & Point3D (void) const
 
bool SetPoint3D (const TVector3 &p3d)
 
TVector2 const & Projection2D (unsigned int view) const
 
double GetDistToWall (void) const
 
bool SameTPC (const TVector3 &p3d, float margin=0.0F) const
 Check if p3d is in the same TPC as the node. More...
 
bool SameTPC (const pma::Vector3D &p3d, float margin=0.0F) const
 
bool IsBranching (void) const
 Belongs to more than one track? More...
 
bool IsTPCEdge (void) const
 Is the first/last in this TPC? More...
 
bool IsVertex (void) const
 Check fIsVertex flag. More...
 
void SetVertex (bool state)
 
void SetVertexToBranching (bool setAllNodes)
 
std::vector< pma::Track3D * > GetBranches (void) const
 
double GetDistance2To (const TVector3 &p3d) const override
 Distance [cm] from the 3D point 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 the next segment, or pevious segment if this is the last node. More...
 
TVector3 GetUnconstrainedProj3D (const TVector2 &p2d, unsigned int view) const override
 In case of a node it is simply 3D position of the node. More...
 
void SetProjection (pma::Hit3D &h) const override
 Set hit 3D position and its 2D projection to the vertex. More...
 
double Length2 (void) const override
 
double SegmentCos (void) const
 Cosine of 3D angle between connected segments. More...
 
double SegmentCosWirePlane (void) const
 
double SegmentCosTransverse (void) const
 
double GetObjFunction (float penaltyValue, float endSegWeight) const
 Objective function minimized during oprimization. More...
 
void Optimize (float penaltyValue, float endSegWeight)
 
void ClearAssigned (pma::Track3D *trk=0) override
 
void ApplyDriftShift (double dx)
 
double GetDriftShift (void) const
 
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
 
unsigned int NHits (unsigned int view) 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)
 
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 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)
 
virtual void Disconnect (void)
 
virtual bool AddNext (pma::SortedObjectBase *nextElement)
 
virtual int RemoveNext (pma::SortedObjectBase *nextElement)
 
virtual pma::SortedObjectBaseNext (unsigned int index=0) const
 
virtual unsigned int NextCount (void) const
 
virtual bool IsLast (void) const
 
virtual bool IsFirst (void) const
 
virtual pma::SortedObjectBasePrev (void) const
 

Static Public Member Functions

static void SetMargin (double m)
 Set allowed node position margin around TPC. More...
 
static float OptFactor (unsigned int view)
 
static void SetOptFactor (unsigned int view, float value)
 

Protected Attributes

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
 
std::vector< pma::SortedObjectBase * > next_vector
 
pma::SortedObjectBasenext
 
pma::SortedObjectBaseprev
 

Static Protected Attributes

static float fOptFactors [3] = { 0.2F, 0.8F, 1.0F }
 

Private Member Functions

bool LimitPoint3D (void)
 Returns true if node position was trimmed to its TPC volume + fMargin. More...
 
void UpdateProj2D (void)
 
double EndPtCos2Transverse (void) const
 
double PiInWirePlane (void) const
 
double PenaltyInWirePlane (void) const
 
double Pi (float endSegWeight, bool doAsymm) const
 
double Penalty (float endSegWeight) const
 
double Mse (void) const
 
double MakeGradient (float penaltyValue, float endSegWeight)
 
double StepWithGradient (float alfa, float tol, float penalty, float weight)
 
double SumDist2Hits (void) const override
 

Private Attributes

geo::TPCGeo const & fTpcGeo
 
double fMinX
 
double fMaxX
 
double fMinY
 
double fMaxY
 
double fMinZ
 
double fMaxZ
 
TVector3 fPoint3D
 
TVector2 fProj2D [3]
 
double fDriftOffset
 
TVector3 fGradient
 
bool fIsVertex
 

Static Private Attributes

static bool fGradFixed [3] = { false, false, false }
 
static double fMargin = 3.0
 

Detailed Description

Definition at line 27 of file PmaNode3D.h.

Constructor & Destructor Documentation

pma::Node3D::Node3D ( void  )

Definition at line 25 of file PmaNode3D.cxx.

References pma::Element3D::fCryo, fProj2D, and pma::Element3D::fTPC.

25  :
27  fMinX(0), fMaxX(0),
28  fMinY(0), fMaxY(0),
29  fMinZ(0), fMaxZ(0),
30  fPoint3D(0, 0, 0),
31  fDriftOffset(0),
32  fIsVertex(false)
33 {
34  fTPC = 0; fCryo = 0;
35 
36  fProj2D[0].Set(0);
37  fProj2D[1].Set(0);
38  fProj2D[2].Set(0);
39 }
double fMinZ
Definition: PmaNode3D.h:127
double fDriftOffset
Definition: PmaNode3D.h:131
int TPC(void) const
TPC index or -1 if out of any TPC.
Definition: PmaElement3D.h:31
TVector2 fProj2D[3]
Definition: PmaNode3D.h:130
double fMaxX
Definition: PmaNode3D.h:127
double fMaxY
Definition: PmaNode3D.h:127
double fMaxZ
Definition: PmaNode3D.h:127
double fMinY
Definition: PmaNode3D.h:127
geo::TPCGeo const & fTpcGeo
Definition: PmaNode3D.h:125
TVector3 fPoint3D
Definition: PmaNode3D.h:129
bool fIsVertex
Definition: PmaNode3D.h:134
double fMinX
Definition: PmaNode3D.h:127
pma::Node3D::Node3D ( const TVector3 &  p3d,
unsigned int  tpc,
unsigned int  cryo,
bool  vtx = false,
double  xshift = 0 
)

Definition at line 41 of file PmaNode3D.cxx.

References pma::Element3D::fCryo, fMaxX, fMaxY, fMaxZ, fMinX, fMinY, fMinZ, pma::Element3D::fTPC, fTpcGeo, geo::TPCGeo::HasPlane(), geo::kZ, geo::BoxBoundedGeo::MaxY(), geo::BoxBoundedGeo::MaxZ(), geo::BoxBoundedGeo::MinY(), geo::BoxBoundedGeo::MinZ(), SetPoint3D(), and tmp.

41  :
43  fDriftOffset(xshift),
44  fIsVertex(vtx)
45 {
46  fTPC = tpc; fCryo = cryo;
47 
48  unsigned int lastPlane = geo::kZ;
49  while ((lastPlane > 0) && !fTpcGeo.HasPlane(lastPlane)) lastPlane--;
50 
51  auto const *detprop = lar::providerFrom<detinfo::DetectorPropertiesService>();
52  fMinX = detprop->ConvertTicksToX(0, lastPlane, tpc, cryo);
53  fMaxX = detprop->ConvertTicksToX(detprop->NumberTimeSamples() - 1, lastPlane, tpc, cryo);
54 // fMinX = fTpcGeo.MinX();
55 // fMaxX = fTpcGeo.MaxX();
56  if (fMaxX < fMinX) { double tmp = fMaxX; fMaxX = fMinX; fMinX = tmp; }
57 
60 
61  SetPoint3D(p3d);
62 }
bool HasPlane(unsigned int iplane) const
Returns whether a plane with index iplane is present in this TPC.
Definition: TPCGeo.h:155
double fMinZ
Definition: PmaNode3D.h:127
double fDriftOffset
Definition: PmaNode3D.h:131
Planes which measure Z direction.
Definition: geo_types.h:79
Float_t tmp
Definition: plot.C:37
int TPC(void) const
TPC index or -1 if out of any TPC.
Definition: PmaElement3D.h:31
double fMaxX
Definition: PmaNode3D.h:127
bool SetPoint3D(const TVector3 &p3d)
Definition: PmaNode3D.cxx:123
double MinZ() const
Returns the world z coordinate of the start of the box.
double fMaxY
Definition: PmaNode3D.h:127
double fMaxZ
Definition: PmaNode3D.h:127
double MaxY() const
Returns the world y coordinate of the end of the box.
double fMinY
Definition: PmaNode3D.h:127
double MaxZ() const
Returns the world z coordinate of the end of the box.
geo::TPCGeo const & fTpcGeo
Definition: PmaNode3D.h:125
double MinY() const
Returns the world y coordinate of the start of the box.
bool fIsVertex
Definition: PmaNode3D.h:134
double fMinX
Definition: PmaNode3D.h:127

Member Function Documentation

void pma::Element3D::AddHit ( pma::Hit3D h)
inlineinherited

Definition at line 65 of file PmaElement3D.h.

References pma::Element3D::fAssignedHits, and pma::Element3D::SetProjection().

Referenced by pma::Track3D::MakeProjection().

66  {
67  fAssignedHits.push_back(h);
68  SetProjection(*h);
69  }
virtual void SetProjection(pma::Hit3D &h) const =0
std::vector< pma::Hit3D * > fAssignedHits
Definition: PmaElement3D.h:113
bool pma::SortedBranchBase::AddNext ( pma::SortedObjectBase nextElement)
virtualinherited

Reimplemented from pma::SortedObjectBase.

Definition at line 71 of file SortedObjects.cxx.

References pma::SortedObjectBase::next, art::productstatus::present(), pma::SortedObjectBase::prev, and pma::SortedObjectBase::RemoveNext().

Referenced by pma::Track3D::AttachBackToSameTPC(), and pma::Track3D::AttachToSameTPC().

72 {
73  if (!nextElement)
74  {
75  mf::LogError("pma::SortedBranchBase") << "Next == 0.";
76  return false;
77  }
78 
79  if (nextElement == this)
80  {
81  mf::LogWarning("pma::SortedBranchBase") << "Next == This.";
82  return false;
83  }
84 
85  bool present = false;
86  for (size_t i = 0; i < next_vector.size(); i++)
87  {
88  if (next_vector[i] == nextElement)
89  {
90  mf::LogWarning("pma::SortedBranchBase") << "Contained.";
91  present = true; break;
92  }
93  }
94  if (!present)
95  {
96  if (nextElement->prev) // && (nextElement->prev != this)
97  nextElement->prev->RemoveNext(nextElement);
98 
99  next = nextElement;
100  next->prev = this;
101  next_vector.push_back(next);
102  return true;
103  }
104  else return false;
105 }
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
std::vector< pma::SortedObjectBase * > next_vector
Definition: SortedObjects.h:88
virtual int RemoveNext(pma::SortedObjectBase *nextElement)
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
pma::SortedObjectBase * next
Definition: SortedObjects.h:53
ProductStatus present()
Definition: ProductStatus.h:16
void pma::Element3D::AddPoint ( TVector3 *  p)
inlineinherited

Definition at line 77 of file PmaElement3D.h.

References pma::Element3D::ClearAssigned(), pma::Element3D::fAssignedPoints, and pma::Element3D::UpdateHitParams().

Referenced by pma::Track3D::MakeProjection().

77 { fAssignedPoints.push_back(p); }
std::vector< TVector3 * > fAssignedPoints
Definition: PmaElement3D.h:114
void pma::Node3D::ApplyDriftShift ( double  dx)
inline

Definition at line 101 of file PmaNode3D.h.

References fDriftOffset, and fPoint3D.

Referenced by pma::Track3D::ApplyDriftShiftInTree().

101 { fPoint3D[0] += dx; fDriftOffset += dx; }
double fDriftOffset
Definition: PmaNode3D.h:131
TVector3 fPoint3D
Definition: PmaNode3D.h:129
void pma::Node3D::ClearAssigned ( pma::Track3D trk = 0)
overridevirtual

Clear hits/points vectors of this element, optionally only those which are owned by given track.

Reimplemented from pma::Element3D.

Definition at line 766 of file PmaNode3D.cxx.

References pma::Element3D::fAssignedHits, pma::Element3D::fAssignedPoints, pma::Element3D::fHitsRadius, pma::SortedBranchBase::Next(), pma::SortedBranchBase::NextCount(), pma::Segment3D::Parent(), and pma::SortedObjectBase::Prev().

Referenced by GetUnconstrainedProj3D(), and pma::Track3D::Split().

767 {
768  if (!trk)
769  {
770  // like in the base class:
771  fAssignedPoints.clear();
772  fAssignedHits.clear();
773  }
774  else
775  {
776  std::vector< pma::Track3D* > to_check;
777  pma::Segment3D* seg;
778  if (Prev())
779  {
780  seg = static_cast< pma::Segment3D* >(Prev());
781  if (seg->Parent() != trk) to_check.push_back(seg->Parent());
782  }
783  for (unsigned int i = 0; i < NextCount(); i++)
784  {
785  seg = static_cast< pma::Segment3D* >(Next(i));
786  if (seg->Parent() != trk) to_check.push_back(seg->Parent());
787  }
788 
789  unsigned int p = 0;
790  while (p < fAssignedPoints.size())
791  {
792  bool found = false;
793  for (size_t t = 0; t < to_check.size(); t++)
794  if (to_check[t]->HasRefPoint(fAssignedPoints[p]))
795  {
796  found = true; break;
797  }
798 
799  if (!found) fAssignedPoints.erase(fAssignedPoints.begin() + p);
800  else p++;
801  }
802 
803  unsigned int h = 0;
804  while (h < fAssignedHits.size())
805  {
806  bool found = false;
808 
809  for (size_t t = 0; (t < to_check.size()) && !found; t++)
810  for (size_t i = 0; i < to_check[t]->size(); i++)
811  {
812  pma::Hit3D* pmaHit = static_cast< pma::Hit3D* >((*(to_check[t]))[i]);
813  if (hit == pmaHit)
814  {
815  found = true; break;
816  }
817  }
818 
819  if (!found) fAssignedHits.erase(fAssignedHits.begin() + h);
820  else h++;
821  }
822  }
823 
824  fHitsRadius = 0.0F;
825 }
virtual unsigned int NextCount(void) const
Definition: SortedObjects.h:84
std::vector< TVector3 * > fAssignedPoints
Definition: PmaElement3D.h:114
std::vector< pma::Hit3D * > fAssignedHits
Definition: PmaElement3D.h:113
Detector simulation of raw signals on wires.
virtual pma::SortedObjectBase * Next(unsigned int index=0) const
Definition: SortedObjects.h:79
double fHitsRadius
Definition: PmaElement3D.h:119
virtual pma::SortedObjectBase * Prev(void) const
Definition: SortedObjects.h:44
pma::Track3D * Parent(void) const
Definition: PmaSegment3D.h:64
int pma::Element3D::Cryo ( void  ) const
inlineinherited
void pma::SortedBranchBase::Disconnect ( void  )
virtualinherited

Reimplemented from pma::SortedObjectBase.

Definition at line 65 of file SortedObjects.cxx.

References pma::SortedObjectBase::prev, and pma::SortedObjectBase::RemoveNext().

66 {
67  while (next_vector.size()) RemoveNext(next_vector.front());
68  if (prev) prev->RemoveNext(this);
69 }
virtual int RemoveNext(pma::SortedObjectBase *nextElement)
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
std::vector< pma::SortedObjectBase * > next_vector
Definition: SortedObjects.h:88
virtual int RemoveNext(pma::SortedObjectBase *nextElement)
double pma::Node3D::EndPtCos2Transverse ( void  ) const
private

Definition at line 321 of file PmaNode3D.cxx.

References fPoint3D, pma::SortedObjectBase::Next(), pma::SortedObjectBase::next, pma::SortedObjectBase::Prev(), and pma::SortedObjectBase::prev.

Referenced by PenaltyInWirePlane(), and SetMargin().

322 {
323  if (prev && next)
324  {
325  auto const & vStart = static_cast< pma::Node3D* >(prev->Prev())->fPoint3D;
326  auto const & vStop = static_cast< pma::Node3D* >(next->Next())->fPoint3D;
327 
328  double dy = vStop.X() - vStart.X();
329  double dz = vStop.Z() - vStart.Z();
330  double len2 = dy * dy + dz * dz;
331  double cosine2 = 0.0;
332  if (len2 > 0.0) cosine2 = dz * dz / len2;
333  return cosine2;
334  }
335  else return 0.0;
336 }
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
pma::SortedObjectBase * next
Definition: SortedObjects.h:53
TVector3 fPoint3D
Definition: PmaNode3D.h:129
virtual pma::SortedObjectBase * Prev(void) const
Definition: SortedObjects.h:44
virtual pma::SortedObjectBase * Next(unsigned int index=0) const
Definition: SortedObjects.h:45
std::vector< pma::Track3D * > pma::Node3D::GetBranches ( void  ) const

Definition at line 406 of file PmaNode3D.cxx.

References pma::SortedBranchBase::Next(), pma::SortedBranchBase::NextCount(), and pma::Segment3D::Parent().

Referenced by pma::VtxCandidate::JoinTracks(), and SetVertexToBranching().

407 {
408  std::vector< pma::Track3D* > branches;
409  if (NextCount())
410  {
411  branches.reserve(NextCount());
412  for (size_t i = 0; i < NextCount(); ++i)
413  {
414  pma::Segment3D* seg = static_cast< pma::Segment3D* >(Next(i));
415  branches.push_back(seg->Parent());
416  }
417  }
418  return branches;
419 }
virtual unsigned int NextCount(void) const
Definition: SortedObjects.h:84
virtual pma::SortedObjectBase * Next(unsigned int index=0) const
Definition: SortedObjects.h:79
pma::Track3D * Parent(void) const
Definition: PmaSegment3D.h:64
pma::Vector3D pma::Node3D::GetDirection3D ( void  ) const
overridevirtual

Get 3D direction cosines of the next segment, or pevious segment if this is the last node.

Implements pma::Element3D.

Definition at line 160 of file PmaNode3D.cxx.

References pma::Element3D::GetDirection3D(), pma::SortedObjectBase::next, and pma::SortedObjectBase::prev.

Referenced by SetVertexToBranching().

161 {
162  pma::Element3D* seg = 0;
163  if (next) { seg = dynamic_cast< pma::Element3D* >(next); }
164  else if (prev) { seg = dynamic_cast< pma::Element3D* >(prev); }
165  else { throw cet::exception("Node3D") << "Isolated vertex." << std::endl; }
166 
167  if (seg) { return seg->GetDirection3D(); }
168  else { throw cet::exception("Node3D") << "Corrupted vertex." << std::endl; }
169 }
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
virtual pma::Vector3D GetDirection3D(void) const =0
Get 3D direction cosines corresponding to this element.
pma::SortedObjectBase * next
Definition: SortedObjects.h:53
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
double pma::Node3D::GetDistance2To ( const TVector3 &  p3d) const
overridevirtual

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

Implements pma::Element3D.

Definition at line 133 of file PmaNode3D.cxx.

References pma::Dist2(), and fPoint3D.

Referenced by pma::Track3D::MakeFastProjection(), and SetVertexToBranching().

134 {
135  return pma::Dist2(fPoint3D, p3d);
136 }
double Dist2(const TVector2 &v1, const TVector2 &v2)
Definition: Utilities.cxx:19
TVector3 fPoint3D
Definition: PmaNode3D.h:129
double pma::Node3D::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 138 of file PmaNode3D.cxx.

References pma::Dist2(), and fProj2D.

139 {
140  return pma::Dist2(fProj2D[view], p2d);
141 }
double Dist2(const TVector2 &v1, const TVector2 &v2)
Definition: Utilities.cxx:19
TVector2 fProj2D[3]
Definition: PmaNode3D.h:130
double pma::Node3D::GetDistToWall ( void  ) const

Definition at line 64 of file PmaNode3D.cxx.

References d, fMaxX, fMaxY, fMaxZ, fMinX, fMinY, fMinZ, and fPoint3D.

Referenced by Projection2D(), and pma::PMAlgTracker::validate().

65 {
66  double d, dmin = fPoint3D.X() - fMinX;
67  d = fMaxX - fPoint3D.X();
68  if (d < dmin) dmin = d;
69 
70  d = fPoint3D.Y() - fMinY;
71  if (d < dmin) dmin = d;
72  d = fMaxY - fPoint3D.Y();
73  if (d < dmin) dmin = d;
74 
75  d = fPoint3D.Z() - fMinZ;
76  if (d < dmin) dmin = d;
77  d = fMaxZ - fPoint3D.Z();
78  if (d < dmin) dmin = d;
79 
80  return dmin;
81 }
double fMinZ
Definition: PmaNode3D.h:127
double fMaxX
Definition: PmaNode3D.h:127
Float_t d
Definition: plot.C:237
double fMaxY
Definition: PmaNode3D.h:127
double fMaxZ
Definition: PmaNode3D.h:127
double fMinY
Definition: PmaNode3D.h:127
TVector3 fPoint3D
Definition: PmaNode3D.h:129
double fMinX
Definition: PmaNode3D.h:127
double pma::Node3D::GetDriftShift ( void  ) const
inline

Definition at line 102 of file PmaNode3D.h.

References fDriftOffset.

Referenced by pma::Track3D::Split().

102 { return fDriftOffset; }
double fDriftOffset
Definition: PmaNode3D.h:131
double pma::Node3D::GetObjFunction ( float  penaltyValue,
float  endSegWeight 
) const

Objective function minimized during oprimization.

Definition at line 522 of file PmaNode3D.cxx.

References Mse(), Penalty(), and PenaltyInWirePlane().

Referenced by GetUnconstrainedProj3D(), MakeGradient(), and StepWithGradient().

523 {
524  return Mse() + penaltyValue * (Penalty(endSegWeight) + PenaltyInWirePlane());
525 }
double Penalty(float endSegWeight) const
Definition: PmaNode3D.cxx:481
double PenaltyInWirePlane(void) const
Definition: PmaNode3D.cxx:358
double Mse(void) const
Definition: PmaNode3D.cxx:500
TVector3 pma::Node3D::GetUnconstrainedProj3D ( const TVector2 &  p2d,
unsigned int  view 
) const
inlineoverridevirtual

In case of a node it is simply 3D position of the node.

Implements pma::Element3D.

Definition at line 73 of file PmaNode3D.h.

References ClearAssigned(), fPoint3D, GetObjFunction(), Length2(), Optimize(), SegmentCos(), SegmentCosTransverse(), SegmentCosWirePlane(), and SetProjection().

73 { return fPoint3D; }
TVector3 fPoint3D
Definition: PmaNode3D.h:129
bool pma::Element3D::HasHit ( const pma::Hit3D h) const
inlineinherited

Definition at line 53 of file PmaElement3D.h.

References pma::Element3D::fAssignedHits.

54  {
55  for (const auto a : fAssignedHits) { if (h == a) return true; }
56  return false;
57  }
std::vector< pma::Hit3D * > fAssignedHits
Definition: PmaElement3D.h:113
pma::Hit3D& pma::Element3D::Hit ( size_t  index)
inlineinherited

Definition at line 59 of file PmaElement3D.h.

References pma::Element3D::fAssignedHits.

Referenced by pma::Track3D::AddNode(), pma::Track3D::DisableSingleViewEnds(), and pma::Track3D::SortHits().

59 { return *(fAssignedHits[index]); }
std::vector< pma::Hit3D * > fAssignedHits
Definition: PmaElement3D.h:113
const std::vector< pma::Hit3D* >& pma::Element3D::Hits ( void  ) const
inlineinherited

Definition at line 51 of file PmaElement3D.h.

References pma::Element3D::fAssignedHits.

51 { return fAssignedHits; }
std::vector< pma::Hit3D * > fAssignedHits
Definition: PmaElement3D.h:113
double pma::Element3D::HitsRadius3D ( unsigned int  view) const
inherited

Definition at line 224 of file PmaElement3D.cxx.

References pma::Dist2(), pma::Element3D::fAssignedHits, and pma::Element3D::fTPC.

Referenced by pma::Element3D::NThisHits().

225 {
226  if (fTPC < 0)
227  {
228  if (!fAssignedHits.empty()) mf::LogWarning("pma::Element3D") << "Hits assigned to TPC-crossing element.";
229  return 0.0F;
230  }
231 
232  TVector3 mean3D(0, 0, 0);
233  size_t nHits = 0;
234  for (auto h : fAssignedHits)
235  if (h->View2D() == view)
236  { mean3D += h->Point3D(); nHits++; }
237  if (!nHits) return 0.0;
238  mean3D *= (1.0 / nHits);
239 
240  double r2, maxR2 = 0.0;
241  for (auto h : fAssignedHits)
242  if (h->View2D() == view)
243  {
244  r2 = pma::Dist2(h->Point3D(), mean3D);
245  if (r2 > maxR2) maxR2 = r2;
246  }
247  return sqrt(maxR2);
248 }
double Dist2(const TVector2 &v1, const TVector2 &v2)
Definition: Utilities.cxx:19
std::vector< pma::Hit3D * > fAssignedHits
Definition: PmaElement3D.h:113
bool pma::Node3D::IsBranching ( void  ) const

Belongs to more than one track?

Definition at line 379 of file PmaNode3D.cxx.

References pma::SortedBranchBase::Next(), pma::SortedBranchBase::NextCount(), pma::Segment3D::Parent(), and pma::SortedObjectBase::prev.

Referenced by pma::PMAlgVertexing::getKinks(), pma::PMAlgVertexing::getVertices(), Projection2D(), and SetVertexToBranching().

380 {
381  size_t nnext = NextCount();
382  if (nnext > 1) return true; // 1 trk -> vtx -> n*trk
383 
384  if (prev && nnext)
385  {
386  pma::Segment3D* segPrev = static_cast< pma::Segment3D* >(prev);
387  pma::Segment3D* segNext = static_cast< pma::Segment3D* >(Next(0));
388  if (segNext->Parent() != segPrev->Parent()) // 1 trk -> vtx -> 1 trk
389  return true;
390  }
391  return false;
392 }
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
virtual unsigned int NextCount(void) const
Definition: SortedObjects.h:84
virtual pma::SortedObjectBase * Next(unsigned int index=0) const
Definition: SortedObjects.h:79
pma::Track3D * Parent(void) const
Definition: PmaSegment3D.h:64
virtual bool pma::SortedObjectBase::IsFirst ( void  ) const
inlinevirtualinherited

Definition at line 41 of file SortedObjects.h.

References pma::SortedObjectBase::prev.

41 { return !prev; }
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
bool pma::Element3D::IsFrozen ( void  ) const
inlineinherited

Check if the vertex 3D position is fixed.

Definition at line 96 of file PmaElement3D.h.

References pma::Element3D::fFrozen.

Referenced by pma::Track3D::AddNode(), and pma::ProjectionMatchingAlg::mergeTracks().

96 { return fFrozen; }
virtual bool pma::SortedBranchBase::IsLast ( void  ) const
inlinevirtualinherited

Reimplemented from pma::SortedObjectBase.

Definition at line 85 of file SortedObjects.h.

85 { return !(next_vector.size()); }
std::vector< pma::SortedObjectBase * > next_vector
Definition: SortedObjects.h:88
bool pma::Node3D::IsTPCEdge ( void  ) const

Is the first/last in this TPC?

Definition at line 394 of file PmaNode3D.cxx.

References pma::SortedBranchBase::Next(), pma::SortedBranchBase::NextCount(), pma::SortedObjectBase::prev, and pma::Element3D::TPC().

Referenced by Projection2D().

395 {
396  if (prev && (NextCount() == 1))
397  {
398  pma::Segment3D* segPrev = static_cast< pma::Segment3D* >(prev);
399  pma::Segment3D* segNext = static_cast< pma::Segment3D* >(Next(0));
400 
401  if ((segPrev->TPC() < 0) || (segNext->TPC() < 0)) return true;
402  }
403  return false;
404 }
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
virtual unsigned int NextCount(void) const
Definition: SortedObjects.h:84
int TPC(void) const
TPC index or -1 if out of any TPC.
Definition: PmaElement3D.h:31
virtual pma::SortedObjectBase * Next(unsigned int index=0) const
Definition: SortedObjects.h:79
bool pma::Node3D::IsVertex ( void  ) const
inline

Check fIsVertex flag.

Definition at line 54 of file PmaNode3D.h.

References fIsVertex.

Referenced by pma::PMAlgVertexing::getKinks().

54 { return fIsVertex; }
bool fIsVertex
Definition: PmaNode3D.h:134
double pma::Element3D::Length ( void  ) const
inlineinherited
double pma::Node3D::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 250 of file PmaNode3D.cxx.

References pma::SortedObjectBase::next, and pma::SortedObjectBase::prev.

Referenced by GetUnconstrainedProj3D(), Pi(), and PiInWirePlane().

251 {
252  double l = 0.0;
253  if (next) l += (static_cast< pma::Segment3D* >(next))->Length();
254  if (prev) l += (static_cast< pma::Segment3D* >(prev))->Length();
255 
256  if (next && prev) return 0.25 * l * l;
257  else return l * l;
258 }
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
pma::SortedObjectBase * next
Definition: SortedObjects.h:53
bool pma::Node3D::LimitPoint3D ( void  )
private

Returns true if node position was trimmed to its TPC volume + fMargin.

Definition at line 99 of file PmaNode3D.cxx.

References fMargin, fMaxX, fMaxY, fMaxZ, fMinX, fMinY, fMinZ, and fPoint3D.

Referenced by SetMargin(), and SetPoint3D().

100 {
101  bool trimmed = false;
102 
103  if (fPoint3D.X() < fMinX - fMargin) { fPoint3D.SetX(fMinX - fMargin); trimmed = true; }
104  if (fPoint3D.X() > fMaxX + fMargin) { fPoint3D.SetX(fMaxX + fMargin); trimmed = true; }
105 
106  if (fPoint3D.Y() < fMinY - fMargin) { fPoint3D.SetY(fMinY - fMargin); trimmed = true; }
107  if (fPoint3D.Y() > fMaxY + fMargin) { fPoint3D.SetY(fMaxY + fMargin); trimmed = true; }
108 
109  if (fPoint3D.Z() < fMinZ - fMargin) { fPoint3D.SetZ(fMinZ - fMargin); trimmed = true; }
110  if (fPoint3D.Z() > fMaxZ + fMargin) { fPoint3D.SetZ(fMaxZ + fMargin); trimmed = true; }
111 
112  return trimmed;
113 }
double fMinZ
Definition: PmaNode3D.h:127
double fMaxX
Definition: PmaNode3D.h:127
double fMaxY
Definition: PmaNode3D.h:127
double fMaxZ
Definition: PmaNode3D.h:127
double fMinY
Definition: PmaNode3D.h:127
TVector3 fPoint3D
Definition: PmaNode3D.h:129
static double fMargin
Definition: PmaNode3D.h:137
double fMinX
Definition: PmaNode3D.h:127
double pma::Node3D::MakeGradient ( float  penaltyValue,
float  endSegWeight 
)
private

Definition at line 527 of file PmaNode3D.cxx.

References E, fGradFixed, fGradient, fPoint3D, GetObjFunction(), pma::Segment3D::Length2(), pma::SortedObjectBase::next, pma::SortedObjectBase::prev, SetPoint3D(), and tmp.

Referenced by SetMargin(), and StepWithGradient().

528 {
529  double l1 = 0.0, l2 = 0.0, minLength2 = 0.0;
530  TVector3 tmp(fPoint3D), gpoint(fPoint3D);
531 
532  pma::Segment3D* seg;
533  if (prev)
534  {
535  seg = static_cast< pma::Segment3D* >(prev);
536  l1 = seg->Length2();
537  }
538  if (next)
539  {
540  seg = static_cast< pma::Segment3D* >(next);
541  l2 = seg->Length2();
542  }
543  if ((l1 > 0.01) && (l1 < l2)) minLength2 = l1;
544  else if ((l2 > 0.01) && (l2 < l1)) minLength2 = l2;
545  else minLength2 = 0.01;
546 
547  double dxi = 0.001 * sqrt(minLength2);
548 
549  if (dxi < 6.0E-37) return 0.0;
550 
551  double gi, g0, gz;
552  gz = g0 = GetObjFunction(penaltyValue, endSegWeight);
553 
554  //if (fQPenaltyFactor > 0.0F) gz += fQPenaltyFactor * QPenalty(); <----------------------- maybe later..
555 
556  if (!fGradFixed[0]) // gradX
557  {
558  gpoint[0] = tmp[0] + dxi;
559  SetPoint3D(gpoint);
560  gi = GetObjFunction(penaltyValue, endSegWeight);
561  fGradient[0] = (g0 - gi) / dxi;
562 
563  gpoint[0] = tmp[0] - dxi;
564  SetPoint3D(gpoint);
565  gi = GetObjFunction(penaltyValue, endSegWeight);
566  fGradient[0] = 0.5 * (fGradient[0] + (gi - g0) / dxi);
567 
568  gpoint[0] = tmp[0];
569  }
570 
571  if (!fGradFixed[1]) // gradY
572  {
573  gpoint[1] = tmp[1] + dxi;
574  SetPoint3D(gpoint);
575  gi = GetObjFunction(penaltyValue, endSegWeight);
576  fGradient[1] = (g0 - gi) / dxi;
577 
578  gpoint[1] = tmp[1] - dxi;
579  SetPoint3D(gpoint);
580  gi = GetObjFunction(penaltyValue, endSegWeight);
581  fGradient[1] = 0.5 * (fGradient[1] + (gi - g0) / dxi);
582 
583  gpoint[1] = tmp[1];
584  }
585 
586  if (!fGradFixed[2]) // gradZ
587  {
588  gpoint[2] = tmp[2] + dxi;
589  SetPoint3D(gpoint);
590  gi = GetObjFunction(penaltyValue, endSegWeight);
591  //if (fQPenaltyFactor > 0.0F) gi += fQPenaltyFactor * QPenalty();
592  fGradient[2] = (gz - gi) / dxi;
593 
594  gpoint[2] = tmp[2] - dxi;
595  SetPoint3D(gpoint);
596  gi = GetObjFunction(penaltyValue, endSegWeight);
597  //if (fQPenaltyFactor > 0.0F) gi += fQPenaltyFactor * QPenalty();
598  fGradient[2] = 0.5 * (fGradient[2] + (gi - gz) / dxi);
599 
600  gpoint[2] = tmp[2];
601  }
602 
603  SetPoint3D(tmp);
604  if (fGradient.Mag2() < 6.0E-37) return 0.0;
605 
606  return g0;
607 }
Float_t E
Definition: plot.C:23
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
Float_t tmp
Definition: plot.C:37
double Length2(void) const override
static bool fGradFixed[3]
Definition: PmaNode3D.h:136
bool SetPoint3D(const TVector3 &p3d)
Definition: PmaNode3D.cxx:123
double GetObjFunction(float penaltyValue, float endSegWeight) const
Objective function minimized during oprimization.
Definition: PmaNode3D.cxx:522
pma::SortedObjectBase * next
Definition: SortedObjects.h:53
TVector3 fPoint3D
Definition: PmaNode3D.h:129
TVector3 fGradient
Definition: PmaNode3D.h:133
double pma::Node3D::Mse ( void  ) const
private

Definition at line 500 of file PmaNode3D.cxx.

References pma::SortedBranchBase::Next(), pma::SortedBranchBase::NextCount(), pma::Element3D::NPrecalcEnabledHits(), pma::SortedObjectBase::prev, and pma::Element3D::SumDist2().

Referenced by GetObjFunction(), and SetMargin().

501 {
502  unsigned int nhits = NPrecalcEnabledHits(); //NEnabledHits();
503  double mse = SumDist2();
504 
505  pma::Segment3D* seg;
506  for (unsigned int i = 0; i < NextCount(); i++)
507  {
508  seg = static_cast< pma::Segment3D* >(Next(i));
509  nhits += seg->NPrecalcEnabledHits(); //NEnabledHits();
510  mse += seg->SumDist2();
511  }
512  if (prev)
513  {
514  seg = static_cast< pma::Segment3D* >(prev);
515  nhits += seg->NPrecalcEnabledHits(); //NEnabledHits();
516  mse += seg->SumDist2();
517  }
518  if (!nhits) return 0.0;
519  else return mse / nhits;
520 }
size_t NPrecalcEnabledHits(void) const
Definition: PmaElement3D.h:73
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
virtual unsigned int NextCount(void) const
Definition: SortedObjects.h:84
double SumDist2(void) const
virtual pma::SortedObjectBase * Next(unsigned int index=0) const
Definition: SortedObjects.h:79
size_t pma::Element3D::NEnabledHits ( unsigned int  view = geo::kUnknown) const
inherited

Definition at line 35 of file PmaElement3D.cxx.

References pma::Element3D::fAssignedHits, geo::kUnknown, and n.

Referenced by pma::Track3D::AddNode(), and pma::Element3D::NHits().

36 {
37  size_t n = 0;
38  for (size_t i = 0; i < fAssignedHits.size(); i++)
39  if (fAssignedHits[i]->IsEnabled() &&
40  ((view == geo::kUnknown) || (view == fAssignedHits[i]->View2D()))) n++;
41  return n;
42 }
Unknown view.
Definition: geo_types.h:83
std::vector< pma::Hit3D * > fAssignedHits
Definition: PmaElement3D.h:113
Char_t n[5]
size_t pma::Element3D::NHits ( void  ) const
inlineinherited
unsigned int pma::Element3D::NHits ( unsigned int  view) const
inlineinherited

Definition at line 90 of file PmaElement3D.h.

References pma::Element3D::fNHits.

90 { return fNHits[view]; }
size_t fNHits[3]
Definition: PmaElement3D.h:117
size_t pma::Element3D::NPoints ( void  ) const
inlineinherited

Definition at line 76 of file PmaElement3D.h.

References pma::Element3D::fAssignedPoints.

Referenced by pma::Track3D::DisableSingleViewEnds().

76 { return fAssignedPoints.size(); }
std::vector< TVector3 * > fAssignedPoints
Definition: PmaElement3D.h:114
size_t pma::Element3D::NPrecalcEnabledHits ( void  ) const
inlineinherited

Definition at line 73 of file PmaElement3D.h.

References pma::Element3D::fNThisHitsEnabledAll.

Referenced by Mse().

73 { return fNThisHitsEnabledAll; }
size_t fNThisHitsEnabledAll
Definition: PmaElement3D.h:116
unsigned int pma::Element3D::NThisHits ( unsigned int  view) const
inlineinherited

Definition at line 91 of file PmaElement3D.h.

References pma::Element3D::fNThisHits, and pma::Element3D::HitsRadius3D().

91 { return fNThisHits[view]; }
size_t fNThisHits[3]
Definition: PmaElement3D.h:115
static float pma::Element3D::OptFactor ( unsigned int  view)
inlinestaticinherited

Definition at line 103 of file PmaElement3D.h.

References pma::Element3D::fOptFactors.

Referenced by pma::Element3D::SumDist2(), pma::Segment3D::SumDist2Hits(), and SumDist2Hits().

103 { return fOptFactors[view]; }
static float fOptFactors[3]
Definition: PmaElement3D.h:121
void pma::Node3D::Optimize ( float  penaltyValue,
float  endSegWeight 
)

Optimize vertex 3D position with given penalty on connected segments angle and weight assigned to the outermost segments. Only MSE is used in case of branching nodes.

Definition at line 756 of file PmaNode3D.cxx.

References pma::Element3D::fFrozen, and StepWithGradient().

Referenced by GetUnconstrainedProj3D(), and pma::Track3D::TuneSinglePass().

757 {
758  if (!fFrozen)
759  {
760  double dg = StepWithGradient(0.1F, 0.002F, penaltyValue, endSegWeight);
761  if (dg > 0.01) dg = StepWithGradient(0.03F, 0.0001F, penaltyValue, endSegWeight);
762  if (dg > 0.0) dg = StepWithGradient(0.03F, 0.0001F, penaltyValue, endSegWeight);
763  }
764 }
double StepWithGradient(float alfa, float tol, float penalty, float weight)
Definition: PmaNode3D.cxx:609
double pma::Node3D::Penalty ( float  endSegWeight) const
private

Definition at line 481 of file PmaNode3D.cxx.

References pma::SortedObjectBase::Next(), pma::SortedBranchBase::Next(), pma::SortedBranchBase::NextCount(), Pi(), pma::SortedObjectBase::Prev(), and pma::SortedObjectBase::prev.

Referenced by GetObjFunction(), and SetMargin().

482 {
483  unsigned int nseg = 1;
484  double penalty = Pi(endSegWeight, true);
485 
486  pma::Node3D* v;
487  for (unsigned int i = 0; i < NextCount(); i++)
488  {
489  v = static_cast< pma::Node3D* >(Next(i)->Next());
490  penalty += v->Pi(endSegWeight, false); nseg++;
491  }
492  if (prev)
493  {
494  v = static_cast< pma::Node3D* >(prev->Prev());
495  penalty += v->Pi(endSegWeight, false); nseg++;
496  }
497  return penalty / nseg;
498 }
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
virtual unsigned int NextCount(void) const
Definition: SortedObjects.h:84
virtual pma::SortedObjectBase * Next(unsigned int index=0) const
Definition: SortedObjects.h:79
virtual pma::SortedObjectBase * Prev(void) const
Definition: SortedObjects.h:44
double Pi(float endSegWeight, bool doAsymm) const
Definition: PmaNode3D.cxx:421
virtual pma::SortedObjectBase * Next(unsigned int index=0) const
Definition: SortedObjects.h:45
double pma::Node3D::PenaltyInWirePlane ( void  ) const
private

Definition at line 358 of file PmaNode3D.cxx.

References EndPtCos2Transverse(), fIsVertex, pma::SortedObjectBase::Next(), pma::SortedObjectBase::next, PiInWirePlane(), pma::SortedObjectBase::Prev(), and pma::SortedObjectBase::prev.

Referenced by GetObjFunction(), and SetMargin().

359 {
360  if (fIsVertex) return 0.0;
361 
362  unsigned int nseg = 1;
363  double penalty = PiInWirePlane();
364  pma::Node3D* v;
365  if (next)
366  {
367  v = static_cast< pma::Node3D* >(next->Next());
368  penalty += v->PiInWirePlane(); nseg++;
369  }
370  if (prev)
371  {
372  v = static_cast< pma::Node3D* >(prev->Prev());
373  penalty += v->PiInWirePlane(); nseg++;
374  }
375  if (penalty > 0.0) return pow(EndPtCos2Transverse(), 10) * penalty / nseg;
376  else return 0.0;
377 }
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
double PiInWirePlane(void) const
Definition: PmaNode3D.cxx:338
double EndPtCos2Transverse(void) const
Definition: PmaNode3D.cxx:321
pma::SortedObjectBase * next
Definition: SortedObjects.h:53
virtual pma::SortedObjectBase * Prev(void) const
Definition: SortedObjects.h:44
virtual pma::SortedObjectBase * Next(unsigned int index=0) const
Definition: SortedObjects.h:45
bool fIsVertex
Definition: PmaNode3D.h:134
double pma::Node3D::Pi ( float  endSegWeight,
bool  doAsymm 
) const
private

Definition at line 421 of file PmaNode3D.cxx.

References pma::Element3D::fHitsRadius, fIsVertex, pma::Element3D::Length(), pma::Segment3D::Length2(), Length2(), pma::SortedObjectBase::Next(), pma::SortedObjectBase::next, pma::SortedBranchBase::Next(), pma::SortedObjectBase::NextCount(), pma::SortedBranchBase::NextCount(), pma::SortedObjectBase::Prev(), pma::SortedObjectBase::prev, scale, SegmentCos(), and pma::Element3D::TPC().

Referenced by Penalty(), and SetMargin().

422 {
423  if (fIsVertex) return 0.0;
424 
425  if (prev && NextCount())
426  {
427  pma::Segment3D* segPrev = static_cast< pma::Segment3D* >(prev);
428  pma::Segment3D* segNext = static_cast< pma::Segment3D* >(Next(0));
429 
430  double scale = 1.0;
431  if ((segPrev->TPC() < 0) || (segNext->TPC() < 0)) scale = 0.5; // lower penalty on segments between tpc's
432 
433  double segCos = SegmentCos();
434 
435  double lAsymmFactor = 0.0;
436  if (doAsymm)
437  {
438  double lPrev = segPrev->Length();
439  double lNext = segNext->Length();
440  double lSum = lPrev + lNext;
441  if (lSum > 0.1)
442  {
443  double lAsymm = (1.0 - segCos) * (lPrev - lNext) / lSum;
444  lAsymmFactor = 0.05 * lAsymm * lAsymm;
445  }
446  }
447 
448  if (fHitsRadius > 0.0F) return scale * (1.0 + segCos + lAsymmFactor) * fHitsRadius * fHitsRadius;
449  else return scale * (1.0 + segCos + lAsymmFactor) * Length2();
450  }
451  else
452  {
453  double pi_result = 0.0;
454  unsigned int nSeg = 0;
455  pma::Segment3D* seg = 0;
456  if (prev)
457  {
458  seg = static_cast< pma::Segment3D* >(prev);
459 
460  SortedObjectBase* prevVtx = seg->Prev();
461  if (prevVtx->Prev()) nSeg++;
462  nSeg += prevVtx->NextCount();
463  }
464  else if (next)
465  {
466  seg = static_cast< pma::Segment3D* >(next);
467 
468  SortedObjectBase* nextVtx = seg->Next(0);
469  nSeg += nextVtx->NextCount() + 1;
470  }
471  else
472  {
473  mf::LogWarning("pma::Node3D") << "pma::Node3D::Pi(): an isolated vertex?";
474  return 0.0;
475  }
476  if (nSeg == 1) pi_result = endSegWeight * seg->Length2();
477  return pi_result;
478  }
479 }
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
virtual unsigned int NextCount(void) const
Definition: SortedObjects.h:84
double Length2(void) const override
int TPC(void) const
TPC index or -1 if out of any TPC.
Definition: PmaElement3D.h:31
Double_t scale
Definition: plot.C:25
virtual unsigned int NextCount(void) const
Definition: SortedObjects.h:46
double SegmentCos(void) const
Cosine of 3D angle between connected segments.
Definition: PmaNode3D.cxx:260
virtual pma::SortedObjectBase * Next(unsigned int index=0) const
Definition: SortedObjects.h:79
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
double fHitsRadius
Definition: PmaElement3D.h:119
pma::SortedObjectBase * next
Definition: SortedObjects.h:53
double Length2(void) const override
Definition: PmaNode3D.cxx:250
virtual pma::SortedObjectBase * Prev(void) const
Definition: SortedObjects.h:44
virtual pma::SortedObjectBase * Next(unsigned int index=0) const
Definition: SortedObjects.h:45
bool fIsVertex
Definition: PmaNode3D.h:134
double Length(void) const
Definition: PmaElement3D.h:49
double pma::Node3D::PiInWirePlane ( void  ) const
private

Definition at line 338 of file PmaNode3D.cxx.

References pma::Element3D::fHitsRadius, geo::kU, Length2(), pma::SortedBranchBase::Next(), pma::SortedBranchBase::NextCount(), pma::Element3D::NHits(), pma::SortedObjectBase::prev, and SegmentCosWirePlane().

Referenced by PenaltyInWirePlane(), and SetMargin().

339 {
340  if (prev && NextCount())
341  {
342  pma::Segment3D* seg0 = dynamic_cast< pma::Segment3D* >(prev);
343  pma::Segment3D* seg1 = dynamic_cast< pma::Segment3D* >(Next(0));
344  unsigned int nInd1 = NHits(geo::kU) + seg0->NHits(geo::kU) + seg1->NHits(geo::kU);
345 
346  if (fHitsRadius > 0.0F)
347  return (1.0 + SegmentCosWirePlane()) * fHitsRadius * fHitsRadius / (4 * nInd1 + 1.0);
348  else return (1.0 + SegmentCosWirePlane()) * Length2() / (4 * nInd1 + 1.0);
349  }
350  else return 0.0;
351 }
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
virtual unsigned int NextCount(void) const
Definition: SortedObjects.h:84
double SegmentCosWirePlane(void) const
Definition: PmaNode3D.cxx:280
Planes which measure U.
Definition: geo_types.h:76
virtual pma::SortedObjectBase * Next(unsigned int index=0) const
Definition: SortedObjects.h:79
double fHitsRadius
Definition: PmaElement3D.h:119
double Length2(void) const override
Definition: PmaNode3D.cxx:250
size_t NHits(void) const
Definition: PmaElement3D.h:71
TVector2 const& pma::Node3D::Projection2D ( unsigned int  view) const
inline
TVector3 const& pma::Element3D::ReferencePoint ( size_t  index) const
inlineinherited

Definition at line 75 of file PmaElement3D.h.

References pma::Element3D::fAssignedPoints.

75 { return *(fAssignedPoints[index]); }
std::vector< TVector3 * > fAssignedPoints
Definition: PmaElement3D.h:114
void pma::Element3D::RemoveHitAt ( size_t  index)
inlineinherited

Definition at line 60 of file PmaElement3D.h.

References pma::Element3D::fAssignedHits.

61  {
62  if (index < fAssignedHits.size())
63  fAssignedHits.erase(fAssignedHits.begin() + index);
64  }
std::vector< pma::Hit3D * > fAssignedHits
Definition: PmaElement3D.h:113
int pma::SortedBranchBase::RemoveNext ( pma::SortedObjectBase nextElement)
virtualinherited

Reimplemented from pma::SortedObjectBase.

Definition at line 107 of file SortedObjects.cxx.

References pma::SortedObjectBase::next, and pma::SortedObjectBase::prev.

Referenced by pma::Track3D::AttachBackToSameTPC(), pma::Track3D::AttachToSameTPC(), and pma::Track3D::Split().

108 {
109  if (!nextElement || (nextElement == this)) return -1;
110 
111  int index = -1;
112  for (unsigned int i = 0; i < next_vector.size(); i++)
113  {
114  if (next_vector[i] == nextElement) { index = i; break; }
115  }
116  if (index >= 0)
117  {
118  if (next_vector[index]->prev != this)
119  {
120  mf::LogError("pma::SortedBranchBase") << "Object structure is broken.";
121  return -1;
122  }
123  next_vector[index]->prev = 0;
124  next_vector.erase(next_vector.begin() + index);
125 
126  if (next_vector.size() > 0) next = next_vector.back();
127  else next = 0;
128  }
129  return index;
130 }
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
std::vector< pma::SortedObjectBase * > next_vector
Definition: SortedObjects.h:88
pma::SortedObjectBase * next
Definition: SortedObjects.h:53
bool pma::Node3D::SameTPC ( const TVector3 &  p3d,
float  margin = 0.0F 
) const

Check if p3d is in the same TPC as the node.

Definition at line 83 of file PmaNode3D.cxx.

References fMaxX, fMaxY, fMaxZ, fMinX, fMinY, and fMinZ.

Referenced by pma::Track3D::GetUnconstrainedProj3D(), pma::ProjectionMatchingAlg::isContained(), Projection2D(), pma::ProjectionMatchingAlg::validate(), pma::ProjectionMatchingAlg::validate_on_adc(), and pma::ProjectionMatchingAlg::validate_on_adc_test().

84 {
85  if (((fMinX - margin) <= p3d.X()) && (p3d.X() <= (fMaxX + margin)) &&
86  ((fMinY - margin) <= p3d.Y()) && (p3d.Y() <= (fMaxY + margin)) &&
87  ((fMinZ - margin) <= p3d.Z()) && (p3d.Z() <= (fMaxZ + margin))) return true;
88  else return false;
89 }
double fMinZ
Definition: PmaNode3D.h:127
double fMaxX
Definition: PmaNode3D.h:127
double fMaxY
Definition: PmaNode3D.h:127
double fMaxZ
Definition: PmaNode3D.h:127
double fMinY
Definition: PmaNode3D.h:127
double fMinX
Definition: PmaNode3D.h:127
bool pma::Node3D::SameTPC ( const pma::Vector3D p3d,
float  margin = 0.0F 
) const

Definition at line 91 of file PmaNode3D.cxx.

References fMaxX, fMaxY, fMaxZ, fMinX, fMinY, and fMinZ.

92 {
93  if (((fMinX - margin) <= p3d.X()) && (p3d.X() <= (fMaxX + margin)) &&
94  ((fMinY - margin) <= p3d.Y()) && (p3d.Y() <= (fMaxY + margin)) &&
95  ((fMinZ - margin) <= p3d.Z()) && (p3d.Z() <= (fMaxZ + margin))) return true;
96  else return false;
97 }
double fMinZ
Definition: PmaNode3D.h:127
double fMaxX
Definition: PmaNode3D.h:127
double fMaxY
Definition: PmaNode3D.h:127
double fMaxZ
Definition: PmaNode3D.h:127
double fMinY
Definition: PmaNode3D.h:127
double fMinX
Definition: PmaNode3D.h:127
double pma::Node3D::SegmentCos ( void  ) const

Cosine of 3D angle between connected segments.

Definition at line 260 of file PmaNode3D.cxx.

References fPoint3D, pma::SortedObjectBase::Next(), pma::SortedObjectBase::next, pma::SortedObjectBase::Prev(), and pma::SortedObjectBase::prev.

Referenced by GetUnconstrainedProj3D(), and Pi().

261 {
262  if (prev && next)
263  {
264  auto const & vStop1 = static_cast< pma::Node3D* >(prev->Prev())->fPoint3D;
265  auto const & vStop2 = static_cast< pma::Node3D* >(next->Next())->fPoint3D;
266  pma::Vector3D v1(vStop1.X() - fPoint3D.X(), vStop1.Y() - fPoint3D.Y(), vStop1.Z() - fPoint3D.Z());
267  pma::Vector3D v2(vStop2.X() - fPoint3D.X(), vStop2.Y() - fPoint3D.Y(), vStop2.Z() - fPoint3D.Z());
268  double mag = sqrt(v1.Mag2() * v2.Mag2());
269  double cosine = 0.0;
270  if (mag != 0.0) cosine = v1.Dot(v2) / mag;
271  return cosine;
272  }
273  else
274  {
275  mf::LogError("pma::Node3D") << "pma::Node3D::SegmentCos(): neighbours not initialized.";
276  return -1.0;
277  }
278 }
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
recob::tracking::Vector_t Vector3D
Definition: Utilities.h:29
pma::SortedObjectBase * next
Definition: SortedObjects.h:53
TVector3 fPoint3D
Definition: PmaNode3D.h:129
virtual pma::SortedObjectBase * Prev(void) const
Definition: SortedObjects.h:44
virtual pma::SortedObjectBase * Next(unsigned int index=0) const
Definition: SortedObjects.h:45
double pma::Node3D::SegmentCosTransverse ( void  ) const

Cosine of 2D angle (in horizontal plane, parallel to drift) between connected segments. Should be changed / generalized for horizontal wire planes (e.g. 2-phase LAr).

Definition at line 300 of file PmaNode3D.cxx.

References fPoint3D, pma::SortedObjectBase::Next(), pma::SortedObjectBase::next, pma::SortedObjectBase::Prev(), and pma::SortedObjectBase::prev.

Referenced by GetUnconstrainedProj3D().

301 {
302  if (prev && next)
303  {
304  auto const & vStop1 = static_cast< pma::Node3D* >(prev->Prev())->fPoint3D;
305  auto const & vStop2 = static_cast< pma::Node3D* >(next->Next())->fPoint3D;
306  pma::Vector2D v1( vStop1.X() - fPoint3D.X(), vStop1.Z() - fPoint3D.Z());
307  pma::Vector2D v2( vStop2.X() - fPoint3D.X(), vStop2.Z() - fPoint3D.Z());
308  double mag = sqrt(v1.Mag2() * v2.Mag2());
309  double cosine = 0.0;
310  if (mag != 0.0) cosine = v1.Dot(v2) / mag;
311  return cosine;
312  }
313  else
314  {
315  mf::LogError("pma::Node3D") << "pma::Node3D::SegmentCosZY(): neighbours not initialized.";
316  return -1.0;
317  }
318 }
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
ROOT::Math::DisplacementVector2D< ROOT::Math::Cartesian2D< double > > Vector2D
Definition: Utilities.h:28
pma::SortedObjectBase * next
Definition: SortedObjects.h:53
TVector3 fPoint3D
Definition: PmaNode3D.h:129
virtual pma::SortedObjectBase * Prev(void) const
Definition: SortedObjects.h:44
virtual pma::SortedObjectBase * Next(unsigned int index=0) const
Definition: SortedObjects.h:45
double pma::Node3D::SegmentCosWirePlane ( void  ) const

Cosine of 2D angle (in plane parallel to wire planes) between connected segments. Should be changed / generalized for horizontal wire planes (e.g. 2-phase LAr).

Definition at line 280 of file PmaNode3D.cxx.

References fPoint3D, pma::SortedObjectBase::Next(), pma::SortedObjectBase::next, pma::SortedObjectBase::Prev(), and pma::SortedObjectBase::prev.

Referenced by GetUnconstrainedProj3D(), and PiInWirePlane().

281 {
282  if (prev && next)
283  {
284  auto const & vStop1 = static_cast< pma::Node3D* >(prev->Prev())->fPoint3D;
285  auto const & vStop2 = static_cast< pma::Node3D* >(next->Next())->fPoint3D;
286  pma::Vector2D v1(vStop1.Y() - fPoint3D.Y(), vStop1.Z() - fPoint3D.Z());
287  pma::Vector2D v2(vStop2.Y() - fPoint3D.Y(), vStop2.Z() - fPoint3D.Z());
288  double mag = sqrt(v1.Mag2() * v2.Mag2());
289  double cosine = 0.0;
290  if (mag != 0.0) cosine = v1.Dot(v2) / mag;
291  return cosine;
292  }
293  else
294  {
295  mf::LogError("pma::Node3D") << "pma::Node3D::SegmentCosZX(): neighbours not initialized.";
296  return -1.0;
297  }
298 }
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
ROOT::Math::DisplacementVector2D< ROOT::Math::Cartesian2D< double > > Vector2D
Definition: Utilities.h:28
pma::SortedObjectBase * next
Definition: SortedObjects.h:53
TVector3 fPoint3D
Definition: PmaNode3D.h:129
virtual pma::SortedObjectBase * Prev(void) const
Definition: SortedObjects.h:44
virtual pma::SortedObjectBase * Next(unsigned int index=0) const
Definition: SortedObjects.h:45
bool pma::Element3D::SelectAllHits ( void  )
inherited

Definition at line 296 of file PmaElement3D.cxx.

References pma::Element3D::fAssignedHits.

Referenced by pma::Track3D::SelectHits(), pma::Element3D::SelectRndHits(), and pma::Element3D::SetFrozen().

297 {
298  bool changed = false;
299  for (auto h : fAssignedHits)
300  {
301  changed |= !(h->IsEnabled());
302  h->SetEnabled(true);
303  }
304  return changed;
305 }
std::vector< pma::Hit3D * > fAssignedHits
Definition: PmaElement3D.h:113
bool pma::Element3D::SelectRndHits ( size_t  nmax_per_view)
inherited

Definition at line 250 of file PmaElement3D.cxx.

References pma::Element3D::fAssignedHits, pma::Element3D::NHits(), and pma::Element3D::SelectAllHits().

Referenced by pma::Element3D::SetFrozen().

251 {
252  if (!nmax_per_view) { return SelectAllHits(); }
253 
254  size_t nhits[3];
255  for (size_t i = 0; i < 3; ++i) nhits[i] = NHits(i);
256 
257  int m[3], count[3];
258  bool state[3];
259  for (size_t i = 0; i < 3; ++i)
260  {
261  if (nhits[i] >= 2 * nmax_per_view)
262  {
263  m[i] = nhits[i] / nmax_per_view;
264  state[i] = true;
265  }
266  else if (nhits[i] > nmax_per_view)
267  {
268  m[i] = nhits[i] / (nhits[i] - nmax_per_view);
269  state[i] = false;
270  }
271  else { m[i] = 0; state[i] = false; }
272 
273  count[i] = 0;
274  }
275 
276  bool b, changed = false;
277  for (auto h : fAssignedHits)
278  {
279  b = h->IsEnabled();
280 
281  size_t view = h->View2D();
282  if (m[view])
283  {
284  if (count[view] % m[view] == 0) h->SetEnabled(state[view]);
285  else h->SetEnabled(!(state[view]));
286 
287  ++count[view];
288  }
289  else h->SetEnabled(true);
290 
291  changed |= (b != h->IsEnabled());
292  }
293  return changed;
294 }
std::vector< pma::Hit3D * > fAssignedHits
Definition: PmaElement3D.h:113
bool SelectAllHits(void)
size_t NHits(void) const
Definition: PmaElement3D.h:71
void pma::Element3D::SetFrozen ( bool  state)
inlineinherited

Fix / relese vertex 3D position.

Definition at line 98 of file PmaElement3D.h.

References pma::Element3D::fFrozen, pma::Element3D::SelectAllHits(), and pma::Element3D::SelectRndHits().

98 { fFrozen = state; }
static void pma::Node3D::SetMargin ( double  m)
inlinestatic

Set allowed node position margin around TPC.

Definition at line 105 of file PmaNode3D.h.

References EndPtCos2Transverse(), fMargin, LimitPoint3D(), MakeGradient(), Mse(), Penalty(), PenaltyInWirePlane(), Pi(), PiInWirePlane(), StepWithGradient(), SumDist2Hits(), UpdateProj2D(), and weight.

Referenced by pma::ProjectionMatchingAlg::ProjectionMatchingAlg().

105 { if (m >= 0.0) fMargin = m; }
static double fMargin
Definition: PmaNode3D.h:137
static void pma::Element3D::SetOptFactor ( unsigned int  view,
float  value 
)
inlinestaticinherited

Definition at line 104 of file PmaElement3D.h.

References pma::Element3D::Element3D(), pma::Element3D::fOptFactors, and fhicl::detail::atom::value().

Referenced by pma::ProjectionMatchingAlg::ProjectionMatchingAlg().

104 { fOptFactors[view] = value; }
static float fOptFactors[3]
Definition: PmaElement3D.h:121
std::string value(boost::any const &)
bool pma::Node3D::SetPoint3D ( const TVector3 &  p3d)

Returns true if the new position was accepted; returns false if the new position was trimmed to fit insite TPC volume + fMargin.

Definition at line 123 of file PmaNode3D.cxx.

References fPoint3D, LimitPoint3D(), and UpdateProj2D().

Referenced by pma::VtxCandidate::JoinTracks(), MakeGradient(), Node3D(), Point3D(), and StepWithGradient().

124 {
125  fPoint3D = p3d;
126 
127  bool accepted = !LimitPoint3D();
128  UpdateProj2D();
129 
130  return accepted;
131 }
bool LimitPoint3D(void)
Returns true if node position was trimmed to its TPC volume + fMargin.
Definition: PmaNode3D.cxx:99
void UpdateProj2D(void)
Definition: PmaNode3D.cxx:115
TVector3 fPoint3D
Definition: PmaNode3D.h:129
void pma::Node3D::SetProjection ( pma::Hit3D h) const
overridevirtual

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

Implements pma::Element3D.

Definition at line 171 of file PmaNode3D.cxx.

References pma::Element3D::fFrozen, fPoint3D, pma::SortedObjectBase::Next(), pma::SortedObjectBase::next, pma::Hit3D::Point2D(), Point3D(), pma::SortedObjectBase::Prev(), pma::SortedObjectBase::prev, Projection2D(), pma::Hit3D::SetPoint3D(), pma::Hit3D::SetProjection(), and pma::Hit3D::View2D().

Referenced by GetUnconstrainedProj3D().

172 {
173  TVector2 gstart;
174  TVector3 g3d;
175  if (prev)
176  {
177  pma::Node3D* vtx = static_cast< pma::Node3D* >(prev->Prev());
178  gstart = vtx->Projection2D(h.View2D());
179  if (!next) g3d = vtx->Point3D();
180  }
181  else if (next)
182  {
183  pma::Node3D* vtx = static_cast< pma::Node3D* >(next->Next());
184  gstart = Projection2D(h.View2D());
185  gstart -= vtx->Projection2D(h.View2D()) - Projection2D(h.View2D());
186  if (!prev)
187  {
188  g3d = fPoint3D;
189  g3d -= vtx->Point3D() - fPoint3D;
190  }
191  }
192  else
193  {
194  mf::LogError("pma::Node3D") << "Isolated vertex.";
195  TVector2 p(Projection2D(h.View2D()));
196  h.SetProjection(p, 0.0F);
197  h.SetPoint3D(fPoint3D);
198  return;
199  }
200 
201  TVector2 v0(h.Point2D());
202  v0 -= Projection2D(h.View2D());
203 
204  TVector2 v1(gstart);
205  v1 -= Projection2D(h.View2D());
206 
207  double v0Norm = v0.Mod();
208  double v1Norm = v1.Mod();
209  double mag = v0Norm * v1Norm;
210  double cosine = 0.0;
211  if (mag != 0.0) cosine = v0 * v1 / mag;
212 
213  TVector2 p(Projection2D(h.View2D()));
214 
215  if (prev && next)
216  {
217  pma::Node3D* vNext = static_cast< pma::Node3D* >(next->Next());
218  TVector2 vN(vNext->Projection2D(h.View2D()));
219  vN -= Projection2D(h.View2D());
220 
221  mag = v0Norm * vN.Mod();
222  double cosineN = 0.0;
223  if (mag != 0.0) cosineN = v0 * vN / mag;
224 
225  // hit on the previous segment side, sorting on the -cosine(prev_seg, point) /max.val. = 1/
226  if (cosineN <= cosine) h.SetProjection(p, -(float)cosine);
227  // hit on the next segment side, sorting on the 1+cosine(next_seg, point) /min.val. = 1/
228  else h.SetProjection(p, 2.0F + (float)cosineN);
229 
230  h.SetPoint3D(fPoint3D);
231  }
232  else
233  {
234  float b = (float)(v0Norm * cosine / v1Norm);
235  if (fFrozen) // limit 3D positions to outermose node if frozen
236  {
237  h.SetPoint3D(fPoint3D);
238  }
239  else // or set 3D positions along the line of outermost segment
240  {
241  g3d -= fPoint3D;
242  h.SetPoint3D(fPoint3D + (g3d * b));
243 
244  p += (v1 * b);
245  }
246  h.SetProjection(p, -b);
247  }
248 }
TVector2 const & Projection2D(unsigned int view) const
Definition: PmaNode3D.h:39
unsigned int View2D(void) const
Definition: PmaHit3D.h:58
TVector3 const & Point3D(void) const
Definition: PmaNode3D.h:33
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
void SetProjection(const TVector2 &p, float b)
Definition: PmaHit3D.h:73
TVector2 const & Point2D(void) const
Definition: PmaHit3D.h:53
void SetPoint3D(const TVector3 &p3d)
Definition: PmaHit3D.h:50
pma::SortedObjectBase * next
Definition: SortedObjects.h:53
TVector3 fPoint3D
Definition: PmaNode3D.h:129
virtual pma::SortedObjectBase * Prev(void) const
Definition: SortedObjects.h:44
virtual pma::SortedObjectBase * Next(unsigned int index=0) const
Definition: SortedObjects.h:45
void pma::Node3D::SetVertex ( bool  state)
inline

Definition at line 55 of file PmaNode3D.h.

References fIsVertex.

55 { fIsVertex = state; }
bool fIsVertex
Definition: PmaNode3D.h:134
void pma::Node3D::SetVertexToBranching ( bool  setAllNodes)
inline

Definition at line 56 of file PmaNode3D.h.

References fIsVertex, GetBranches(), GetDirection3D(), GetDistance2To(), and IsBranching().

57  {
58  if (setAllNodes || !fIsVertex) fIsVertex = IsBranching();
59  }
bool IsBranching(void) const
Belongs to more than one track?
Definition: PmaNode3D.cxx:379
bool fIsVertex
Definition: PmaNode3D.h:134
void pma::Element3D::SortHits ( void  )
inherited

Definition at line 44 of file PmaElement3D.cxx.

References pma::Element3D::fAssignedHits.

Referenced by pma::Track3D::AddNode(), pma::Track3D::SortHits(), and pma::Element3D::UpdateProjection().

45 {
46  std::sort(fAssignedHits.begin(), fAssignedHits.end(), pma::bTrajectory3DOrderLess());
47 }
std::vector< pma::Hit3D * > fAssignedHits
Definition: PmaElement3D.h:113
double pma::Node3D::StepWithGradient ( float  alfa,
float  tol,
float  penalty,
float  weight 
)
private

Definition at line 609 of file PmaNode3D.cxx.

References fGradient, fPoint3D, GetObjFunction(), MakeGradient(), SetPoint3D(), t1, t2, and tmp.

Referenced by Optimize(), and SetMargin().

610 {
611  unsigned int steps = 0;
612  double t, t1, t2, t3, g, g0, g1, g2, g3, p1, p2;
613  double eps = 6.0E-37, zero_tol = 1.0E-15;
614  TVector3 tmp(fPoint3D), gpoint(fPoint3D);
615 
616  g = MakeGradient(penalty, weight);
617  if (g < zero_tol) return 0.0;
618  g0 = g;
619 
620  //**** first three points ****//
621  alfa *= 0.8F;
622  t2 = 0.0; g2 = g;
623  t3 = 0.0; g3 = g;
624  do
625  {
626  t1 = t2; g1 = g2;
627  t2 = t3; g2 = g3;
628 
629  alfa *= 1.25F;
630  t3 += alfa;
631  gpoint = tmp;
632  gpoint += (fGradient * t3);
633  if (!SetPoint3D(gpoint)) // stepped out of allowed volume
634  {
635  //std::cout << "**** SetPoint trimmed 1 ****" << std::endl;
636  g3 = GetObjFunction(penalty, weight);
637  if (g3 < g2) return (g0 - g3) / g3; // exit with the node at the border
638  else { SetPoint3D(tmp); return 0.0; } // exit with restored original position
639  }
640 
641  g3 = GetObjFunction(penalty, weight);
642 
643  if (g3 < zero_tol) return 0.0;
644 
645  if (++steps > 1000) { SetPoint3D(tmp); return 0.0; }
646 
647  } while (g3 < g2);
648  //****************************//
649 
650  //*** first step overshoot ***//
651  if (steps == 1)
652  {
653  t2 = t3; g2 = g3;
654  do
655  {
656  t3 = t2; g3 = g2;
657  t2 = (t1 * g3 + t3 * g1) / (g1 + g3);
658 
659  // small shift...
660  t2 = 0.05 * t3 + 0.95 * t2;
661 
662  // break: starting point is at the minimum
663  //if (t2 == t1) { SetPoint3D(tmp); return 0.0F; }
664 
665  // break: starting point is very close to the minimum
666  if (fabs(t2 - t1) < tol) { SetPoint3D(tmp); return 0.0; }
667 
668  gpoint = tmp;
669  gpoint += (fGradient * t2);
670  if (!SetPoint3D(gpoint)) // select the best point to exit
671  {
672  //std::cout << "**** SetPoint trimmed 2 ****" << std::endl;
673  g2 = GetObjFunction(penalty, weight);
674  if (g2 < g0) return (g0 - g2) / g2; // exit with the node at the border
675  else if (g1 < g0)
676  {
677  gpoint = tmp; gpoint += (fGradient * t1);
678  return (g0 - g1) / g1;
679  }
680  else if (g3 < g0)
681  {
682  gpoint = tmp; gpoint += (fGradient * t3);
683  return (g0 - g3) / g3;
684  }
685  else { SetPoint3D(tmp); return 0.0; }
686  }
687  g2 = GetObjFunction(penalty, weight);
688 
689  if (g2 < zero_tol) return 0.0;
690  steps++;
691 
692  } while (g2 >= g1);
693  }
694  //****************************//
695 
696  while (fabs(t1 - t3) > tol)
697  {
698  //*** 3-point minimization ***//
699  if ((fabs(t2 - t1) < eps) || (fabs(t2 - t3) < eps))
700  break; // minimum on the edge
701  if ((fabs(g2 - g1) < eps) && (fabs(g2 - g3) < eps))
702  break; // ~singularity
703 
704  p1 = (t2 - t1) * (g2 - g3);
705  p2 = (t2 - t3) * (g2 - g1);
706  if (fabs(p1 - p2) < eps) break; // ~linearity
707 
708  t = t2 + ((t2 - t1) * p1 - (t2 - t3) * p2) / (2 * (p2 - p1));
709  if ((t <= t1) || (t >= t3))
710  t = (t1 * g3 + t3 * g1) / (g1 + g3);
711 
712  gpoint = tmp;
713  gpoint += (fGradient * t);
714  if (!SetPoint3D(gpoint)) // select the best point to exit
715  {
716  //std::cout << "**** SetPoint trimmed 3 ****" << std::endl;
717  g = GetObjFunction(penalty, weight);
718  if ((g < g0) && (g < g1) && (g < g3)) return (g0 - g) / g; // exit with the node at the border
719  else if ((g1 < g0) && (g1 < g3))
720  {
721  gpoint = tmp; gpoint += (fGradient * t1);
722  return (g0 - g1) / g1;
723  }
724  else if (g3 < g0)
725  {
726  gpoint = tmp; gpoint += (fGradient * t3);
727  return (g0 - g3) / g3;
728  }
729  else { SetPoint3D(tmp); return 0.0; }
730  }
731 
732  g = GetObjFunction(penalty, weight);
733  if (g < zero_tol) return 0.0;
734  steps++;
735  //****************************//
736 
737  //*** select next 3 points ***//
738  if (fabs(t - t2) < 0.2 * tol) break; // start in a new direction
739  if (g < g2)
740  {
741  if (t < t2) { t3 = t2; g3 = g2; }
742  else { t1 = t2; g1 = g2; }
743  t2 = t; g2 = g;
744  }
745  else
746  {
747  if (t < t2) { t1 = t; g1 = g; }
748  else { t3 = t; g3 = g; }
749  }
750  //****************************//
751  }
752 
753  return (g0 - g) / g;
754 }
TTree * t1
Definition: plottest35.C:26
Float_t tmp
Definition: plot.C:37
bool SetPoint3D(const TVector3 &p3d)
Definition: PmaNode3D.cxx:123
TTree * t2
Definition: plottest35.C:36
double MakeGradient(float penaltyValue, float endSegWeight)
Definition: PmaNode3D.cxx:527
double weight
Definition: plottest35.C:25
double GetObjFunction(float penaltyValue, float endSegWeight) const
Objective function minimized during oprimization.
Definition: PmaNode3D.cxx:522
TVector3 fPoint3D
Definition: PmaNode3D.h:129
TVector3 fGradient
Definition: PmaNode3D.h:133
double pma::Element3D::SumDist2 ( void  ) const
inherited

Definition at line 171 of file PmaElement3D.cxx.

References d, pma::Element3D::fAssignedHits, pma::Element3D::fAssignedPoints, pma::Element3D::fTPC, pma::Element3D::GetDistance2To(), and pma::Element3D::SumDist2Hits().

Referenced by Mse(), and pma::Element3D::UpdateProjection().

172 {
173  if (fTPC < 0)
174  {
175  if (!fAssignedHits.empty()) mf::LogWarning("pma::Element3D") << "Hits assigned to TPC-crossing element.";
176  return 0.0F;
177  }
178 
179  double hit_sum = SumDist2Hits();
180 
181  if (fAssignedPoints.size())
182  {
183  double d, ref_sum = 0.0F;
184  for (auto p : fAssignedPoints)
185  {
186  d = sqrt( GetDistance2To(*p) ) - 0.5; // guide by ref points up to ~ 3D resolution
187  if (d > 0.0) ref_sum += d * d;
188  }
189  if (fAssignedHits.size())
190  {
191  ref_sum *= 0.2 * fAssignedHits.size() / fAssignedPoints.size();
192  }
193  hit_sum += ref_sum;
194  }
195 
196  return hit_sum;
197 }
std::vector< TVector3 * > fAssignedPoints
Definition: PmaElement3D.h:114
Float_t d
Definition: plot.C:237
std::vector< pma::Hit3D * > fAssignedHits
Definition: PmaElement3D.h:113
virtual double GetDistance2To(const TVector3 &p3d) const =0
Distance [cm] from the 3D point to the object 3D.
virtual double SumDist2Hits(void) const =0
double pma::Element3D::SumDist2 ( unsigned int  view) const
inherited

Definition at line 199 of file PmaElement3D.cxx.

References pma::Element3D::fAssignedHits, pma::Element3D::fTPC, pma::Element3D::GetDistance2To(), geo::kUnknown, and pma::Element3D::OptFactor().

200 {
201  if (fTPC < 0)
202  {
203  if (!fAssignedHits.empty()) mf::LogWarning("pma::Element3D") << "Hits assigned to TPC-crossing element.";
204  return 0.0F;
205  }
206 
207  double hit_sum = 0.0F;
208  for (auto h : fAssignedHits)
209  {
210  if (h->IsEnabled())
211  {
212  unsigned int hitView = h->View2D();
213  if ((view == geo::kUnknown) || (view == hitView))
214  {
215  hit_sum += OptFactor(hitView) * // alpha_i
216  h->GetSigmaFactor() * // hit_amp / hit_max_amp
217  GetDistance2To(h->Point2D(), hitView); // hit_to_fit_dist^2
218  }
219  }
220  }
221  return hit_sum;
222 }
Unknown view.
Definition: geo_types.h:83
std::vector< pma::Hit3D * > fAssignedHits
Definition: PmaElement3D.h:113
virtual double GetDistance2To(const TVector3 &p3d) const =0
Distance [cm] from the 3D point to the object 3D.
static float OptFactor(unsigned int view)
Definition: PmaElement3D.h:103
double pma::Node3D::SumDist2Hits ( void  ) const
overrideprivatevirtual

Implements pma::Element3D.

Definition at line 143 of file PmaNode3D.cxx.

References pma::Dist2(), pma::Element3D::fAssignedHits, fProj2D, and pma::Element3D::OptFactor().

Referenced by SetMargin().

144 {
145  double sum = 0.0F;
146  for (auto h : fAssignedHits)
147  {
148  if (h->IsEnabled())
149  {
150  unsigned int view = h->View2D();
151 
152  sum += OptFactor(view) * // alpha_i
153  h->GetSigmaFactor() * // hit_amp / hit_max_amp
154  pma::Dist2(h->Point2D(), fProj2D[view]);
155  }
156  }
157  return sum;
158 }
double Dist2(const TVector2 &v1, const TVector2 &v2)
Definition: Utilities.cxx:19
TVector2 fProj2D[3]
Definition: PmaNode3D.h:130
std::vector< pma::Hit3D * > fAssignedHits
Definition: PmaElement3D.h:113
static float OptFactor(unsigned int view)
Definition: PmaElement3D.h:103
double pma::Element3D::SumHitsQ ( unsigned int  view) const
inlineinherited

Definition at line 89 of file PmaElement3D.h.

References pma::Element3D::fSumHitsQ.

89 { return fSumHitsQ[view]; }
double fSumHitsQ[3]
Definition: PmaElement3D.h:118
void pma::Element3D::UpdateHitParams ( void  )
inherited

Definition at line 56 of file PmaElement3D.cxx.

References pma::Element3D::fAssignedHits, pma::Element3D::fHitsRadius, pma::Element3D::fNHits, pma::Element3D::fNThisHits, pma::Element3D::fNThisHitsEnabledAll, pma::Element3D::fSumHitsQ, pma::GetHitsRadius2D(), geo::kU, geo::kV, geo::kZ, pma::SortedObjectBase::Next(), pma::SortedObjectBase::NextCount(), and pma::SortedObjectBase::Prev().

Referenced by pma::Element3D::AddPoint().

57 {
58  std::vector< pma::Hit3D* > hitsColl, hitsInd1, hitsInd2;
59  for (size_t i = 0; i < 3; ++i) fNThisHitsEnabledAll = 0;
60  for (auto h : fAssignedHits)
61  {
62  if (h->IsEnabled()) fNThisHitsEnabledAll++;
63  switch (h->View2D())
64  {
65  case geo::kZ: hitsColl.push_back(h); break;
66  case geo::kV: hitsInd2.push_back(h); break;
67  case geo::kU: hitsInd1.push_back(h); break;
68  }
69  }
70  fNThisHits[0] = hitsInd1.size();
71  fNThisHits[1] = hitsInd2.size();
72  fNThisHits[2] = hitsColl.size();
73 
74  pma::SortedObjectBase const * chain = dynamic_cast< pma::SortedObjectBase* >(this);
75  pma::Element3D* el = 0;
76  for (size_t b = 0; b < chain->NextCount(); b++)
77  {
78  el = dynamic_cast< pma::Element3D* >(chain->Next(b));
79  if (el)
80  for (auto h : el->fAssignedHits)
81  {
82  switch (h->View2D())
83  {
84  case geo::kZ: hitsColl.push_back(h); break;
85  case geo::kV: hitsInd2.push_back(h); break;
86  case geo::kU: hitsInd1.push_back(h); break;
87  }
88  }
89  }
90  el = dynamic_cast< pma::Element3D* >(chain->Prev());
91  if (el)
92  {
93  for (auto h : el->fAssignedHits)
94  {
95  switch (h->View2D())
96  {
97  case geo::kZ: hitsColl.push_back(h); break;
98  case geo::kV: hitsInd2.push_back(h); break;
99  case geo::kU: hitsInd1.push_back(h); break;
100  }
101  }
102  }
103 
104  fHitsRadius = GetHitsRadius2D(hitsColl);
105  double r = GetHitsRadius2D(hitsInd2);
106  if (r > fHitsRadius) fHitsRadius = r;
107  r = GetHitsRadius2D(hitsInd1);
108  if (r > fHitsRadius) fHitsRadius = r;
109 
110  float amp, sigmaMax = 0.0F;
111  fSumHitsQ[0] = 0.0; fNHits[0] = hitsInd1.size();
112  for (size_t i = 0; i < hitsInd1.size(); i++)
113  {
114  amp = hitsInd1[i]->GetAmplitude();
115  if (amp > sigmaMax) sigmaMax = amp;
116  fSumHitsQ[0] += amp;
117  }
118  for (size_t i = 0; i < hitsInd1.size(); i++)
119  {
120  if (sigmaMax > 0.0F)
121  {
122  amp = hitsInd1[i]->GetAmplitude();
123  if (amp > 0.0F)
124  hitsInd1[i]->SetSigmaFactor((float)sqrt(amp / sigmaMax));
125  else hitsInd1[i]->SetSigmaFactor(0.01F);
126  }
127  else hitsInd1[i]->SetSigmaFactor(1.0F);
128  }
129 
130  sigmaMax = 0.0F;
131  fSumHitsQ[1] = 0.0; fNHits[1] = hitsInd2.size();
132  for (size_t i = 0; i < hitsInd2.size(); i++)
133  {
134  amp = hitsInd2[i]->GetAmplitude();
135  if (amp > sigmaMax) sigmaMax = amp;
136  fSumHitsQ[1] += amp;
137  }
138  for (size_t i = 0; i < hitsInd2.size(); i++)
139  {
140  if (sigmaMax > 0.0F)
141  {
142  amp = hitsInd2[i]->GetAmplitude();
143  if (amp > 0.0F)
144  hitsInd2[i]->SetSigmaFactor((float)sqrt(amp / sigmaMax));
145  else hitsInd2[i]->SetSigmaFactor(0.01F);
146  }
147  else hitsInd2[i]->SetSigmaFactor(1.0F);
148  }
149 
150  sigmaMax = 0.0F;
151  fSumHitsQ[2] = 0.0; fNHits[2] = hitsColl.size();
152  for (size_t i = 0; i < hitsColl.size(); i++)
153  {
154  amp = hitsColl[i]->SummedADC();
155  if (amp > sigmaMax) sigmaMax = amp;
156  fSumHitsQ[2] += amp;
157  }
158  for (size_t i = 0; i < hitsColl.size(); i++)
159  {
160  if (sigmaMax > 0.0F)
161  {
162  amp = hitsColl[i]->SummedADC();
163  if (amp > 0.0F)
164  hitsColl[i]->SetSigmaFactor((float)sqrt(amp / sigmaMax));
165  else hitsColl[i]->SetSigmaFactor(0.01F);
166  }
167  else hitsColl[i]->SetSigmaFactor(1.0F);
168  }
169 }
double fSumHitsQ[3]
Definition: PmaElement3D.h:118
double GetHitsRadius2D(const std::vector< pma::Hit3D * > &hits, bool exact=false)
Definition: Utilities.cxx:78
Planes which measure V.
Definition: geo_types.h:77
Planes which measure Z direction.
Definition: geo_types.h:79
size_t fNThisHits[3]
Definition: PmaElement3D.h:115
Planes which measure U.
Definition: geo_types.h:76
virtual unsigned int NextCount(void) const
Definition: SortedObjects.h:46
size_t fNHits[3]
Definition: PmaElement3D.h:117
std::vector< pma::Hit3D * > fAssignedHits
Definition: PmaElement3D.h:113
size_t fNThisHitsEnabledAll
Definition: PmaElement3D.h:116
double fHitsRadius
Definition: PmaElement3D.h:119
virtual pma::SortedObjectBase * Prev(void) const
Definition: SortedObjects.h:44
virtual pma::SortedObjectBase * Next(unsigned int index=0) const
Definition: SortedObjects.h:45
void pma::Node3D::UpdateProj2D ( void  )
private

Definition at line 115 of file PmaNode3D.cxx.

References fDriftOffset, fPoint3D, fProj2D, fTpcGeo, geo::TPCGeo::Nplanes(), geo::TPCGeo::Plane(), and geo::PlaneGeo::PlaneCoordinate().

Referenced by SetMargin(), and SetPoint3D().

116 {
117  for (size_t i = 0; i < fTpcGeo.Nplanes(); ++i)
118  {
120  }
121 }
unsigned int Nplanes() const
Number of planes in this tpc.
Definition: TPCGeo.h:145
double fDriftOffset
Definition: PmaNode3D.h:131
TVector2 fProj2D[3]
Definition: PmaNode3D.h:130
geo::TPCGeo const & fTpcGeo
Definition: PmaNode3D.h:125
TVector3 fPoint3D
Definition: PmaNode3D.h:129
PlaneGeo const & Plane(geo::View_t view) const
Return the plane in the tpc with View_t view.
Definition: TPCGeo.cxx:299
double PlaneCoordinate(geo::Point_t const &point) const
Returns the coordinate of the point on the plane.
Definition: PlaneGeo.h:704
void pma::Element3D::UpdateProjection ( void  )
inlineinherited

Definition at line 84 of file PmaElement3D.h.

References pma::Element3D::fAssignedHits, pma::Element3D::SetProjection(), pma::Element3D::SortHits(), and pma::Element3D::SumDist2().

84 { for (auto h : fAssignedHits) SetProjection(*h); }
virtual void SetProjection(pma::Hit3D &h) const =0
std::vector< pma::Hit3D * > fAssignedHits
Definition: PmaElement3D.h:113

Member Data Documentation

std::vector< TVector3* > pma::Element3D::fAssignedPoints
protectedinherited
int pma::Element3D::fCryo
protectedinherited

Definition at line 108 of file PmaElement3D.h.

Referenced by pma::Element3D::Cryo(), Node3D(), and pma::Segment3D::Segment3D().

double pma::Node3D::fDriftOffset
private

Definition at line 131 of file PmaNode3D.h.

Referenced by ApplyDriftShift(), GetDriftShift(), and UpdateProj2D().

bool pma::Element3D::fFrozen
protectedinherited
bool pma::Node3D::fGradFixed = { false, false, false }
staticprivate

Definition at line 136 of file PmaNode3D.h.

Referenced by MakeGradient().

TVector3 pma::Node3D::fGradient
private

Definition at line 133 of file PmaNode3D.h.

Referenced by MakeGradient(), and StepWithGradient().

double pma::Element3D::fHitsRadius
protectedinherited
bool pma::Node3D::fIsVertex
private

Definition at line 134 of file PmaNode3D.h.

Referenced by IsVertex(), PenaltyInWirePlane(), Pi(), SetVertex(), and SetVertexToBranching().

double pma::Node3D::fMargin = 3.0
staticprivate

Definition at line 137 of file PmaNode3D.h.

Referenced by LimitPoint3D(), and SetMargin().

double pma::Node3D::fMaxX
private

Definition at line 127 of file PmaNode3D.h.

Referenced by GetDistToWall(), LimitPoint3D(), Node3D(), and SameTPC().

double pma::Node3D::fMaxY
private

Definition at line 127 of file PmaNode3D.h.

Referenced by GetDistToWall(), LimitPoint3D(), Node3D(), and SameTPC().

double pma::Node3D::fMaxZ
private

Definition at line 127 of file PmaNode3D.h.

Referenced by GetDistToWall(), LimitPoint3D(), Node3D(), and SameTPC().

double pma::Node3D::fMinX
private

Definition at line 127 of file PmaNode3D.h.

Referenced by GetDistToWall(), LimitPoint3D(), Node3D(), and SameTPC().

double pma::Node3D::fMinY
private

Definition at line 127 of file PmaNode3D.h.

Referenced by GetDistToWall(), LimitPoint3D(), Node3D(), and SameTPC().

double pma::Node3D::fMinZ
private

Definition at line 127 of file PmaNode3D.h.

Referenced by GetDistToWall(), LimitPoint3D(), Node3D(), and SameTPC().

size_t pma::Element3D::fNHits[3]
protectedinherited
size_t pma::Element3D::fNThisHits[3]
protectedinherited
size_t pma::Element3D::fNThisHitsEnabledAll
protectedinherited
float pma::Element3D::fOptFactors = { 0.2F, 0.8F, 1.0F }
staticprotectedinherited

Definition at line 121 of file PmaElement3D.h.

Referenced by pma::Element3D::OptFactor(), and pma::Element3D::SetOptFactor().

TVector2 pma::Node3D::fProj2D[3]
private

Definition at line 130 of file PmaNode3D.h.

Referenced by GetDistance2To(), Node3D(), Projection2D(), SumDist2Hits(), and UpdateProj2D().

double pma::Element3D::fSumHitsQ[3]
protectedinherited
int pma::Element3D::fTPC
protectedinherited
geo::TPCGeo const& pma::Node3D::fTpcGeo
private

Definition at line 125 of file PmaNode3D.h.

Referenced by Node3D(), and UpdateProj2D().

std::vector< pma::SortedObjectBase* > pma::SortedBranchBase::next_vector
protectedinherited

Definition at line 88 of file SortedObjects.h.


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