|
|
Go to the documentation of this file. 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> > {
39 template <
typename Num2>
43 template <
typename Num2>
50 template <
typename Num2>
54 inline unsigned long dim()
const {
return this->
size(); }
63 void getMidpoint(Numeric* coord,
unsigned long coordLen)
const;
71 template <
typename Num2>
72 bool isInsideLower(
const Num2* coord,
unsigned long coordLen)
const;
73 template <
typename Num2>
74 bool isInsideUpper(
const Num2* coord,
unsigned long coordLen)
const;
75 template <
typename Num2>
77 template <
typename Num2>
78 bool isInside(
const Num2* coord,
unsigned long coordLen)
const;
106 BoxND&
expand(
const double* scales,
unsigned long lenScales);
111 template <
typename Num2>
113 template <
typename Num2>
115 template <
typename Num2>
116 BoxND&
shift(
const Num2* shifts,
unsigned long lenShifts);
147 inline gs::ClassId
classId()
const {
return gs::ClassId(*
this); }
148 bool write(std::ostream& of)
const;
152 static inline unsigned version() {
return 1; }
153 static void restore(
const gs::ClassId&
id, std::istream&
in,
BoxND* box);
159 template <
typename Numeric>
162 template <
typename Numeric>
170 #include "Alignment/Geners/interface/GenericIO.hh"
171 #include "Alignment/Geners/interface/IOIsUnsigned.hh"
174 template <
typename Numeric>
175 template <
typename Num2>
177 const unsigned long dim =
r.size();
180 for (
unsigned long i = 0;
i < dim; ++
i) {
187 template <
typename Numeric>
188 template <
typename Num2>
190 const unsigned long dim =
limits.size();
193 Numeric zero = Numeric();
194 for (
unsigned long i = 0;
i < dim; ++
i) {
204 template <
typename Numeric>
205 template <
typename Num2>
207 if ((
void*)
this == (
void*)(&
r))
209 const unsigned long n =
r.size();
212 for (
unsigned long i = 0;
i <
n; ++
i) {
219 template <
typename Numeric>
221 Numeric
v(static_cast<Numeric>(1));
222 const unsigned long mydim = this->
size();
223 for (
unsigned long i = 0
U;
i < mydim; ++
i)
224 v *= (*
this)[
i].length();
228 template <
typename Numeric>
230 const unsigned long mydim = this->
size();
231 if (mydim ==
r.size()) {
232 Numeric
v(static_cast<Numeric>(1));
233 for (
unsigned long i = 0
U;
i < mydim; ++
i)
234 v *= (*
this)[
i].overlapLength(
r[
i]);
237 return static_cast<Numeric>(0);
240 template <
typename Numeric>
242 const unsigned long mydim = this->
size();
243 if (mydim ==
r.size()) {
245 for (
unsigned long i = 0
U;
i < mydim; ++
i)
246 f *= (*
this)[
i].overlapFraction(
r[
i]);
252 template <
typename Numeric>
254 const unsigned long mydim = this->
size();
255 if (coordLen < mydim)
259 for (
unsigned long i = 0
U;
i < mydim; ++
i)
260 coord[
i] = (*
this)[
i].midpoint();
264 template <
typename Numeric>
265 template <
typename Num2>
267 if (coordLen != this->
size())
269 "In npstat::BoxND::isInsideLower: "
270 "incompatible point dimensionality");
272 for (
unsigned long i = 0;
i < coordLen; ++
i)
273 if (!myptr[
i].isInsideLower(coords[
i]))
278 template <
typename Numeric>
279 template <
typename Num2>
281 if (coordLen != this->
size())
283 "In npstat::BoxND::isInsideUpper: "
284 "incompatible point dimensionality");
286 for (
unsigned long i = 0;
i < coordLen; ++
i)
287 if (!myptr[
i].isInsideUpper(coords[
i]))
292 template <
typename Numeric>
293 template <
typename Num2>
295 if (coordLen != this->
size())
297 "In npstat::BoxND::isInsideWithBounds: "
298 "incompatible point dimensionality");
300 for (
unsigned long i = 0;
i < coordLen; ++
i)
301 if (!myptr[
i].isInsideWithBounds(coords[
i]))
306 template <
typename Numeric>
307 template <
typename Num2>
309 if (coordLen != this->
size())
312 for (
unsigned long i = 0;
i < coordLen; ++
i)
313 if (!myptr[
i].isInside(coords[
i]))
318 template <
typename Numeric>
320 const unsigned long mydim = this->
size();
321 for (
unsigned long i = 0;
i < mydim; ++
i)
326 template <
typename Numeric>
328 const unsigned long mydim = this->
size();
329 for (
unsigned long i = 0;
i < mydim; ++
i)
330 (*
this)[
i].moveMidpointTo0();
334 template <
typename Numeric>
336 const unsigned long mydim = this->
size();
337 for (
unsigned long i = 0;
i < mydim; ++
i)
338 (*
this)[
i].expand(
r);
342 template <
typename Numeric>
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];
354 template <
typename Numeric>
356 const unsigned long mydim = this->
size();
357 if (mydim != scales.size())
359 for (
unsigned long i = 0;
i < mydim; ++
i)
360 (*
this)[
i].expand(scales[
i]);
364 template <
typename Numeric>
366 const unsigned long mydim = this->
size();
367 if (mydim != lenScales)
371 for (
unsigned long i = 0;
i < mydim; ++
i)
372 (*
this)[
i].expand(scales[
i]);
377 template <
typename Numeric>
379 const unsigned long mydim = this->
size();
380 for (
unsigned long i = 0;
i < mydim; ++
i)
385 template <
typename Numeric>
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];
397 template <
typename Numeric>
398 template <
typename Num2>
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]);
410 template <
typename Numeric>
411 template <
typename Num2>
413 const unsigned long mydim = this->
size();
414 if (mydim != shiftsLen)
418 for (
unsigned long i = 0;
i < mydim; ++
i)
419 (*
this)[
i] += static_cast<Numeric>(shifts[
i]);
424 template <
typename Numeric>
425 template <
typename Num2>
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]);
437 template <
typename Numeric>
443 template <
typename Numeric>
445 const Numeric one = static_cast<Numeric>(1);
450 template <
typename Numeric>
459 template <
typename Numeric>
461 static const std::string na(gs::template_class_name<Numeric>(
"npstat::BoxND"));
465 template <
typename Numeric>
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) {
474 return gs::write_item(of,
limits);
477 template <
typename Numeric>
479 static const gs::ClassId current(gs::ClassId::makeId<
BoxND<Numeric> >());
480 current.ensureSameId(
id);
482 std::vector<Numeric>
limits;
485 throw gs::IOReadFailure(
"In npstat::BoxND::restore: input stream failure");
486 const unsigned long nlimits =
limits.size();
488 throw gs::IOInvalidData(
"In npstat::BoxND::restore: bad limits");
491 b->reserve(nlimits / 2UL);
492 for (
unsigned long i = 0;
i < nlimits / 2UL; ++
i)
497 template <
typename Numeric>
499 const unsigned long dim =
l.size();
502 for (
unsigned long i = 0;
i < dim; ++
i)
508 template <
typename Numeric>
513 #endif // NPSTAT_BOXND_HH_
double overlapFraction(const BoxND &r) const
BoxND & operator*=(double r)
bool isInsideUpper(const Num2 *coord, unsigned long coordLen) const
BoxND & shift(const Num2 *shifts, unsigned long lenShifts)
const Numeric min() const
bool isInside(const Num2 *coord, unsigned long coordLen) const
void getMidpoint(Numeric *coord, unsigned long coordLen) const
bool isInsideWithBounds(const Num2 *coord, unsigned long coordLen) const
BoxND(const unsigned long dim)
static unsigned version()
BoxND & operator-=(const std::vector< Num2 > &shifts)
static BoxND unitBox(unsigned long ndim)
Numeric overlapVolume(const BoxND &r) const
BoxND(const unsigned long dim, const Interval< Numeric > &v)
gs::ClassId classId() const
static const char * classname()
void clear(HadCaloObj &c)
static BoxND allSpace(unsigned long ndim)
bool write(std::ostream &of) const
static BoxND sizeTwoBox(unsigned long ndim)
const Numeric max() const
Basic3DVector unit() const
bool operator!=(const npstat::BoxND< Numeric > &l, const npstat::BoxND< Numeric > &r)
Template to represent intervals in one dimension.
BoxND & operator+=(const std::vector< Num2 > &shifts)
unsigned long dim() const
bool isInsideLower(const Num2 *coord, unsigned long coordLen) const
BoxND & operator/=(double r)
Exceptions for the npstat namespace.
static void restore(const gs::ClassId &id, std::istream &in, BoxND *box)
bool operator==(const npstat::BoxND< Numeric > &l, const npstat::BoxND< Numeric > &r)
BoxND & copyFrom(const BoxND< Num2 > &r)