61 unsigned int lastPlane =
geo::kZ;
86 if (d < dmin) dmin =
d;
89 if (d < dmin) dmin =
d;
91 if (d < dmin) dmin =
d;
94 if (d < dmin) dmin =
d;
96 if (d < dmin) dmin =
d;
104 if (((
fMinX - margin) <= p3d.X()) && (p3d.X() <= (
fMaxX + margin)) &&
105 ((
fMinY - margin) <= p3d.Y()) && (p3d.Y() <= (
fMaxY + margin)) &&
106 ((
fMinZ - margin) <= p3d.Z()) && (p3d.Z() <= (
fMaxZ + margin)))
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)))
126 bool trimmed =
false;
194 if (
h->IsEnabled()) {
195 unsigned int view =
h->View2D();
198 h->GetSigmaFactor() *
256 double v0Norm = v0.Mod();
257 double v1Norm = v1.Mod();
258 double mag = v0Norm * v1Norm;
260 if (mag != 0.0) cosine = v0 * v1 / mag;
269 mag = v0Norm * vN.Mod();
270 double cosineN = 0.0;
271 if (mag != 0.0) cosineN = v0 * vN / mag;
282 float b = (
float)(v0Norm * cosine / v1Norm);
321 double mag = sqrt(v1.Mag2() * v2.Mag2());
323 if (mag != 0.0) cosine = v1.Dot(v2) / mag;
327 mf::LogError(
"pma::Node3D") <<
"pma::Node3D::SegmentCos(): neighbours not initialized.";
340 double mag = sqrt(v1.Mag2() * v2.Mag2());
342 if (mag != 0.0) cosine = v1.Dot(v2) / mag;
346 mf::LogError(
"pma::Node3D") <<
"pma::Node3D::SegmentCosZX(): neighbours not initialized.";
359 double mag = sqrt(v1.Mag2() * v2.Mag2());
361 if (mag != 0.0) cosine = v1.Dot(v2) / mag;
365 mf::LogError(
"pma::Node3D") <<
"pma::Node3D::SegmentCosZY(): neighbours not initialized.";
378 double dy = vStop.X() - vStart.X();
379 double dz = vStop.Z() - vStart.Z();
380 double len2 = dy * dy + dz * dz;
381 double cosine2 = 0.0;
382 if (len2 > 0.0) cosine2 = dz * dz / len2;
416 unsigned int nseg = 1;
439 if (nnext > 1)
return true;
457 if ((segPrev->
TPC() < 0) || (segNext->
TPC() < 0))
return true;
462 std::vector<pma::Track3D*>
465 std::vector<pma::Track3D*> branches;
468 for (
size_t i = 0; i <
NextCount(); ++i) {
470 branches.push_back(seg->
Parent());
486 if ((segPrev->
TPC() < 0) || (segNext->
TPC() < 0))
491 double lAsymmFactor = 0.0;
493 double lPrev = segPrev->
Length();
494 double lNext = segNext->
Length();
495 double lSum = lPrev + lNext;
497 double lAsymm = (1.0 - segCos) * (lPrev - lNext) / lSum;
498 lAsymmFactor = 0.05 * lAsymm * lAsymm;
505 return scale * (1.0 + segCos + lAsymmFactor) *
Length2();
508 double pi_result = 0.0;
509 unsigned int nSeg = 0;
515 if (prevVtx->
Prev()) nSeg++;
525 mf::LogWarning(
"pma::Node3D") <<
"pma::Node3D::Pi(): an isolated vertex?";
528 if (nSeg == 1) pi_result = endSegWeight * seg->
Length2();
536 unsigned int nseg = 1;
537 double penalty =
Pi(endSegWeight,
true);
540 for (
unsigned int i = 0; i <
NextCount(); i++) {
542 penalty += v->
Pi(endSegWeight,
false);
547 penalty += v->
Pi(endSegWeight,
false);
550 return penalty / nseg;
560 for (
unsigned int i = 0; i <
NextCount(); i++) {
585 double l1 = 0.0, l2 = 0.0, minLength2 = 0.0;
597 if ((l1 > 0.01) && (l1 < l2))
599 else if ((l2 > 0.01) && (l2 < l1))
604 double dxi = 0.001 * sqrt(minLength2);
606 if (dxi < 6.0
E-37)
return 0.0;
615 gpoint[0] =
tmp[0] + dxi;
620 gpoint[0] =
tmp[0] - dxi;
630 gpoint[1] =
tmp[1] + dxi;
635 gpoint[1] =
tmp[1] - dxi;
645 gpoint[2] =
tmp[2] + dxi;
651 gpoint[2] =
tmp[2] - dxi;
661 if (
fGradient.Mag2() < 6.0E-37)
return 0.0;
669 unsigned int steps = 0;
670 double t,
t1, t2, t3,
g, g0, g1,
g2, g3, p1, p2;
671 double eps = 6.0E-37, zero_tol = 1.0E-15;
675 if (g < zero_tol)
return 0.0;
699 return (g0 - g3) / g3;
708 if (g3 < zero_tol)
return 0.0;
710 if (++steps > 1000) {
725 t2 = (t1 * g3 + t3 * g1) / (g1 + g3);
728 t2 = 0.05 * t3 + 0.95 * t2;
734 if (fabs(t2 - t1) <
tol) {
746 return (g0 - g2) /
g2;
750 return (g0 - g1) / g1;
755 return (g0 - g3) / g3;
764 if (g2 < zero_tol)
return 0.0;
771 while (fabs(t1 - t3) > tol) {
773 if ((fabs(t2 - t1) < eps) || (fabs(t2 - t3) < eps))
break;
774 if ((fabs(g2 - g1) < eps) && (fabs(g2 - g3) < eps))
break;
776 p1 = (t2 -
t1) * (g2 - g3);
777 p2 = (t2 - t3) * (g2 - g1);
778 if (fabs(p1 - p2) < eps)
break;
780 t = t2 + ((t2 -
t1) * p1 - (t2 - t3) * p2) / (2 * (p2 - p1));
781 if ((t <= t1) || (t >= t3)) t = (t1 * g3 + t3 * g1) / (g1 + g3);
789 if ((g < g0) && (g < g1) && (g < g3))
791 else if ((g1 < g0) && (g1 < g3)) {
794 return (g0 - g1) / g1;
799 return (g0 - g3) / g3;
808 if (g < zero_tol)
return 0.0;
813 if (fabs(t - t2) < 0.2 * tol)
break;
847 if (dg > 0.01) dg =
StepWithGradient(0.03F, 0.0001F, penaltyValue, endSegWeight);
848 if (dg > 0.0) dg =
StepWithGradient(0.03F, 0.0001F, penaltyValue, endSegWeight);
861 std::vector<pma::Track3D*> to_check;
865 if (seg->
Parent() != trk) to_check.push_back(seg->
Parent());
867 for (
unsigned int i = 0; i <
NextCount(); i++) {
869 if (seg->
Parent() != trk) to_check.push_back(seg->
Parent());
875 for (
size_t t = 0;
t < to_check.size();
t++)
892 for (
size_t t = 0; (
t < to_check.size()) && !found;
t++)
893 for (
size_t i = 0; i < to_check[
t]->size(); i++) {
size_t NPrecalcEnabledHits(void) const
bool HasPlane(unsigned int iplane) const
Returns whether a plane with index iplane is present in this TPC.
TVector3 const & Point3D() const
TVector2 const & Projection2D(unsigned int view) const
double Length2() const override
static constexpr double g
double Penalty(float endSegWeight) const
Implementation of the Projection Matching Algorithm.
TVector2 const & Point2D() const noexcept
double Dist2(const TVector2 &v1, const TVector2 &v2)
unsigned int Nplanes() const
Number of planes in this tpc.
void ClearAssigned(pma::Track3D *trk=0) override
Implementation of the Projection Matching Algorithm.
pma::SortedObjectBase * prev
double GetDistance2To(const TVector3 &p3d) const override
Distance [cm] from the 3D point to the point 3D.
pma::Vector3D GetDirection3D() const override
bool LimitPoint3D()
Returns true if node position was trimmed to its TPC volume + fMargin.
virtual unsigned int NextCount(void) const
std::vector< pma::Track3D * > GetBranches() const
void Optimize(float penaltyValue, float endSegWeight)
Planes which measure Z direction.
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
double Length2(void) const override
bool IsTPCEdge() const
Is the first/last in this TPC?
recob::tracking::Vector_t Vector3D
static bool fGradFixed[3]
art framework interface to geometry description
virtual pma::Vector3D GetDirection3D(void) const =0
Get 3D direction cosines corresponding to this element.
double SegmentCosWirePlane() const
int TPC(void) const
TPC index or -1 if out of any TPC.
double PenaltyInWirePlane() const
double GetDistToWall() const
virtual unsigned int NextCount(void) const
double PiInWirePlane() const
std::vector< TVector3 * > fAssignedPoints
double SegmentCos() const
Cosine of 3D angle between connected segments.
bool SetPoint3D(const TVector3 &p3d)
double MinZ() const
Returns the world z coordinate of the start of the box.
double StepWithGradient(float alfa, float tol, float penalty, float weight)
double SegmentCosTransverse() const
std::vector< pma::Hit3D * > fAssignedHits
unsigned int NumberTimeSamples() const
double EndPtCos2Transverse() const
bool SameTPC(const TVector3 &p3d, float margin=0.0F) const
Check if p3d is in the same TPC as the node.
void SetProjection(const TVector2 &p, float b)
double SumDist2(void) const
Detector simulation of raw signals on wires.
double MaxY() const
Returns the world y coordinate of the end of the box.
double ConvertTicksToX(double ticks, int p, int t, int c) const
double MakeGradient(float penaltyValue, float endSegWeight)
unsigned int View2D() const noexcept
Implementation of the Projection Matching Algorithm.
virtual pma::SortedObjectBase * Next(unsigned int index=0) const
Encapsulate the construction of a single detector plane.
double GetObjFunction(float penaltyValue, float endSegWeight) const
Objective function minimized during oprimization.
double MaxZ() const
Returns the world z coordinate of the end of the box.
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
void SetPoint3D(const TVector3 &p3d)
ROOT::Math::DisplacementVector2D< ROOT::Math::Cartesian2D< double > > Vector2D
bool IsBranching() const
Belongs to more than one track?
pma::SortedObjectBase * next
double SumDist2Hits() const override
geo::TPCGeo const & fTpcGeo
PlaneGeo const & Plane(geo::View_t view) const
Return the plane in the tpc with View_t view.
virtual pma::SortedObjectBase * Prev(void) const
LArSoft geometry interface.
void SetProjection(pma::Hit3D &h) const override
Set hit 3D position and its 2D projection to the vertex.
double MinY() const
Returns the world y coordinate of the start of the box.
pma::Track3D * Parent(void) const
double Pi(float endSegWeight, bool doAsymm) const
virtual pma::SortedObjectBase * Next(unsigned int index=0) const
double PlaneCoordinate(geo::Point_t const &point) const
Returns the coordinate of the point on the plane.
double Length(void) const
cet::coded_exception< error, detail::translate > exception
QTextStream & endl(QTextStream &s)
static float OptFactor(unsigned int view)
Encapsulate the construction of a single detector plane.