CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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

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

Default constructor makes a 0-dimensional box

Definition at line 27 of file BoxND.h.

27 {}
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 30 of file BoxND.h.

30  :
31  std::vector<Interval<Numeric> >(dim) {}
unsigned long dim() const
Definition: BoxND.h:57
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 34 of file BoxND.h.

34  :
35  std::vector<Interval<Numeric> >(dim, v) {}
unsigned long dim() const
Definition: BoxND.h:57
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 195 of file BoxND.h.

References i, and relativeConstraints::value.

196  {
197  const unsigned long dim = limits.size();
198  if (dim)
199  {
200  this->reserve(dim);
201  Numeric zero = Numeric();
202  for (unsigned long i=0; i<dim; ++i)
203  {
204  const Numeric value(static_cast<Numeric>(limits[i]));
205  if (value >= zero)
206  this->push_back(Interval<Numeric>(zero, value));
207  else
208  this->push_back(Interval<Numeric>(value, zero));
209  }
210  }
211  }
int i
Definition: DBlmapReader.cc:9
unsigned long dim() const
Definition: BoxND.h:57
template<typename Numeric >
template<typename Num2 >
npstat::BoxND< Numeric >::BoxND ( const BoxND< Num2 > &  r)
explicit

Converting constructor

Definition at line 179 of file BoxND.h.

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

180  {
181  const unsigned long dim = r.size();
182  if (dim)
183  {
184  this->reserve(dim);
185  for (unsigned long i=0; i<dim; ++i)
186  {
187  const Interval<Num2>& ri(r[i]);
188  this->push_back(Interval<Numeric>(ri.min(), ri.max()));
189  }
190  }
191  }
int i
Definition: DBlmapReader.cc:9
unsigned long dim() const
Definition: BoxND.h:57

Member Function Documentation

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

References i, bookConverter::max, npstat::Interval< Numeric >::setMin(), and relativeConstraints::value.

495  {
496  const Numeric maxval = std::numeric_limits<Numeric>::max();
497  Interval<Numeric> i(static_cast<Numeric>(0), maxval);
499  i.setMin(-maxval);
500  return BoxND<Numeric>(ndim, i);
501  }
int i
Definition: DBlmapReader.cc:9
template<typename Numeric>
gs::ClassId npstat::BoxND< Numeric >::classId ( ) const
inline

Methods related to I/O

Definition at line 150 of file BoxND.h.

150 {return gs::ClassId(*this);}
template<typename Numeric >
const char * npstat::BoxND< Numeric >::classname ( )
static

Definition at line 504 of file BoxND.h.

References AlCaHLTBitMon_QueryRunRegistry::string.

505  {
506  static const std::string na(gs::template_class_name<Numeric>("npstat::BoxND"));
507  return na.c_str();
508  }
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.

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

Definition at line 215 of file BoxND.h.

References hitfit::clear(), i, npstat::Interval< Numeric >::max(), npstat::Interval< Numeric >::min(), and n.

216  {
217  if ((void *)this == (void *)(&r))
218  return *this;
219  const unsigned long n = r.size();
220  this->clear();
221  this->reserve(n);
222  for (unsigned long i=0; i<n; ++i)
223  {
224  const Interval<Num2>& ir(r[i]);
225  this->push_back(Interval<Numeric>(ir.min(), ir.max()));
226  }
227  return *this;
228  }
int i
Definition: DBlmapReader.cc:9
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
Definition: matutil.cc:167
template<typename Numeric>
unsigned long npstat::BoxND< Numeric >::dim ( ) const
inline

Box dimensionality

Definition at line 57 of file BoxND.h.

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

57 {return this->size();}
tuple size
Write out results.
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 363 of file BoxND.h.

References i, and findQualityFiles::size.

364  {
365  const unsigned long mydim = this->size();
366  for (unsigned long i=0; i<mydim; ++i)
367  (*this)[i].expand(r);
368  return *this;
369  }
int i
Definition: DBlmapReader.cc:9
tuple size
Write out results.
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 385 of file BoxND.h.

References i, and findQualityFiles::size.

387  {
388  const unsigned long mydim = this->size();
389  if (mydim != scales.size()) throw npstat::NpstatInvalidArgument(
390  "In npstat::BoxND::expand: incompatible argument dimensionality");
391  for (unsigned long i=0; i<mydim; ++i)
392  (*this)[i].expand(scales[i]);
393  return *this;
394  }
int i
Definition: DBlmapReader.cc:9
tuple size
Write out results.
template<typename Numeric >
BoxND< Numeric > & npstat::BoxND< Numeric >::expand ( const double *  scales,
unsigned long  lenScales 
)

Definition at line 397 of file BoxND.h.

