CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
npstat::Interval< Numeric > Class Template Reference

#include <Interval.h>

Public Member Functions

Intervalexpand (double r)
 
void getBounds (Numeric *pmin, Numeric *pmax) const
 
 Interval ()
 
 Interval (const Numeric max)
 
 Interval (const Numeric min, const Numeric max, const bool swapIfOutOfOrder=false)
 
bool isInside (const Numeric value) const
 
bool isInsideLower (const Numeric value) const
 
bool isInsideUpper (const Numeric value) const
 
bool isInsideWithBounds (const Numeric value) const
 
Numeric length () const
 
template<typename Num2 >
void linearMap (const Interval< Num2 > &r, double *a, double *b) const
 
const Numeric max () const
 
Numeric midpoint () const
 
const Numeric min () const
 
IntervalmoveMidpointTo0 ()
 
Intervaloperator*= (double r)
 
Intervaloperator+= (const Numeric value)
 
Intervaloperator-= (const Numeric value)
 
Intervaloperator/= (double r)
 
Interval overlap (const Interval &r) const
 
double overlapFraction (const Interval &r) const
 
Numeric overlapLength (const Interval &r) const
 
void setBounds (const Numeric minval, const Numeric maxval, const bool swapIfOutOfOrder=false)
 
void setMax (const Numeric value)
 
void setMin (const Numeric value)
 

Private Attributes

Numeric max_
 
Numeric min_
 

Detailed Description

template<typename Numeric>
class npstat::Interval< Numeric >

Representation of 1-d intervals. The following invariant is maintained: min() will not exceed max().

See BoxND class for rectangles, boxes, and hyperboxes.

Definition at line 25 of file Interval.h.

Constructor & Destructor Documentation

◆ Interval() [1/3]

template<typename Numeric>
npstat::Interval< Numeric >::Interval ( )
inline

Both lower and upper interval bounds are set to Numeric()

Definition at line 28 of file Interval.h.

28 : min_(Numeric()), max_(Numeric()) {}

◆ Interval() [2/3]

template<typename Numeric>
npstat::Interval< Numeric >::Interval ( const Numeric  max)
inlineexplicit

Minimum is set to Numeric(), maximum to the given argument. An exception is thrown if the argument is smaller than Numeric().

Definition at line 34 of file Interval.h.

34  : min_(Numeric()), max_(max) {
35  if (min_ > max_)
36  throw npstat::NpstatInvalidArgument("In npstat::Interval constructor: invalid limits");
37  }

References npstat::Interval< Numeric >::max_, and npstat::Interval< Numeric >::min_.

◆ Interval() [3/3]

template<typename Numeric>
npstat::Interval< Numeric >::Interval ( const Numeric  min,
const Numeric  max,
const bool  swapIfOutOfOrder = false 
)
inline

Constructor from both bounds. Set "swapIfOutOfOrder" argument to "true" if the minimum can be larger than the maximum (in this case the bounds will be swapped internally).

Definition at line 44 of file Interval.h.

44  : min_(min), max_(max) {
45  if (min_ > max_) {
46  if (swapIfOutOfOrder)
48  else
49  throw npstat::NpstatInvalidArgument("In npstat::Interval constructor: invalid limits");
50  }
51  }

References npstat::Interval< Numeric >::max_, npstat::Interval< Numeric >::min_, and std::swap().

Member Function Documentation

◆ expand()

template<typename Numeric >
Interval< Numeric > & npstat::Interval< Numeric >::expand ( double  r)
inline

Scaling the bounds by a constant in such a way that the midpoint remains unchanged

Definition at line 230 of file Interval.h.

230  {
231  const double r = fabs(ir);
232  if (r != 1.0) {
233  const Numeric center(static_cast<Numeric>((max_ + min_) * 0.5));
234  min_ = center + (min_ - center) * r;
235  max_ = center + (max_ - center) * r;
236  }
237  return *this;
238  }

References alignCSCRings::r.

◆ getBounds()

template<typename Numeric>
void npstat::Interval< Numeric >::getBounds ( Numeric *  pmin,
Numeric *  pmax 
) const
inline

Return both bounds

Definition at line 84 of file Interval.h.

84  {
85  *pmin = min_;
86  *pmax = max_;
87  }

References npstat::Interval< Numeric >::max_, npstat::Interval< Numeric >::min_, and trackingParticleMuon_cfi::pmin.

◆ isInside()

template<typename Numeric>
bool npstat::Interval< Numeric >::isInside ( const Numeric  value) const
inline

Is the point completely inside the interval (and does not coincide with any bound)?

Definition at line 108 of file Interval.h.

108 { return value > min_ && value < max_; }

References npstat::Interval< Numeric >::max_, and npstat::Interval< Numeric >::min_.

◆ isInsideLower()

template<typename Numeric>
bool npstat::Interval< Numeric >::isInsideLower ( const Numeric  value) const
inline

Is the point inside the interval or on the lower boundary?

