pub struct LineFit {}Expand description
A straight line through a pointcloud, parametrized in z, since that is our best constrained value
x(z) = x0 + tx * (z - z0) y(z) = y0 + ty * (z - z0)
The anchor z0 is fixed to the mean z of the hits, so the line has 4 free parameters (x0, y0, tx, ty). The 6 parameter model of line3d is degenerate (the anchor can slide along the line and the direction vector can be scaled), which only introduces flat directions for a minimizer.
For the standard chi2 (sum of squared, normalized residuals) the fit decouples into two independent weighted linear regressions x(z) and y(z), which can be solved analytically (LineFit::fit).
The python version minimizes the sum of the normalized distances instead (sum of sqrt(rx^2/sx^2 + ry^2/sy^2)), which is less sensitive to outliers, but has no closed form solution. This is available through LineFit::fit_sum_of_distances, which uses the analytic solution as a seed for a Nelder-Mead minimization.
Fields§
§x0: f32anchor point
y0: f32§z0: f32§tx: f32slopes dx/dz and dy/dz
ty: f32§x0_err: f32parameter errors (from the analytic chi2 fit)
y0_err: f32§tx_err: f32§ty_err: f32§chi2: f32sum of the squared, normalized residuals
cost: f32value of the minimized cost function. For the analytic fit this is the same as chi2
ndof: u322*npoints - 4
npoints: u32§status: FitStatusImplementations§
Source§impl LineFit
impl LineFit
pub fn new() -> Self
Sourcepub fn fit(
xs: &[f32],
ys: &[f32],
zs: &[f32],
errs_x: Option<&[f32]>,
errs_y: Option<&[f32]>,
) -> Option<Self>
pub fn fit( xs: &[f32], ys: &[f32], zs: &[f32], errs_x: Option<&[f32]>, errs_y: Option<&[f32]>, ) -> Option<Self>
Analytic, weighted least squares fit of a straight line to the given points.
Returns None if there are less than 2 points, or all points have the same z (the line can not be described as a function of z)
§Arguments:
- errs_x, errs_y : errors on x and y for each point. If None, LINEFIT_DEFAULT_ERR_XY will be used
Sourcepub fn fit_sum_of_distances(
xs: &[f32],
ys: &[f32],
zs: &[f32],
errs_x: Option<&[f32]>,
errs_y: Option<&[f32]>,
) -> Option<Self>
pub fn fit_sum_of_distances( xs: &[f32], ys: &[f32], zs: &[f32], errs_x: Option<&[f32]>, errs_y: Option<&[f32]>, ) -> Option<Self>
Fit a straight line to the given points by minimizing the sum of the normalized distances, as done in the python version of the linefit.
The analytic chi2 fit is used as a seed for the minimization with the Nelder-Mead algorithm. The parameter errors are the ones of the seed.
Sourcepub fn fit_cleaned(
xs: &[f32],
ys: &[f32],
zs: &[f32],
ts: &[f32],
errs_x: Option<&[f32]>,
errs_y: Option<&[f32]>,
cleaning: &LineFitCleaning,
) -> Option<CleanedLineFit>
pub fn fit_cleaned( xs: &[f32], ys: &[f32], zs: &[f32], ts: &[f32], errs_x: Option<&[f32]>, errs_y: Option<&[f32]>, cleaning: &LineFitCleaning, ) -> Option<CleanedLineFit>
Fit a straight line, using only hits within a cylinder around the line (LineFitCleaning::cylinder_radius).
The hits have to be ordered in time, with the TOF hits first. Tracker hits do not have a time (NaN).
- The first line is constructed through the first two hits with a time. These are not necessarily one outer and one inner TOF hit, fit_cleaned_event makes sure of that, using the paddle ids.
- All hits within the cylinder around the line are accepted, the others rejected.
- The line is fitted to the accepted hits.
- The radius of the cylinder shrinks, if this is configured (LineFitCleaning::final_radius).
- Steps 2) to 4) are repeated with the fitted line until the final radius is reached and the accepted hits do not change anymore, or LineFitCleaning::max_iterations is reached.
If a fit after the first one fails (e.g. less than 2 hits are accepted with a smaller radius), the fit of the iteration before is returned, with its accepted hits and the status FitStatus::FallbackPreviousIteration.
Returns None if there are less than 2 hits with a time, the first two of them are at the same position, or the first fit fails (less than 2 hits are accepted or they can not be fit).
§Arguments:
- ts : hit times, NaN for tracker hits
- errs_x, errs_y : errors on x and y for each point. If None, LINEFIT_DEFAULT_ERR_XY will be used
Sourcepub fn fit_cleaned_event(
event: &TelemetryEvent,
cleaning: &LineFitCleaning,
) -> Option<CleanedLineFit>
pub fn fit_cleaned_event( event: &TelemetryEvent, cleaning: &LineFitCleaning, ) -> Option<CleanedLineFit>
Fit a straight line to the hits of an event, using only hits within a cylinder around the line, see fit_cleaned.
The first line is constructed through the first outer and the first inner TOF hit (in time), the inner TOF being the paddles up to TOF_INNER_MAX_PADDLE_ID.
The hits are the TOF hits (in the order of event.tof_event.hits), followed by the tracker hits (in the order of event.tracker_hits), so for the n TOF hits, accepted[k] is the TOF hit k for k < n and the tracker hit k - n otherwise. Tracker hits without coordinates are never accepted.
Returns None if the TOF paddle information has not been set for the event (TofEvent::set_paddles), there is no outer or no inner TOF hit with a time, or the fit fails (see fit_cleaned).
Sourcepub fn fit_cleaned_with_seed(
xs: &[f32],
ys: &[f32],
zs: &[f32],
errs_x: Option<&[f32]>,
errs_y: Option<&[f32]>,
seed: (usize, usize),
cleaning: &LineFitCleaning,
) -> Option<CleanedLineFit>
pub fn fit_cleaned_with_seed( xs: &[f32], ys: &[f32], zs: &[f32], errs_x: Option<&[f32]>, errs_y: Option<&[f32]>, seed: (usize, usize), cleaning: &LineFitCleaning, ) -> Option<CleanedLineFit>
Fit a straight line, using only hits within a cylinder around the line, see fit_cleaned. The first line is constructed through the two hits with the indices given by seed.
Sourcepub fn distance(&self, x: f32, y: f32, z: f32) -> f32
pub fn distance(&self, x: f32, y: f32, z: f32) -> f32
Distance of a point from the line (in the units of the coordinates)
Trait Implementations§
impl Copy for LineFit
impl StructuralPartialEq for LineFit
Auto Trait Implementations§
impl Freeze for LineFit
impl RefUnwindSafe for LineFit
impl Send for LineFit
impl Sync for LineFit
impl Unpin for LineFit
impl UnsafeUnpin for LineFit
impl UnwindSafe for LineFit
Blanket Implementations§
Source§impl<T> AggregateExpressionMethods for T
impl<T> AggregateExpressionMethods for T
Source§fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
DISTINCT modifier for aggregate functions Read moreSource§fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
ALL modifier for aggregate functions Read moreSource§fn aggregate_filter<P>(self, f: P) -> Self::Output
fn aggregate_filter<P>(self, f: P) -> Self::Output
Source§fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoSql for T
impl<T> IntoSql for T
Source§fn into_sql<T>(self) -> Self::Expression
fn into_sql<T>(self) -> Self::Expression
self to an expression for Diesel’s query builder. Read moreSource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
&self to an expression for Diesel’s query builder. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
impl<T> Scalar for T
impl<T> SendAlias for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.