CMS 3D CMS Logo

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 7 of file Grid1D.h.

Member Typedef Documentation

◆ Scalar

typedef float Grid1D::Scalar

Definition at line 9 of file Grid1D.h.

Constructor & Destructor Documentation

◆ Grid1D() [1/2]

Grid1D::Grid1D ( )
inline

Definition at line 12 of file Grid1D.h.

12 {}

◆ Grid1D() [2/2]

Grid1D::Grid1D ( Scalar  lower,
Scalar  upper,
int  nodes 
)
inline

Definition at line 14 of file Grid1D.h.

References class-composition::nodes.

14  : lower_(lower), upper_(upper), edges_(nodes - 2) {
15  stepinv_ = (nodes - 1) / (upper - lower);
16  }
Scalar upper() const
Definition: Grid1D.h:20
int edges_
Definition: Grid1D.h:69
Scalar lower() const
Definition: Grid1D.h:19
Scalar stepinv_
Definition: Grid1D.h:66
int nodes() const
Definition: Grid1D.h:21
Scalar upper_
Definition: Grid1D.h:68
Scalar lower_
Definition: Grid1D.h:67

Member Function Documentation

◆ cells()

int Grid1D::cells ( ) const
inline

Definition at line 22 of file Grid1D.h.

22 { return edges_ + 1; }
int edges_
Definition: Grid1D.h:69

◆ closestNode()

Scalar Grid1D::closestNode ( Scalar  a) const
inline

Definition at line 46 of file Grid1D.h.

References a, b, HltBtagPostValidation_cff::c, f, SiStripPI::max, SiStripPI::min, class-composition::nodes, and createJobs::tmp.

46  {
47  Scalar b = (a - lower()) / step();
48  Scalar c = floor(b);
49  Scalar tmp = (b - c < 0.5) ? std::max(c, 0.f) : std::min(c + 1.f, static_cast<Scalar>(nodes() - 1));
50  return tmp * step() + lower();
51  }
float Scalar
Definition: Grid1D.h:9
Scalar lower() const
Definition: Grid1D.h:19
Scalar step() const
Definition: Grid1D.h:18
double f[11][100]
int nodes() const
Definition: Grid1D.h:21
double b
Definition: hdecay.h:118
double a
Definition: hdecay.h:119
tmp
align.sh
Definition: createJobs.py:716

◆ index() [1/2]

int Grid1D::index ( Scalar  a,
Scalar f 
) const
inline

Definition at line 29 of file Grid1D.h.

References a, b, and f.

Referenced by BeautifulSoup.PageElement::insert(), LinearGridInterpolator3D::interpolate(), and RectangularCylindricalMFGrid::uncheckedValueInTesla().

29  {
30  Scalar b;
31  f = modff((a - lower()) * stepinv_, &b);
32  return b;
33  }
float Scalar
Definition: Grid1D.h:9
Scalar lower() const
Definition: Grid1D.h:19
Scalar stepinv_
Definition: Grid1D.h:66
double f[11][100]
double b
Definition: hdecay.h:118
double a
Definition: hdecay.h:119

◆ index() [2/2]

int Grid1D::index ( Scalar  a) const
inline

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

Definition at line 54 of file Grid1D.h.

References a, hgcalTBTopologyTester_cfi::cells, SiStripPI::max, and SiStripPI::min.

Referenced by BeautifulSoup.PageElement::insert().

54  {
55  int ind = static_cast<int>((a - lower()) / step());
56  // FIXME: this causes an exception to be thrown later. Should be tested
57  // more carefully before release
58  // if (ind < -1 || ind > cells()) {
59  // std::cout << "**** ind = " << ind << " cells: " << cells() << std::endl;
60  // return -1;
61  // }
62  return std::max(0, std::min(cells() - 1, ind));
63  }
int cells() const
Definition: Grid1D.h:22
Scalar lower() const
Definition: Grid1D.h:19
Scalar step() const
Definition: Grid1D.h:18
double a
Definition: hdecay.h:119

◆ inRange()

bool Grid1D::inRange ( int  i) const
inline

Definition at line 26 of file Grid1D.h.

References mps_fire::i.

26 { return i >= 0 && i <= edges_; }
int edges_
Definition: Grid1D.h:69

◆ lower()

Scalar Grid1D::lower ( ) const
inline

◆ node()

Scalar Grid1D::node ( int  i) const
inline

Definition at line 24 of file Grid1D.h.

References mps_fire::i.

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

24 { return i * step() + lower(); }
Scalar lower() const
Definition: Grid1D.h:19
Scalar step() const
Definition: Grid1D.h:18

◆ nodes()

int Grid1D::nodes ( ) const
inline

◆ normalize()

void Grid1D::normalize ( int &  ind,
Scalar f 
) const
inline

Definition at line 36 of file Grid1D.h.

References f.

Referenced by LinearGridInterpolator3D::interpolate().

36  {
37  if (ind < 0) {
38  f -= ind;
39  ind = 0;
40  } else if (ind > edges_) {
41  f += ind - edges_;
42  ind = edges_;
43  }
44  }
int edges_
Definition: Grid1D.h:69
double f[11][100]

◆ step()

Scalar Grid1D::step ( ) const
inline

◆ upper()

Scalar Grid1D::upper ( ) const
inline

Member Data Documentation

◆ edges_

int Grid1D::edges_
private

Definition at line 69 of file Grid1D.h.

◆ lower_

Scalar Grid1D::lower_
private

Definition at line 67 of file Grid1D.h.

◆ stepinv_

Scalar Grid1D::stepinv_
private

Definition at line 66 of file Grid1D.h.

◆ upper_

Scalar Grid1D::upper_
private

Definition at line 68 of file Grid1D.h.