30 : fTpcGeo(
art::ServiceHandle<
geo::Geometry const>()->TPC())
31 , fChannelMap(
art::ServiceHandle<
geo::WireReadout>()->
Get())
64 unsigned int lastPlane =
geo::kZ;
88 if (d < dmin) dmin =
d;
91 if (d < dmin) dmin =
d;
93 if (d < dmin) dmin =
d;
96 if (d < dmin) dmin =
d;
98 if (d < dmin) dmin =
d;
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)))
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)))
125 bool trimmed =
false;
190 if (h->IsEnabled()) {
191 unsigned int view = h->View2D();
194 h->GetSigmaFactor() *
209 throw cet::exception(
"Node3D") <<
"Isolated vertex." << std::endl;
214 throw cet::exception(
"Node3D") <<
"Corrupted vertex." << std::endl;
250 double v0Norm = v0.Mod();
251 double v1Norm = v1.Mod();
252 double mag = v0Norm * v1Norm;
254 if (mag != 0.0) cosine = v0 * v1 / mag;
263 mag = v0Norm * vN.Mod();
264 double cosineN = 0.0;
265 if (mag != 0.0) cosineN = v0 * vN / mag;
276 float b = (float)(v0Norm * cosine / v1Norm);
313 double mag = sqrt(v1.Mag2() * v2.Mag2());
315 if (mag != 0.0) cosine = v1.Dot(v2) / mag;
319 mf::LogError(
"pma::Node3D") <<
"pma::Node3D::SegmentCos(): neighbours not initialized.";
331 double mag = sqrt(v1.Mag2() * v2.Mag2());
333 if (mag != 0.0) cosine = v1.Dot(v2) / mag;
337 mf::LogError(
"pma::Node3D") <<
"pma::Node3D::SegmentCosZX(): neighbours not initialized.";
349 double mag = sqrt(v1.Mag2() * v2.Mag2());
351 if (mag != 0.0) cosine = v1.Dot(v2) / mag;
355 mf::LogError(
"pma::Node3D") <<
"pma::Node3D::SegmentCosZY(): neighbours not initialized.";
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;
403 unsigned int nseg = 1;
425 if (nnext > 1)
return true;
442 if ((segPrev->
TPC() < 0) || (segNext->
TPC() < 0))
return true;
449 std::vector<pma::Track3D*> branches;
452 for (
size_t i = 0; i <
NextCount(); ++i) {
454 branches.push_back(seg->
Parent());
469 if ((segPrev->
TPC() < 0) || (segNext->
TPC() < 0))
474 double lAsymmFactor = 0.0;
476 double lPrev = segPrev->
Length();
477 double lNext = segNext->
Length();
478 double lSum = lPrev + lNext;
480 double lAsymm = (1.0 - segCos) * (lPrev - lNext) / lSum;
481 lAsymmFactor = 0.05 * lAsymm * lAsymm;
488 return scale * (1.0 + segCos + lAsymmFactor) *
Length2();
491 double pi_result = 0.0;
492 unsigned int nSeg = 0;
498 if (prevVtx->
Prev()) nSeg++;
508 mf::LogWarning(
"pma::Node3D") <<
"pma::Node3D::Pi(): an isolated vertex?";
511 if (nSeg == 1) pi_result = endSegWeight * seg->
Length2();
518 unsigned int nseg = 1;
519 double penalty =
Pi(endSegWeight,
true);
522 for (
unsigned int i = 0; i <
NextCount(); i++) {
524 penalty += v->
Pi(endSegWeight,
false);
529 penalty += v->
Pi(endSegWeight,
false);
532 return penalty / nseg;
541 for (
unsigned int i = 0; i <
NextCount(); i++) {
564 double l1 = 0.0, l2 = 0.0, minLength2 = 0.0;
576 if ((l1 > 0.01) && (l1 < l2))
578 else if ((l2 > 0.01) && (l2 < l1))
583 double dxi = 0.001 * sqrt(minLength2);
585 if (dxi < 6.0
E-37)
return 0.0;
592 gpoint[0] =
tmp[0] + dxi;
597 gpoint[0] =
tmp[0] - dxi;
607 gpoint[1] =
tmp[1] + dxi;
612 gpoint[1] =
tmp[1] - dxi;
622 gpoint[2] =
tmp[2] + dxi;
627 gpoint[2] =
tmp[2] - dxi;
636 if (
fGradient.Mag2() < 6.0E-37)
return 0.0;
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;
649 if (g < zero_tol)
return 0.0;
673 return (g0 - g3) / g3;
682 if (g3 < zero_tol)
return 0.0;
684 if (++steps > 1000) {
699 t2 = (t1 * g3 + t3 * g1) / (g1 + g3);
702 t2 = 0.05 * t3 + 0.95 *
t2;
705 if (fabs(t2 - t1) < tol) {
716 return (g0 - g2) / g2;
720 return (g0 - g1) / g1;
725 return (g0 - g3) / g3;
734 if (g2 < zero_tol)
return 0.0;
741 while (fabs(t1 - t3) > tol) {
743 if ((fabs(t2 - t1) < eps) || (fabs(t2 - t3) < eps))
break;
744 if ((fabs(g2 - g1) < eps) && (fabs(g2 - g3) < eps))
break;
746 p1 = (t2 -
t1) * (g2 - g3);
747 p2 = (t2 - t3) * (g2 - g1);
748 if (fabs(p1 - p2) < eps)
break;
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);
758 if ((g < g0) && (g < g1) && (g < g3))
760 else if ((g1 < g0) && (g1 < g3)) {
763 return (g0 - g1) / g1;
768 return (g0 - g3) / g3;
777 if (g < zero_tol)
return 0.0;
782 if (fabs(t - t2) < 0.2 * tol)
break;
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);
828 std::vector<pma::Track3D*> to_check;
832 if (seg->
Parent() != trk) to_check.push_back(seg->
Parent());
834 for (
unsigned int i = 0; i <
NextCount(); i++) {
836 if (seg->
Parent() != trk) to_check.push_back(seg->
Parent());
842 for (
size_t t = 0; t < to_check.size(); t++)
859 for (
size_t t = 0; (t < to_check.size()) && !found; t++)
860 for (
size_t i = 0; i < to_check[t]->size(); i++) {
size_t NPrecalcEnabledHits(void) const
TVector3 const & Point3D() const
TVector2 const & Projection2D(unsigned int view) const
double Length2() const override
std::vector< TVector3 * > fAssignedPoints
double Penalty(float endSegWeight) const
Implementation of the Projection Matching Algorithm.
TVector2 const & Point2D() const noexcept
double Dist2(const TVector2 &v1, const TVector2 &v2)
void ClearAssigned(pma::Track3D *trk=0) override
Implementation of the Projection Matching Algorithm.
The data type to uniquely identify a Plane.
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.
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
virtual pma::SortedObjectBase * Next(unsigned int=0) const
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
double Length2(void) const override
bool IsTPCEdge() const
Is the first/last in this TPC?
bool HasPlane(PlaneID const &planeid) const
Returns whether we have the specified plane.
recob::tracking::Vector_t Vector3D
static bool fGradFixed[3]
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
double SegmentCos() const
Cosine of 3D angle between connected segments.
Geometry information for a single wire plane.The plane is represented in the geometry by a solid whic...
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
unsigned int NumberTimeSamples() const
Point_t toPoint(Point const &p)
Convert the specified point into a geo::Point_t.
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.
std::vector< pma::Hit3D * > fAssignedHits
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.
geo::WireReadoutGeom const & fChannelMap
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)
range_type< T > Iterate() const
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
IDparameter< geo::TPCID > TPCID
Member type of validated geo::TPCID parameter.
virtual pma::SortedObjectBase * Prev(void) const
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.
TPCID const & ID() const
Returns the identifier of this TPC.
pma::Track3D * Parent(void) const
double Pi(float endSegWeight, bool doAsymm) const
double Length(void) const
art framework interface to geometry description
cet::coded_exception< error, detail::translate > exception
static float OptFactor(unsigned int view)
Encapsulate the construction of a single detector plane .