LArSoft  v10_04_05
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
 
geo::WireReadoutGeom const & fChannelMap
 
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 31 of file PmaNode3D.h.

Constructor & Destructor Documentation

pma::Node3D::Node3D ( )

Definition at line 29 of file PmaNode3D.cxx.

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

32  , fMinX(0)
33  , fMaxX(0)
34  , fMinY(0)
35  , fMaxY(0)
36  , fMinZ(0)
37  , fMaxZ(0)
38  , fPoint3D(0, 0, 0)
39  , fDriftOffset(0)
40  , fIsVertex(false)
41 {
42  fTPC = 0;
43  fCryo = 0;
44 
45  fProj2D[0].Set(0);
46  fProj2D[1].Set(0);
47  fProj2D[2].Set(0);
48 }
double fMinZ
Definition: PmaNode3D.h:147
double fDriftOffset
Definition: PmaNode3D.h:153
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
Definition: AddMC.C:8
int TPC(void) const
TPC index or -1 if out of any TPC.
Definition: PmaElement3D.h:35
TVector2 fProj2D[3]
Definition: PmaNode3D.h:151
double fMaxX
Definition: PmaNode3D.h:147
double fMaxY
Definition: PmaNode3D.h:147
double fMaxZ
Definition: PmaNode3D.h:147
double fMinY
Definition: PmaNode3D.h:147
geo::WireReadoutGeom const & fChannelMap
Definition: PmaNode3D.h:145
geo::TPCGeo const & fTpcGeo
Definition: PmaNode3D.h:144
TVector3 fPoint3D
Definition: PmaNode3D.h:150
bool fIsVertex
Definition: PmaNode3D.h:156
double fMinX
Definition: PmaNode3D.h:147
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 50 of file PmaNode3D.cxx.

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

58  , fDriftOffset(xshift)
59  , fIsVertex(vtx)
60 {
61  fTPC = tpc;
62  fCryo = cryo;
63 
64  unsigned int lastPlane = geo::kZ;
65  while ((lastPlane > 0) && !fChannelMap.HasPlane(geo::PlaneID{fTpcGeo.ID(), lastPlane}))
66  lastPlane--;
67 
68  fMinX = detProp.ConvertTicksToX(0, lastPlane, tpc, cryo);
69  fMaxX = detProp.ConvertTicksToX(detProp.NumberTimeSamples() - 1, lastPlane, tpc, cryo);
70  if (fMaxX < fMinX) {
71  double tmp = fMaxX;
72  fMaxX = fMinX;
73  fMinX = tmp;
74  }
75 
76  fMinY = fTpcGeo.MinY();
77  fMaxY = fTpcGeo.MaxY();
78  fMinZ = fTpcGeo.MinZ();
79  fMaxZ = fTpcGeo.MaxZ();
80 
81  SetPoint3D(p3d);
82 }
double fMinZ
Definition: PmaNode3D.h:147
double fDriftOffset
Definition: PmaNode3D.h:153
The data type to uniquely identify a Plane.
Definition: geo_types.h:364
Planes which measure Z direction.
Definition: geo_types.h:134
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
Definition: AddMC.C:8
Float_t tmp
Definition: plot.C:35
bool HasPlane(PlaneID const &planeid) const
Returns whether we have the specified plane.
int TPC(void) const
TPC index or -1 if out of any TPC.
Definition: PmaElement3D.h:35
double fMaxX
Definition: PmaNode3D.h:147
bool SetPoint3D(const TVector3 &p3d)
Definition: PmaNode3D.cxx:166
double MinZ() const
Returns the world z coordinate of the start of the box.
double fMaxY
Definition: PmaNode3D.h:147
The data type to uniquely identify a TPC.
Definition: geo_types.h:306
double fMaxZ
Definition: PmaNode3D.h:147
double MaxY() const
Returns the world y coordinate of the end of the box.
double fMinY
Definition: PmaNode3D.h:147
geo::WireReadoutGeom const & fChannelMap
Definition: PmaNode3D.h:145
double MaxZ() const
Returns the world z coordinate of the end of the box.
geo::TPCGeo const & fTpcGeo
Definition: PmaNode3D.h:144
double MinY() const
Returns the world y coordinate of the start of the box.
bool fIsVertex
Definition: PmaNode3D.h:156
double fMinX
Definition: PmaNode3D.h:147

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 113 of file PmaNode3D.h.

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

