Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:21:54

0001 // @(#)root/mathcore:$Id$
0002 // Author: L. Moneta Wed Aug 30 11:05:02 2006
0003 
0004 /**********************************************************************
0005  *                                                                    *
0006  * Copyright (c) 2006  LCG ROOT Math Team, CERN/PH-SFT                *
0007  *                                                                    *
0008  *                                                                    *
0009  **********************************************************************/
0010 
0011 // Header file for class DataRange
0012 
0013 #ifndef ROOT_Fit_DataRange
0014 #define ROOT_Fit_DataRange
0015 
0016 #include <vector>
0017 #include <utility>
0018 
0019 namespace ROOT {
0020 
0021    namespace Fit {
0022 
0023 
0024 //___________________________________________________________________________________
0025 /**
0026    class describing the range in the coordinates
0027    it supports  multiple range in a coordinate.
0028    The range dimension is the dimension of the coordinate, its size is
0029    the number of interval for each coordinate.
0030    Default range is -inf, inf
0031    Range can be modified with the add range method
0032 
0033    @ingroup FitData
0034 */
0035 class DataRange {
0036 
0037 public:
0038 
0039    typedef std::vector<std::pair<double,double> > RangeSet;
0040    typedef std::vector< RangeSet >   RangeIntervals;
0041 
0042    /**
0043       Default constructor (infinite range)
0044    */
0045    explicit DataRange (unsigned int dim = 1) :
0046       fRanges ( std::vector<RangeSet> (dim) )
0047    {}
0048 
0049    /**
0050       construct a range for [xmin, xmax]
0051     */
0052    DataRange(double xmin, double xmax);
0053 
0054    /**
0055       construct a range for [xmin, xmax] , [ymin, ymax]
0056     */
0057    DataRange(double xmin, double xmax, double ymin, double ymax);
0058    /**
0059       construct a range for [xmin, xmax] , [ymin, ymax] , [zmin, zmax]
0060     */
0061    DataRange(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax);
0062    /**
0063       get range dimension
0064     */
0065    unsigned int NDim() const { return fRanges.size(); }
0066 
0067    /**
0068       return range size for coordinate icoord (starts from zero)
0069       Size == 0 indicates no range is present [-inf, + inf]
0070    */
0071    unsigned int Size(unsigned int icoord = 0) const {
0072       return icoord <  fRanges.size() ? fRanges[icoord].size() : 0;
0073    }
0074 
0075    /**
0076       return true if a range has been set in any of  the coordinates
0077       i.e. when  it is not [-inf,+inf] for all coordinates
0078       Avoid in case of multi-dim to loop on all the coordinated and ask the size
0079     */
0080    bool IsSet() const {
0081       for (unsigned int icoord = 0; icoord < fRanges.size(); ++icoord)
0082          if (!fRanges[icoord].empty()) return true;
0083       return false;
0084    }
0085 
0086    /**
0087        return the vector of ranges for the coordinate icoord
0088    */
0089    const RangeSet & Ranges(unsigned int icoord = 0) const {
0090       // return icoord <  fRanges.size() ? fRanges[icoord] : RangeSet();
0091       return fRanges.at(icoord);
0092    }
0093 
0094    /**
0095        return the i-th range for the coordinate icoord.
0096        Useful method when only one range is present for the given coordinate
0097    */
0098    std::pair<double, double> operator() (unsigned int icoord = 0,unsigned int irange = 0) const;
0099 
0100    /**
0101       get the i-th range for given coordinate. If range does not exist
0102       return -inf, +inf
0103     */
0104    void GetRange(unsigned int irange, unsigned int icoord, double & xmin, double & xmax) const {
0105       if (Size(icoord)<= irange) GetInfRange(xmin,xmax);
0106       else {
0107          xmin = fRanges[icoord][irange].first;
0108          xmax = fRanges[icoord][irange].second;
0109       }
0110    }
0111    /**
0112       get the first range for given coordinate. If range does not exist
0113       return -inf, +inf
0114     */
0115    void GetRange(unsigned int icoord, double & xmin, double & xmax) const {
0116       if (Size(icoord) == 0) GetInfRange(xmin,xmax);
0117       else {
0118          xmin = fRanges[icoord].front().first;
0119          xmax = fRanges[icoord].front().second;
0120       }
0121    }
0122    /**
0123       get first range for the x - coordinate
0124     */
0125    void GetRange(double & xmin, double & xmax,unsigned int irange = 0) const {  GetRange(irange,0,xmin,xmax); }
0126    /**
0127       get range for the x and y coordinates
0128     */
0129    void GetRange(double & xmin, double & xmax, double & ymin, double & ymax,unsigned int irange = 0) const {
0130       GetRange(irange,0,xmin,xmax); GetRange(irange,1,ymin,ymax);
0131    }
0132    /**
0133       get range for the x and y and z coordinates
0134     */
0135    void GetRange(double & xmin, double & xmax, double & ymin, double & ymax, double & zmin, double & zmax,unsigned int irange=0) const {
0136       GetRange(irange,0,xmin,xmax); GetRange(irange,1,ymin,ymax); GetRange(irange,2,zmin,zmax);
0137    }
0138    /**
0139       get range for coordinates and fill the vector
0140     */
0141    void GetRange(double * xmin, double * xmax, unsigned int irange = 0)   const {
0142       for (unsigned int i = 0; i < fRanges.size(); ++i)
0143          GetRange(irange,i,xmin[i],xmax[i]);
0144    }
0145 
0146    /**
0147       Destructor (no operations)
0148    */
0149    ~DataRange ()  {}
0150 
0151 
0152 
0153    /**
0154       add a range [xmin,xmax] for the new coordinate icoord
0155       Adding a range does not delete existing one, but takes the OR with
0156       existing ranges.
0157       if want to replace range use method SetRange, which replace range with existing one
0158     */
0159    void AddRange(unsigned  int  icoord , double xmin, double xmax );
0160 
0161    /**
0162       add a range [xmin,xmax] for the first coordinate icoord
0163     */
0164    void AddRange(double xmin, double xmax ) { AddRange(0,xmin,xmax); }
0165    /**
0166       add a range [xmin,xmax] for the first and [ymin,ymax] for the second coordinate
0167     */
0168    void AddRange(double xmin, double xmax, double ymin, double ymax ) { AddRange(0,xmin,xmax); AddRange(1,ymin,ymax); }
0169    /**
0170       add a range [xmin,xmax] for the first and [ymin,ymax] for the second coordinate and
0171       [zmin,zmax] for the third coordinate
0172     */
0173    void AddRange(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax ) {
0174       AddRange(0,xmin,xmax); AddRange(1,ymin,ymax); AddRange(2,zmin,zmax); }
0175 
0176    /**
0177       set a range [xmin,xmax] for the new coordinate icoord
0178       If more range exists for other coordinates, delete the existing one and use it the new one
0179       Use Add range if want to keep the union of the existing ranges
0180     */
0181    void SetRange(unsigned  int  icoord , double xmin, double xmax );
0182 
0183    /**
0184       set a range [xmin,xmax] for the first coordinate icoord
0185     */
0186    void SetRange(double xmin, double xmax ) { SetRange(0,xmin,xmax); }
0187    /**
0188       set a range [xmin,xmax] for the first and [ymin,ymax] for the second coordinate
0189     */
0190    void SetRange(double xmin, double xmax, double ymin, double ymax ) { SetRange(0,xmin,xmax); SetRange(1,ymin,ymax); }
0191    /**
0192       set a range [xmin,xmax] for the first and [ymin,ymax] for the second coordinate and
0193       [zmin,zmax] for the third coordinate
0194     */
0195    void SetRange(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax ) {
0196       SetRange(0,xmin,xmax); SetRange(1,ymin,ymax); SetRange(2,zmin,zmax); }
0197 
0198    /**
0199       clear all ranges in one coordinate (is now -inf, +inf)
0200     */
0201    void Clear (unsigned  int  icoord = 0 );
0202 
0203    /**
0204       check if a point is inside the range for the given coordinate
0205     */
0206    bool IsInside(double x, unsigned int icoord = 0) const;
0207 
0208    /**
0209       check if a multi-dimpoint is inside the range
0210     */
0211    bool IsInside(const double *x) const {
0212       bool ret = true;
0213       for (unsigned int idim = 0; idim < fRanges.size(); ++idim) {
0214          ret &= IsInside(x[idim],idim);
0215          if (!ret) return ret;
0216       }
0217       return ret;
0218    }
0219 
0220 protected:
0221    /**
0222        internal function to remove all the existing ranges between xmin and xmax
0223        called when a new range is inserted
0224    */
0225    void CleanRangeSet(unsigned int icoord, double xmin, double xmax);
0226 
0227    // get the full range (-inf, +inf)
0228    static void GetInfRange(double &x1, double &x2);
0229 
0230 private:
0231 
0232    RangeIntervals fRanges;  ///< list of all ranges
0233 
0234 
0235 };
0236 
0237    } // end namespace Fit
0238 
0239 } // end namespace ROOT
0240 
0241 
0242 #endif /* ROOT_Fit_DataRange */