CMS 3D CMS Logo

Public Member Functions | Private Attributes

npstat::LinearMapper1d Class Reference

#include <LinearMapper1d.h>

List of all members.

Public Member Functions

double a () const
double b () const
LinearMapper1d inverse () const
 LinearMapper1d ()
 LinearMapper1d (const double x0, const double y0, const double x1, const double y1)
 LinearMapper1d (const double ca, const double cb)
double operator() (const double &x) const
LinearMapper1d operator* (const LinearMapper1d &r) const

Private Attributes

double a_
double b_

Detailed Description

Functor which performs linear mapping in 1-d

Definition at line 18 of file LinearMapper1d.h.


Constructor & Destructor Documentation

npstat::LinearMapper1d::LinearMapper1d ( ) [inline]

Default constructor builds an identity transformation

Definition at line 22 of file LinearMapper1d.h.

Referenced by inverse(), and operator*().

: a_(1.0), b_(0.0) {}
npstat::LinearMapper1d::LinearMapper1d ( const double  x0,
const double  y0,
const double  x1,
const double  y1 
) [inline]

Transform definition from two points. The point at x0 is mapped into y0, the point at x1 is mapped into y1. The linear transformation is thus fully defined.

Definition at line 29 of file LinearMapper1d.h.

References a_, and b_.

        {
            const double dx = x1 - x0;
            if (!dx) throw npstat::NpstatInvalidArgument(
                "In npstat::LinearMapper1d constructor: "
                "invalid arguments (x0 == x1)");
            a_ = (y1 - y0)/dx;
            b_ = ((y0 + y1) - a_*(x0 + x1))/2.0;
        }
npstat::LinearMapper1d::LinearMapper1d ( const double  ca,
const double  cb 
) [inline]

Explicitly provide the transform coefficients as in y = ca*x + cb

Definition at line 41 of file LinearMapper1d.h.

            : a_(ca), b_(cb) {}

Member Function Documentation

double npstat::LinearMapper1d::a ( ) const [inline]

Get the linear coefficient of the transform

Definition at line 48 of file LinearMapper1d.h.

References a_.

{return a_;}
double npstat::LinearMapper1d::b ( ) const [inline]

Get the transform constant

Definition at line 51 of file LinearMapper1d.h.

References b_.

{return b_;}
LinearMapper1d npstat::LinearMapper1d::inverse ( ) const [inline]

Create the inverse transform

Definition at line 54 of file LinearMapper1d.h.

References a_, b_, and LinearMapper1d().

Referenced by npstat::densityScanHistoMap().

        {
            if (!a_) throw npstat::NpstatInvalidArgument(
                "In npstat::LinearMapper1d::inverse: "
                "mapping is not invertible");
            return LinearMapper1d(1.0/a_, -b_/a_);
        }
double npstat::LinearMapper1d::operator() ( const double &  x) const [inline]

Perform the transformation

Definition at line 45 of file LinearMapper1d.h.

References a_, and b_.

{return a_*x + b_;}
LinearMapper1d npstat::LinearMapper1d::operator* ( const LinearMapper1d r) const [inline]

Sequence of two transforms: the one on the right is applied first

Definition at line 63 of file LinearMapper1d.h.

References a_, b_, and LinearMapper1d().

        {
            return LinearMapper1d(a_*r.a_, a_*r.b_ + b_);
        }

Member Data Documentation

double npstat::LinearMapper1d::a_ [private]

Definition at line 69 of file LinearMapper1d.h.

Referenced by a(), inverse(), LinearMapper1d(), operator()(), and operator*().

double npstat::LinearMapper1d::b_ [private]

Definition at line 70 of file LinearMapper1d.h.

Referenced by b(), inverse(), LinearMapper1d(), operator()(), and operator*().