CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions
npstat::BoxND< Numeric > Struct Template Reference

#include <BoxND.h>

Inheritance diagram for npstat::BoxND< Numeric >:

Public Member Functions

 BoxND ()
 
 BoxND (const unsigned long dim)
 
 BoxND (const unsigned long dim, const Interval< Numeric > &v)
 
template<typename Num2 >
 BoxND (const std::vector< Num2 > &limits)
 
template<typename Num2 >
 BoxND (const BoxND< Num2 > &r)
 
template<typename Num2 >
BoxNDcopyFrom (const BoxND< Num2 > &r)
 
template<typename Num2 >
BoxND< Numeric > & copyFrom (const BoxND< Num2 > &r)
 
unsigned long dim () const
 
BoxNDexpand (double r)
 
void getMidpoint (Numeric *coord, unsigned long coordLen) const
 
BoxNDmoveToOrigin ()
 
template<typename Num2 >
BoxND< Numeric > & operator+= (const std::vector< Num2 > &shifts)
 
template<typename Num2 >
BoxND< Numeric > & operator-= (const std::vector< Num2 > &shifts)
 
double overlapFraction (const BoxND &r) const
 
Numeric overlapVolume (const BoxND &r) const
 
template<typename Num2 >
BoxND< Numeric > & shift (const Num2 *shifts, const unsigned long shiftsLen)
 
Numeric volume () const
 
template<typename Num2 >
bool isInsideLower (const Num2 *coord, unsigned long coordLen) const
 
template<typename Num2 >
bool isInsideUpper (const Num2 *coord, unsigned long coordLen) const
 
template<typename Num2 >
bool isInsideWithBounds (const Num2 *coord, unsigned long coordLen) const
 
template<typename Num2 >
bool isInside (const Num2 *coord, unsigned long coordLen) const
 
BoxNDoperator*= (double r)
 
BoxNDoperator/= (double r)
 
BoxNDoperator*= (const std::vector< double > &scales)
 
BoxNDoperator/= (const std::vector< double > &scales)
 
BoxNDexpand (const std::vector< double > &scales)
 
BoxNDexpand (const double *scales, unsigned long lenScales)
 
template<typename Num2 >
BoxNDoperator+= (const std::vector< Num2 > &shifts)
 
template<typename Num2 >
BoxNDoperator-= (const std::vector< Num2 > &shifts)
 
template<typename Num2 >
BoxNDshift (const Num2 *shifts, unsigned long lenShifts)
 
gs::ClassId classId () const
 
bool write (std::ostream &of) const
 

Static Public Member Functions

static BoxND allSpace (unsigned long ndim)
 
static const char * classname ()
 
static void restore (const gs::ClassId &id, std::istream &in, BoxND *box)
 
static BoxND sizeTwoBox (unsigned long ndim)
 
static BoxND unitBox (unsigned long ndim)
 
static unsigned version ()
 

Detailed Description

template<typename Numeric>
struct npstat::BoxND< Numeric >

Class to represent rectangles, boxes, and hyperboxes

Definition at line 24 of file BoxND.h.

Constructor & Destructor Documentation

◆ BoxND() [1/5]

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

Default constructor makes a 0-dimensional box

Definition at line 26 of file BoxND.h.

26 {}

◆ BoxND() [2/5]

template<typename Numeric>
npstat::BoxND< Numeric >::BoxND ( const unsigned long  dim)
inlineexplicit

Interval in each dimension is made by its default constructor

Definition at line 29 of file BoxND.h.

29 : std::vector<Interval<Numeric> >(dim) {}
unsigned long dim() const
Definition: BoxND.h:54

◆ BoxND() [3/5]

template<typename Numeric>
npstat::BoxND< Numeric >::BoxND ( const unsigned long  dim,
const Interval< Numeric > &  v 
)
inline

Use the same interval in each dimension

Definition at line 32 of file BoxND.h.

32 : std::vector<Interval<Numeric> >(dim, v) {}
unsigned long dim() const
Definition: BoxND.h:54

◆ BoxND() [4/5]

template<typename Numeric >
template<typename Num2 >
npstat::BoxND< Numeric >::BoxND ( const std::vector< Num2 > &  limits)
explicit

Constructor where one of the limits will be 0 and the other will be generated from the given vector (which also determines the dimensionality)

Definition at line 189 of file BoxND.h.

