LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
pma::Node3D Class Referencefinal

#include "PmaNode3D.h"

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

Public Member Functions

 Node3D ()
 
 Node3D (detinfo::DetectorPropertiesData const &detProp, const TVector3 &p3d, unsigned int tpc, unsigned int cryo, bool vtx=false, double xshift=0)
 
TVector3 const & Point3D () const
 
bool SetPoint3D (const TVector3 &p3d)
 
TVector2 const & Projection2D (unsigned int view) const
 
double GetDistToWall () 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 () const
 Belongs to more than one track? More...
 
bool IsTPCEdge () const
 Is the first/last in this TPC? More...
 
bool IsVertex () const
 Check fIsVertex flag. More...
 
void SetVertex (bool state)
 
void SetVertexToBranching (bool setAllNodes)
 
std::vector< pma::Track3D * > GetBranches () 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
 
pma::Vector3D GetDirection3D () const override
 
TVector3 GetUnconstrainedProj3D (const TVector2 &, unsigned int) 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 () const override
 
double SegmentCos () const
 Cosine of 3D angle between connected segments. More...
 
double SegmentCosWirePlane () const
 
double SegmentCosTransverse () 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 () 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 ()
 Returns true if node position was trimmed to its TPC volume + fMargin. More...
 
void UpdateProj2D ()
 
double EndPtCos2Transverse () const
 
double PiInWirePlane () const
 
double PenaltyInWirePlane () const
 
double Pi (float endSegWeight, bool doAsymm) const
 
double Penalty (float endSegWeight) const
 
double Mse () const
 
double MakeGradient (float penaltyValue, float endSegWeight)
 
double StepWithGradient (float alfa, float tol, float penalty, float weight)
 
double SumDist2Hits () 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 34 of file PmaNode3D.h.

Constructor & Destructor Documentation

pma::Node3D::Node3D ( )

Definition at line 28 of file PmaNode3D.cxx.

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

30  , fMinX(0)
31  , fMaxX(0)
32  , fMinY(0)
33  , fMaxY(0)
34  , fMinZ(0)
35  , fMaxZ(0)
36  , fPoint3D(0, 0, 0)
37  , fDriftOffset(0)
38  , fIsVertex(false)
39 {
40  fTPC = 0;
41  fCryo = 0;
42 
43  fProj2D[0].Set(0);
44  fProj2D[1].Set(0);
45  fProj2D[2].Set(0);
46 }
double fMinZ
Definition: PmaNode3D.h:149
double fDriftOffset
Definition: PmaNode3D.h:155
int TPC(void) const
TPC index or -1 if out of any TPC.
Definition: PmaElement3D.h:35
TVector2 fProj2D[3]
Definition: PmaNode3D.h:153
double fMaxX
Definition: PmaNode3D.h:149
double fMaxY
Definition: PmaNode3D.h:149
double fMaxZ
Definition: PmaNode3D.h:149
double fMinY
Definition: PmaNode3D.h:149
geo::TPCGeo const & fTpcGeo
Definition: PmaNode3D.h:147
TVector3 fPoint3D
Definition: PmaNode3D.h:152
bool fIsVertex
Definition: PmaNode3D.h:158
double fMinX
Definition: PmaNode3D.h:149
pma::Node3D::Node3D ( detinfo::DetectorPropertiesData const &  detProp,
const TVector3 &  p3d,
unsigned int  tpc,
unsigned int  cryo,
bool  vtx = false,
double  xshift = 0 
)

Definition at line 48 of file PmaNode3D.cxx.

References detinfo::DetectorPropertiesData::ConvertTicksToX(), 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(), detinfo::DetectorPropertiesData::NumberTimeSamples(), SetPoint3D(), and tmp.

55  , fDriftOffset(xshift)
56  , fIsVertex(vtx)
57 {
58  fTPC = tpc;
59  fCryo = cryo;
60 
61  unsigned int lastPlane = geo::kZ;
62  while ((lastPlane > 0) && !fTpcGeo.HasPlane(lastPlane))
63  lastPlane--;
64 
65  fMinX = detProp.ConvertTicksToX(0, lastPlane, tpc, cryo);
66  fMaxX = detProp.ConvertTicksToX(detProp.NumberTimeSamples() - 1, lastPlane, tpc, cryo);
67  if (fMaxX < fMinX) {
68  double tmp = fMaxX;
69  fMaxX = fMinX;
70  fMinX = tmp;
71  }
72 
73  fMinY = fTpcGeo.MinY();
74  fMaxY = fTpcGeo.MaxY();
75  fMinZ = fTpcGeo.MinZ();
76  fMaxZ = fTpcGeo.MaxZ();
77 
78  SetPoint3D(p3d);
79 }
bool HasPlane(unsigned int iplane) const
Returns whether a plane with index iplane is present in this TPC.
Definition: TPCGeo.h:147
double fMinZ
Definition: PmaNode3D.h:149
double fDriftOffset
Definition: PmaNode3D.h:155
Planes which measure Z direction.
Definition: geo_types.h:138
Float_t tmp
Definition: plot.C:35
int TPC(void) const
TPC index or -1 if out of any TPC.
Definition: PmaElement3D.h:35
double fMaxX
Definition: PmaNode3D.h:149
bool SetPoint3D(const TVector3 &p3d)
Definition: PmaNode3D.cxx:162
double MinZ() const
Returns the world z coordinate of the start of the box.
double fMaxY
Definition: PmaNode3D.h:149
The data type to uniquely identify a TPC.
Definition: geo_types.h:381
double fMaxZ
Definition: PmaNode3D.h:149
double MaxY() const
Returns the world y coordinate of the end of the box.
double fMinY
Definition: PmaNode3D.h:149
double MaxZ() const
Returns the world z coordinate of the end of the box.
geo::TPCGeo const & fTpcGeo
Definition: PmaNode3D.h:147
double MinY() const
Returns the world y coordinate of the start of the box.
bool fIsVertex
Definition: PmaNode3D.h:158
double fMinX
Definition: PmaNode3D.h:149

Member Function Documentation

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

Definition at line 70 of file PmaElement3D.h.

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

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

71  {
72  fAssignedHits.push_back(h);
73  SetProjection(*h);
74  }
virtual void SetProjection(pma::Hit3D &h) const =0
std::vector< pma::Hit3D * > fAssignedHits
Definition: PmaElement3D.h:122
bool pma::SortedBranchBase::AddNext ( pma::SortedObjectBase nextElement)
virtualinherited

Reimplemented from pma::SortedObjectBase.

Definition at line 69 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().

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

Definition at line 82 of file PmaElement3D.h.

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

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

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

Definition at line 116 of file PmaNode3D.h.

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

117  {
118  fPoint3D[0] += dx;
119  fDriftOffset += dx;
120  }
double fDriftOffset
Definition: PmaNode3D.h:155
TVector3 fPoint3D
Definition: PmaNode3D.h:152
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 825 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 pma::Track3D::Split().

