CMS 3D CMS Logo

Public Member Functions | Static Public Member Functions

npstat::BoxND< Numeric > Struct Template Reference

#include <BoxND.h>

Inheritance diagram for npstat::BoxND< Numeric >:
vector

List of all members.

Public Member Functions

 BoxND ()
 BoxND (const unsigned long dim)
template<typename Num2 >
 BoxND (const std::vector< Num2 > &limits)
template<typename Num2 >
 BoxND (const BoxND< Num2 > &r)
 BoxND (const unsigned long dim, const Interval< Numeric > &v)
template<typename Num2 >
BoxNDcopyFrom (const BoxND< Num2 > &r)
unsigned long dim () const
BoxNDexpand (double r)
void getMidpoint (Numeric *coord, unsigned long coordLen) const
BoxNDmoveToOrigin ()
double overlapFraction (const BoxND &r) const
Numeric overlapVolume (const BoxND &r) const
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.

{}
template<typename Numeric>
npstat::BoxND< Numeric >::BoxND ( const unsigned long  dim) [inline, explicit]

Interval in each dimension is made by its default constructor

Definition at line 30 of file BoxND.h.

                                                       :
            std::vector<Interval<Numeric> >(dim) {}
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.

                                                                          :
            std::vector<Interval<Numeric> >(dim, v) {}
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, relativeConstraints::value, and zero.

    {
        const unsigned long dim = limits.size();
        if (dim)
        {
            this->reserve(dim);
            Numeric zero = Numeric();
            for (unsigned long i=0; i<dim; ++i)
            {
                const Numeric value(static_cast<Numeric>(limits[i]));
                if (value >= zero)
                    this->push_back(Interval<Numeric>(zero, value));
                else
                    this->push_back(Interval<Numeric>(value, zero));
            }
        }
    }
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().

    {
        const unsigned long dim = r.size();
        if (dim)
        {
            this->reserve(dim);
            for (unsigned long i=0; i<dim; ++i)
            {
                const Interval<Num2>& ri(r[i]);
                this->push_back(Interval<Numeric>(ri.min(), ri.max()));
            }
        }
    }

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().

    {
        const Numeric maxval = std::numeric_limits<Numeric>::max();
        Interval<Numeric> i(-maxval, maxval);
        return BoxND<Numeric>(ndim, i);
    }
template<typename Numeric>
gs::ClassId npstat::BoxND< Numeric >::classId ( ) const [inline]

Methods related to I/O

Definition at line 150 of file BoxND.h.

