8#include <tracking/trackingUtilities/numerics/SinEqLine.h>
10#include <framework/logging/Logger.h>
15using namespace TrackingUtilities;
21 if (root > 0)
return root;
26 if (root > 0)
return root;
28 for (
int iHalfPeriod = 1; iHalfPeriod <= maxIHalfPeriod; ++iHalfPeriod) {
32 if (root > 0)
return root;
57 if (xLineIsPlusOne > xLineIsMinusOne) {
60 }
else if (xLineIsPlusOne < xLineIsMinusOne) {
69 if (not(lowerX < upperX))
return NAN;
71 ROOT::Math::XYVector lower(lowerX,
map(lowerX));
72 ROOT::Math::XYVector upper(upperX,
map(upperX));
77 B2INFO(
"Coverage early");
86 ROOT::Math::XYVector last(lower);
87 ROOT::Math::XYVector current(upper);
89 ROOT::Math::XYVector next;
90 next.SetX(
secantX(last, current));
91 next.SetY(
map(next.x()));
95 if (not updatedBound)
return NAN;
99 last.SetXY(current.X(), current.Y());
100 current.SetXY(next.X(), next.Y());
103 next.SetY(
map(next.x()));
107 if (not updatedBound) {
110 next.SetX(
secantX(last, current));
111 next.SetY(
map(next.x()));
115 if (not updatedBound) {
117 next.SetX(
middleX(lower, upper));
118 next.SetY(
map(next.x()));
121 if (not updatedBound)
break;
136 return (lower.x() + upper.x()) / 2.0;
141 return (lower.x() * upper.y() - upper.x() * lower.y()) / (upper.y() - lower.y());
146 return pos.x() - pos.y() /
gradient(pos.x());
152 if (not
isBetween(lower, next, upper))
return false;
154 EIncDec incDecInfo =
getEIncDec(lower, upper);
155 if (incDecInfo == EIncDec::c_Increasing) {
156 if (next.y() > 0.0 and upper.y() > 0.0) {
157 upper.SetXY(next.X(), next.Y());
160 }
else if (next.y() <= 0.0 and lower.y() <= 0.0) {
161 lower.SetXY(next.X(), next.Y());
168 }
else if (incDecInfo == EIncDec::c_Decreasing) {
169 if (next.y() >= 0 and lower.y() >= 0.0) {
170 lower.SetXY(next.X(), next.Y());
173 }
else if (next.y() < 0 and upper.y() < 0) {
174 upper.SetXY(next.X(), next.Y());
188 double extremumInFirstHalfPeriod = acos(slope);
190 double extremumInFirstPeriod =
191 isEven(iHalfPeriod) ? extremumInFirstHalfPeriod : 2 * M_PI - extremumInFirstHalfPeriod;
194 return extremumInFirstPeriod + 2 * M_PI * iPeriod;
double getIntercept() const
Getter for the intercept.
static double getConvergedBound(const ROOT::Math::XYVector &lower, const ROOT::Math::XYVector &upper)
Returns the better solution x from the bounds of the interval.
static bool updateBounds(ROOT::Math::XYVector &lower, ROOT::Math::XYVector &upper, const ROOT::Math::XYVector &next)
Replaces the lower or upper bound inplace if the next candidate position is valid and within the inte...
static double secantX(const ROOT::Math::XYVector &lower, const ROOT::Math::XYVector &upper)
Fall back shrinking method to the secant algorithm.
static double middleX(const ROOT::Math::XYVector &lower, const ROOT::Math::XYVector &upper)
Simple fall back shrinking method using trivial division of the interval.
double computeExtremumXInHalfPeriod(int iHalfPeriod) const
Get the local extremum that is located in the half period indicated by the given index.
bool hasLargeSlope() const
Indicates that the slope is so large such that the function has no local extrema.
double computeRootInInterval(double lowerX, double upperX) const
Computes the solution in between the given x values. The x values are generally chosen consecutive lo...
static EIncDec getEIncDec(const ROOT::Math::XYVector &lower, const ROOT::Math::XYVector &upper)
Determines if the function is increasing or decreasing in the interval.
double getSlope() const
Getter for the slope.
double computeSmallestPositiveRoot(int maxIHalfPeriod=5) const
double computeRootForLargeSlope() const
Compute single solution in the case that fabs(slope) >= 1.
static bool changesSign(const ROOT::Math::XYVector &lower, const ROOT::Math::XYVector &upper)
Checks if the function changes sign in the interval.
double computeRootLargerThanExtemumInHalfPeriod(int iHalfPeriod) const
Computes the solution that is addressed by the given half period index.
static bool isBetween(const ROOT::Math::XYVector &lower, const ROOT::Math::XYVector &next, const ROOT::Math::XYVector &upper)
Check is next position is within the interval given by lower and upper.
static int getIPeriodFromIHalfPeriod(int iHalfPeriod)
Helper function to translate the index of the half period to index of the containing period.
double gradient(const double x) const
Interpreting as the function f this method calculates the gradient as need in Newtons algorithms.
double map(const double x) const
Interpreting as the function f this method carries out the translation from x to y coordinates.
double newtonX(const ROOT::Math::XYVector &pos) const
Shrinking method of the newton algorithm return the next candidate root.
static bool isConverged(const ROOT::Math::XYVector &lower, const ROOT::Math::XYVector &upper)
Check if the interval has shrunk close enough to the solution.
Abstract base class for different kinds of events.