826 {
827  if (!trk) {
828  // like in the base class:
829  fAssignedPoints.clear();
830  fAssignedHits.clear();
831  }
832  else {
833  std::vector<pma::Track3D*> to_check;
834  pma::Segment3D* seg;
835  if (Prev()) {
836  seg = static_cast<pma::Segment3D*>(Prev());
837  if (seg->Parent() != trk) to_check.push_back(seg->Parent());
838  }
839  for (unsigned int i = 0; i < NextCount(); i++) {
840  seg = static_cast<pma::Segment3D*>(Next(i));
841  if (seg->Parent() != trk) to_check.push_back(seg->Parent());
842  }
843 
844  unsigned int p = 0;
845  while (p < fAssignedPoints.size()) {
846  bool found = false;
847  for (size_t t = 0; t < to_check.size(); t++)
848  if (to_check[t]->HasRefPoint(fAssignedPoints[p])) {
849  found = true;
850  break;
851  }
852 
853  if (!found)
854  fAssignedPoints.erase(fAssignedPoints.begin() + p);
855  else
856  p++;
857  }
858 
859  unsigned int h = 0;
860  while (h < fAssignedHits.size()) {
861  bool found = false;
863 
864  for (size_t t = 0; (t < to_check.size()) && !found; t++)
865  for (size_t i = 0; i < to_check[t]->size(); i++) {
866  pma::Hit3D* pmaHit = static_cast<pma::Hit3D*>((*(to_check[t]))[i]);
867  if (hit == pmaHit) {
868  found = true;
869  break;
870  }
871  }
872 
873  if (!found)
874  fAssignedHits.erase(fAssignedHits.begin() + h);
875  else
876  h++;
877  }
878  }
879 
880  fHitsRadius = 0.0F;
881 }
std::vector< TVector3 * > fAssignedPoints
Definition: PmaElement3D.h:123
virtual unsigned int NextCount(void) const
Definition: SortedObjects.h:84
Detector simulation of raw signals on wires.
std::vector< pma::Hit3D * > fAssignedHits
Definition: PmaElement3D.h:122
virtual pma::SortedObjectBase * Next(unsigned int index=0) const
Definition: SortedObjects.h:77
double fHitsRadius
Definition: PmaElement3D.h:128
virtual pma::SortedObjectBase * Prev(void) const
Definition: SortedObjects.h:42
pma::Track3D * Parent(void) const
Definition: PmaSegment3D.h:66
int pma::Element3D::Cryo ( void  ) const
inlineinherited
void pma::SortedBranchBase::Disconnect ( void  )
virtualinherited

Reimplemented from pma::SortedObjectBase.

Definition at line 62 of file SortedObjects.cxx.

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

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

Definition at line 357 of file PmaNode3D.cxx.

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

Referenced by PenaltyInWirePlane().

358 {
359  if (prev && next) {
360  auto const& vStart = static_cast<pma::Node3D*>(prev->Prev())->fPoint3D;
361  auto const& vStop = static_cast<pma::Node3D*>(next->Next())->fPoint3D;
362 
363  double dy = vStop.X() - vStart.X();
364  double dz = vStop.Z() - vStart.Z();
365  double len2 = dy * dy + dz * dz;
366  double cosine2 = 0.0;
367  if (len2 > 0.0) cosine2 = dz * dz / len2;
368  return cosine2;
369  }
370  else
371  return 0.0;
372 }
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
virtual pma::SortedObjectBase * Next(unsigned int=0) const
Definition: SortedObjects.h:43
pma::SortedObjectBase * next
Definition: SortedObjects.h:53
TVector3 fPoint3D
Definition: PmaNode3D.h:152
virtual pma::SortedObjectBase * Prev(void) const
Definition: SortedObjects.h:42
std::vector< pma::Track3D * > pma::Node3D::GetBranches ( ) const

Definition at line 443 of file PmaNode3D.cxx.

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

Referenced by pma::VtxCandidate::JoinTracks().

444 {
445  std::vector<pma::Track3D*> branches;
446  if (NextCount()) {
447  branches.reserve(NextCount());
448  for (size_t i = 0; i < NextCount(); ++i) {
449  pma::Segment3D* seg = static_cast<pma::Segment3D*>(Next(i));
450  branches.push_back(seg->Parent());
451  }
452  }
453  return branches;
454 }
virtual unsigned int NextCount(void) const
Definition: SortedObjects.h:84
virtual pma::SortedObjectBase * Next(unsigned int index=0) const
Definition: SortedObjects.h:77
pma::Track3D * Parent(void) const
Definition: PmaSegment3D.h:66
pma::Vector3D pma::Node3D::GetDirection3D ( void  ) const
overridevirtual

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

Implements pma::Element3D.

Definition at line 197 of file PmaNode3D.cxx.

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

198 {
199  pma::Element3D* seg = 0;
200  if (next) { seg = dynamic_cast<pma::Element3D*>(next); }
201  else if (prev) {
202  seg = dynamic_cast<pma::Element3D*>(prev);
203  }
204  else {
205  throw cet::exception("Node3D") << "Isolated vertex." << std::endl;
206  }
207 
208  if (seg) { return seg->GetDirection3D(); }
209  else {
210  throw cet::exception("Node3D") << "Corrupted vertex." << std::endl;
211  }
212 }
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 172 of file PmaNode3D.cxx.

References pma::Dist2(), and fPoint3D.

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

173 {
174  return pma::Dist2(fPoint3D, p3d);
175 }
double Dist2(const TVector2 &v1, const TVector2 &v2)
Definition: Utilities.cxx:39
TVector3 fPoint3D
Definition: PmaNode3D.h:152
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 177 of file PmaNode3D.cxx.

References pma::Dist2(), and fProj2D.

178 {
179  return pma::Dist2(fProj2D[view], p2d);
180 }
double Dist2(const TVector2 &v1, const TVector2 &v2)
Definition: Utilities.cxx:39
TVector2 fProj2D[3]
Definition: PmaNode3D.h:153
double pma::Node3D::GetDistToWall ( ) const

Definition at line 81 of file PmaNode3D.cxx.

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

Referenced by pma::PMAlgTracker::validate().

82 {
83  double d, dmin = fPoint3D.X() - fMinX;
84  d = fMaxX - fPoint3D.X();
85  if (d < dmin) dmin = d;
86 
87  d = fPoint3D.Y() - fMinY;
88  if (d < dmin) dmin = d;
89  d = fMaxY - fPoint3D.Y();
90  if (d < dmin) dmin = d;
91 
92  d = fPoint3D.Z() - fMinZ;
93  if (d < dmin) dmin = d;
94  d = fMaxZ - fPoint3D.Z();
95  if (d < dmin) dmin = d;
96 
97  return dmin;
98 }
double fMinZ
Definition: PmaNode3D.h:149
double fMaxX
Definition: PmaNode3D.h:149
Float_t d
Definition: plot.C:235
double fMaxY
Definition: PmaNode3D.h:149
double fMaxZ
Definition: PmaNode3D.h:149
double fMinY
Definition: PmaNode3D.h:149
TVector3 fPoint3D
Definition: PmaNode3D.h:152
double fMinX
Definition: PmaNode3D.h:149
double pma::Node3D::GetDriftShift ( ) const
inline

Definition at line 121 of file PmaNode3D.h.

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

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

Objective function minimized during oprimization.

Definition at line 553 of file PmaNode3D.cxx.

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

Referenced by MakeGradient(), and StepWithGradient().

554 {
555  return Mse() + penaltyValue * (Penalty(endSegWeight) + PenaltyInWirePlane());
556 }
double Penalty(float endSegWeight) const
Definition: PmaNode3D.cxx:512
double PenaltyInWirePlane() const
Definition: PmaNode3D.cxx:395
double Mse() const
Definition: PmaNode3D.cxx:531
TVector3 pma::Node3D::GetUnconstrainedProj3D ( const TVector2 &  ,
unsigned int   
) const
inlineoverridevirtual

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

Implements pma::Element3D.

Definition at line 86 of file PmaNode3D.h.

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

Definition at line 57 of file PmaElement3D.h.

References pma::Element3D::fAssignedHits.

58  {
59  for (const auto a : fAssignedHits) {
60  if (h == a) return true;
61  }
62  return false;
63  }
std::vector< pma::Hit3D * > fAssignedHits
Definition: PmaElement3D.h:122
pma::Hit3D& pma::Element3D::Hit ( size_t  index)
inlineinherited

Definition at line 65 of file PmaElement3D.h.

References pma::Element3D::fAssignedHits.

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

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

Definition at line 55 of file PmaElement3D.h.

References pma::Element3D::fAssignedHits.

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

Definition at line 209 of file PmaElement3D.cxx.

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

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