References i, and findQualityFiles::size.

399  {
400  const unsigned long mydim = this->size();
401  if (mydim != lenScales) throw npstat::NpstatInvalidArgument(
402  "In npstat::BoxND::expand: incompatible argument dimensionality");
403  if (mydim)
404  {
405  assert(scales);
406  for (unsigned long i=0; i<mydim; ++i)
407  (*this)[i].expand(scales[i]);
408  }
409  return *this;
410  }
int i
Definition: DBlmapReader.cc:9
tuple size
Write out results.
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 271 of file BoxND.h.

References i, and findQualityFiles::size.

273  {
274  const unsigned long mydim = this->size();
275  if (coordLen < mydim) throw npstat::NpstatInvalidArgument(
276  "In npstat::BoxND::getMidpoint: insufficient output buffer length");
277  if (mydim)
278  {
279  assert(coord);
280  for (unsigned long i=0U; i<mydim; ++i)
281  coord[i] = (*this)[i].midpoint();
282  }
283  }
int i
Definition: DBlmapReader.cc:9
tuple size
Write out results.
template<typename Numeric >
template<typename Num2 >
bool npstat::BoxND< Numeric >::isInside ( const Num2 *  coord,
unsigned long  coordLen 
) const

Definition at line 332 of file BoxND.h.

References i, and findQualityFiles::size.

334  {
335  if (coordLen != this->size()) throw npstat::NpstatInvalidArgument(
336  "In npstat::BoxND::isInside: incompatible point dimensionality");
337  const Interval<Numeric>* myptr = &(*this)[0];
338  for (unsigned long i=0; i<coordLen; ++i)
339  if (!myptr[i].isInside(coords[i]))
340  return false;
341  return true;
342  }
int i
Definition: DBlmapReader.cc:9
bool isInside(const Num2 *coord, unsigned long coordLen) const
Definition: BoxND.h:332
tuple size
Write out results.
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 287 of file BoxND.h.

References i, and findQualityFiles::size.

289  {
290  if (coordLen != this->size()) throw npstat::NpstatInvalidArgument(
291  "In npstat::BoxND::isInsideLower: "
292  "incompatible point dimensionality");
293  const Interval<Numeric>* myptr = &(*this)[0];
294  for (unsigned long i=0; i<coordLen; ++i)
295  if (!myptr[i].isInsideLower(coords[i]))
296  return false;
297  return true;
298  }
int i
Definition: DBlmapReader.cc:9
bool isInsideLower(const Num2 *coord, unsigned long coordLen) const
Definition: BoxND.h:287
tuple size
Write out results.
template<typename Numeric >
template<typename Num2 >
bool npstat::BoxND< Numeric >::isInsideUpper ( const Num2 *  coord,
unsigned long  coordLen 
) const

Definition at line 302 of file BoxND.h.

References i, and findQualityFiles::size.

304  {
305  if (coordLen != this->size()) throw npstat::NpstatInvalidArgument(
306  "In npstat::BoxND::isInsideUpper: "
307  "incompatible point dimensionality");
308  const Interval<Numeric>* myptr = &(*this)[0];
309  for (unsigned long i=0; i<coordLen; ++i)
310  if (!myptr[i].isInsideUpper(coords[i]))
311  return false;
312  return true;
313  }
int i
Definition: DBlmapReader.cc:9
bool isInsideUpper(const Num2 *coord, unsigned long coordLen) const
Definition: BoxND.h:302
tuple size
Write out results.
template<typename Numeric >
template<typename Num2 >
bool npstat::BoxND< Numeric >::isInsideWithBounds ( const Num2 *  coord,
unsigned long  coordLen 
) const

Definition at line 317 of file BoxND.h.

References i, and findQualityFiles::size.

319  {
320  if (coordLen != this->size()) throw npstat::NpstatInvalidArgument(
321  "In npstat::BoxND::isInsideWithBounds: "
322  "incompatible point dimensionality");
323  const Interval<Numeric>* myptr = &(*this)[0];
324  for (unsigned long i=0; i<coordLen; ++i)
325  if (!myptr[i].isInsideWithBounds(coords[i]))
326  return false;
327  return true;
328  }
int i
Definition: DBlmapReader.cc:9
bool isInsideWithBounds(const Num2 *coord, unsigned long coordLen) const
Definition: BoxND.h:317
tuple size
Write out results.
template<typename Numeric >
BoxND< Numeric > & npstat::BoxND< Numeric >::moveToOrigin ( )

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

Definition at line 354 of file BoxND.h.

References i, and findQualityFiles::size.

