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

References i, and relativeConstraints::value.

195  {
196  const unsigned long dim = limits.size();
197  if (dim)
198  {
199  this->reserve(dim);
200  Numeric zero = Numeric();
201  for (unsigned long i=0; i<dim; ++i)
202  {
203  const Numeric value(static_cast<Numeric>(limits[i]));
204  if (value >= zero)
205  this->push_back(Interval<Numeric>(zero, value));
206  else
207  this->push_back(Interval<Numeric>(value, zero));
208  }
209  }
210  }
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 178 of file BoxND.h.

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

179  {
180  const unsigned long dim = r.size();
181  if (dim)
182  {
183  this->reserve(dim);
184  for (unsigned long i=0; i<dim; ++i)
185  {
186  const Interval<Num2>& ri(r[i]);
187  this->push_back(Interval<Numeric>(ri.min(), ri.max()));
188  }
189  }
190  }
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 493 of file BoxND.h.

References i, and max().

494  {
495  const Numeric maxval = std::numeric_limits<Numeric>::max();
496  Interval<Numeric> i(-maxval, maxval);
497  return BoxND<Numeric>(ndim, i);
498  }
int i
Definition: DBlmapReader.cc:9
const T & max(const T &a, const T &b)
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 501 of file BoxND.h.

References AlCaHLTBitMon_QueryRunRegistry::string.

502  {
503  static const std::string na(gs::template_class_name<Numeric>("npstat::BoxND"));
504  return na.c_str();
505  }
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 214 of file BoxND.h.

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

215  {
216  if ((void *)this == (void *)(&r))
217  return *this;
218  const unsigned long n = r.size();
219  this->clear();
220  this->reserve(n);
221  for (unsigned long i=0; i<n; ++i)
222  {
223  const Interval<Num2>& ir(r[i]);
224  this->push_back(Interval<Numeric>(ir.min(), ir.max()));
225  }
226  return *this;
227  }
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 362 of file BoxND.h.

References i, and findQualityFiles::size.

363  {
364  const unsigned long mydim = this->size();
365  for (unsigned long i=0; i<mydim; ++i)
366  (*this)[i].expand(r);
367  return *this;
368  }
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 384 of file BoxND.h.

References i, and findQualityFiles::size.

386  {
387  const unsigned long mydim = this->size();
388  if (mydim != scales.size()) throw npstat::NpstatInvalidArgument(
389  "In npstat::BoxND::expand: incompatible argument dimensionality");
390  for (unsigned long i=0; i<mydim; ++i)
391  (*this)[i].expand(scales[i]);
392  return *this;
393  }
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 396 of file BoxND.h.

References i, and findQualityFiles::size.

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

References i, and findQualityFiles::size.

272  {
273  const unsigned long mydim = this->size();
274  if (coordLen < mydim) throw npstat::NpstatInvalidArgument(
275  "In npstat::BoxND::getMidpoint: insufficient output buffer length");
276  if (mydim)
277  {
278  assert(coord);
279  for (unsigned long i=0U; i<mydim; ++i)
280  coord[i] = (*this)[i].midpoint();
281  }
282  }
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 331 of file BoxND.h.

References i, and findQualityFiles::size.

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

References i, and findQualityFiles::size.

288  {
289  if (coordLen != this->size()) throw npstat::NpstatInvalidArgument(
290  "In npstat::BoxND::isInsideLower: "
291  "incompatible point dimensionality");
292  const Interval<Numeric>* myptr = &(*this)[0];
293  for (unsigned long i=0; i<coordLen; ++i)
294  if (!myptr[i].isInsideLower(coords[i]))
295  return false;
296  return true;
297  }
int i
Definition: DBlmapReader.cc:9
bool isInsideLower(const Num2 *coord, unsigned long coordLen) const
Definition: BoxND.h:286
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 301 of file BoxND.h.

References i, and findQualityFiles::size.

303  {
304  if (coordLen != this->size()) throw npstat::NpstatInvalidArgument(
305  "In npstat::BoxND::isInsideUpper: "
306  "incompatible point dimensionality");
307  const Interval<Numeric>* myptr = &(*this)[0];
308  for (unsigned long i=0; i<coordLen; ++i)
309  if (!myptr[i].isInsideUpper(coords[i]))
310  return false;
311  return true;
312  }
int i
Definition: DBlmapReader.cc:9
bool isInsideUpper(const Num2 *coord, unsigned long coordLen) const
Definition: BoxND.h:301
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 316 of file BoxND.h.

References i, and findQualityFiles::size.

318  {
319  if (coordLen != this->size()) throw npstat::NpstatInvalidArgument(
320  "In npstat::BoxND::isInsideWithBounds: "
321  "incompatible point dimensionality");
322  const Interval<Numeric>* myptr = &(*this)[0];
323  for (unsigned long i=0; i<coordLen; ++i)
324  if (!myptr[i].isInsideWithBounds(coords[i]))
325  return false;
326  return true;
327  }
int i
Definition: DBlmapReader.cc:9
bool isInsideWithBounds(const Num2 *coord, unsigned long coordLen) const
Definition: BoxND.h:316
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 353 of file BoxND.h.