114  {
115  fPoint3D[0] += dx;
116  fDriftOffset += dx;
117  }
double fDriftOffset
Definition: PmaNode3D.h:153
TVector3 fPoint3D
Definition: PmaNode3D.h:150
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 820 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().

821 {
822  if (!trk) {
823  // like in the base class:
824  fAssignedPoints.clear();
825  fAssignedHits.clear();
826  }
827  else {
828  std::vector<pma::Track3D*> to_check;
829  pma::Segment3D* seg;
830  if (Prev()) {
831  seg = static_cast<pma::Segment3D*>(Prev());
832  if (seg->Parent() != trk) to_check.push_back(seg->Parent());
833  }
834  for (unsigned int i = 0; i < NextCount(); i++) {
835  seg = static_cast<pma::Segment3D*>(Next(i));
836  if (seg->Parent() != trk) to_check.push_back(seg->Parent());
837  }
838 
839  unsigned int p = 0;
840  while (p < fAssignedPoints.size()) {
841  bool found = false;
842  for (size_t t = 0; t < to_check.size(); t++)
843  if (to_check[t]->HasRefPoint(fAssignedPoints[p])) {
844  found = true;
845  break;
846  }
847 
848  if (!found)
849  fAssignedPoints.erase(fAssignedPoints.begin() + p);
850  else
851  p++;
852  }
853 
854  unsigned int h = 0;
855  while (h < fAssignedHits.size()) {
856  bool found = false;
858 
859  for (size_t t = 0; (t < to_check.size()) && !found; t++)
860  for (size_t i = 0; i < to_check[t]->size(); i++) {
861  pma::Hit3D* pmaHit = static_cast<pma::Hit3D*>((*(to_check[t]))[i]);
862  if (hit == pmaHit) {
863  found = true;
864  break;
865  }
866  }
867 
868  if (!found)
869  fAssignedHits.erase(fAssignedHits.begin() + h);
870  else
871  h++;
872  }
873  }
874 
875  fHitsRadius = 0.0F;
876 }
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 361 of file PmaNode3D.cxx.

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

Referenced by PenaltyInWirePlane().

362 {
363  if (prev && next) {
364  auto const& vStart = static_cast<pma::Node3D*>(prev->Prev())->fPoint3D;
365  auto const& vStop = static_cast<pma::Node3D*>(next->Next())->fPoint3D;
366 
367  double dy = vStop.X() - vStart.X();
368  double dz = vStop.Z() - vStart.Z();
369  double len2 = dy * dy + dz * dz;
370  double cosine2 = 0.0;
371  if (len2 > 0.0) cosine2 = dz * dz / len2;
372  return cosine2;
373  }
374  else
375  return 0.0;
376 }
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:150
virtual pma::SortedObjectBase * Prev(void) const
Definition: SortedObjects.h:42
std::vector< pma::Track3D * > pma::Node3D::GetBranches ( ) const

Definition at line 447 of file PmaNode3D.cxx.

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

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

448 {
449  std::vector<pma::Track3D*> branches;
450  if (NextCount()) {
451  branches.reserve(NextCount());
452  for (size_t i = 0; i < NextCount(); ++i) {
453  pma::Segment3D* seg = static_cast<pma::Segment3D*>(Next(i));
454  branches.push_back(seg->Parent());
455  }
456  }
457  return branches;
458 }
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 201 of file PmaNode3D.cxx.

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

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

References pma::Dist2(), and fPoint3D.

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

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

References pma::Dist2(), and fProj2D.

182 {
183  return pma::Dist2(fProj2D[view], p2d);
184 }
double Dist2(const TVector2 &v1, const TVector2 &v2)
Definition: Utilities.cxx:39
TVector2 fProj2D[3]
Definition: PmaNode3D.h:151
double pma::Node3D::GetDistToWall ( ) const