210 {
211  if (fTPC < 0) {
212  if (!fAssignedHits.empty())
213  mf::LogWarning("pma::Element3D") << "Hits assigned to TPC-crossing element.";
214  return 0.0F;
215  }
216 
217  TVector3 mean3D(0, 0, 0);
218  size_t nHits = 0;
219  for (auto h : fAssignedHits)
220  if (h->View2D() == view) {
221  mean3D += h->Point3D();
222  nHits++;
223  }
224  if (!nHits) return 0.0;
225  mean3D *= (1.0 / nHits);
226 
227  double r2, maxR2 = 0.0;
228  for (auto h : fAssignedHits)
229  if (h->View2D() == view) {
230  r2 = pma::Dist2(h->Point3D(), mean3D);
231  if (r2 > maxR2) maxR2 = r2;
232  }
233  return sqrt(maxR2);
234 }
double Dist2(const TVector2 &v1, const TVector2 &v2)
Definition: Utilities.cxx:39
std::vector< pma::Hit3D * > fAssignedHits
Definition: PmaElement3D.h:122
bool pma::Node3D::IsBranching ( ) const

Belongs to more than one track?

Definition at line 418 of file PmaNode3D.cxx.

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

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

419 {
420  size_t nnext = NextCount();
421  if (nnext > 1) return true; // 1 trk -> vtx -> n*trk
422 
423  if (prev && nnext) {
424  pma::Segment3D* segPrev = static_cast<pma::Segment3D*>(prev);
425  pma::Segment3D* segNext = static_cast<pma::Segment3D*>(Next(0));
426  if (segNext->Parent() != segPrev->Parent()) // 1 trk -> vtx -> 1 trk
427  return true;
428  }
429  return false;
430 }
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:77
pma::Track3D * Parent(void) const
Definition: PmaSegment3D.h:66
virtual bool pma::SortedObjectBase::IsFirst ( void  ) const
inlinevirtualinherited

Definition at line 39 of file SortedObjects.h.

References pma::SortedObjectBase::prev.