189  {
190  const unsigned long dim = limits.size();
191  if (dim) {
192  this->reserve(dim);
193  Numeric zero = Numeric();
194  for (unsigned long i = 0; i < dim; ++i) {
195  const Numeric value(static_cast<Numeric>(limits[i]));
196  if (value >= zero)
197  this->push_back(Interval<Numeric>(zero, value));
198  else
199  this->push_back(Interval<Numeric>(value, zero));
200  }
201  }
202  }
Definition: value.py:1
deadvectors [0] push_back({0.0175431, 0.538005, 6.80997, 13.29})
unsigned long dim() const
Definition: BoxND.h:54

◆ BoxND() [5/5]

template<typename Numeric >
template<typename Num2 >
npstat::BoxND< Numeric >::BoxND ( const BoxND< Num2 > &  r)
explicit

Converting constructor

Definition at line 176 of file BoxND.h.

176  {
177  const unsigned long dim = r.size();
178  if (dim) {
179  this->reserve(dim);
180  for (unsigned long i = 0; i < dim; ++i) {
181  const Interval<Num2>& ri(r[i]);
182  this->push_back(Interval<Numeric>(ri.min(), ri.max()));
183  }
184  }
185  }
deadvectors [0] push_back({0.0175431, 0.538005, 6.80997, 13.29})
unsigned long dim() const
Definition: BoxND.h:54

Member Function Documentation

◆ allSpace()

template<typename Numeric >
BoxND< Numeric > npstat::BoxND< Numeric >::allSpace ( unsigned long  ndim)
static

Box with all upper limits set to maximum possible Numeric number and with lower limits set to negative maximum (this will not work with unsigned long types)

Definition at line 451 of file BoxND.h.

451  {
452  const Numeric maxval = std::numeric_limits<Numeric>::max();
453  Interval<Numeric> i(static_cast<Numeric>(0), maxval);
455  i.setMin(-maxval);
456  return BoxND<Numeric>(ndim, i);
457  }

◆ classId()

template<typename Numeric>
gs::ClassId npstat::BoxND< Numeric >::classId ( ) const
inline

Methods related to I/O

Definition at line 147 of file BoxND.h.

147 { return gs::ClassId(*this); }

◆ classname()

template<typename Numeric >
const char * npstat::BoxND< Numeric >::classname ( )
static

Definition at line 460 of file BoxND.h.

460  {
461  static const std::string na(gs::template_class_name<Numeric>("npstat::BoxND"));
462  return na.c_str();
463  }

◆ copyFrom() [1/2]

template<typename Numeric>
template<typename Num2 >
BoxND& npstat::BoxND< Numeric >::copyFrom ( const BoxND< Num2 > &  r)

Get the data from a box of a different type. This method works essentially as a converting assignment operator.

◆ copyFrom() [2/2]

template<typename Numeric>
template<typename Num2 >
BoxND<Numeric>& npstat::BoxND< Numeric >::copyFrom ( const BoxND< Num2 > &  r)

Definition at line 206 of file BoxND.h.

206  {
207  if ((void*)this == (void*)(&r))
208  return *this;
209  const unsigned long n = r.size();
210  this->clear();
211  this->reserve(n);
212  for (unsigned long i = 0; i < n; ++i) {
213  const Interval<Num2>& ir(r[i]);
214  this->push_back(Interval<Numeric>(ir.min(), ir.max()));
215  }
216  return *this;
217  }
deadvectors [0] push_back({0.0175431, 0.538005, 6.80997, 13.29})
void clear(EGIsoObj &c)
Definition: egamma.h:82

◆ dim()

template<typename Numeric>
unsigned long npstat::BoxND< Numeric >::dim ( ) const
inline

Box dimensionality

Definition at line 54 of file BoxND.h.

Referenced by npstat::ArrayND< Numeric >::processSubrange().

54 { return this->size(); }
size
Write out results.

◆ expand() [1/3]

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

Scaling of all limits by a constant in such a way that the midpoint remains unchanged

Definition at line 335 of file BoxND.h.

335  {
336  const unsigned long mydim = this->size();
337  for (unsigned long i = 0; i < mydim; ++i)
338  (*this)[i].expand(r);
339  return *this;
340  }
size
Write out results.

◆ expand() [2/3]

template<typename Numeric >
BoxND< Numeric > & npstat::BoxND< Numeric >::expand ( const std::vector< double > &  scales)

Scaling of all limits in such a way that the midpoint remains unchanged, using a different scaling factor in each dimension

Definition at line 355 of file BoxND.h.

355  {
356  const unsigned long mydim = this->size();
357  if (mydim != scales.size())
358  throw npstat::NpstatInvalidArgument("In npstat::BoxND::expand: incompatible argument dimensionality");
359  for (unsigned long i = 0; i < mydim; ++i)
360  (*this)[i].expand(scales[i]);
361  return *this;
362  }
size
Write out results.