Definition at line 96 of file Interval.h.

96 { return value >= min_ && value < max_; }

References npstat::Interval< Numeric >::max_, and npstat::Interval< Numeric >::min_.

◆ isInsideUpper()

template<typename Numeric>
bool npstat::Interval< Numeric >::isInsideUpper ( const Numeric  value) const
inline

Is the point inside the interval or on the upper boundary?

Definition at line 99 of file Interval.h.

99 { return value > min_ && value <= max_; }

References npstat::Interval< Numeric >::max_, and npstat::Interval< Numeric >::min_.

◆ isInsideWithBounds()

template<typename Numeric>
bool npstat::Interval< Numeric >::isInsideWithBounds ( const Numeric  value) const
inline

Is the point inside the interval or on one of the boundaries?

Definition at line 102 of file Interval.h.

102 { return value >= min_ && value <= max_; }

References npstat::Interval< Numeric >::max_, and npstat::Interval< Numeric >::min_.

◆ length()

template<typename Numeric>
Numeric npstat::Interval< Numeric >::length ( ) const
inline

Interval length

Definition at line 90 of file Interval.h.

90 { return max_ - min_; }

References npstat::Interval< Numeric >::max_, and npstat::Interval< Numeric >::min_.

◆ linearMap()

template<typename Numeric >
template<typename Num2 >
void npstat::Interval< Numeric >::linearMap ( const Interval< Num2 > &  r,
double *  a,
double *  b 
) const

Derive the coefficients a and b such that the linear mapping y = a*x + b maps the lower limit of this interval into the lower limit of the argument interval and the upper limit of this interval into the upper limit of the argument interval

Definition at line 267 of file Interval.h.

267  {
268  if (max_ == min_)
269  throw npstat::NpstatDomainError("In npstat::Interval::linearMap: zero length interval");
270  assert(a);
271  assert(b);
272  const Num2 rmax(r.max());
273  const Num2 rmin(r.min());
274  *a = static_cast<double>((rmax - rmin) * 1.0 / (max_ - min_));
275  *b = static_cast<double>((rmax + rmin) - *a * (max_ + min_)) / 2.0;
276  }

References a, cms::cuda::assert(), b, and alignCSCRings::r.

◆ max()

template<typename Numeric>
const Numeric npstat::Interval< Numeric >::max ( ) const
inline

◆ midpoint()

template<typename Numeric>
Numeric npstat::Interval< Numeric >::midpoint ( ) const
inline

The middle point of the interval

Definition at line 93 of file Interval.h.

93 { return static_cast<Numeric>((max_ + min_) * 0.5); }

References npstat::Interval< Numeric >::max_, and npstat::Interval< Numeric >::min_.

◆ min()

template<typename Numeric>
const Numeric npstat::Interval< Numeric >::min ( ) const
inline

◆ moveMidpointTo0()

template<typename Numeric >
Interval< Numeric > & npstat::Interval< Numeric >::moveMidpointTo0 ( )
inline

Move the interval so that the midpoint ends up at 0

Definition at line 222 of file Interval.h.

222  {
223  const Numeric len = max_ - min_;
224  max_ = len / static_cast<Numeric>(2);
225  min_ = -max_;
226  return *this;
227  }

◆ operator*=()

template<typename Numeric >
Interval< Numeric > & npstat::Interval< Numeric >::operator*= ( double  r)
inline

Scaling of both the minimum and the maximum by a constant. Minimum and maximum will be swapped internally in case the constant is negative.

Definition at line 213 of file Interval.h.

213  {
214  min_ *= r;
215  max_ *= r;
216  if (max_ < min_)
217  std::swap(min_, max_);
218  return *this;
219  }

References alignCSCRings::r, and std::swap().

◆ operator+=()

template<typename Numeric >
Interval< Numeric > & npstat::Interval< Numeric >::operator+= ( const Numeric  value)
inline

Shift both interval bounds by a constant

Definition at line 252 of file Interval.h.

252  {
253  min_ += r;
254  max_ += r;
255  return *this;
256  }

References alignCSCRings::r.

◆ operator-=()

template<typename Numeric >
Interval< Numeric > & npstat::Interval< Numeric >::operator-= ( const Numeric  value)
inline

Definition at line 259 of file Interval.h.

259  {
260  min_ -= r;
261  max_ -= r;
262  return *this;
263  }

References alignCSCRings::r.

◆ operator/=()

template<typename Numeric >
Interval< Numeric > & npstat::Interval< Numeric >::operator/= ( double  r)
inline

Definition at line 241 of file Interval.h.

241  {
242  if (!r)
243  throw npstat::NpstatDomainError("In npstat::Interval::operator/=: division by zero");
244  min_ /= r;
245  max_ /= r;
246  if (max_ < min_)
247  std::swap(min_, max_);
248  return *this;
249  }

References alignCSCRings::r, and std::swap().

◆ overlap()

