CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Types | Public Member Functions | Private Attributes
Grid1D Class Reference

#include <Grid1D.h>

Public Types

typedef float Scalar
 

Public Member Functions

int cells () const
 
Scalar closestNode (Scalar a) const
 
 Grid1D ()
 
 Grid1D (Scalar lower, Scalar upper, int nodes)
 
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. More...
 
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.

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

Definition at line 14 of file Grid1D.h.

References stepinv_.

14  :
16  stepinv_ = (nodes-1)/(upper - lower);
17  }
int edges_
Definition: Grid1D.h:77
Scalar stepinv_
Definition: Grid1D.h:74
int nodes() const
Definition: Grid1D.h:23
Scalar lower() const
Definition: Grid1D.h:21
Scalar upper_
Definition: Grid1D.h:76
Scalar lower_
Definition: Grid1D.h:75
Scalar upper() const
Definition: Grid1D.h:22

Member Function Documentation

int Grid1D::cells ( ) const
inline

Definition at line 24 of file Grid1D.h.

References edges_.

Referenced by index().

24 {return edges_+1;}
int edges_
Definition: Grid1D.h:77
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.

52  {
53  Scalar b = (a-lower())/step();
54  Scalar c = floor(b);
55  Scalar tmp = (b-c < 0.5) ? std::max(c,0.f) : std::min(c+1.f,static_cast<Scalar>(nodes()-1));
56  return tmp*step()+lower();
57  }
Scalar step() const
Definition: Grid1D.h:20
float Scalar
Definition: Grid1D.h:9
#define min(a, b)
Definition: mlp_lapack.h:161
const T & max(const T &a, const T &b)
int nodes() const
Definition: Grid1D.h:23
double f[11][100]
Scalar lower() const
Definition: Grid1D.h:21
double b
Definition: hdecay.h:120
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
double a
Definition: hdecay.h:121
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().

33  {
34  Scalar b;
35  f = modff((a-lower())*stepinv_, &b);
36  return b;
37  }
float Scalar
Definition: Grid1D.h:9
Scalar stepinv_
Definition: Grid1D.h:74
double f[11][100]
Scalar lower() const
Definition: Grid1D.h:21
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
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().

60  {
61  int ind = static_cast<int>((a-lower())/step());
62  // FIXME: this causes an exception to be thrown later. Should be tested
63  // more carefully before release
64  // if (ind < -1 || ind > cells()) {
65  // std::cout << "**** ind = " << ind << " cells: " << cells() << std::endl;
66  // return -1;
67  // }
68  return std::max(0, std::min( cells()-1, ind));
69  }
Scalar step() const
Definition: Grid1D.h:20
#define min(a, b)
Definition: mlp_lapack.h:161
const T & max(const T &a, const T &b)
int cells() const
Definition: Grid1D.h:24
Scalar lower() const
Definition: Grid1D.h:21
double a
Definition: hdecay.h:121
bool Grid1D::inRange ( int  i) const
inline

Definition at line 28 of file Grid1D.h.

References edges_.

28  {
29  return i>=0 && i<=edges_;
30  }
int i
Definition: DBlmapReader.cc:9
int edges_
Definition: Grid1D.h:77
Scalar Grid1D::lower ( ) const
inline
Scalar Grid1D::node ( int  i) const
inline

Definition at line 26 of file Grid1D.h.

References lower(), and step().

Referenced by Grid3D::dump(), LinearGridInterpolator3D::interpolate(), MFGrid3D::nodePosition(), and RectangularCylindricalMFGrid::uncheckedValueInTesla().

26 { return i*step() + lower();}
Scalar step() const
Definition: Grid1D.h:20
int i
Definition: DBlmapReader.cc:9
Scalar lower() const
Definition: Grid1D.h:21
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().

40  {
41  if (ind<0) {
42  f -= ind;
43  ind = 0;
44  }
45  else if (ind>edges_) {
46  f += ind-edges_;
47  ind = edges_;
48  }
49  }
int edges_
Definition: Grid1D.h:77
double f[11][100]
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().

Scalar Grid1D::lower_
private

Definition at line 75 of file Grid1D.h.

Referenced by lower().

Scalar Grid1D::stepinv_
private

Definition at line 74 of file Grid1D.h.

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

Scalar Grid1D::upper_
private

Definition at line 76 of file Grid1D.h.

Referenced by upper().