Definition at line 84 of file PmaNode3D.cxx.

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

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

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

Definition at line 118 of file PmaNode3D.h.

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

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

Objective function minimized during oprimization.

Definition at line 557 of file PmaNode3D.cxx.

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

Referenced by MakeGradient(), and StepWithGradient().

558 {
559  return Mse() + penaltyValue * (Penalty(endSegWeight) + PenaltyInWirePlane());
560 }
double Penalty(float endSegWeight) const
Definition: PmaNode3D.cxx:516
double PenaltyInWirePlane() const
Definition: PmaNode3D.cxx:399
double Mse() const
Definition: PmaNode3D.cxx:535
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 83 of file PmaNode3D.h.

83 { return fPoint3D; }
TVector3 fPoint3D
Definition: PmaNode3D.h:150
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 422 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().

423 {
424  size_t nnext = NextCount();
425  if (nnext > 1) return true; // 1 trk -> vtx -> n*trk
426 
427  if (prev && nnext) {
428  pma::Segment3D* segPrev = static_cast<pma::Segment3D*>(prev);
429  pma::Segment3D* segNext = static_cast<pma::Segment3D*>(Next(0));
430  if (segNext->Parent() != segPrev->Parent()) // 1 trk -> vtx -> 1 trk
431  return true;
432  }
433  return false;
434 }
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 436 of file PmaNode3D.cxx.

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

437 {
438  if (prev && (NextCount() == 1)) {
439  pma::Segment3D* segPrev = static_cast<pma::Segment3D*>(prev);
440  pma::Segment3D* segNext = static_cast<pma::Segment3D*>(Next(0));
441 
442  if ((segPrev->TPC() < 0) || (segNext->TPC() < 0)) return true;
443  }
444  return false;
445 }
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 62 of file PmaNode3D.h.

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

62 { return fIsVertex; }
bool fIsVertex
Definition: PmaNode3D.h:156
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 292 of file PmaNode3D.cxx.

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

Referenced by Pi(), and PiInWirePlane().

293 {
294  double l = 0.0;
295  if (next) l += (static_cast<pma::Segment3D*>(next))->Length();
296  if (prev) l += (static_cast<pma::Segment3D*>(prev))->Length();
297 
298  if (next && prev)
299  return 0.25 * l * l;
300  else
301  return l * l;
302 }
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 123 of file PmaNode3D.cxx.

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

Referenced by SetPoint3D().

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

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