References i, and findQualityFiles::size.

354  {
355  const unsigned long mydim = this->size();
356  for (unsigned long i=0; i<mydim; ++i)
357  (*this)[i].moveMidpointTo0();
358  return *this;
359  }
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 344 of file BoxND.h.

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

345  {
346  const unsigned long mydim = this->size();
347  for (unsigned long i=0; i<mydim; ++i)
348  (*this)[i] *= r;
349  return *this;
350  }
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 371 of file BoxND.h.

References i, and findQualityFiles::size.

373  {
374  const unsigned long mydim = this->size();
375  if (mydim != scales.size()) throw npstat::NpstatInvalidArgument(
376  "In npstat::BoxND::operator*=: "
377  "incompatible argument dimensionality");
378  for (unsigned long i=0; i<mydim; ++i)
379  (*this)[i] *= scales[i];
380  return *this;
381  }
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 435 of file BoxND.h.

References i, and findQualityFiles::size.

436  {
437  const unsigned long mydim = this->size();
438  if (mydim != shifts.size()) throw npstat::NpstatInvalidArgument(
439  "In npstat::BoxND::operator+=: "
440  "incompatible argument dimensionality");
441  for (unsigned long i=0; i<mydim; ++i)
442  (*this)[i] += static_cast<Numeric>(shifts[i]);
443  return *this;
444  }
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 465 of file BoxND.h.

References i, and findQualityFiles::size.

466  {
467  const unsigned long mydim = this->size();
468  if (mydim != shifts.size()) throw npstat::NpstatInvalidArgument(
469  "In npstat::BoxND::operator-=: "
470  "incompatible argument dimensionality");
471  for (unsigned long i=0; i<mydim; ++i)
472  (*this)[i] -= static_cast<Numeric>(shifts[i]);
473  return *this;
474  }
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 412 of file BoxND.h.

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

413  {
414  const unsigned long mydim = this->size();
415  for (unsigned long i=0; i<mydim; ++i)
416  (*this)[i] /= r;
417  return *this;
418  }
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 421 of file BoxND.h.

References i, and findQualityFiles::size.

423  {
424  const unsigned long mydim = this->size();
425  if (mydim != scales.size()) throw npstat::NpstatInvalidArgument(
426  "In npstat::BoxND::operator/=: "
427  "incompatible argument dimensionality");
428  for (unsigned long i=0; i<mydim; ++i)
429  (*this)[i] /= scales[i];
430  return *this;
431  }
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 255 of file BoxND.h.

References f, i, and findQualityFiles::size.

256  {
257  const unsigned long mydim = this->size();
258  if (mydim == r.size())
259  {
260  double f = 1.0;
261  for (unsigned long i=0U; i<mydim; ++i)
262  f *= (*this)[i].overlapFraction(r[i]);
263  return f;
264  }
265  else
266  return 0.0;
267  }
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 240 of file BoxND.h.

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

241  {
242  const unsigned long mydim = this->size();
243  if (mydim == r.size())
244  {
245  Numeric v(static_cast<Numeric>(1));
246  for (unsigned long i=0U; i<mydim; ++i)
247  v *= (*this)[i].overlapLength(r[i]);
248  return v;
249  }
250  else
251  return static_cast<Numeric>(0);
252  }
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 522 of file BoxND.h.

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

523  {
524  static const gs::ClassId current(gs::ClassId::makeId<BoxND<Numeric> >());
525  current.ensureSameId(id);
526 
527  std::vector<Numeric> limits;
528  gs::restore_item(in, &limits);
529  if (in.fail())
530  throw gs::IOReadFailure("In npstat::BoxND::restore: input stream failure");
531  const unsigned long nlimits = limits.size();
532  if (nlimits % 2UL)
533  throw gs::IOInvalidData("In npstat::BoxND::restore: bad limits");
534  assert(b);
535  b->clear();
536  b->reserve(nlimits/2UL);
537  for (unsigned long i=0; i<nlimits/2UL; ++i)
538  b->push_back(npstat::Interval<Numeric>(limits[2U*i], limits[2U*i+1U]));
539  }
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 448 of file BoxND.h.

References i, and findQualityFiles::size.

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

References i.

486  {
487  const Numeric one = static_cast<Numeric>(1);
488  Interval<Numeric> i(-one, one);
489  return BoxND<Numeric>(ndim, i);
490  }
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 477 of file BoxND.h.

References csvLumiCalc::unit.

478  {
479  Interval<Numeric> unit(static_cast<Numeric>(0),
480  static_cast<Numeric>(1));
481  return BoxND<Numeric>(ndim, unit);
482  }
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 230 of file BoxND.h.

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

231  {
232  Numeric v(static_cast<Numeric>(1));
233  const unsigned long mydim = this->size();
234  for (unsigned long i=0U; i<mydim; ++i)
235  v *= (*this)[i].length();
236  return v;
237  }
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 508 of file BoxND.h.

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

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