1 #ifndef NPSTAT_BOXND_HH_
2 #define NPSTAT_BOXND_HH_
16 #include "Alignment/Geners/interface/ClassId.hh"
23 template <
typename Numeric>
24 struct BoxND :
public std::vector<Interval<Numeric> >
30 inline explicit BoxND(
const unsigned long dim) :
31 std::vector<
Interval<Numeric> >(dim) {}
35 std::vector<
Interval<Numeric> >(dim, v) {}
42 template <
typename Num2>
43 explicit BoxND(
const std::vector<Num2>& limits);
46 template <
typename Num2>
53 template <
typename Num2>
57 inline unsigned long dim()
const {
return this->
size();}
66 void getMidpoint(Numeric* coord,
unsigned long coordLen)
const;
74 template <
typename Num2>
75 bool isInsideLower(
const Num2* coord,
unsigned long coordLen)
const;
76 template <
typename Num2>
77 bool isInsideUpper(
const Num2* coord,
unsigned long coordLen)
const;
78 template <
typename Num2>
80 template <
typename Num2>
81 bool isInside(
const Num2* coord,
unsigned long coordLen)
const;
109 BoxND&
expand(
const double* scales,
unsigned long lenScales);
114 template <
typename Num2>
116 template <
typename Num2>
118 template <
typename Num2>
119 BoxND&
shift(
const Num2* shifts,
unsigned long lenShifts);
150 inline gs::ClassId
classId()
const {
return gs::ClassId(*
this);}
151 bool write(std::ostream& of)
const;
156 static void restore(
const gs::ClassId&
id, std::istream&
in,
BoxND* box);
162 template <
typename Numeric>
165 template <
typename Numeric>
173 #include "Alignment/Geners/interface/GenericIO.hh"
174 #include "Alignment/Geners/interface/IOIsUnsigned.hh"
177 template <
typename Numeric>
178 template <
typename Num2>
181 const unsigned long dim = r.size();
185 for (
unsigned long i=0;
i<dim; ++
i)
193 template <
typename Numeric>
194 template <
typename Num2>
197 const unsigned long dim = limits.size();
201 Numeric zero = Numeric();
202 for (
unsigned long i=0;
i<dim; ++
i)
204 const Numeric
value(static_cast<Numeric>(limits[
i]));
213 template <
typename Numeric>
214 template <
typename Num2>
217 if ((
void *)
this == (
void *)(&r))
219 const unsigned long n = r.size();
222 for (
unsigned long i=0;
i<
n; ++
i)
230 template <
typename Numeric>
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();
240 template <
typename Numeric>
243 const unsigned long mydim = this->
size();
244 if (mydim == r.size())
246 Numeric
v(static_cast<Numeric>(1));
247 for (
unsigned long i=0U;
i<mydim; ++
i)
248 v *= (*
this)[
i].overlapLength(r[
i]);
252 return static_cast<Numeric
>(0);
255 template <
typename Numeric>
258 const unsigned long mydim = this->
size();
259 if (mydim == r.size())
262 for (
unsigned long i=0U;
i<mydim; ++
i)
263 f *= (*
this)[
i].overlapFraction(r[
i]);
270 template <
typename Numeric>
272 const unsigned long coordLen)
const
274 const unsigned long mydim = this->
size();
276 "In npstat::BoxND::getMidpoint: insufficient output buffer length");
280 for (
unsigned long i=0U;
i<mydim; ++
i)
281 coord[
i] = (*
this)[
i].midpoint();
285 template <
typename Numeric>
286 template <
typename Num2>
288 const unsigned long coordLen)
const
291 "In npstat::BoxND::isInsideLower: "
292 "incompatible point dimensionality");
294 for (
unsigned long i=0;
i<coordLen; ++
i)
295 if (!myptr[
i].isInsideLower(coords[
i]))
300 template <
typename Numeric>
301 template <
typename Num2>
303 const unsigned long coordLen)
const
306 "In npstat::BoxND::isInsideUpper: "
307 "incompatible point dimensionality");
309 for (
unsigned long i=0;
i<coordLen; ++
i)
310 if (!myptr[
i].isInsideUpper(coords[
i]))
315 template <
typename Numeric>
316 template <
typename Num2>
318 const unsigned long coordLen)
const
321 "In npstat::BoxND::isInsideWithBounds: "
322 "incompatible point dimensionality");
324 for (
unsigned long i=0;
i<coordLen; ++
i)
325 if (!myptr[
i].isInsideWithBounds(coords[
i]))
330 template <
typename Numeric>
331 template <
typename Num2>
333 const unsigned long coordLen)
const
336 "In npstat::BoxND::isInside: incompatible point dimensionality");
338 for (
unsigned long i=0;
i<coordLen; ++
i)
339 if (!myptr[
i].isInside(coords[
i]))
344 template <
typename Numeric>
347 const unsigned long mydim = this->
size();
348 for (
unsigned long i=0;
i<mydim; ++
i)
353 template <
typename Numeric>
356 const unsigned long mydim = this->
size();
357 for (
unsigned long i=0;
i<mydim; ++
i)
358 (*
this)[
i].moveMidpointTo0();
362 template <
typename Numeric>
365 const unsigned long mydim = this->
size();
366 for (
unsigned long i=0;
i<mydim; ++
i)
367 (*
this)[
i].expand(r);
371 template <
typename Numeric>
373 const std::vector<double>& scales)
375 const unsigned long mydim = this->
size();
377 "In npstat::BoxND::operator*=: "
378 "incompatible argument dimensionality");
379 for (
unsigned long i=0;
i<mydim; ++
i)
380 (*
this)[
i] *= scales[
i];
384 template <
typename Numeric>
386 const std::vector<double>& scales)
388 const unsigned long mydim = this->
size();
390 "In npstat::BoxND::expand: incompatible argument dimensionality");
391 for (
unsigned long i=0;
i<mydim; ++
i)
392 (*
this)[
i].expand(scales[
i]);
396 template <
typename Numeric>
398 const double* scales,
const unsigned long lenScales)
400 const unsigned long mydim = this->
size();
402 "In npstat::BoxND::expand: incompatible argument dimensionality");
406 for (
unsigned long i=0;
i<mydim; ++
i)
407 (*
this)[
i].expand(scales[
i]);
412 template <
typename Numeric>
415 const unsigned long mydim = this->
size();
416 for (
unsigned long i=0;
i<mydim; ++
i)
421 template <
typename Numeric>
423 const std::vector<double>& scales)
425 const unsigned long mydim = this->
size();
427 "In npstat::BoxND::operator/=: "
428 "incompatible argument dimensionality");
429 for (
unsigned long i=0;
i<mydim; ++
i)
430 (*
this)[
i] /= scales[
i];
434 template <
typename Numeric>
435 template <
typename Num2>
438 const unsigned long mydim = this->
size();
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]);
447 template <
typename Numeric>
448 template <
typename Num2>
450 const Num2* shifts,
const unsigned long shiftsLen)
452 const unsigned long mydim = this->
size();
454 "In npstat::BoxND::shift: incompatible argument dimensionality");
458 for (
unsigned long i=0;
i<mydim; ++
i)
459 (*
this)[
i] +=
static_cast<Numeric
>(shifts[
i]);
464 template <
typename Numeric>
465 template <
typename Num2>
468 const unsigned long mydim = this->
size();
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]);
477 template <
typename Numeric>
481 static_cast<Numeric>(1));
485 template <
typename Numeric>
488 const Numeric one =
static_cast<Numeric
>(1);
493 template <
typename Numeric>
503 template<
typename Numeric>
506 static const std::string na(gs::template_class_name<Numeric>(
"npstat::BoxND"));
510 template<
typename Numeric>
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)
518 limits.push_back((*
this)[
i].
min());
519 limits.push_back((*
this)[
i].
max());
521 return gs::write_item(of, limits);
524 template<
typename Numeric>
528 current.ensureSameId(
id);
530 std::vector<Numeric> limits;
531 gs::restore_item(in, &limits);
533 throw gs::IOReadFailure(
"In npstat::BoxND::restore: input stream failure");
534 const unsigned long nlimits = limits.size();
536 throw gs::IOInvalidData(
"In npstat::BoxND::restore: bad limits");
539 b->reserve(nlimits/2UL);
540 for (
unsigned long i=0;
i<nlimits/2UL; ++
i)
545 template <
typename Numeric>
548 const unsigned long dim = l.size();
551 for (
unsigned long i=0;
i<dim; ++
i)
557 template <
typename Numeric>
564 #endif // NPSTAT_BOXND_HH_
BoxND(const unsigned long dim)
bool isInside(const Num2 *coord, unsigned long coordLen) const
static BoxND unitBox(unsigned long ndim)
bool write(std::ostream &of) const
static void restore(const gs::ClassId &id, std::istream &in, BoxND *box)
BoxND & operator*=(double r)
void getMidpoint(Numeric *coord, unsigned long coordLen) const
bool isInsideWithBounds(const Num2 *coord, unsigned long coordLen) const
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &)
const Numeric max() const
unsigned long dim() const
Exceptions for the npstat namespace.
BoxND & operator+=(const std::vector< Num2 > &shifts)
static unsigned version()
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
bool isInsideLower(const Num2 *coord, unsigned long coordLen) const
bool operator==(const QGLikelihoodParameters &lhs, const QGLikelihoodCategory &rhs)
Test if parameters are compatible with category.
static BoxND allSpace(unsigned long ndim)
static const char * classname()
static BoxND sizeTwoBox(unsigned long ndim)
Numeric overlapVolume(const BoxND &r) const
BoxND & operator-=(const std::vector< Num2 > &shifts)
void setMin(const Numeric value)
double overlapFraction(const BoxND &r) const
BoxND & shift(const Num2 *shifts, unsigned long lenShifts)
BoxND(const unsigned long dim, const Interval< Numeric > &v)
BoxND & operator/=(double r)
const Numeric min() const
gs::ClassId classId() const
BoxND & copyFrom(const BoxND< Num2 > &r)
bool isInsideUpper(const Num2 *coord, unsigned long coordLen) const
tuple size
Write out results.