◆ expand() [3/3]

template<typename Numeric >
BoxND< Numeric > & npstat::BoxND< Numeric >::expand ( const double *  scales,
unsigned long  lenScales 
)

Definition at line 365 of file BoxND.h.

365  {
366  const unsigned long mydim = this->size();
367  if (mydim != lenScales)
368  throw npstat::NpstatInvalidArgument("In npstat::BoxND::expand: incompatible argument dimensionality");
369  if (mydim) {
370  assert(scales);
371  for (unsigned long i = 0; i < mydim; ++i)
372  (*this)[i].expand(scales[i]);
373  }
374  return *this;
375  }
size
Write out results.
assert(be >=bs)

◆ getMidpoint()

template<typename Numeric>
void npstat::BoxND< Numeric >::getMidpoint ( Numeric *  coord,
unsigned long  coordLen 
) const

Midpoint for every coordinate. The size of the "coord" array should be at least as large as the box dimensionality.

Definition at line 253 of file BoxND.h.

253  {
254  const unsigned long mydim = this->size();
255  if (coordLen < mydim)
256  throw npstat::NpstatInvalidArgument("In npstat::BoxND::getMidpoint: insufficient output buffer length");
257  if (mydim) {
258  assert(coord);
259  for (unsigned long i = 0U; i < mydim; ++i)
260  coord[i] = (*this)[i].midpoint();
261  }
262  }
size
Write out results.
assert(be >=bs)

◆ isInside()

template<typename Numeric >
template<typename Num2 >
bool npstat::BoxND< Numeric >::isInside ( const Num2 *  coord,
unsigned long  coordLen 
) const

Definition at line 308 of file BoxND.h.

308  {
309  if (coordLen != this->size())
310  throw npstat::NpstatInvalidArgument("In npstat::BoxND::isInside: incompatible point dimensionality");
311  const Interval<Numeric>* myptr = &(*this)[0];
312  for (unsigned long i = 0; i < coordLen; ++i)
313  if (!myptr[i].isInside(coords[i]))
314  return false;
315  return true;
316  }
size
Write out results.
bool isInside(const Num2 *coord, unsigned long coordLen) const
Definition: BoxND.h:308

◆ isInsideLower()

template<typename Numeric >
template<typename Num2 >
bool npstat::BoxND< Numeric >::isInsideLower ( const Num2 *  coord,
unsigned long  coordLen 
) const

This method return "true" if the corresponding function of the Interval returns "true" for every coordinate. There must be an automatic conversion from Num2 type into Numeric.

Definition at line 266 of file BoxND.h.

266  {
267  if (coordLen != this->size())
269  "In npstat::BoxND::isInsideLower: "
270  "incompatible point dimensionality");
271  const Interval<Numeric>* myptr = &(*this)[0];
272  for (unsigned long i = 0; i < coordLen; ++i)
273  if (!myptr[i].isInsideLower(coords[i]))
274  return false;
275  return true;
276  }
size
Write out results.
bool isInsideLower(const Num2 *coord, unsigned long coordLen) const
Definition: BoxND.h:266

◆ isInsideUpper()

template<typename Numeric >
template<typename Num2 >
bool npstat::BoxND< Numeric >::isInsideUpper ( const Num2 *  coord,
unsigned long  coordLen 
) const

Definition at line 280 of file BoxND.h.

280  {
281  if (coordLen != this->size())
283  "In npstat::BoxND::isInsideUpper: "
284  "incompatible point dimensionality");
285  const Interval<Numeric>* myptr = &(*this)[0];
286  for (unsigned long i = 0; i < coordLen; ++i)
287  if (!myptr[i].isInsideUpper(coords[i]))
288  return false;
289  return true;
290  }
size
Write out results.
bool isInsideUpper(const Num2 *coord, unsigned long coordLen) const
Definition: BoxND.h:280

◆ isInsideWithBounds()

template<typename Numeric >
template<typename Num2 >
bool npstat::BoxND< Numeric >::isInsideWithBounds ( const Num2 *  coord,
unsigned long  coordLen 
) const

Definition at line 294 of file BoxND.h.

294  {
295  if (coordLen != this->size())
297  "In npstat::BoxND::isInsideWithBounds: "
298  "incompatible point dimensionality");
299  const Interval<Numeric>* myptr = &(*this)[0];
300  for (unsigned long i = 0; i < coordLen; ++i)
301  if (!myptr[i].isInsideWithBounds(coords[i]))
302  return false;
303  return true;
304  }
size
Write out results.
bool isInsideWithBounds(const Num2 *coord, unsigned long coordLen) const
Definition: BoxND.h:294

◆ moveToOrigin()

