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"
176 template <
typename Numeric>
177 template <
typename Num2>
180 const unsigned long dim = r.size();
184 for (
unsigned long i=0;
i<dim; ++
i)
192 template <
typename Numeric>
193 template <
typename Num2>
196 const unsigned long dim = limits.size();
200 Numeric zero = Numeric();
201 for (
unsigned long i=0;
i<dim; ++
i)
203 const Numeric
value(static_cast<Numeric>(limits[
i]));
212 template <
typename Numeric>
213 template <
typename Num2>
216 if ((
void *)
this == (
void *)(&r))
218 const unsigned long n = r.size();
221 for (
unsigned long i=0;
i<
n; ++
i)
229 template <
typename Numeric>
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();
239 template <
typename Numeric>
242 const unsigned long mydim = this->
size();
243 if (mydim == r.size())
245 Numeric
v(static_cast<Numeric>(1));
246 for (
unsigned long i=0U;
i<mydim; ++
i)
247 v *= (*
this)[
i].overlapLength(r[
i]);
251 return static_cast<Numeric
>(0);
254 template <
typename Numeric>
257 const unsigned long mydim = this->
size();
258 if (mydim == r.size())
261 for (
unsigned long i=0U;
i<mydim; ++
i)
262 f *= (*
this)[
i].overlapFraction(r[
i]);
269 template <
typename Numeric>
271 const unsigned long coordLen)
const
273 const unsigned long mydim = this->
size();
275 "In npstat::BoxND::getMidpoint: insufficient output buffer length");
279 for (
unsigned long i=0U;
i<mydim; ++
i)
280 coord[
i] = (*
this)[
i].midpoint();
284 template <
typename Numeric>
285 template <
typename Num2>
287 const unsigned long coordLen)
const
290 "In npstat::BoxND::isInsideLower: "
291 "incompatible point dimensionality");
293 for (
unsigned long i=0;
i<coordLen; ++
i)
294 if (!myptr[
i].isInsideLower(coords[
i]))
299 template <
typename Numeric>
300 template <
typename Num2>
302 const unsigned long coordLen)
const
305 "In npstat::BoxND::isInsideUpper: "
306 "incompatible point dimensionality");
308 for (
unsigned long i=0;
i<coordLen; ++
i)
309 if (!myptr[
i].isInsideUpper(coords[
i]))
314 template <
typename Numeric>
315 template <
typename Num2>
317 const unsigned long coordLen)
const
320 "In npstat::BoxND::isInsideWithBounds: "
321 "incompatible point dimensionality");
323 for (
unsigned long i=0;
i<coordLen; ++
i)
324 if (!myptr[
i].isInsideWithBounds(coords[
i]))
329 template <
typename Numeric>
330 template <
typename Num2>
332 const unsigned long coordLen)
const
335 "In npstat::BoxND::isInside: incompatible point dimensionality");
337 for (
unsigned long i=0;
i<coordLen; ++
i)
338 if (!myptr[
i].isInside(coords[
i]))
343 template <
typename Numeric>
346 const unsigned long mydim = this->
size();
347 for (
unsigned long i=0;
i<mydim; ++
i)
352 template <
typename Numeric>
355 const unsigned long mydim = this->
size();
356 for (
unsigned long i=0;
i<mydim; ++
i)
357 (*
this)[
i].moveMidpointTo0();
361 template <
typename Numeric>
364 const unsigned long mydim = this->
size();
365 for (
unsigned long i=0;
i<mydim; ++
i)
366 (*
this)[
i].expand(r);
370 template <
typename Numeric>
372 const std::vector<double>& scales)
374 const unsigned long mydim = this->
size();
376 "In npstat::BoxND::operator*=: "
377 "incompatible argument dimensionality");
378 for (
unsigned long i=0;
i<mydim; ++
i)
379 (*
this)[
i] *= scales[
i];
383 template <
typename Numeric>
385 const std::vector<double>& scales)
387 const unsigned long mydim = this->
size();
389 "In npstat::BoxND::expand: incompatible argument dimensionality");
390 for (
unsigned long i=0;
i<mydim; ++
i)
391 (*
this)[
i].expand(scales[
i]);
395 template <
typename Numeric>
397 const double* scales,
const unsigned long lenScales)
399 const unsigned long mydim = this->
size();
401 "In npstat::BoxND::expand: incompatible argument dimensionality");
405 for (
unsigned long i=0;
i<mydim; ++
i)
406 (*
this)[
i].expand(scales[
i]);
411 template <
typename Numeric>
414 const unsigned long mydim = this->
size();
415 for (
unsigned long i=0;
i<mydim; ++
i)
420 template <
typename Numeric>
422 const std::vector<double>& scales)
424 const unsigned long mydim = this->
size();
426 "In npstat::BoxND::operator/=: "
427 "incompatible argument dimensionality");
428 for (
unsigned long i=0;
i<mydim; ++
i)
429 (*
this)[
i] /= scales[
i];
433 template <
typename Numeric>
434 template <
typename Num2>
437 const unsigned long mydim = this->
size();
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]);
446 template <
typename Numeric>
447 template <
typename Num2>
449 const Num2* shifts,
const unsigned long shiftsLen)
451 const unsigned long mydim = this->
size();
453 "In npstat::BoxND::shift: incompatible argument dimensionality");
457 for (
unsigned long i=0;
i<mydim; ++
i)
458 (*
this)[
i] +=
static_cast<Numeric
>(shifts[
i]);
463 template <
typename Numeric>
464 template <
typename Num2>
467 const unsigned long mydim = this->
size();
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]);
476 template <
typename Numeric>
480 static_cast<Numeric>(1));
484 template <
typename Numeric>
487 const Numeric one =
static_cast<Numeric
>(1);
492 template <
typename Numeric>
500 template<
typename Numeric>
503 static const std::string na(gs::template_class_name<Numeric>(
"npstat::BoxND"));
507 template<
typename Numeric>
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)
515 limits.push_back((*
this)[
i].
min());
516 limits.push_back((*
this)[
i].
max());
518 return gs::write_item(of, limits);
521 template<
typename Numeric>
525 current.ensureSameId(
id);
527 std::vector<Numeric> limits;
528 gs::restore_item(in, &limits);
530 throw gs::IOReadFailure(
"In npstat::BoxND::restore: input stream failure");
531 const unsigned long nlimits = limits.size();
533 throw gs::IOInvalidData(
"In npstat::BoxND::restore: bad limits");
536 b->reserve(nlimits/2UL);
537 for (
unsigned long i=0;
i<nlimits/2UL; ++
i)
542 template <
typename Numeric>
545 const unsigned long dim = l.size();
548 for (
unsigned long i=0;
i<dim; ++
i)
554 template <
typename Numeric>
561 #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 &)
bool operator==(const CaloTower &t1, const CaloTower &t2)
const Numeric max() const
unsigned long dim() const
Exceptions for the npstat namespace.
BoxND & operator+=(const std::vector< Num2 > &shifts)
const T & max(const T &a, const T &b)
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
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)
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.