Skip to main content

LineFit

Struct LineFit 

Source
pub struct LineFit {
Show 14 fields pub x0: f32, pub y0: f32, pub z0: f32, pub tx: f32, pub ty: f32, pub x0_err: f32, pub y0_err: f32, pub tx_err: f32, pub ty_err: f32, pub chi2: f32, pub cost: f32, pub ndof: u32, pub npoints: u32, pub status: FitStatus,
}
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: f32

anchor point

§y0: f32§z0: f32§tx: f32

slopes dx/dz and dy/dz

§ty: f32§x0_err: f32

parameter errors (from the analytic chi2 fit)

§y0_err: f32§tx_err: f32§ty_err: f32§chi2: f32

sum of the squared, normalized residuals

§cost: f32

value of the minimized cost function. For the analytic fit this is the same as chi2

§ndof: u32

2*npoints - 4

§npoints: u32§status: FitStatus

Implementations§

Source§

impl LineFit

Source

pub fn new() -> Self

Source

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
Source

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.

Source

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).

  1. 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.
  2. All hits within the cylinder around the line are accepted, the others rejected.
  3. The line is fitted to the accepted hits.
  4. The radius of the cylinder shrinks, if this is configured (LineFitCleaning::final_radius).
  5. 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
Source

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).

Source

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.

Source

pub fn distance(&self, x: f32, y: f32, z: f32) -> f32

Distance of a point from the line (in the units of the coordinates)

Source

pub fn eval(&self, z: f32) -> (f32, f32, f32)

Evaluate the line at a given z

Source

pub fn direction(&self) -> (f32, f32, f32)

Unit direction vector of the line, pointing towards +z

Source

pub fn cos_theta(&self) -> f32

Cosine of the zenith angle of the line

Source

pub fn line3d_params(&self) -> (f32, f32, f32, f32, f32, f32)

The parameters of the line in the form as expected by line3d (x_a, y_a, z_a, dx, dy, dz)

Trait Implementations§

Source§

impl Clone for LineFit

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for LineFit

Source§

impl Debug for LineFit

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for LineFit

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for LineFit

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for LineFit

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> AggregateExpressionMethods for T

Source§

fn aggregate_distinct(self) -> Self::Output
where Self: DistinctDsl,

DISTINCT modifier for aggregate functions Read more
Source§

fn aggregate_all(self) -> Self::Output
where Self: AllDsl,

ALL modifier for aggregate functions Read more
Source§

fn aggregate_filter<P>(self, f: P) -> Self::Output
where P: AsExpression<Bool>, Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,

Add an aggregate function filter Read more
Source§

fn aggregate_order<O>(self, o: O) -> Self::Output
where Self: OrderAggregateDsl<O>,

Add an aggregate function order Read more
Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts 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>

Converts 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)

Converts &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)

Converts &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
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> IntoSql for T

Source§

fn into_sql<T>(self) -> Self::Expression

Convert self to an expression for Diesel’s query builder. Read more
Source§

fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
where &'a Self: AsExpression<T>, T: SqlType + TypedExpressionType,

Convert &self to an expression for Diesel’s query builder. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

Source§

impl<T> SendAlias for T

Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> SyncAlias for T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WindowExpressionMethods for T

Source§

fn over(self) -> Self::Output
where Self: OverDsl,

Turn a function call into a window function call Read more
Source§

fn window_filter<P>(self, f: P) -> Self::Output
where P: AsExpression<Bool>, Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,

Add a filter to the current window function Read more
Source§

fn partition_by<E>(self, expr: E) -> Self::Output
where Self: PartitionByDsl<E>,

Add a partition clause to the current window function Read more
Source§

fn window_order<E>(self, expr: E) -> Self::Output
where Self: OrderWindowDsl<E>,

Add a order clause to the current window function Read more
Source§

fn frame_by<E>(self, expr: E) -> Self::Output
where Self: FrameDsl<E>,

Add a frame clause to the current window function Read more