563 {
564  double l1 = 0.0, l2 = 0.0, minLength2 = 0.0;
565  TVector3 tmp(fPoint3D), gpoint(fPoint3D);
566 
567  pma::Segment3D* seg;
568  if (prev) {
569  seg = static_cast<pma::Segment3D*>(prev);
570  l1 = seg->Length2();
571  }
572  if (next) {
573  seg = static_cast<pma::Segment3D*>(next);
574  l2 = seg->Length2();
575  }
576  if ((l1 > 0.01) && (l1 < l2))
577  minLength2 = l1;
578  else if ((l2 > 0.01) && (l2 < l1))
579  minLength2 = l2;
580  else
581  minLength2 = 0.01;
582 
583  double dxi = 0.001 * sqrt(minLength2);
584 
585  if (dxi < 6.0E-37) return 0.0;
586 
587  double gi, g0, gz;
588  gz = g0 = GetObjFunction(penaltyValue, endSegWeight);
589 
590  if (!fGradFixed[0]) // gradX
591  {
592  gpoint[0] = tmp[0] + dxi;
593  SetPoint3D(gpoint);
594  gi = GetObjFunction(penaltyValue, endSegWeight);
595  fGradient[0] = (g0 - gi) / dxi;
596 
597  gpoint[0] = tmp[0] - dxi;
598  SetPoint3D(gpoint);
599  gi = GetObjFunction(penaltyValue, endSegWeight);
600  fGradient[0] = 0.5 * (fGradient[0] + (gi - g0) / dxi);
601 
602  gpoint[0] = tmp[0];
603  }
604 
605  if (!fGradFixed[1]) // gradY
606  {
607  gpoint[1] = tmp[1] + dxi;
608  SetPoint3D(gpoint);
609  gi = GetObjFunction(penaltyValue, endSegWeight);
610  fGradient[1] = (g0 - gi) / dxi;
611 
612  gpoint[1] = tmp[1] - dxi;
613  SetPoint3D(gpoint);
614  gi = GetObjFunction(penaltyValue, endSegWeight);
615  fGradient[1] = 0.5 * (fGradient[1] + (gi - g0) / dxi);
616 
617  gpoint[1] = tmp[1];
618  }
619 
620  if (!fGradFixed[2]) // gradZ
621  {
622  gpoint[2] = tmp[2] + dxi;
623  SetPoint3D(gpoint);
624  gi = GetObjFunction(penaltyValue, endSegWeight);
625  fGradient[2] = (gz - gi) / dxi;
626 
627  gpoint[2] = tmp[2] - dxi;
628  SetPoint3D(gpoint);
629  gi = GetObjFunction(penaltyValue, endSegWeight);
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:158
Float_t E
Definition: plot.C:20
bool SetPoint3D(const TVector3 &p3d)
Definition: PmaNode3D.cxx:166
double GetObjFunction(float penaltyValue, float endSegWeight) const
Objective function minimized during oprimization.
Definition: PmaNode3D.cxx:557
pma::SortedObjectBase * next
Definition: SortedObjects.h:53
TVector3 fPoint3D
Definition: PmaNode3D.h:150
TVector3 fGradient
Definition: PmaNode3D.h:155
double pma::Node3D::Mse ( ) const
private

Definition at line 535 of file PmaNode3D.cxx.

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

Referenced by GetObjFunction().

536 {
537  unsigned int nhits = NPrecalcEnabledHits(); //NEnabledHits();
538  double mse = SumDist2();
539 
540  pma::Segment3D* seg;
541  for (unsigned int i = 0; i < NextCount(); i++) {
542  seg = static_cast<pma::Segment3D*>(Next(i));
543  nhits += seg->NPrecalcEnabledHits(); //NEnabledHits();
544  mse += seg->SumDist2();
545  }
546  if (prev) {
547  seg = static_cast<pma::Segment3D*>(prev);
548  nhits += seg->NPrecalcEnabledHits(); //NEnabledHits();
549  mse += seg->SumDist2();
550  }
551  if (!nhits)
552  return 0.0;
553  else
554  return mse / nhits;
555 }
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:138
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 811 of file PmaNode3D.cxx.

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

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

812 {
813  if (!fFrozen) {
814  double dg = StepWithGradient(0.1F, 0.002F, penaltyValue, endSegWeight);
815  if (dg > 0.01) dg = StepWithGradient(0.03F, 0.0001F, penaltyValue, endSegWeight);
816  if (dg > 0.0) dg = StepWithGradient(0.03F, 0.0001F, penaltyValue, endSegWeight);
817  }
818 }
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 516 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().

517 {
518  unsigned int nseg = 1;
519  double penalty = Pi(endSegWeight, true);
520 
521  pma::Node3D* v;
522  for (unsigned int i = 0; i < NextCount(); i++) {
523  v = static_cast<pma::Node3D*>(Next(i)->Next());
524  penalty += v->Pi(endSegWeight, false);
525  nseg++;
526  }
527  if (prev) {
528  v = static_cast<pma::Node3D*>(prev->Prev());
529  penalty += v->Pi(endSegWeight, false);
530  nseg++;
531  }
532  return penalty / nseg;
533 }
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:460
double pma::Node3D::PenaltyInWirePlane ( ) const
private

Definition at line 399 of file PmaNode3D.cxx.

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

Referenced by GetObjFunction().

400 {
401  if (fIsVertex) return 0.0;
402 
403  unsigned int nseg = 1;
404  double penalty = PiInWirePlane();
405  pma::Node3D* v;
406  if (next) {
407  v = static_cast<pma::Node3D*>(next->Next());
408  penalty += v->PiInWirePlane();
409  nseg++;
410  }
411  if (prev) {
412  v = static_cast<pma::Node3D*>(prev->Prev());
413  penalty += v->PiInWirePlane();
414  nseg++;
415  }
416  if (penalty > 0.0)
417  return pow(EndPtCos2Transverse(), 10) * penalty / nseg;
418  else
419  return 0.0;
420 }
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:378
double EndPtCos2Transverse() const
Definition: PmaNode3D.cxx:361
pma::SortedObjectBase * next
Definition: SortedObjects.h:53
virtual pma::SortedObjectBase * Prev(void) const
Definition: SortedObjects.h:42
bool fIsVertex
Definition: PmaNode3D.h:156
double pma::Node3D::Pi ( float  endSegWeight,
bool  doAsymm 
) const
private

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

461 {
462  if (fIsVertex) return 0.0;
463 
464  if (prev && NextCount()) {
465  pma::Segment3D* segPrev = static_cast<pma::Segment3D*>(prev);
466  pma::Segment3D* segNext = static_cast<pma::Segment3D*>(Next(0));
467 
468  double scale = 1.0;
469  if ((segPrev->TPC() < 0) || (segNext->TPC() < 0))
470  scale = 0.5; // lower penalty on segments between tpc's
471 
472  double segCos = SegmentCos();
473 
474  double lAsymmFactor = 0.0;
475  if (doAsymm) {
476  double lPrev = segPrev->Length();
477  double lNext = segNext->Length();
478  double lSum = lPrev + lNext;
479  if (lSum > 0.1) {
480  double lAsymm = (1.0 - segCos) * (lPrev - lNext) / lSum;
481  lAsymmFactor = 0.05 * lAsymm * lAsymm;
482  }
483  }
484 
485  if (fHitsRadius > 0.0F)
486  return scale * (1.0 + segCos + lAsymmFactor) * fHitsRadius * fHitsRadius;
487  else
488  return scale * (1.0 + segCos + lAsymmFactor) * Length2();
489  }
490  else {
491  double pi_result = 0.0;
492  unsigned int nSeg = 0;
493  pma::Segment3D* seg = 0;
494  if (prev) {
495  seg = static_cast<pma::Segment3D*>(prev);
496 
497  SortedObjectBase* prevVtx = seg->Prev();
498  if (prevVtx->Prev()) nSeg++;
499  nSeg += prevVtx->NextCount();
500  }
501  else if (next) {
502  seg = static_cast<pma::Segment3D*>(next);
503 
504  SortedObjectBase* nextVtx = seg->Next();
505  nSeg += nextVtx->NextCount() + 1;
506  }
507  else {
508  mf::LogWarning("pma::Node3D") << "pma::Node3D::Pi(): an isolated vertex?";
509  return 0.0;
510  }
511  if (nSeg == 1) pi_result = endSegWeight * seg->Length2();
512  return pi_result;
513  }
514 }
double Length2() const override
Definition: PmaNode3D.cxx:292
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:304
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:156
double Length(void) const
Definition: PmaElement3D.h:53
double pma::Node3D::PiInWirePlane ( ) const
private

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

379 {
380  if (prev && NextCount()) {
381  pma::Segment3D* seg0 = dynamic_cast<pma::Segment3D*>(prev);
382  pma::Segment3D* seg1 = dynamic_cast<pma::Segment3D*>(Next(0));
383  unsigned int nInd1 = NHits(geo::kU) + seg0->NHits(geo::kU) + seg1->NHits(geo::kU);
384 
385  if (fHitsRadius > 0.0F)
386  return (1.0 + SegmentCosWirePlane()) * fHitsRadius * fHitsRadius / (4 * nInd1 + 1.0);
387  else
388  return (1.0 + SegmentCosWirePlane()) * Length2() / (4 * nInd1 + 1.0);
389  }
390  else
391  return 0.0;
392 }
double Length2() const override
Definition: PmaNode3D.cxx:292
pma::SortedObjectBase * prev
Definition: SortedObjects.h:54
virtual unsigned int NextCount(void) const
Definition: SortedObjects.h:84
double SegmentCosWirePlane() const
Definition: PmaNode3D.cxx:324
Planes which measure U.
Definition: geo_types.h:131
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 103 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().

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

Definition at line 113 of file PmaNode3D.cxx.

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

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

Cosine of 3D angle between connected segments.

Definition at line 304 of file PmaNode3D.cxx.

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

Referenced by Pi().

305 {
306  if (prev && next) {
307  auto const& vStop1 = static_cast<pma::Node3D*>(prev->Prev())->fPoint3D;
308  auto const& vStop2 = static_cast<pma::Node3D*>(next->Next())->fPoint3D;
309  pma::Vector3D v1(
310  vStop1.X() - fPoint3D.X(), vStop1.Y() - fPoint3D.Y(), vStop1.Z() - fPoint3D.Z());
311  pma::Vector3D v2(
312  vStop2.X() - fPoint3D.X(), vStop2.Y() - fPoint3D.Y(), vStop2.Z() - fPoint3D.Z());
313  double mag = sqrt(v1.Mag2() * v2.Mag2());
314  double cosine = 0.0;
315  if (mag != 0.0) cosine = v1.Dot(v2) / mag;
316  return cosine;
317  }
318  else {
319  mf::LogError("pma::Node3D") << "pma::Node3D::SegmentCos(): neighbours not initialized.";
320  return -1.0;
321  }
322 }
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:150
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 342 of file PmaNode3D.cxx.

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

343 {
344  if (prev && next) {
345  auto const& vStop1 = static_cast<pma::Node3D*>(prev->Prev())->fPoint3D;
346  auto const& vStop2 = static_cast<pma::Node3D*>(next->Next())->fPoint3D;
347  pma::Vector2D v1(vStop1.X() - fPoint3D.X(), vStop1.Z() - fPoint3D.Z());
348  pma::Vector2D v2(vStop2.X() - fPoint3D.X(), vStop2.Z() - fPoint3D.Z());
349  double mag = sqrt(v1.Mag2() * v2.Mag2());
350  double cosine = 0.0;
351  if (mag != 0.0) cosine = v1.Dot(v2) / mag;
352  return cosine;
353  }
354  else {
355  mf::LogError("pma::Node3D") << "pma::Node3D::SegmentCosZY(): neighbours not initialized.";
356  return -1.0;
357  }
358 }
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:150
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 324 of file PmaNode3D.cxx.

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

Referenced by PiInWirePlane().

325 {
326  if (prev && next) {
327  auto const& vStop1 = static_cast<pma::Node3D*>(prev->Prev())->fPoint3D;
328  auto const& vStop2 = static_cast<pma::Node3D*>(next->Next())->fPoint3D;
329  pma::Vector2D v1(vStop1.Y() - fPoint3D.Y(), vStop1.Z() - fPoint3D.Z());
330  pma::Vector2D v2(vStop2.Y() - fPoint3D.Y(), vStop2.Z() - fPoint3D.Z());
331  double mag = sqrt(v1.Mag2() * v2.Mag2());
332  double cosine = 0.0;
333  if (mag != 0.0) cosine = v1.Dot(v2) / mag;
334  return cosine;
335  }
336  else {
337  mf::LogError("pma::Node3D") << "pma::Node3D::SegmentCosZX(): neighbours not initialized.";
338  return -1.0;
339  }
340 }
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:150
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 121 of file PmaNode3D.h.

References weight.

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

122  {
123  if (m >= 0.0) fMargin = m;
124  }
static double fMargin
Definition: PmaNode3D.h:159
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 166 of file PmaNode3D.cxx.

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

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

167 {
168  fPoint3D = p3d;
169 
170  bool accepted = !LimitPoint3D();
171  UpdateProj2D();
172 
173  return accepted;
174 }
bool LimitPoint3D()
Returns true if node position was trimmed to its TPC volume + fMargin.
Definition: PmaNode3D.cxx:123
void UpdateProj2D()
Definition: PmaNode3D.cxx:157
TVector3 fPoint3D
Definition: PmaNode3D.h:150
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 218 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().

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

Definition at line 63 of file PmaNode3D.h.

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

Definition at line 64 of file PmaNode3D.h.

65  {
66  if (setAllNodes || !fIsVertex) fIsVertex = IsBranching();
67  }
bool IsBranching() const
Belongs to more than one track?
Definition: PmaNode3D.cxx:422
bool fIsVertex
Definition: PmaNode3D.h:156
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 very close to the minimum
705  if (fabs(t2 - t1) < tol) {
706  SetPoint3D(tmp);
707  return 0.0;
708  }
709 
710  gpoint = tmp;
711  gpoint += (fGradient * t2);
712  if (!SetPoint3D(gpoint)) // select the best point to exit
713  {
714  g2 = GetObjFunction(penalty, weight);
715  if (g2 < g0)
716  return (g0 - g2) / g2; // exit with the node at the border
717  else if (g1 < g0) {
718  gpoint = tmp;
719  gpoint += (fGradient * t1);
720  return (g0 - g1) / g1;
721  }
722  else if (g3 < g0) {
723  gpoint = tmp;
724  gpoint += (fGradient * t3);
725  return (g0 - g3) / g3;
726  }
727  else {
728  SetPoint3D(tmp);
729  return 0.0;
730  }
731  }
732  g2 = GetObjFunction(penalty, weight);
733 
734  if (g2 < zero_tol) return 0.0;
735  steps++;
736 
737  } while (g2 >= g1);
738  }
739  //****************************//
740 
741  while (fabs(t1 - t3) > tol) {
742  //*** 3-point minimization ***//
743  if ((fabs(t2 - t1) < eps) || (fabs(t2 - t3) < eps)) break; // minimum on the edge
744  if ((fabs(g2 - g1) < eps) && (fabs(g2 - g3) < eps)) break; // ~singularity
745 
746  p1 = (t2 - t1) * (g2 - g3);
747  p2 = (t2 - t3) * (g2 - g1);
748  if (fabs(p1 - p2) < eps) break; // ~linearity
749 
750  t = t2 + ((t2 - t1) * p1 - (t2 - t3) * p2) / (2 * (p2 - p1));
751  if ((t <= t1) || (t >= t3)) t = (t1 * g3 + t3 * g1) / (g1 + g3);
752 
753  gpoint = tmp;
754  gpoint += (fGradient * t);
755  if (!SetPoint3D(gpoint)) // select the best point to exit
756  {
757  g = GetObjFunction(penalty, weight);
758  if ((g < g0) && (g < g1) && (g < g3))
759  return (g0 - g) / g; // exit with the node at the border
760  else if ((g1 < g0) && (g1 < g3)) {
761  gpoint = tmp;
762  gpoint += (fGradient * t1);
763  return (g0 - g1) / g1;
764  }
765  else if (g3 < g0) {
766  gpoint = tmp;
767  gpoint += (fGradient * t3);
768  return (g0 - g3) / g3;
769  }
770  else {
771  SetPoint3D(tmp);
772  return 0.0;
773  }
774  }
775 
776  g = GetObjFunction(penalty, weight);
777  if (g < zero_tol) return 0.0;
778  steps++;
779  //****************************//
780 
781  //*** select next 3 points ***//
782  if (fabs(t - t2) < 0.2 * tol) break; // start in a new direction
783  if (g < g2) {
784  if (t < t2) {
785  t3 = t2;
786  g3 = g2;
787  }
788  else {
789  t1 = t2;
790  g1 = g2;
791  }
792  t2 = t;
793  g2 = g;
794  }
795  else {
796  if (t < t2) {
797  t1 = t;
798  g1 = g;
799  }
800  else {
801  t3 = t;
802  g3 = g;
803  }
804  }
805  //****************************//
806  }
807 
808  return (g0 - g) / g;
809 }
TTree * t1
Definition: plottest35.C:26
Float_t tmp
Definition: plot.C:35
bool SetPoint3D(const TVector3 &p3d)
Definition: PmaNode3D.cxx:166
TTree * t2
Definition: plottest35.C:36
double MakeGradient(float penaltyValue, float endSegWeight)
Definition: PmaNode3D.cxx:562
double weight
Definition: plottest35.C:25
double GetObjFunction(float penaltyValue, float endSegWeight) const
Objective function minimized during oprimization.
Definition: PmaNode3D.cxx:557
TVector3 fPoint3D
Definition: PmaNode3D.h:150
TVector3 fGradient
Definition: PmaNode3D.h:155
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:138
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 186 of file PmaNode3D.cxx.

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

