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

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 ()
 
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)
 
Intervaloperator*= (double r)
 
Intervaloperator/= (double r)
 
Intervaloperator+= (const Numeric value)
 
Intervaloperator-= (const Numeric value)
 
Intervalexpand (double r)
 

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

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

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

Definition at line 29 of file Interval.h.

29 : min_(Numeric()), max_(Numeric()) {}
Numeric min_
Definition: Interval.h:176
Numeric max_
Definition: Interval.h:177
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 35 of file Interval.h.

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

36  : min_(Numeric()), max_(max)
37  {
39  "In npstat::Interval constructor: invalid limits");
40  }
Numeric min_
Definition: Interval.h:176
const Numeric max() const
Definition: Interval.h:94
Numeric max_
Definition: Interval.h:177
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 47 of file Interval.h.

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

49  : min_(min), max_(max)
50  {
51  if (min_ > max_)
52  {
53  if (swapIfOutOfOrder)
55  else
57  "In npstat::Interval constructor: invalid limits");
58  }
59  }
Numeric min_
Definition: Interval.h:176
const Numeric max() const
Definition: Interval.h:94
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Numeric max_
Definition: Interval.h:177
const Numeric min() const
Definition: Interval.h:91

Member Function Documentation

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

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

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

258  {
259  const double r = fabs(ir);
260  if (r != 1.0)
261  {
262  const Numeric center(static_cast<Numeric>((max_ + min_)*0.5));
263  min_ = center + (min_ - center)*r;
264  max_ = center + (max_ - center)*r;
265  }
266  return *this;
267  }
Numeric min_
Definition: Interval.h:176
Numeric max_
Definition: Interval.h:177
template<typename Numeric>
void npstat::Interval< Numeric >::getBounds ( Numeric *  pmin,
Numeric *  pmax 
) const
inline

Return both bounds

Definition at line 97 of file Interval.h.

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

98  {*pmin = min_; *pmax = max_;}
Numeric min_
Definition: Interval.h:176
Numeric max_
Definition: Interval.h:177
template<typename Numeric>
bool npstat::Interval< Numeric >::isInside ( const Numeric  value) const
inline
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 108 of file Interval.h.

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

109  {return value >= min_ && value < max_;}
Numeric min_
Definition: Interval.h:176
Definition: value.py:1
Numeric max_
Definition: Interval.h:177
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 112 of file Interval.h.

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

113  {return value > min_ && value <= max_;}
Numeric min_
Definition: Interval.h:176
Definition: value.py:1
Numeric max_
Definition: Interval.h:177
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 116 of file Interval.h.

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

117  {return value >= min_ && value <= max_;}
Numeric min_
Definition: Interval.h:176
Definition: value.py:1
Numeric max_
Definition: Interval.h:177
template<typename Numeric>
Numeric npstat::Interval< Numeric >::length ( ) const
inline

Interval length

Definition at line 101 of file Interval.h.

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

101 {return max_ - min_;}
Numeric min_
Definition: Interval.h:176
Numeric max_
Definition: Interval.h:177
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 299 of file Interval.h.

References npstat::Interval< Numeric >::max(), npstat::Interval< Numeric >::max_, npstat::Interval< Numeric >::min(), and npstat::Interval< Numeric >::min_.

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

301  {
302  if (max_ == min_) throw npstat::NpstatDomainError(
303  "In npstat::Interval::linearMap: zero length interval");
304  assert(a);
305  assert(b);
306  const Num2 rmax(r.max());
307  const Num2 rmin(r.min());
308  *a = static_cast<double>((rmax - rmin)*1.0/(max_ - min_));
309  *b = static_cast<double>((rmax + rmin) - *a*(max_ + min_))/2.0;
310  }
Numeric min_
Definition: Interval.h:176
Numeric max_
Definition: Interval.h:177
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
template<typename Numeric>
const Numeric npstat::Interval< Numeric >::max ( ) const
inline
template<typename Numeric>
Numeric npstat::Interval< Numeric >::midpoint ( ) const
inline

The middle point of the interval

Definition at line 104 of file Interval.h.

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

105  {return static_cast<Numeric>((max_ + min_)*0.5);}
Numeric min_
Definition: Interval.h:176
Numeric max_
Definition: Interval.h:177
template<typename Numeric>
const Numeric npstat::Interval< Numeric >::min ( ) const
inline
template<typename Numeric >
Interval< Numeric > & npstat::Interval< Numeric >::moveMidpointTo0 ( )
inline

Move the interval so that the midpoint ends up at 0

Definition at line 248 of file Interval.h.

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

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