template<typename Numeric >
BoxND< Numeric > & npstat::BoxND< Numeric >::moveToOrigin ( )

Moving this object so that the midpoint is (0, 0, ..., 0)

Definition at line 327 of file BoxND.h.

327  {
328  const unsigned long mydim = this->size();
329  for (unsigned long i = 0; i < mydim; ++i)
330  (*this)[i].moveMidpointTo0();
331  return *this;
332  }
size
Write out results.

◆ operator*=() [1/2]

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

Scaling of all limits by a constant

Definition at line 319 of file BoxND.h.

319  {
320  const unsigned long mydim = this->size();
321  for (unsigned long i = 0; i < mydim; ++i)
322  (*this)[i] *= r;
323  return *this;
324  }
size
Write out results.

◆ operator*=() [2/2]

template<typename Numeric >
BoxND< Numeric > & npstat::BoxND< Numeric >::operator*= ( const std::vector< double > &  scales)

Scaling by a different constant in each dimension

Definition at line 343 of file BoxND.h.

343  {
344  const unsigned long mydim = this->size();
345  if (mydim != scales.size())
347  "In npstat::BoxND::operator*=: "
348  "incompatible argument dimensionality");
349  for (unsigned long i = 0; i < mydim; ++i)
350  (*this)[i] *= scales[i];
351  return *this;
352  }
size
Write out results.

◆ operator+=() [1/2]

template<typename Numeric>
template<typename Num2 >
BoxND& npstat::BoxND< Numeric >::operator+= ( const std::vector< Num2 > &  shifts)

Shifting this object

◆ operator+=() [2/2]

template<typename Numeric>
template<typename Num2 >
BoxND<Numeric>& npstat::BoxND< Numeric >::operator+= ( const std::vector< Num2 > &  shifts)

Definition at line 399 of file BoxND.h.

399  {
400  const unsigned long mydim = this->size();
401  if (mydim != shifts.size())
403  "In npstat::BoxND::operator+=: "
404  "incompatible argument dimensionality");
405  for (unsigned long i = 0; i < mydim; ++i)
406  (*this)[i] += static_cast<Numeric>(shifts[i]);
407  return *this;
408  }
size
Write out results.

◆ operator-=() [1/2]

template<typename Numeric>
template<typename Num2 >
BoxND& npstat::BoxND< Numeric >::operator-= ( const std::vector< Num2 > &  shifts)

◆ operator-=() [2/2]

template<typename Numeric>
template<typename Num2 >
BoxND<Numeric>& npstat::BoxND< Numeric >::operator-= ( const std::vector< Num2 > &  shifts)

Definition at line 426 of file BoxND.h.

426  {
427  const unsigned long mydim = this->size();
428  if (mydim != shifts.size())
430  "In npstat::BoxND::operator-=: "
431  "incompatible argument dimensionality");
432  for (unsigned long i = 0; i < mydim; ++i)
433  (*this)[i] -= static_cast<Numeric>(shifts[i]);
434  return *this;
435  }
size
Write out results.

◆ operator/=() [1/2]

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

Definition at line 378 of file BoxND.h.

378  {
379  const unsigned long mydim = this->size();
380  for (unsigned long i = 0; i < mydim; ++i)
381  (*this)[i] /= r;
382  return *this;
383  }
size
Write out results.

◆ operator/=() [2/2]

template<typename Numeric >
BoxND< Numeric > & npstat::BoxND< Numeric >::operator/= ( const std::vector< double > &  scales)

Definition at line 386 of file BoxND.h.

386  {
387  const unsigned long mydim = this->size();
388  if (mydim != scales.size())
390  "In npstat::BoxND::operator/=: "
391  "incompatible argument dimensionality");
392  for (unsigned long i = 0; i < mydim; ++i)
393  (*this)[i] /= scales[i];
394  return *this;
395  }
size
Write out results.

◆ overlapFraction()

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

A faster way to calculate overlapVolume(r)/volume()

Definition at line 241 of file BoxND.h.

241  {
242  const unsigned long mydim = this->size();
243  if (mydim == r.size()) {
244  double f = 1.0;
245  for (unsigned long i = 0U; i < mydim; ++i)
246  f *= (*this)[i].overlapFraction(r[i]);
247  return f;
248  } else
249  return 0.0;
250  }
size
Write out results.
double f[11][100]

◆ overlapVolume()

template<typename Numeric >
Numeric npstat::BoxND< Numeric >::overlapVolume ( const BoxND< Numeric > &  r) const

Overlap volume with another box

Definition at line 229 of file BoxND.h.