187 {
188  double sum = 0.0F;
189  for (auto h : fAssignedHits) {
190  if (h->IsEnabled()) {
191  unsigned int view = h->View2D();
192 
193  sum += OptFactor(view) * // alpha_i
194  h->GetSigmaFactor() * // hit_amp / hit_max_amp
195  pma::Dist2(h->Point2D(), fProj2D[view]);
196  }
197  }
198  return sum;
199 }
double Dist2(const TVector2 &v1, const TVector2 &v2)
Definition: Utilities.cxx:39
TVector2 fProj2D[3]
Definition: PmaNode3D.h:151
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:132
Planes which measure Z direction.
Definition: geo_types.h:134
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:131
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 157 of file PmaNode3D.cxx.

References fChannelMap, fDriftOffset, fPoint3D, fProj2D, fTpcGeo, geo::TPCGeo::ID(), geo::Iterable< IterationPolicy, Transform >::Iterate(), and geo::vect::toPoint().

Referenced by SetPoint3D().

158 {
159  unsigned int i = 0;
160  for (auto const& plane : fChannelMap.Iterate<geo::PlaneGeo>(fTpcGeo.ID())) {
161  fProj2D[i++].Set(plane.PlaneCoordinate(geo::vect::toPoint(fPoint3D)),
162  fPoint3D.X() - fDriftOffset);
163  }
164 }
double fDriftOffset
Definition: PmaNode3D.h:153
TVector2 fProj2D[3]
Definition: PmaNode3D.h:151
Geometry information for a single wire plane.The plane is represented in the geometry by a solid whic...
Definition: PlaneGeo.h:67
Point_t toPoint(Point const &p)
Convert the specified point into a geo::Point_t.
geo::WireReadoutGeom const & fChannelMap
Definition: PmaNode3D.h:145
range_type< T > Iterate() const
Definition: Iterable.h:121
geo::TPCGeo const & fTpcGeo
Definition: PmaNode3D.h:144
TVector3 fPoint3D
Definition: PmaNode3D.h:150
TPCID const & ID() const
Returns the identifier of this TPC.
Definition: TPCGeo.h:147
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
geo::WireReadoutGeom const& pma::Node3D::fChannelMap
private

Definition at line 145 of file PmaNode3D.h.

Referenced by Node3D(), and UpdateProj2D().

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 153 of file PmaNode3D.h.

Referenced by UpdateProj2D().

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

Definition at line 158 of file PmaNode3D.h.

Referenced by MakeGradient().

TVector3 pma::Node3D::fGradient
private

Definition at line 155 of file PmaNode3D.h.

Referenced by MakeGradient(), and StepWithGradient().

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

Definition at line 156 of file PmaNode3D.h.

Referenced by PenaltyInWirePlane(), and Pi().

double pma::Node3D::fMargin = 3.0
staticprivate

Definition at line 159 of file PmaNode3D.h.

Referenced by LimitPoint3D().

double pma::Node3D::fMaxX
private

Definition at line 147 of file PmaNode3D.h.

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

double pma::Node3D::fMaxY
private

Definition at line 147 of file PmaNode3D.h.

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

double pma::Node3D::fMaxZ
private

Definition at line 147 of file PmaNode3D.h.

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

double pma::Node3D::fMinX
private

Definition at line 147 of file PmaNode3D.h.

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

double pma::Node3D::fMinY
private

Definition at line 147 of file PmaNode3D.h.

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

double pma::Node3D::fMinZ
private

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