39 { 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 105 of file PmaElement3D.h.

References pma::Element3D::fFrozen.

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

105 { 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 ( ) const

Is the first/last in this TPC?

Definition at line 432 of file PmaNode3D.cxx.

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

433 {
434  if (prev && (NextCount() == 1)) {
435  pma::Segment3D* segPrev = static_cast<pma::Segment3D*>(prev);
436  pma::Segment3D* segNext = static_cast<pma::Segment3D*>(Next(0));
437 
438  if ((segPrev->TPC() < 0) || (segNext->TPC() < 0)) return true;
439  }
440  return false;
441 }
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:35
virtual pma::SortedObjectBase * Next(unsigned int index=0) const
Definition: SortedObjects.h:77
bool pma::Node3D::IsVertex ( ) const
inline

Check fIsVertex flag.

Definition at line 65 of file PmaNode3D.h.

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

65 { return fIsVertex; }
bool fIsVertex
Definition: PmaNode3D.h:158
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 288 of file PmaNode3D.cxx.

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

Referenced by Pi(), and PiInWirePlane().

289 {
290  double l = 0.0;
291  if (next) l += (static_cast<pma::Segment3D*>(next))->Length();
292  if (prev) l += (static_cast<pma::Segment3D*>(prev))->Length();
293 
294  if (next && prev)
295  return 0.25 * l * l;
296  else
297  return l * l;
298 }
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
pma::SortedObjectBase * next
Definition: SortedObjects.h:53
bool pma::Node3D::LimitPoint3D ( )
private

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

Definition at line 120 of file PmaNode3D.cxx.

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

Referenced by SetPoint3D().

121 {
122  bool trimmed = false;
123 
124  if (fPoint3D.X() < fMinX - fMargin) {
125  fPoint3D.SetX(fMinX - fMargin);
126  trimmed = true;
127  }
128  if (fPoint3D.X() > fMaxX + fMargin) {
129  fPoint3D.SetX(fMaxX + fMargin);
130  trimmed = true;
131  }
132 
133  if (fPoint3D.Y() < fMinY - fMargin) {
134  fPoint3D.SetY(fMinY - fMargin);
135  trimmed = true;
136  }
137  if (fPoint3D.Y() > fMaxY + fMargin) {
138  fPoint3D.SetY(fMaxY + fMargin);
139  trimmed = true;
140  }
141 
142  if (fPoint3D.Z() < fMinZ - fMargin) {
143  fPoint3D.SetZ(fMinZ - fMargin);
144  trimmed = true;
145  }
146  if (fPoint3D.Z() > fMaxZ + fMargin) {
147  fPoint3D.SetZ(fMaxZ + fMargin);
148  trimmed = true;
149  }
150 
151  return trimmed;
152 }
double fMinZ
Definition: PmaNode3D.h:149
double fMaxX
Definition: PmaNode3D.h:149
double fMaxY
Definition: PmaNode3D.h:149
double fMaxZ
Definition: PmaNode3D.h:149
double fMinY
Definition: PmaNode3D.h:149
TVector3 fPoint3D
Definition: PmaNode3D.h:152
static double fMargin
Definition: PmaNode3D.h:161
double fMinX
Definition: PmaNode3D.h:149
double pma::Node3D::MakeGradient ( float  penaltyValue,
float  endSegWeight 
)
private

Definition at line 558 of file PmaNode3D.cxx.

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

Referenced by StepWithGradient().

559 {
560  double l1 = 0.0, l2 = 0.0, minLength2 = 0.0;
561  TVector3 tmp(fPoint3D), gpoint(fPoint3D);
562 
563  pma::Segment3D* seg;
564  if (prev) {
565  seg = static_cast<pma::Segment3D*>(prev);
566  l1 = seg->Length2();
567  }
568  if (next) {
569  seg = static_cast<pma::Segment3D*>(next);
570  l2 = seg->Length2();
571  }
572  if ((l1 > 0.01) && (l1 < l2))
573  minLength2 = l1;
574  else if ((l2 > 0.01) && (l2 < l1))
575  minLength2 = l2;
576  else
577  minLength2 = 0.01;
578 
579  double dxi = 0.001 * sqrt(minLength2);
580 
581  if (dxi < 6.0E-37) return 0.0;
582 
583  double gi, g0, gz;
584  gz = g0 = GetObjFunction(penaltyValue, endSegWeight);
585 
586  //if (fQPenaltyFactor > 0.0F) gz += fQPenaltyFactor * QPenalty(); <----------------------- maybe later..
587 
588  if (!fGradFixed[0]) // gradX
589  {
590  gpoint[0] = tmp[0] + dxi;
591  SetPoint3D(gpoint);
592  gi = GetObjFunction(penaltyValue, endSegWeight);
593  fGradient[0] = (g0 - gi) / dxi;
594 
595  gpoint[0] = tmp[0] - dxi;
596  SetPoint3D(gpoint);
597  gi = GetObjFunction(penaltyValue, endSegWeight);
598  fGradient[0] = 0.5 * (fGradient[0] + (gi - g0) / dxi);
599 
600  gpoint[0] = tmp[0];
601  }
602 
603  if (!fGradFixed[1]) // gradY
604  {
605  gpoint[1] = tmp[1] + dxi;
606  SetPoint3D(gpoint);
607  gi = GetObjFunction(penaltyValue, endSegWeight);
608  fGradient[1] = (g0 - gi) / dxi;
609 
610  gpoint[1] = tmp[1] - dxi;
611  SetPoint3D(gpoint);
612  gi = GetObjFunction(penaltyValue, endSegWeight);
613  fGradient[1] = 0.5 * (fGradient[1] + (gi - g0) / dxi);
614 
615  gpoint[1] = tmp[1];
616  }
617 
618  if (!fGradFixed[2]) // gradZ
619  {
620  gpoint[2] = tmp[2] + dxi;
621  SetPoint3D(gpoint);
622  gi = GetObjFunction(penaltyValue, endSegWeight);
623  //if (fQPenaltyFactor > 0.0F) gi += fQPenaltyFactor * QPenalty();
624  fGradient[2] = (gz - gi) / dxi;
625 
626  gpoint[2] = tmp[2] - dxi;
627  SetPoint3D(gpoint);
628  gi = GetObjFunction(penaltyValue, endSegWeight);
629  //if (fQPenaltyFactor > 0.0F) gi += fQPenaltyFactor * QPenalty();
630  fGradient[2] = 0.5 * (fGradient[2] + (gi - gz) / dxi);
631 
632  gpoint[2] = tmp[2];
633  }
634 
635  SetPoint3D(tmp);
636  if (fGradient.Mag2() < 6.0E-37) return 0.0;
637 
638  return g0;
639 }
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
Float_t tmp
Definition: plot.C:35
double Length2(void) const override
static bool fGradFixed[3]
Definition: PmaNode3D.h:160
Float_t E
Definition: plot.C:20
bool SetPoint3D(const TVector3 &p3d)
Definition: PmaNode3D.cxx:162
double GetObjFunction(float penaltyValue, float endSegWeight) const
Objective function minimized during oprimization.
Definition: PmaNode3D.cxx:553
pma::SortedObjectBase * next
Definition: SortedObjects.h:53
TVector3 fPoint3D
Definition: PmaNode3D.h:152
TVector3 fGradient
Definition: PmaNode3D.h:157
double pma::Node3D::Mse ( ) const
private

Definition at line 531 of file PmaNode3D.cxx.

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

Referenced by GetObjFunction().

532 {
533  unsigned int nhits = NPrecalcEnabledHits(); //NEnabledHits();
534  double mse = SumDist2();
535 
536  pma::Segment3D* seg;
537  for (unsigned int i = 0; i < NextCount(); i++) {
538  seg = static_cast<pma::Segment3D*>(Next(i));
539  nhits += seg->NPrecalcEnabledHits(); //NEnabledHits();
540  mse += seg->SumDist2();
541  }
542  if (prev) {
543  seg = static_cast<pma::Segment3D*>(prev);
544  nhits += seg->NPrecalcEnabledHits(); //NEnabledHits();
545  mse += seg->SumDist2();
546  }
547  if (!nhits)
548  return 0.0;
549  else
550  return mse / nhits;
551 }
size_t NPrecalcEnabledHits(void) const
Definition: PmaElement3D.h:78
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:77
size_t pma::Element3D::NEnabledHits ( unsigned int  view = geo::kUnknown) const
inherited

Definition at line 34 of file PmaElement3D.cxx.

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

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

35 {
36  size_t n = 0;
37  for (size_t i = 0; i < fAssignedHits.size(); i++)
38  if (fAssignedHits[i]->IsEnabled() &&
39  ((view == geo::kUnknown) || (view == fAssignedHits[i]->View2D())))
40  n++;
41  return n;
42 }
Unknown view.
Definition: geo_types.h:142
std::vector< pma::Hit3D * > fAssignedHits
Definition: PmaElement3D.h:122
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 99 of file PmaElement3D.h.

References pma::Element3D::fNHits.

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

Definition at line 81 of file PmaElement3D.h.

References pma::Element3D::fAssignedPoints.

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

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

Definition at line 78 of file PmaElement3D.h.

References pma::Element3D::fNThisHitsEnabledAll.

Referenced by Mse().

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

Definition at line 100 of file PmaElement3D.h.

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

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

Definition at line 112 of file PmaElement3D.h.

References pma::Element3D::fOptFactors.

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

112 { return fOptFactors[view]; }
static float fOptFactors[3]
Definition: PmaElement3D.h:130
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 816 of file PmaNode3D.cxx.

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

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

817 {
818  if (!fFrozen) {
819  double dg = StepWithGradient(0.1F, 0.002F, penaltyValue, endSegWeight);
820  if (dg > 0.01) dg = StepWithGradient(0.03F, 0.0001F, penaltyValue, endSegWeight);
821  if (dg > 0.0) dg = StepWithGradient(0.03F, 0.0001F, penaltyValue, endSegWeight);
822  }
823 }
double StepWithGradient(float alfa, float tol, float penalty, float weight)
Definition: PmaNode3D.cxx:641
double pma::Node3D::Penalty ( float  endSegWeight) const
private

Definition at line 512 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().

513 {
514  unsigned int nseg = 1;
515  double penalty = Pi(endSegWeight, true);
516 
517  pma::Node3D* v;
518  for (unsigned int i = 0; i < NextCount(); i++) {
519  v = static_cast<pma::Node3D*>(Next(i)->Next());
520  penalty += v->Pi(endSegWeight, false);
521  nseg++;
522  }
523  if (prev) {
524  v = static_cast<pma::Node3D*>(prev->Prev());
525  penalty += v->Pi(endSegWeight, false);
526  nseg++;
527  }
528  return penalty / nseg;
529 }
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
virtual unsigned int NextCount(void) const
Definition: SortedObjects.h:84
virtual pma::SortedObjectBase * Next(unsigned int=0) const
Definition: SortedObjects.h:43
virtual pma::SortedObjectBase * Next(unsigned int index=0) const
Definition: SortedObjects.h:77
virtual pma::SortedObjectBase * Prev(void) const
Definition: SortedObjects.h:42
double Pi(float endSegWeight, bool doAsymm) const
Definition: PmaNode3D.cxx:456
double pma::Node3D::PenaltyInWirePlane ( ) const
private

Definition at line 395 of file PmaNode3D.cxx.

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

Referenced by GetObjFunction().

396 {
397  if (fIsVertex) return 0.0;
398 
399  unsigned int nseg = 1;
400  double penalty = PiInWirePlane();
401  pma::Node3D* v;
402  if (next) {
403  v = static_cast<pma::Node3D*>(next->Next());
404  penalty += v->PiInWirePlane();
405  nseg++;
406  }
407  if (prev) {
408  v = static_cast<pma::Node3D*>(prev->Prev());
409  penalty += v->PiInWirePlane();
410  nseg++;
411  }
412  if (penalty > 0.0)
413  return pow(EndPtCos2Transverse(), 10) * penalty / nseg;
414  else
415  return 0.0;
416 }
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
virtual pma::SortedObjectBase * Next(unsigned int=0) const
Definition: SortedObjects.h:43
double PiInWirePlane() const
Definition: PmaNode3D.cxx:374
double EndPtCos2Transverse() const
Definition: PmaNode3D.cxx:357
pma::SortedObjectBase * next
Definition: SortedObjects.h:53
virtual pma::SortedObjectBase * Prev(void) const
Definition: SortedObjects.h:42
bool fIsVertex
Definition: PmaNode3D.h:158
double pma::Node3D::Pi ( float  endSegWeight,
bool  doAsymm 
) const
private

Definition at line 456 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().

457 {
458  if (fIsVertex) return 0.0;
459 
460  if (prev && NextCount()) {
461  pma::Segment3D* segPrev = static_cast<pma::Segment3D*>(prev);
462  pma::Segment3D* segNext = static_cast<pma::Segment3D*>(Next(0));
463 
464  double scale = 1.0;
465  if ((segPrev->TPC() < 0) || (segNext->TPC() < 0))
466  scale = 0.5; // lower penalty on segments between tpc's
467 
468  double segCos = SegmentCos();
469 
470  double lAsymmFactor = 0.0;
471  if (doAsymm) {
472  double lPrev = segPrev->Length();
473  double lNext = segNext->Length();
474  double lSum = lPrev + lNext;
475  if (lSum > 0.1) {
476  double lAsymm = (1.0 - segCos) * (lPrev - lNext) / lSum;
477  lAsymmFactor = 0.05 * lAsymm * lAsymm;
478  }
479  }
480 
481  if (fHitsRadius > 0.0F)
482  return scale * (1.0 + segCos + lAsymmFactor) * fHitsRadius * fHitsRadius;
483  else
484  return scale * (1.0 + segCos + lAsymmFactor) * Length2();
485  }
486  else {
487  double pi_result = 0.0;
488  unsigned int nSeg = 0;
489  pma::Segment3D* seg = 0;
490  if (prev) {
491  seg = static_cast<pma::Segment3D*>(prev);
492 
493  SortedObjectBase* prevVtx = seg->Prev();
494  if (prevVtx->Prev()) nSeg++;
495  nSeg += prevVtx->NextCount();
496  }
497  else if (next) {
498  seg = static_cast<pma::Segment3D*>(next);
499 
500  SortedObjectBase* nextVtx = seg->Next();
501  nSeg += nextVtx->NextCount() + 1;
502  }
503  else {
504  mf::LogWarning("pma::Node3D") << "pma::Node3D::Pi(): an isolated vertex?";
505  return 0.0;
506  }
507  if (nSeg == 1) pi_result = endSegWeight * seg->Length2();
508  return pi_result;
509  }
510 }
double Length2() const override
Definition: PmaNode3D.cxx:288
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
virtual unsigned int NextCount(void) const
Definition: SortedObjects.h:84
virtual pma::SortedObjectBase * Next(unsigned int=0) const
Definition: SortedObjects.h:43
double Length2(void) const override
int TPC(void) const
TPC index or -1 if out of any TPC.
Definition: PmaElement3D.h:35
Double_t scale
Definition: plot.C:24
virtual unsigned int NextCount(void) const
Definition: SortedObjects.h:44
double SegmentCos() const
Cosine of 3D angle between connected segments.
Definition: PmaNode3D.cxx:300
virtual pma::SortedObjectBase * Next(unsigned int index=0) const
Definition: SortedObjects.h:77
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
double fHitsRadius
Definition: PmaElement3D.h:128
pma::SortedObjectBase * next
Definition: SortedObjects.h:53
virtual pma::SortedObjectBase * Prev(void) const
Definition: SortedObjects.h:42
bool fIsVertex
Definition: PmaNode3D.h:158
double Length(void) const
Definition: PmaElement3D.h:53
double pma::Node3D::PiInWirePlane ( ) const
private

Definition at line 374 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().

375 {
376  if (prev && NextCount()) {
377  pma::Segment3D* seg0 = dynamic_cast<pma::Segment3D*>(prev);
378  pma::Segment3D* seg1 = dynamic_cast<pma::Segment3D*>(Next(0));
379  unsigned int nInd1 = NHits(geo::kU) + seg0->NHits(geo::kU) + seg1->NHits(geo::kU);
380 
381  if (fHitsRadius > 0.0F)
382  return (1.0 + SegmentCosWirePlane()) * fHitsRadius * fHitsRadius / (4 * nInd1 + 1.0);
383  else
384  return (1.0 + SegmentCosWirePlane()) * Length2() / (4 * nInd1 + 1.0);
385  }
386  else
387  return 0.0;
388 }
double Length2() const override
Definition: PmaNode3D.cxx:288
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
virtual unsigned int NextCount(void) const
Definition: SortedObjects.h:84
double SegmentCosWirePlane() const
Definition: PmaNode3D.cxx:320
Planes which measure U.
Definition: geo_types.h:135
virtual pma::SortedObjectBase * Next(unsigned int index=0) const
Definition: SortedObjects.h:77
double fHitsRadius
Definition: PmaElement3D.h:128
size_t NHits(void) const
Definition: PmaElement3D.h:76
TVector2 const& pma::Node3D::Projection2D ( unsigned int  view) const
inline
TVector3 const& pma::Element3D::ReferencePoint ( size_t  index) const
inlineinherited

Definition at line 80 of file PmaElement3D.h.

References pma::Element3D::fAssignedPoints.

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

Definition at line 66 of file PmaElement3D.h.

References pma::Element3D::fAssignedHits.

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

67  {
68  if (index < fAssignedHits.size()) fAssignedHits.erase(fAssignedHits.begin() + index);
69  }
std::vector< pma::Hit3D * > fAssignedHits
Definition: PmaElement3D.h:122
int pma::SortedBranchBase::RemoveNext ( pma::SortedObjectBase nextElement)
virtualinherited

Reimplemented from pma::SortedObjectBase.

Definition at line 102 of file SortedObjects.cxx.

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

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

103 {
104  if (!nextElement || (nextElement == this)) return -1;
105 
106  int index = -1;
107  for (unsigned int i = 0; i < next_vector.size(); i++) {
108  if (next_vector[i] == nextElement) {
109  index = i;
110  break;
111  }
112  }
113  if (index >= 0) {
114  if (next_vector[index]->prev != this) {
115  mf::LogError("pma::SortedBranchBase") << "Object structure is broken.";
116  return -1;
117  }
118  next_vector[index]->prev = 0;
119  next_vector.erase(next_vector.begin() + index);
120 
121  if (next_vector.size() > 0)
122  next = next_vector.back();
123  else
124  next = 0;
125  }
126  return index;
127 }
std::vector< pma::SortedObjectBase * > next_vector
Definition: SortedObjects.h:88
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
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 100 of file PmaNode3D.cxx.

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

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

101 {
102  if (((fMinX - margin) <= p3d.X()) && (p3d.X() <= (fMaxX + margin)) &&
103  ((fMinY - margin) <= p3d.Y()) && (p3d.Y() <= (fMaxY + margin)) &&
104  ((fMinZ - margin) <= p3d.Z()) && (p3d.Z() <= (fMaxZ + margin)))
105  return true;
106  else
107  return false;
108 }
double fMinZ
Definition: PmaNode3D.h:149
double fMaxX
Definition: PmaNode3D.h:149
double fMaxY
Definition: PmaNode3D.h:149
double fMaxZ
Definition: PmaNode3D.h:149
double fMinY
Definition: PmaNode3D.h:149
double fMinX
Definition: PmaNode3D.h:149
bool pma::Node3D::SameTPC ( const pma::Vector3D p3d,
float  margin = 0.0F 
) const

Definition at line 110 of file PmaNode3D.cxx.

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

111 {
112  if (((fMinX - margin) <= p3d.X()) && (p3d.X() <= (fMaxX + margin)) &&
113  ((fMinY - margin) <= p3d.Y()) && (p3d.Y() <= (fMaxY + margin)) &&
114  ((fMinZ - margin) <= p3d.Z()) && (p3d.Z() <= (fMaxZ + margin)))
115  return true;
116  else
117  return false;
118 }
double fMinZ
Definition: PmaNode3D.h:149
double fMaxX
Definition: PmaNode3D.h:149
double fMaxY
Definition: PmaNode3D.h:149
double fMaxZ
Definition: PmaNode3D.h:149
double fMinY
Definition: PmaNode3D.h:149
double fMinX
Definition: PmaNode3D.h:149
double pma::Node3D::SegmentCos ( ) const

Cosine of 3D angle between connected segments.

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 Pi().

301 {
302  if (prev && next) {
303  auto const& vStop1 = static_cast<pma::Node3D*>(prev->Prev())->fPoint3D;
304  auto const& vStop2 = static_cast<pma::Node3D*>(next->Next())->fPoint3D;
305  pma::Vector3D v1(
306  vStop1.X() - fPoint3D.X(), vStop1.Y() - fPoint3D.Y(), vStop1.Z() - fPoint3D.Z());
307  pma::Vector3D v2(
308  vStop2.X() - fPoint3D.X(), vStop2.Y() - fPoint3D.Y(), vStop2.Z() - fPoint3D.Z());
309  double mag = sqrt(v1.Mag2() * v2.Mag2());
310  double cosine = 0.0;
311  if (mag != 0.0) cosine = v1.Dot(v2) / mag;
312  return cosine;
313  }
314  else {
315  mf::LogError("pma::Node3D") << "pma::Node3D::SegmentCos(): neighbours not initialized.";
316  return -1.0;
317  }
318 }
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
virtual pma::SortedObjectBase * Next(unsigned int=0) const
Definition: SortedObjects.h:43
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
recob::tracking::Vector_t Vector3D
Definition: Utilities.h:34
pma::SortedObjectBase * next
Definition: SortedObjects.h:53
TVector3 fPoint3D
Definition: PmaNode3D.h:152
virtual pma::SortedObjectBase * Prev(void) const
Definition: SortedObjects.h:42
double pma::Node3D::SegmentCosTransverse ( ) 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 338 of file PmaNode3D.cxx.

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

339 {
340  if (prev && next) {
341  auto const& vStop1 = static_cast<pma::Node3D*>(prev->Prev())->fPoint3D;
342  auto const& vStop2 = static_cast<pma::Node3D*>(next->Next())->fPoint3D;
343  pma::Vector2D v1(vStop1.X() - fPoint3D.X(), vStop1.Z() - fPoint3D.Z());
344  pma::Vector2D v2(vStop2.X() - fPoint3D.X(), vStop2.Z() - fPoint3D.Z());
345  double mag = sqrt(v1.Mag2() * v2.Mag2());
346  double cosine = 0.0;
347  if (mag != 0.0) cosine = v1.Dot(v2) / mag;
348  return cosine;
349  }
350  else {
351  mf::LogError("pma::Node3D") << "pma::Node3D::SegmentCosZY(): neighbours not initialized.";
352  return -1.0;
353  }
354 }
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
virtual pma::SortedObjectBase * Next(unsigned int=0) const
Definition: SortedObjects.h:43
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
ROOT::Math::DisplacementVector2D< ROOT::Math::Cartesian2D< double > > Vector2D
Definition: Utilities.h:33
pma::SortedObjectBase * next
Definition: SortedObjects.h:53
TVector3 fPoint3D
Definition: PmaNode3D.h:152
virtual pma::SortedObjectBase * Prev(void) const
Definition: SortedObjects.h:42
double pma::Node3D::SegmentCosWirePlane ( ) 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 320 of file PmaNode3D.cxx.

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

Referenced by PiInWirePlane().

321 {
322  if (prev && next) {
323  auto const& vStop1 = static_cast<pma::Node3D*>(prev->Prev())->fPoint3D;
324  auto const& vStop2 = static_cast<pma::Node3D*>(next->Next())->fPoint3D;
325  pma::Vector2D v1(vStop1.Y() - fPoint3D.Y(), vStop1.Z() - fPoint3D.Z());
326  pma::Vector2D v2(vStop2.Y() - fPoint3D.Y(), vStop2.Z() - fPoint3D.Z());
327  double mag = sqrt(v1.Mag2() * v2.Mag2());
328  double cosine = 0.0;
329  if (mag != 0.0) cosine = v1.Dot(v2) / mag;
330  return cosine;
331  }
332  else {
333  mf::LogError("pma::Node3D") << "pma::Node3D::SegmentCosZX(): neighbours not initialized.";
334  return -1.0;
335  }
336 }
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
virtual pma::SortedObjectBase * Next(unsigned int=0) const
Definition: SortedObjects.h:43
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
ROOT::Math::DisplacementVector2D< ROOT::Math::Cartesian2D< double > > Vector2D
Definition: Utilities.h:33
pma::SortedObjectBase * next
Definition: SortedObjects.h:53
TVector3 fPoint3D
Definition: PmaNode3D.h:152
virtual pma::SortedObjectBase * Prev(void) const
Definition: SortedObjects.h:42
bool pma::Element3D::SelectAllHits ( void  )
inherited

Definition at line 284 of file PmaElement3D.cxx.

References pma::Element3D::fAssignedHits.

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

285 {
286  bool changed = false;
287  for (auto h : fAssignedHits) {
288  changed |= !(h->IsEnabled());
289  h->SetEnabled(true);
290  }
291  return changed;
292 }
std::vector< pma::Hit3D * > fAssignedHits
Definition: PmaElement3D.h:122
bool pma::Element3D::SelectRndHits ( size_t  nmax_per_view)
inherited

Definition at line 236 of file PmaElement3D.cxx.

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

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

237 {
238  if (!nmax_per_view) { return SelectAllHits(); }
239 
240  size_t nhits[3];
241  for (size_t i = 0; i < 3; ++i)
242  nhits[i] = NHits(i);
243 
244  int m[3], count[3];
245  bool state[3];
246  for (size_t i = 0; i < 3; ++i) {
247  if (nhits[i] >= 2 * nmax_per_view) {
248  m[i] = nhits[i] / nmax_per_view;
249  state[i] = true;
250  }
251  else if (nhits[i] > nmax_per_view) {
252  m[i] = nhits[i] / (nhits[i] - nmax_per_view);
253  state[i] = false;
254  }
255  else {
256  m[i] = 0;
257  state[i] = false;
258  }
259 
260  count[i] = 0;
261  }
262 
263  bool b, changed = false;
264  for (auto h : fAssignedHits) {
265  b = h->IsEnabled();
266 
267  size_t view = h->View2D();
268  if (m[view]) {
269  if (count[view] % m[view] == 0)
270  h->SetEnabled(state[view]);
271  else
272  h->SetEnabled(!(state[view]));
273 
274  ++count[view];
275  }
276  else
277  h->SetEnabled(true);
278 
279  changed |= (b != h->IsEnabled());
280  }
281  return changed;
282 }
std::vector< pma::Hit3D * > fAssignedHits
Definition: PmaElement3D.h:122
bool SelectAllHits(void)
size_t NHits(void) const
Definition: PmaElement3D.h:76
void pma::Element3D::SetFrozen ( bool  state)
inlineinherited

Fix / relese vertex 3D position.

Definition at line 107 of file PmaElement3D.h.

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

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

Set allowed node position margin around TPC.

Definition at line 124 of file PmaNode3D.h.

References weight.

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

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

Definition at line 113 of file PmaElement3D.h.

References pma::Element3D::Element3D(), pma::Element3D::fOptFactors, and value.

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

113 { fOptFactors[view] = value; }
static float fOptFactors[3]
Definition: PmaElement3D.h:130
double value
Definition: spectrum.C:18
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 162 of file PmaNode3D.cxx.

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

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

163 {
164  fPoint3D = p3d;
165 
166  bool accepted = !LimitPoint3D();
167  UpdateProj2D();
168 
169  return accepted;
170 }
bool LimitPoint3D()
Returns true if node position was trimmed to its TPC volume + fMargin.
Definition: PmaNode3D.cxx:120
void UpdateProj2D()
Definition: PmaNode3D.cxx:154
TVector3 fPoint3D
Definition: PmaNode3D.h:152
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 214 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().

215 {
216  TVector2 gstart;
217  TVector3 g3d;
218  if (prev) {
219  pma::Node3D* vtx = static_cast<pma::Node3D*>(prev->Prev());
220  gstart = vtx->Projection2D(h.View2D());
221  if (!next) g3d = vtx->Point3D();
222  }
223  else if (next) {
224  pma::Node3D* vtx = static_cast<pma::Node3D*>(next->Next());
225  gstart = Projection2D(h.View2D());
226  gstart -= vtx->Projection2D(h.View2D()) - Projection2D(h.View2D());
227  if (!prev) {
228  g3d = fPoint3D;
229  g3d -= vtx->Point3D() - fPoint3D;
230  }
231  }
232  else {
233  mf::LogError("pma::Node3D") << "Isolated vertex.";
234  TVector2 p(Projection2D(h.View2D()));
235  h.SetProjection(p, 0.0F);
236  h.SetPoint3D(fPoint3D);
237  return;
238  }
239 
240  TVector2 v0(h.Point2D());
241  v0 -= Projection2D(h.View2D());
242 
243  TVector2 v1(gstart);
244  v1 -= Projection2D(h.View2D());
245 
246  double v0Norm = v0.Mod();
247  double v1Norm = v1.Mod();
248  double mag = v0Norm * v1Norm;
249  double cosine = 0.0;
250  if (mag != 0.0) cosine = v0 * v1 / mag;
251 
252  TVector2 p(Projection2D(h.View2D()));
253 
254  if (prev && next) {
255  pma::Node3D* vNext = static_cast<pma::Node3D*>(next->Next());
256  TVector2 vN(vNext->Projection2D(h.View2D()));
257  vN -= Projection2D(h.View2D());
258 
259  mag = v0Norm * vN.Mod();
260  double cosineN = 0.0;
261  if (mag != 0.0) cosineN = v0 * vN / mag;
262 
263  // hit on the previous segment side, sorting on the -cosine(prev_seg, point) /max.val. = 1/
264  if (cosineN <= cosine) h.SetProjection(p, -(float)cosine);
265  // hit on the next segment side, sorting on the 1+cosine(next_seg, point) /min.val. = 1/
266  else
267  h.SetProjection(p, 2.0F + (float)cosineN);
268 
269  h.SetPoint3D(fPoint3D);
270  }
271  else {
272  float b = (float)(v0Norm * cosine / v1Norm);
273  if (fFrozen) // limit 3D positions to outermose node if frozen
274  {
275  h.SetPoint3D(fPoint3D);
276  }
277  else // or set 3D positions along the line of outermost segment
278  {
279  g3d -= fPoint3D;
280  h.SetPoint3D(fPoint3D + (g3d * b));
281 
282  p += (v1 * b);
283  }
284  h.SetProjection(p, -b);
285  }
286 }
TVector3 const & Point3D() const
Definition: PmaNode3D.h:44
TVector2 const & Projection2D(unsigned int view) const
Definition: PmaNode3D.h:50
TVector2 const & Point2D() const noexcept
Definition: PmaHit3D.h:55
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
virtual pma::SortedObjectBase * Next(unsigned int=0) const
Definition: SortedObjects.h:43
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
void SetProjection(const TVector2 &p, float b)
Definition: PmaHit3D.h:75
unsigned int View2D() const noexcept
Definition: PmaHit3D.h:60
void SetPoint3D(const TVector3 &p3d)
Definition: PmaHit3D.h:52
pma::SortedObjectBase * next
Definition: SortedObjects.h:53
TVector3 fPoint3D
Definition: PmaNode3D.h:152
virtual pma::SortedObjectBase * Prev(void) const
Definition: SortedObjects.h:42
void pma::Node3D::SetVertex ( bool  state)
inline

Definition at line 66 of file PmaNode3D.h.

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

Definition at line 67 of file PmaNode3D.h.

68  {
69  if (setAllNodes || !fIsVertex) fIsVertex = IsBranching();
70  }
bool IsBranching() const
Belongs to more than one track?
Definition: PmaNode3D.cxx:418
bool fIsVertex
Definition: PmaNode3D.h:158
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:122
double pma::Node3D::StepWithGradient ( float  alfa,
float  tol,
float  penalty,
float  weight 
)
private

Definition at line 641 of file PmaNode3D.cxx.

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

Referenced by Optimize().

642 {
643  unsigned int steps = 0;
644  double t, t1, t2, t3, g, g0, g1, g2, g3, p1, p2;
645  double eps = 6.0E-37, zero_tol = 1.0E-15;
646  TVector3 tmp(fPoint3D), gpoint(fPoint3D);
647 
648  g = MakeGradient(penalty, weight);
649  if (g < zero_tol) return 0.0;
650  g0 = g;
651 
652  //**** first three points ****//
653  alfa *= 0.8F;
654  t2 = 0.0;
655  g2 = g;
656  t3 = 0.0;
657  g3 = g;
658  do {
659  t1 = t2;
660  g1 = g2;
661  t2 = t3;
662  g2 = g3;
663 
664  alfa *= 1.25F;
665  t3 += alfa;
666  gpoint = tmp;
667  gpoint += (fGradient * t3);
668  if (!SetPoint3D(gpoint)) // stepped out of allowed volume
669  {
670  //std::cout << "**** SetPoint trimmed 1 ****" << std::endl;
671  g3 = GetObjFunction(penalty, weight);
672  if (g3 < g2)
673  return (g0 - g3) / g3; // exit with the node at the border
674  else {
675  SetPoint3D(tmp);
676  return 0.0;
677  } // exit with restored original position
678  }
679 
680  g3 = GetObjFunction(penalty, weight);
681 
682  if (g3 < zero_tol) return 0.0;
683 
684  if (++steps > 1000) {
685  SetPoint3D(tmp);
686  return 0.0;
687  }
688 
689  } while (g3 < g2);
690  //****************************//
691 
692  //*** first step overshoot ***//
693  if (steps == 1) {
694  t2 = t3;
695  g2 = g3;
696  do {
697  t3 = t2;
698  g3 = g2;
699  t2 = (t1 * g3 + t3 * g1) / (g1 + g3);
700 
701  // small shift...
702  t2 = 0.05 * t3 + 0.95 * t2;
703 
704  // break: starting point is at the minimum
705  //if (t2 == t1) { SetPoint3D(tmp); return 0.0F; }
706 
707  // break: starting point is very close to the minimum
708  if (fabs(t2 - t1) < tol) {
709  SetPoint3D(tmp);
710  return 0.0;
711  }
712 
713  gpoint = tmp;
714  gpoint += (fGradient * t2);
715  if (!SetPoint3D(gpoint)) // select the best point to exit
716  {
717  //std::cout << "**** SetPoint trimmed 2 ****" << std::endl;
718  g2 = GetObjFunction(penalty, weight);
719  if (g2 < g0)
720  return (g0 - g2) / g2; // exit with the node at the border
721  else if (g1 < g0) {
722  gpoint = tmp;
723  gpoint += (fGradient * t1);
724  return (g0 - g1) / g1;
725  }
726  else if (g3 < g0) {
727  gpoint = tmp;
728  gpoint += (fGradient * t3);
729  return (g0 - g3) / g3;
730  }
731  else {
732  SetPoint3D(tmp);
733  return 0.0;
734  }
735  }
736  g2 = GetObjFunction(penalty, weight);
737 
738  if (g2 < zero_tol) return 0.0;
739  steps++;
740 
741  } while (g2 >= g1);
742  }
743  //****************************//
744 
745  while (fabs(t1 - t3) > tol) {
746  //*** 3-point minimization ***//
747  if ((fabs(t2 - t1) < eps) || (fabs(t2 - t3) < eps)) break; // minimum on the edge
748  if ((fabs(g2 - g1) < eps) && (fabs(g2 - g3) < eps)) break; // ~singularity
749 
750  p1 = (t2 - t1) * (g2 - g3);
751  p2 = (t2 - t3) * (g2 - g1);
752  if (fabs(p1 - p2) < eps) break; // ~linearity
753 
754  t = t2 + ((t2 - t1) * p1 - (t2 - t3) * p2) / (2 * (p2 - p1));
755  if ((t <= t1) || (t >= t3)) t = (t1 * g3 + t3 * g1) / (g1 + g3);
756 
757  gpoint = tmp;
758  gpoint += (fGradient * t);
759  if (!SetPoint3D(gpoint)) // select the best point to exit
760  {
761  //std::cout << "**** SetPoint trimmed 3 ****" << std::endl;
762  g = GetObjFunction(penalty, weight);
763  if ((g < g0) && (g < g1) && (g < g3))
764  return (g0 - g) / g; // exit with the node at the border
765  else if ((g1 < g0) && (g1 < g3)) {
766  gpoint = tmp;
767  gpoint += (fGradient * t1);
768  return (g0 - g1) / g1;
769  }
770  else if (g3 < g0) {
771  gpoint = tmp;
772  gpoint += (fGradient * t3);
773  return (g0 - g3) / g3;
774  }
775  else {
776  SetPoint3D(tmp);
777  return 0.0;
778  }
779  }
780 
781  g = GetObjFunction(penalty, weight);
782  if (g < zero_tol) return 0.0;
783  steps++;
784  //****************************//
785 
786  //*** select next 3 points ***//
787  if (fabs(t - t2) < 0.2 * tol) break; // start in a new direction
788  if (g < g2) {
789  if (t < t2) {
790  t3 = t2;
791  g3 = g2;
792  }
793  else {
794  t1 = t2;
795  g1 = g2;
796  }
797  t2 = t;
798  g2 = g;
799  }
800  else {
801  if (t < t2) {
802  t1 = t;
803  g1 = g;
804  }
805  else {
806  t3 = t;
807  g3 = g;
808  }
809  }
810  //****************************//
811  }
812 
813  return (g0 - g) / g;
814 }
TTree * t1
Definition: plottest35.C:26
Float_t tmp
Definition: plot.C:35
bool SetPoint3D(const TVector3 &p3d)
Definition: PmaNode3D.cxx:162
TTree * t2
Definition: plottest35.C:36
double MakeGradient(float penaltyValue, float endSegWeight)
Definition: PmaNode3D.cxx:558
double weight
Definition: plottest35.C:25
double GetObjFunction(float penaltyValue, float endSegWeight) const
Objective function minimized during oprimization.
Definition: PmaNode3D.cxx:553
TVector3 fPoint3D
Definition: PmaNode3D.h:152
TVector3 fGradient
Definition: PmaNode3D.h:157
double pma::Element3D::SumDist2 ( void  ) const
inherited

Definition at line 164 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().

165 {
166  if (fTPC < 0) {
167  if (!fAssignedHits.empty())
168  mf::LogWarning("pma::Element3D") << "Hits assigned to TPC-crossing element.";
169  return 0.0F;
170  }
171 
172  double hit_sum = SumDist2Hits();
173 
174  if (fAssignedPoints.size()) {
175  double d, ref_sum = 0.0F;
176  for (auto p : fAssignedPoints) {
177  d = sqrt(GetDistance2To(*p)) - 0.5; // guide by ref points up to ~ 3D resolution
178  if (d > 0.0) ref_sum += d * d;
179  }
180  if (fAssignedHits.size()) { ref_sum *= 0.2 * fAssignedHits.size() / fAssignedPoints.size(); }
181  hit_sum += ref_sum;
182  }
183 
184  return hit_sum;
185 }
std::vector< TVector3 * > fAssignedPoints
Definition: PmaElement3D.h:123
Float_t d
Definition: plot.C:235
std::vector< pma::Hit3D * > fAssignedHits
Definition: PmaElement3D.h:122
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 187 of file PmaElement3D.cxx.

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

188 {
189  if (fTPC < 0) {
190  if (!fAssignedHits.empty())
191  mf::LogWarning("pma::Element3D") << "Hits assigned to TPC-crossing element.";
192  return 0.0F;
193  }
194 
195  double hit_sum = 0.0F;
196  for (auto h : fAssignedHits) {
197  if (h->IsEnabled()) {
198  unsigned int hitView = h->View2D();
199  if ((view == geo::kUnknown) || (view == hitView)) {
200  hit_sum += OptFactor(hitView) * // alpha_i
201  h->GetSigmaFactor() * // hit_amp / hit_max_amp
202  GetDistance2To(h->Point2D(), hitView); // hit_to_fit_dist^2
203  }
204  }
205  }
206  return hit_sum;
207 }
Unknown view.
Definition: geo_types.h:142
std::vector< pma::Hit3D * > fAssignedHits
Definition: PmaElement3D.h:122
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:112
double pma::Node3D::SumDist2Hits ( void  ) const
overrideprivatevirtual

Implements pma::Element3D.

Definition at line 182 of file PmaNode3D.cxx.

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

183 {
184  double sum = 0.0F;
185  for (auto h : fAssignedHits) {
186  if (h->IsEnabled()) {
187  unsigned int view = h->View2D();
188 
189  sum += OptFactor(view) * // alpha_i
190  h->GetSigmaFactor() * // hit_amp / hit_max_amp
191  pma::Dist2(h->Point2D(), fProj2D[view]);
192  }
193  }
194  return sum;
195 }
double Dist2(const TVector2 &v1, const TVector2 &v2)
Definition: Utilities.cxx:39
TVector2 fProj2D[3]
Definition: PmaNode3D.h:153
std::vector< pma::Hit3D * > fAssignedHits
Definition: PmaElement3D.h:122
Double_t sum
Definition: plot.C:31
static float OptFactor(unsigned int view)
Definition: PmaElement3D.h:112
double pma::Element3D::SumHitsQ ( unsigned int  view) const
inlineinherited

Definition at line 98 of file PmaElement3D.h.

References pma::Element3D::fSumHitsQ.

98 { return fSumHitsQ[view]; }
double fSumHitsQ[3]
Definition: PmaElement3D.h:127
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(), pma::SortedObjectBase::Prev(), and r.

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

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

Definition at line 154 of file PmaNode3D.cxx.

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

Referenced by SetPoint3D().

155 {
156  for (size_t i = 0; i < fTpcGeo.Nplanes(); ++i) {
158  fPoint3D.X() - fDriftOffset);
159  }
160 }
unsigned int Nplanes() const
Number of planes in this tpc.
Definition: TPCGeo.h:137
double fDriftOffset
Definition: PmaNode3D.h:155
::geo::Point_t toPoint(Point const &p)
Convert the specified point into a geo::Point_t.
TVector2 fProj2D[3]
Definition: PmaNode3D.h:153
geo::TPCGeo const & fTpcGeo
Definition: PmaNode3D.h:147
TVector3 fPoint3D
Definition: PmaNode3D.h:152
PlaneGeo const & Plane(geo::View_t view) const
Return the plane in the tpc with View_t view.
Definition: TPCGeo.cxx:252
double PlaneCoordinate(geo::Point_t const &point) const
Returns the coordinate of the point on the plane.
Definition: PlaneGeo.h:777
void pma::Element3D::UpdateProjection ( void  )
inlineinherited

Definition at line 89 of file PmaElement3D.h.

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

90  {
91  for (auto h : fAssignedHits)
92  SetProjection(*h);
93  }
virtual void SetProjection(pma::Hit3D &h) const =0
std::vector< pma::Hit3D * > fAssignedHits
Definition: PmaElement3D.h:122

Member Data Documentation

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

Definition at line 117 of file PmaElement3D.h.

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

double pma::Node3D::fDriftOffset
private

Definition at line 155 of file PmaNode3D.h.

Referenced by UpdateProj2D().

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

Definition at line 160 of file PmaNode3D.h.

Referenced by MakeGradient().

TVector3 pma::Node3D::fGradient
private

Definition at line 157 of file PmaNode3D.h.

Referenced by MakeGradient(), and StepWithGradient().

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

Definition at line 158 of file PmaNode3D.h.

Referenced by PenaltyInWirePlane(), and Pi().

double pma::Node3D::fMargin = 3.0
staticprivate

Definition at line 161 of file PmaNode3D.h.

Referenced by LimitPoint3D().

double pma::Node3D::fMaxX
private

Definition at line 149 of file PmaNode3D.h.

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

double pma::Node3D::fMaxY
private

Definition at line 149 of file PmaNode3D.h.

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

double pma::Node3D::fMaxZ
private

Definition at line 149 of file PmaNode3D.h.

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

double pma::Node3D::fMinX
private

Definition at line 149 of file PmaNode3D.h.

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

double pma::Node3D::fMinY
private

Definition at line 149 of file PmaNode3D.h.

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

double pma::Node3D::fMinZ
private

Definition at line 149 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 130 of file PmaElement3D.h.

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

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

Definition at line 153 of file PmaNode3D.h.

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

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

Definition at line 147 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: