10#include <tracking/trackingUtilities/numerics/Modulo.h>
12#include <tracking/trackingUtilities/geometry/Line2D.h>
14#include <tracking/trackingUtilities/numerics/EIncDec.h>
16#include <Math/Vector2D.h>
26 namespace TrackingUtilities {
54 SinEqLine(
const double slope,
const double intercept) :
61 double map(
const double x)
const
70 {
return floor(x / M_PI); }
89 double newtonX(
const ROOT::Math::XYVector& pos)
const;
92 static double secantX(
const ROOT::Math::XYVector& lower,
const ROOT::Math::XYVector& upper);
95 static double middleX(
const ROOT::Math::XYVector& lower,
const ROOT::Math::XYVector& upper);
98 static bool updateBounds(ROOT::Math::XYVector& lower, ROOT::Math::XYVector& upper,
const ROOT::Math::XYVector& next);
101 static bool isBetween(
const ROOT::Math::XYVector& lower,
const ROOT::Math::XYVector& next,
const ROOT::Math::XYVector& upper)
102 {
return lower.x() < next.x() and next.x() < upper.x(); }
105 static bool isConverged(
const ROOT::Math::XYVector& lower,
const ROOT::Math::XYVector& upper)
107 return fabs(lower.y()) < 10e-7 or fabs(upper.y()) < 10e-7;
111 static double getConvergedBound(
const ROOT::Math::XYVector& lower,
const ROOT::Math::XYVector& upper)
113 if (not std::isfinite(lower.y()) or not std::isfinite(upper.y())) {
117 if (fabs(lower.y()) <= fabs(upper.y())) {
121 if (fabs(lower.y()) > fabs(upper.y())) {
130 static bool changesSign(
const ROOT::Math::XYVector& lower,
const ROOT::Math::XYVector& upper)
131 {
return (lower.y() > 0 and upper.y() < 0) or (lower.y() < 0 and upper.y() > 0); }
134 static EIncDec
getEIncDec(
const ROOT::Math::XYVector& lower,
const ROOT::Math::XYVector& upper)
136 if (lower.y() < upper.y()) {
137 return EIncDec::c_Increasing;
138 }
else if (lower.y() > upper.y()) {
139 return EIncDec::c_Decreasing;
140 }
else if (lower.y() == upper.y()) {
141 return EIncDec::c_Constant;
143 return EIncDec::c_Invalid;
153 {
return isEven(iHalfPeriod) ? iHalfPeriod / 2 : (iHalfPeriod - 1) / 2; }
A two dimensional normal line.
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.
double m_intercept
Memory for the intercept.
SinEqLine(const double slope, const double intercept)
Constructor taking the slope and intercept of the line that shall be superimposed with the sin curve.
bool hasLargeSlope() const
Indicates that the slope is so large such that the function has no local extrema.
static int getIHalfPeriod(const double x)
Returns the half period index in which the x position is located.
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.
double m_slope
Memory for the slope.
SinEqLine()
Default constructor initializing slope and intercept to zero.
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.
SinEqLine(const Line2D &line2D)
Constructor taking the line that shall be superimposed with the sin curve.
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.