249  {
250  const Numeric len = max_ - min_;
251  max_ = len/static_cast<Numeric>(2);
252  min_ = -max_;
253  return *this;
254  }
Numeric min_
Definition: Interval.h:176
Numeric max_
Definition: Interval.h:177
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 238 of file Interval.h.

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

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

239  {
240  min_ *= r;
241  max_ *= r;
242  if (max_ < min_)
243  std::swap(min_, max_);
244  return *this;
245  }
Numeric min_
Definition: Interval.h:176
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Numeric max_
Definition: Interval.h:177
template<typename Numeric >
Interval< Numeric > & npstat::Interval< Numeric >::operator+= ( const Numeric  value)
inline

Shift both interval bounds by a constant

Definition at line 282 of file Interval.h.

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

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

283  {
284  min_ += r;
285  max_ += r;
286  return *this;
287  }
Numeric min_
Definition: Interval.h:176
Numeric max_
Definition: Interval.h:177
template<typename Numeric >
Interval< Numeric > & npstat::Interval< Numeric >::operator-= ( const Numeric  value)
inline

Definition at line 290 of file Interval.h.

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

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

291  {
292  min_ -= r;
293  max_ -= r;
294  return *this;
295  }
Numeric min_
Definition: Interval.h:176
Numeric max_
Definition: Interval.h:177
template<typename Numeric >
Interval< Numeric > & npstat::Interval< Numeric >::operator/= ( double  r)
inline

Definition at line 270 of file Interval.h.

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

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

271  {
272  if (!r) throw npstat::NpstatDomainError(
273  "In npstat::Interval::operator/=: division by zero");
274  min_ /= r;
275  max_ /= r;
276  if (max_ < min_)
277  std::swap(min_, max_);
278  return *this;
279  }
Numeric min_
Definition: Interval.h:176
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Numeric max_
Definition: Interval.h:177
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 195 of file Interval.h.

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

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

197  {
198  Interval<Numeric> over;
199  if (max_ == r.min_)
200  over.setBounds(max_, max_);
201  else if (r.max_ == min_)
202  over.setBounds(min_, min_);
203  else if (max_ > r.min_ && r.max_ > min_)
204  {
205  over.min_ = min_ < r.min_ ? r.min_ : min_;
206  over.max_ = max_ < r.max_ ? max_ : r.max_;
207  }
208  return over;
209  }
Numeric min_
Definition: Interval.h:176
Numeric max_
Definition: Interval.h:177
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 225 of file Interval.h.

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

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

226  {
227  if (max_ > r.min_ && r.max_ > min_)
228  {
229  const Numeric mn = min_ < r.min_ ? r.min_ : min_;
230  const Numeric mx = max_ < r.max_ ? max_ : r.max_;
231  return (mx - mn)*1.0/(max_ - min_);
232  }
233  else
234  return 0.0;
235  }
Numeric min_
Definition: Interval.h:176
Numeric max_
Definition: Interval.h:177
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 212 of file Interval.h.

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

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

213  {
214  if (max_ > r.min_ && r.max_ > min_)
215  {
216  const Numeric mn = min_ < r.min_ ? r.min_ : min_;
217  const Numeric mx = max_ < r.max_ ? max_ : r.max_;
218  return mx - mn;
219  }
220  else
221  return Numeric();
222  }
Numeric min_
Definition: Interval.h:176
Numeric max_
Definition: Interval.h:177
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 78 of file Interval.h.

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

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

80  {
81  if (maxval < minval && !swapIfOutOfOrder)
83  "In npstat::Interval::setBounds: invalid limits");
84  min_ = minval;
85  max_ = maxval;
86  if (swapIfOutOfOrder && min_ > max_)
88  }
Numeric min_
Definition: Interval.h:176
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Numeric max_
Definition: Interval.h:177
template<typename Numeric>
void npstat::Interval< Numeric >::setMax ( const Numeric  value)
inline

Set the upper interval bound

Definition at line 70 of file Interval.h.

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

71  {
73  "In npstat::Interval::setMax: argument below min");
74  max_ = value;
75  }
Numeric min_
Definition: Interval.h:176
Definition: value.py:1
Numeric max_
Definition: Interval.h:177
template<typename Numeric>
void npstat::Interval< Numeric >::setMin ( const Numeric  value)
inline

Set the lower interval bound

Definition at line 62 of file Interval.h.

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

Referenced by npstat::BoxND< Numeric >::allSpace().

63  {
65  "In npstat::Interval::setMin: argument above max");
66  min_ = value;
67  }
Numeric min_
Definition: Interval.h:176
Definition: value.py:1
Numeric max_
Definition: Interval.h:177

Member Data Documentation

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