355  {
356  const unsigned long mydim = this->size();
357  for (unsigned long i=0; i<mydim; ++i)
358  (*this)[i].moveMidpointTo0();
359  return *this;
360  }
int i
Definition: DBlmapReader.cc:9
tuple size
Write out results.
template<typename Numeric >
BoxND< Numeric > & npstat::BoxND< Numeric >::operator*= ( double  r)

Scaling of all limits by a constant

Definition at line 345 of file BoxND.h.

References i, alignCSCRings::r, and findQualityFiles::size.

346  {
347  const unsigned long mydim = this->size();
348  for (unsigned long i=0; i<mydim; ++i)
349  (*this)[i] *= r;
350  return *this;
351  }
int i
Definition: DBlmapReader.cc:9
tuple size
Write out results.
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 372 of file BoxND.h.

References i, and findQualityFiles::size.

374  {
375  const unsigned long mydim = this->size();
376  if (mydim != scales.size()) throw npstat::NpstatInvalidArgument(
377  "In npstat::BoxND::operator*=: "
378  "incompatible argument dimensionality");
379  for (unsigned long i=0; i<mydim; ++i)
380  (*this)[i] *= scales[i];
381  return *this;
382  }
int i
Definition: DBlmapReader.cc:9
tuple size
Write out results.
template<typename Numeric>
template<typename Num2 >
BoxND& npstat::BoxND< Numeric >::operator+= ( const std::vector< Num2 > &  shifts)

Shifting this object

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

Definition at line 436 of file BoxND.h.

References i, and findQualityFiles::size.

437  {
438  const unsigned long mydim = this->size();
439  if (mydim != shifts.size()) throw npstat::NpstatInvalidArgument(
440  "In npstat::BoxND::operator+=: "
441  "incompatible argument dimensionality");
442  for (unsigned long i=0; i<mydim; ++i)
443  (*this)[i] += static_cast<Numeric>(shifts[i]);
444  return *this;
445  }
int i
Definition: DBlmapReader.cc:9
tuple size
Write out results.
template<typename Numeric>
template<typename Num2 >
BoxND& npstat::BoxND< Numeric >::operator-= ( const std::vector< Num2 > &  shifts)
template<typename Numeric>
template<typename Num2 >
BoxND<Numeric>& npstat::BoxND< Numeric >::operator-= ( const std::vector< Num2 > &  shifts)

Definition at line 466 of file BoxND.h.

References i, and findQualityFiles::size.

467  {
468  const unsigned long mydim = this->size();
469  if (mydim != shifts.size()) throw npstat::NpstatInvalidArgument(
470  "In npstat::BoxND::operator-=: "
471  "incompatible argument dimensionality");
472  for (unsigned long i=0; i<mydim; ++i)
473  (*this)[i] -= static_cast<Numeric>(shifts[i]);
474  return *this;
475  }
int i
Definition: DBlmapReader.cc:9
tuple size
Write out results.
template<typename Numeric >
BoxND< Numeric > & npstat::BoxND< Numeric >::operator/= ( double  r)

Definition at line 413 of file BoxND.h.

References i, alignCSCRings::r, and findQualityFiles::size.

414  {
415  const unsigned long mydim = this->size();
416  for (unsigned long i=0; i<mydim; ++i)
417  (*this)[i] /= r;
418  return *this;
419  }
int i
Definition: DBlmapReader.cc:9
tuple size
Write out results.
template<typename Numeric >
BoxND< Numeric > & npstat::BoxND< Numeric >::operator/= ( const std::vector< double > &  scales)

Definition at line 422 of file BoxND.h.

References i, and findQualityFiles::size.

424  {
425  const unsigned long mydim = this->size();
426  if (mydim != scales.size()) throw npstat::NpstatInvalidArgument(
427  "In npstat::BoxND::operator/=: "
428  "incompatible argument dimensionality");
429  for (unsigned long i=0; i<mydim; ++i)
430  (*this)[i] /= scales[i];
431  return *this;
432  }
int i
Definition: DBlmapReader.cc:9
tuple size
Write out results.
template<typename Numeric >
double npstat::BoxND< Numeric >::overlapFraction ( const BoxND< Numeric > &  r) const

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

Definition at line 256 of file BoxND.h.

References f, i, and findQualityFiles::size.

257  {
258  const unsigned long mydim = this->size();
259  if (mydim == r.size())
260  {
261  double f = 1.0;
262  for (unsigned long i=0U; i<mydim; ++i)
263  f *= (*this)[i].overlapFraction(r[i]);
264  return f;
265  }
266  else
267  return 0.0;
268  }
int i
Definition: DBlmapReader.cc:9
double f[11][100]
tuple size
Write out results.
template<typename Numeric >
Numeric npstat::BoxND< Numeric >::overlapVolume ( const BoxND< Numeric > &  r) const