template<typename Numeric >
Interval< Numeric > npstat::Interval< Numeric >::overlap ( const Interval< Numeric > &  r) const
inline

The following function returns default-constructed empty interval in case this interval and the argument interval do not overlap

Definition at line 179 of file Interval.h.

179  {
180  Interval<Numeric> over;
181  if (max_ == r.min_)
182  over.setBounds(max_, max_);
183  else if (r.max_ == min_)
184  over.setBounds(min_, min_);
185  else if (max_ > r.min_ && r.max_ > min_) {
186  over.min_ = min_ < r.min_ ? r.min_ : min_;
187  over.max_ = max_ < r.max_ ? max_ : r.max_;
188  }
189  return over;
190  }

References npstat::Interval< Numeric >::max_, npstat::Interval< Numeric >::min_, alignCSCRings::r, and npstat::Interval< Numeric >::setBounds().

◆ overlapFraction()

template<typename Numeric >
double npstat::Interval< Numeric >::overlapFraction ( const Interval< Numeric > &  r) const
inline

Same as overlapLength(r)/length() but a tad faster

Definition at line 203 of file Interval.h.

203  {
204  if (max_ > r.min_ && r.max_ > min_) {
205  const Numeric mn = min_ < r.min_ ? r.min_ : min_;
206  const Numeric mx = max_ < r.max_ ? max_ : r.max_;
207  return (mx - mn) * 1.0 / (max_ - min_);
208  } else
209  return 0.0;
210  }

References alignCSCRings::r.

◆ overlapLength()

template<typename Numeric >
Numeric npstat::Interval< Numeric >::overlapLength ( const Interval< Numeric > &  r) const
inline

Same as overlap.length() but a tad faster

Definition at line 193 of file Interval.h.

193  {
194  if (max_ > r.min_ && r.max_ > min_) {
195  const Numeric mn = min_ < r.min_ ? r.min_ : min_;
196  const Numeric mx = max_ < r.max_ ? max_ : r.max_;
197  return mx - mn;
198  } else
199  return Numeric();
200  }

References alignCSCRings::r.

◆ setBounds()

template<typename Numeric>
void npstat::Interval< Numeric >::setBounds ( const Numeric  minval,
const Numeric  maxval,
const bool  swapIfOutOfOrder = false 
)
inline

Set both interval bounds

Definition at line 68 of file Interval.h.

68  {
69  if (maxval < minval && !swapIfOutOfOrder)
70  throw npstat::NpstatInvalidArgument("In npstat::Interval::setBounds: invalid limits");
71  min_ = minval;
72  max_ = maxval;
73  if (swapIfOutOfOrder && min_ > max_)
75  }

References npstat::Interval< Numeric >::max_, npstat::Interval< Numeric >::min_, and std::swap().

Referenced by npstat::Interval< Numeric >::overlap().

◆ setMax()

template<typename Numeric>
void npstat::Interval< Numeric >::setMax ( const Numeric  value)
inline

Set the upper interval bound

Definition at line 61 of file Interval.h.

61  {
62  if (value < min_)
63  throw npstat::NpstatInvalidArgument("In npstat::Interval::setMax: argument below min");
64  max_ = value;
65  }

References npstat::Interval< Numeric >::max_, npstat::Interval< Numeric >::min_, and relativeConstraints::value.

◆ setMin()

template<typename Numeric>
void npstat::Interval< Numeric >::setMin ( const Numeric  value)
inline

Set the lower interval bound

Definition at line 54 of file Interval.h.

54  {
55  if (value > max_)
56  throw npstat::NpstatInvalidArgument("In npstat::Interval::setMin: argument above max");
57  min_ = value;
58  }

References npstat::Interval< Numeric >::max_, npstat::Interval< Numeric >::min_, and relativeConstraints::value.

Member Data Documentation

◆ max_

template<typename Numeric>
Numeric npstat::Interval< Numeric >::max_
private

◆ min_

template<typename Numeric>
Numeric npstat::Interval< Numeric >::min_
private
npstat::Interval::min
const Numeric min() const
Definition: Interval.h:78
cms::cuda::assert
assert(be >=bs)
std::swap
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Definition: DataFrameContainer.h:209
npstat::NpstatInvalidArgument
Definition: NpstatException.h:38
b
double b
Definition: hdecay.h:118
a
double a
Definition: hdecay.h:119
value
Definition: value.py:1
npstat::NpstatDomainError
Definition: NpstatException.h:54
npstat::Interval::max
const Numeric max() const
Definition: Interval.h:81
alignCSCRings.r
r
Definition: alignCSCRings.py:93
npstat::Interval::min_
Numeric min_
Definition: Interval.h:160
relativeConstraints.value
value
Definition: relativeConstraints.py:53
npstat::Interval::max_
Numeric max_
Definition: Interval.h:161
trackingParticleMuon_cfi.pmin
pmin
Definition: trackingParticleMuon_cfi.py:10