{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.

    {
        static const std::string na(gs::template_class_name<Numeric>("npstat::BoxND"));
        return na.c_str();
    }
template<typename Numeric >
template<typename Num2 >
BoxND< Numeric > & 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.

Definition at line 214 of file BoxND.h.

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

    {
        if ((void *)this == (void *)(&r))
            return *this;
        const unsigned long n = r.size();
        this->clear();
        this->reserve(n);
        for (unsigned long i=0; i<n; ++i)
        {
            const Interval<Num2>& ir(r[i]);
            this->push_back(Interval<Numeric>(ir.min(), ir.max()));
        }
        return *this;
    }
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().

{return this->size();}
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.

    {
        const unsigned long mydim = this->size();
        for (unsigned long i=0; i<mydim; ++i)
            (*this)[i].expand(r);
        return *this;
    }
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.

    {
        const unsigned long mydim = this->size();
        if (mydim != scales.size()) throw npstat::NpstatInvalidArgument(
            "In npstat::BoxND::expand: incompatible argument dimensionality");
        for (unsigned long i=0; i<mydim; ++i)
            (*this)[i].expand(scales[i]);
        return *this;
    }
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.

    {
        const unsigned long mydim = this->size();
        if (mydim != lenScales) throw npstat::NpstatInvalidArgument(
            "In npstat::BoxND::expand: incompatible argument dimensionality");
        if (mydim)
        {
            assert(scales);
            for (unsigned long i=0; i<mydim; ++i)
                (*this)[i].expand(scales[i]);
        }
        return *this;
    }
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.

    {
        const unsigned long mydim = this->size();
        if (coordLen < mydim) throw npstat::NpstatInvalidArgument(
            "In npstat::BoxND::getMidpoint: insufficient output buffer length");
        if (mydim)
        {
            assert(coord);
            for (unsigned  long i=0U; i<mydim; ++i)
                coord[i] = (*this)[i].midpoint();
        }
    }
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.

    {
        if (coordLen != this->size()) throw npstat::NpstatInvalidArgument(
            "In npstat::BoxND::isInside: incompatible point dimensionality");
        const Interval<Numeric>* myptr = &(*this)[0];
        for (unsigned long i=0; i<coordLen; ++i)
            if (!myptr[i].isInside(coords[i]))
                return false;
        return true;
    }
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.

    {
        if (coordLen != this->size()) throw npstat::NpstatInvalidArgument(
            "In npstat::BoxND::isInsideLower: "
            "incompatible point dimensionality");
        const Interval<Numeric>* myptr = &(*this)[0];
        for (unsigned long i=0; i<coordLen; ++i)
            if (!myptr[i].isInsideLower(coords[i]))
                return false;
        return true;
    }
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.

    {
        if (coordLen != this->size()) throw npstat::NpstatInvalidArgument(
            "In npstat::BoxND::isInsideUpper: "
            "incompatible point dimensionality");
        const Interval<Numeric>* myptr = &(*this)[0];
        for (unsigned long i=0; i<coordLen; ++i)
            if (!myptr[i].isInsideUpper(coords[i]))
                return false;
        return true;
    }
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.

    {
        if (coordLen != this->size()) throw npstat::NpstatInvalidArgument(
            "In npstat::BoxND::isInsideWithBounds: "
            "incompatible point dimensionality");
        const Interval<Numeric>* myptr = &(*this)[0];
        for (unsigned long i=0; i<coordLen; ++i)
            if (!myptr[i].isInsideWithBounds(coords[i]))
                return false;
        return true;
    }
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.

    {
        const unsigned long mydim = this->size();
        for (unsigned long i=0; i<mydim; ++i)
            (*this)[i].moveMidpointTo0();
        return *this;
    }
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.

    {
        const unsigned long mydim = this->size();
        for (unsigned long i=0; i<mydim; ++i)
            (*this)[i] *= r;
        return *this;
    }
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.

    {
        const unsigned long mydim = this->size();
        if (mydim != scales.size()) throw npstat::NpstatInvalidArgument(
            "In npstat::BoxND::operator*=: "
            "incompatible argument dimensionality");
        for (unsigned long i=0; i<mydim; ++i)
            (*this)[i] *= scales[i];
        return *this;
    }
template<typename Numeric >
template<typename Num2 >
BoxND< Numeric > & npstat::BoxND< Numeric >::operator+= ( const std::vector< Num2 > &  shifts)

Shifting this object

Definition at line 435 of file BoxND.h.

References i, and findQualityFiles::size.

    {
        const unsigned long mydim = this->size();
        if (mydim != shifts.size()) throw npstat::NpstatInvalidArgument(
            "In npstat::BoxND::operator+=: "
            "incompatible argument dimensionality");
        for (unsigned long i=0; i<mydim; ++i)
            (*this)[i] += static_cast<Numeric>(shifts[i]);
        return *this;
    }
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.

    {
        const unsigned long mydim = this->size();
        if (mydim != shifts.size()) throw npstat::NpstatInvalidArgument(
            "In npstat::BoxND::operator-=: "
            "incompatible argument dimensionality");
        for (unsigned long i=0; i<mydim; ++i)
            (*this)[i] -= static_cast<Numeric>(shifts[i]);
        return *this;
    }
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.

    {
        const unsigned long mydim = this->size();
        for (unsigned long i=0; i<mydim; ++i)
            (*this)[i] /= r;
        return *this;
    }
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.

    {
        const unsigned long mydim = this->size();
        if (mydim != scales.size()) throw npstat::NpstatInvalidArgument(
            "In npstat::BoxND::operator/=: "
            "incompatible argument dimensionality");
        for (unsigned long i=0; i<mydim; ++i)
            (*this)[i] /= scales[i];
        return *this;
    }
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.

    {
        const unsigned long mydim = this->size();
        if (mydim == r.size())
        {
            double f = 1.0;
            for (unsigned long i=0U; i<mydim; ++i)
                f *= (*this)[i].overlapFraction(r[i]);
            return f;
        }
        else
            return 0.0;
    }
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 v.

    {
        const unsigned long mydim = this->size();
        if (mydim == r.size())
        {
            Numeric v(static_cast<Numeric>(1));
            for (unsigned long i=0U; i<mydim; ++i)
                v *= (*this)[i].overlapLength(r[i]);
            return v;
        }
        else
            return static_cast<Numeric>(0);
    }
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.

    {
        static const gs::ClassId current(gs::ClassId::makeId<BoxND<Numeric> >());
        current.ensureSameId(id);

        std::vector<Numeric> limits;
        gs::restore_item(in, &limits);
        if (in.fail())
            throw gs::IOReadFailure("In npstat::BoxND::restore: input stream failure");
        const unsigned long nlimits = limits.size();
        if (nlimits % 2UL)
            throw gs::IOInvalidData("In npstat::BoxND::restore: bad limits");
        assert(b);
        b->clear();
        b->reserve(nlimits/2UL);
        for (unsigned long i=0; i<nlimits/2UL; ++i)
            b->push_back(npstat::Interval<Numeric>(limits[2U*i], limits[2U*i+1U]));
    }
template<typename Numeric >
template<typename Num2 >
BoxND< Numeric > & npstat::BoxND< Numeric >::shift ( const Num2 *  shifts,
unsigned long  lenShifts 
)

Definition at line 448 of file BoxND.h.

References i, and findQualityFiles::size.

    {
        const unsigned long mydim = this->size();
        if (mydim != shiftsLen) throw npstat::NpstatInvalidArgument(
            "In npstat::BoxND::shift: incompatible argument dimensionality");
        if (mydim)
        {
            assert(shifts);
            for (unsigned long i=0; i<mydim; ++i)
                (*this)[i] += static_cast<Numeric>(shifts[i]);
        }
        return *this;
    }
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.

    {
        const Numeric one = static_cast<Numeric>(1);
        Interval<Numeric> i(-one, one);
        return BoxND<Numeric>(ndim, i);
    }
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.

    {
        Interval<Numeric> unit(static_cast<Numeric>(0),
                               static_cast<Numeric>(1));
        return BoxND<Numeric>(ndim, unit);
    }
template<typename Numeric>
static unsigned npstat::BoxND< Numeric >::version ( ) [inline, static]

Definition at line 155 of file BoxND.h.

{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 v.

    {
        Numeric v(static_cast<Numeric>(1));
        const unsigned long mydim = this->size();
        for (unsigned long i=0U; i<mydim; ++i)
            v *= (*this)[i].length();
        return v;
    }
template<typename Numeric >
bool npstat::BoxND< Numeric >::write ( std::ostream &  of) const

Definition at line 508 of file BoxND.h.

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

    {
        const unsigned long mydim = this->size();
        std::vector<Numeric> limits;
        limits.reserve(2UL*mydim);
        for (unsigned long i=0; i<mydim; ++i)
        {
            limits.push_back((*this)[i].min());
            limits.push_back((*this)[i].max());
        }
        return gs::write_item(of, limits);
    }