229  {
230  const unsigned long mydim = this->size();
231  if (mydim == r.size()) {
232  Numeric v(static_cast<Numeric>(1));
233  for (unsigned long i = 0U; i < mydim; ++i)
234  v *= (*this)[i].overlapLength(r[i]);
235  return v;
236  } else
237  return static_cast<Numeric>(0);
238  }
size
Write out results.

◆ restore()

template<typename Numeric >
void npstat::BoxND< Numeric >::restore ( const gs::ClassId &  id,
std::istream &  in,
BoxND< Numeric > *  box 
)
static

Definition at line 478 of file BoxND.h.

478  {
479  static const gs::ClassId current(gs::ClassId::makeId<BoxND<Numeric> >());
480  current.ensureSameId(id);
481 
482  std::vector<Numeric> limits;
483  gs::restore_item(in, &limits);
484  if (in.fail())
485  throw gs::IOReadFailure("In npstat::BoxND::restore: input stream failure");
486  const unsigned long nlimits = limits.size();
487  if (nlimits % 2UL)
488  throw gs::IOInvalidData("In npstat::BoxND::restore: bad limits");
489  assert(b);
490  b->clear();
491  b->reserve(nlimits / 2UL);
492  for (unsigned long i = 0; i < nlimits / 2UL; ++i)
493  b->push_back(npstat::Interval<Numeric>(limits[2U * i], limits[2U * i + 1U]));
494  }
assert(be >=bs)
double b
Definition: hdecay.h:120

◆ shift() [1/2]

template<typename Numeric>
template<typename Num2 >
BoxND& npstat::BoxND< Numeric >::shift ( const Num2 *  shifts,
unsigned long  lenShifts 
)

◆ shift() [2/2]

template<typename Numeric>
template<typename Num2 >
BoxND<Numeric>& npstat::BoxND< Numeric >::shift ( const Num2 *  shifts,
const unsigned long  shiftsLen 
)

Definition at line 412 of file BoxND.h.

412  {
413  const unsigned long mydim = this->size();
414  if (mydim != shiftsLen)
415  throw npstat::NpstatInvalidArgument("In npstat::BoxND::shift: incompatible argument dimensionality");
416  if (mydim) {
417  assert(shifts);
418  for (unsigned long i = 0; i < mydim; ++i)
419  (*this)[i] += static_cast<Numeric>(shifts[i]);
420  }
421  return *this;
422  }
size
Write out results.
assert(be >=bs)

◆ sizeTwoBox()

template<typename Numeric >
BoxND< Numeric > npstat::BoxND< Numeric >::sizeTwoBox ( unsigned long  ndim)
static

Box with lower limit -1 and upper limit 1 in all coordinates. Note that this will produce nonsense in case the Numeric type is unsigned.

Definition at line 444 of file BoxND.h.

444  {
445  const Numeric one = static_cast<Numeric>(1);
446  Interval<Numeric> i(-one, one);
447  return BoxND<Numeric>(ndim, i);
448  }

◆ unitBox()

template<typename Numeric >
BoxND< Numeric > npstat::BoxND< Numeric >::unitBox ( unsigned long  ndim)
static

Box with lower limit 0 and upper limit 1 in all coordinates

Definition at line 438 of file BoxND.h.

438  {
439  Interval<Numeric> unit(static_cast<Numeric>(0), static_cast<Numeric>(1));
440  return BoxND<Numeric>(ndim, unit);
441  }
Basic3DVector unit() const

◆ version()

template<typename Numeric>
static unsigned npstat::BoxND< Numeric >::version ( )
inlinestatic

Definition at line 152 of file BoxND.h.

Referenced by validation.Sample::datasetpattern(), and validation.Sample::filename().

152 { return 1; }

◆ volume()

template<typename Numeric >
Numeric npstat::BoxND< Numeric >::volume ( void  ) const

Box volume

Definition at line 220 of file BoxND.h.

220  {
221  Numeric v(static_cast<Numeric>(1));
222  const unsigned long mydim = this->size();
223  for (unsigned long i = 0U; i < mydim; ++i)
224  v *= (*this)[i].length();
225  return v;
226  }
size
Write out results.

◆ write()

template<typename Numeric >
bool npstat::BoxND< Numeric >::write ( std::ostream &  of) const

Definition at line 466 of file BoxND.h.

466  {
467  const unsigned long mydim = this->size();
468  std::vector<Numeric> limits;
469  limits.reserve(2UL * mydim);
470  for (unsigned long i = 0; i < mydim; ++i) {
471  limits.push_back((*this)[i].min());
472  limits.push_back((*this)[i].max());
473  }
474  return gs::write_item(of, limits);
475  }
size
Write out results.