Overlap volume with another box

Definition at line 241 of file BoxND.h.

References i, findQualityFiles::size, and findQualityFiles::v.

242  {
243  const unsigned long mydim = this->size();
244  if (mydim == r.size())
245  {
246  Numeric v(static_cast<Numeric>(1));
247  for (unsigned long i=0U; i<mydim; ++i)
248  v *= (*this)[i].overlapLength(r[i]);
249  return v;
250  }
251  else
252  return static_cast<Numeric>(0);
253  }
int i
Definition: DBlmapReader.cc:9
tuple size
Write out results.
template<typename Numeric >
void npstat::BoxND< Numeric >::restore ( const gs::ClassId &  id,
std::istream &  in,
BoxND< Numeric > *  box 
)
static

Definition at line 525 of file BoxND.h.

References cond::rpcobimon::current, and i.

526  {
527  static const gs::ClassId current(gs::ClassId::makeId<BoxND<Numeric> >());
528  current.ensureSameId(id);
529 
530  std::vector<Numeric> limits;
531  gs::restore_item(in, &limits);
532  if (in.fail())
533  throw gs::IOReadFailure("In npstat::BoxND::restore: input stream failure");
534  const unsigned long nlimits = limits.size();
535  if (nlimits % 2UL)
536  throw gs::IOInvalidData("In npstat::BoxND::restore: bad limits");
537  assert(b);
538  b->clear();
539  b->reserve(nlimits/2UL);
540  for (unsigned long i=0; i<nlimits/2UL; ++i)
541  b->push_back(npstat::Interval<Numeric>(limits[2U*i], limits[2U*i+1U]));
542  }
int i
Definition: DBlmapReader.cc:9
double b
Definition: hdecay.h:120
template<typename Numeric>
template<typename Num2 >
BoxND& npstat::BoxND< Numeric >::shift ( const Num2 *  shifts,
unsigned long  lenShifts 
)
template<typename Numeric>
template<typename Num2 >
BoxND<Numeric>& npstat::BoxND< Numeric >::shift ( const Num2 *  shifts,
const unsigned long  shiftsLen 
)

Definition at line 449 of file BoxND.h.

References i, and findQualityFiles::size.

451  {
452  const unsigned long mydim = this->size();
453  if (mydim != shiftsLen) throw npstat::NpstatInvalidArgument(
454  "In npstat::BoxND::shift: incompatible argument dimensionality");
455  if (mydim)
456  {
457  assert(shifts);
458  for (unsigned long i=0; i<mydim; ++i)
459  (*this)[i] += static_cast<Numeric>(shifts[i]);
460  }
461  return *this;
462  }
int i
Definition: DBlmapReader.cc:9
tuple size
Write out results.
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 486 of file BoxND.h.

References i.

487  {
488  const Numeric one = static_cast<Numeric>(1);
489  Interval<Numeric> i(-one, one);
490  return BoxND<Numeric>(ndim, i);
491  }
int i
Definition: DBlmapReader.cc:9
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 478 of file BoxND.h.

References csvLumiCalc::unit.

479  {
480  Interval<Numeric> unit(static_cast<Numeric>(0),
481  static_cast<Numeric>(1));
482  return BoxND<Numeric>(ndim, unit);
483  }
string unit
Definition: csvLumiCalc.py:46
template<typename Numeric>
static unsigned npstat::BoxND< Numeric >::version ( )
inlinestatic

Definition at line 155 of file BoxND.h.

155 {return 1;}
template<typename Numeric >
Numeric npstat::BoxND< Numeric >::volume ( void  ) const

Box volume

Definition at line 231 of file BoxND.h.

References i, findQualityFiles::size, and findQualityFiles::v.

232  {
233  Numeric v(static_cast<Numeric>(1));
234  const unsigned long mydim = this->size();
235  for (unsigned long i=0U; i<mydim; ++i)
236  v *= (*this)[i].length();
237  return v;
238  }
int i
Definition: DBlmapReader.cc:9
tuple size
Write out results.
template<typename Numeric >
bool npstat::BoxND< Numeric >::write ( std::ostream &  of) const

Definition at line 511 of file BoxND.h.

References i, bookConverter::max, min(), and findQualityFiles::size.

512  {
513  const unsigned long mydim = this->size();
514  std::vector<Numeric> limits;
515  limits.reserve(2UL*mydim);
516  for (unsigned long i=0; i<mydim; ++i)
517  {
518  limits.push_back((*this)[i].min());
519  limits.push_back((*this)[i].max());
520  }
521  return gs::write_item(of, limits);
522  }
int i
Definition: DBlmapReader.cc:9
T min(T a, T b)
Definition: MathUtil.h:58
tuple size
Write out results.