CMS 3D CMS Logo

Public Types | Public Member Functions | Private Attributes

Grid1D Class Reference

#include <Grid1D.h>

List of all members.

Public Types

typedef float Scalar

Public Member Functions

int cells () const
Scalar closestNode (Scalar a) const
 Grid1D (Scalar lower, Scalar upper, int nodes)
 Grid1D ()
int index (Scalar a, Scalar &f) const
int index (Scalar a) const
 returns valid index, or -1 if the value is outside range +/- one cell.
bool inRange (int i) const
Scalar lower () const
Scalar node (int i) const
int nodes () const
void normalize (int &ind, Scalar &f) const
Scalar step () const
Scalar upper () const

Private Attributes

int edges_
Scalar lower_
Scalar stepinv_
Scalar upper_

Detailed Description

Definition at line 6 of file Grid1D.h.


Member Typedef Documentation

typedef float Grid1D::Scalar

Definition at line 9 of file Grid1D.h.


Constructor & Destructor Documentation

Grid1D::Grid1D ( ) [inline]

Definition at line 12 of file Grid1D.h.

{}
Grid1D::Grid1D ( Scalar  lower,
Scalar  upper,
int  nodes 
) [inline]

Definition at line 14 of file Grid1D.h.

References stepinv_.


Member Function Documentation

int Grid1D::cells ( ) const [inline]

Definition at line 24 of file Grid1D.h.

References edges_.

Referenced by index().

{return  edges_+1;}
Scalar Grid1D::closestNode ( Scalar  a) const [inline]

Definition at line 52 of file Grid1D.h.

References b, trackerHits::c, f, lower(), max(), min, nodes(), step(), and tmp.

                                      {
    Scalar b = (a-lower())/step();
    Scalar c = floor(b);
    Scalar tmp = (b-c < 0.5) ? std::max(c,0.f) : std::min(c+1.f,static_cast<Scalar>(nodes()-1));
    return tmp*step()+lower();
  }
int Grid1D::index ( Scalar  a) const [inline]

returns valid index, or -1 if the value is outside range +/- one cell.

Definition at line 60 of file Grid1D.h.

References cells(), lower(), max(), min, and step().

                             {
    int ind = static_cast<int>((a-lower())/step());
    // FIXME: this causes an exception to be thrown later. Should be tested
    // more carefully before release
    //  if (ind < -1 || ind > cells()) {
    //     std::cout << "**** ind = " << ind << " cells: " << cells() << std::endl;
    //    return -1;
    //  }
    return std::max(0, std::min( cells()-1, ind));
  }
int Grid1D::index ( Scalar  a,
Scalar f 
) const [inline]

Definition at line 33 of file Grid1D.h.

References b, lower(), and stepinv_.

Referenced by MFGrid3D::index(), LinearGridInterpolator3D::interpolate(), and RectangularCylindricalMFGrid::uncheckedValueInTesla().

                                        {
    Scalar b;
    f = modff((a-lower())*stepinv_, &b);
    return b;
  }
bool Grid1D::inRange ( int  i) const [inline]

Definition at line 28 of file Grid1D.h.

References edges_.

                            {
    return i>=0 && i<=edges_;
  }
Scalar Grid1D::lower ( ) const [inline]
Scalar Grid1D::node ( int  i) const [inline]
int Grid1D::nodes ( ) const [inline]
void Grid1D::normalize ( int &  ind,
Scalar f 
) const [inline]

Definition at line 40 of file Grid1D.h.

References edges_.

Referenced by LinearGridInterpolator3D::interpolate().

                                               {
    if (ind<0) {
      f -= ind;
      ind = 0;
    }
    else if (ind>edges_) {
      f += ind-edges_;
      ind = edges_;
    }
  }
Scalar Grid1D::step ( ) const [inline]
Scalar Grid1D::upper ( ) const [inline]

Member Data Documentation

int Grid1D::edges_ [private]

Definition at line 77 of file Grid1D.h.

Referenced by cells(), inRange(), nodes(), and normalize().

Definition at line 75 of file Grid1D.h.

Referenced by lower().

Definition at line 74 of file Grid1D.h.

Referenced by Grid1D(), index(), and step().

Definition at line 76 of file Grid1D.h.

Referenced by upper().