DataRange.h

Go to the documentation of this file.
00001 // @(#)root/mathcore:$Id: DataRange.h 36558 2010-11-09 15:13:13Z moneta $
00002 // Author: L. Moneta Wed Aug 30 11:05:02 2006
00003 
00004 /**********************************************************************
00005  *                                                                    *
00006  * Copyright (c) 2006  LCG ROOT Math Team, CERN/PH-SFT                *
00007  *                                                                    *
00008  *                                                                    *
00009  **********************************************************************/
00010 
00011 // Header file for class DataRange
00012 
00013 #ifndef ROOT_Fit_DataRange
00014 #define ROOT_Fit_DataRange
00015 
00016 #include <vector>
00017 
00018 namespace ROOT { 
00019 
00020    namespace Fit { 
00021 
00022 
00023 //___________________________________________________________________________________
00024 /** 
00025    class describing the range in the coordinates 
00026    it supports  multiple range in a coordinate. 
00027    The rnage dimension is the dimension of the coordinate, its size is 
00028    the number of interval for each coordinate. 
00029    Default range is -inf, inf
00030    Range can be modified with the add range method
00031 
00032    @ingroup FitData
00033 */ 
00034 class DataRange {
00035 
00036 public: 
00037 
00038    typedef std::vector<std::pair<double,double> > RangeSet;
00039    typedef std::vector< RangeSet >   RangeIntervals; 
00040 
00041    /** 
00042       Default constructor (infinite range) 
00043    */ 
00044    explicit DataRange (unsigned int dim = 1) :
00045       fRanges ( std::vector<RangeSet> (dim) )
00046    {}
00047 
00048    /**
00049       construct a range for [xmin, xmax] 
00050     */
00051    DataRange(double xmin, double xmax);  
00052 
00053    /**
00054       construct a range for [xmin, xmax] , [ymin, ymax] 
00055     */
00056    DataRange(double xmin, double xmax, double ymin, double ymax);  
00057    /**
00058       construct a range for [xmin, xmax] , [ymin, ymax] , [zmin, zmax] 
00059     */
00060    DataRange(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax); 
00061    /**
00062       get range dimension
00063     */ 
00064    unsigned int NDim() const { return fRanges.size(); }
00065 
00066    /**
00067       return range size for coordinate icoord (starts from zero)
00068       Size == 0 indicates no range is present [-inf, + inf]
00069    */
00070    unsigned int Size(unsigned int icoord = 0) const { 
00071       return icoord <  fRanges.size() ? fRanges[icoord].size() : 0;
00072    }
00073 
00074    /**
00075       return true if a range has been set in any of  the coordinates 
00076       i.e. when  it is not [-inf,+inf] for all coordinates
00077       Avoid in case of multi-dim to loop on all the coordinated and ask the size
00078     */   
00079    bool IsSet() const { 
00080       for (unsigned int icoord = 0; icoord < fRanges.size(); ++icoord) 
00081          if (fRanges[icoord].size() > 0) return true; 
00082       return false; 
00083    }
00084 
00085    /** 
00086        return the vector of ranges for the coordinate icoord
00087    */ 
00088    const RangeSet & Ranges(unsigned int icoord = 0) const { 
00089       // return icoord <  fRanges.size() ? fRanges[icoord] : RangeSet(); 
00090       return fRanges.at(icoord); 
00091    }
00092 
00093    /** 
00094        return the i-th range for the coordinate icoord.
00095        Useful method when only one range is present for the given coordinate 
00096    */ 
00097    std::pair<double, double> operator() (unsigned int icoord = 0,unsigned int irange = 0) const;
00098 
00099    /**
00100       get the first range for given coordinate. If range does not exist
00101       return -inf, +inf
00102     */
00103    void GetRange(unsigned int icoord, double & xmin, double & xmax) const { 
00104       if (Size(icoord) == 0) GetInfRange(xmin,xmax);
00105       else { 
00106          xmin = fRanges[icoord].front().first; 
00107          xmax = fRanges[icoord].front().second; 
00108       }
00109    }
00110    /**
00111       get first range for the x - coordinate
00112     */
00113    void GetRange(double & xmin, double & xmax) const {  GetRange(0,xmin,xmax); }
00114    /**
00115       get first range for the x and y coordinates
00116     */
00117    void GetRange(double & xmin, double & xmax, double & ymin, double & ymax) const {  
00118       GetRange(0,xmin,xmax); GetRange(1,ymin,ymax); 
00119    }
00120    /**
00121       get first range for the x and y and z coordinates
00122     */
00123    void GetRange(double & xmin, double & xmax, double & ymin, double & ymax, double & zmin, double & zmax) const {  
00124       GetRange(0,xmin,xmax); GetRange(1,ymin,ymax); GetRange(2,zmin,zmax); 
00125    }
00126    /**
00127       get first range for coordinates and fill the vector
00128     */
00129    void GetRange(double * xmin, double * xmax)   const {  
00130       for (unsigned int i = 0; i < fRanges.size(); ++i) 
00131          GetRange(i,xmin[i],xmax[i]); 
00132    }
00133 
00134    /** 
00135       Destructor (no operations)
00136    */ 
00137    ~DataRange ()  {}  
00138 
00139 
00140 
00141    /**
00142       add a range [xmin,xmax] for the new coordinate icoord 
00143       Adding a range does not delete existing one, but takes the OR with 
00144       existing ranges. 
00145       if want to replace range use method SetRange, which replace range with existing one
00146     */
00147    void AddRange(unsigned  int  icoord , double xmin, double xmax ); 
00148 
00149    /**
00150       add a range [xmin,xmax] for the first coordinate icoord 
00151     */
00152    void AddRange(double xmin, double xmax ) { AddRange(0,xmin,xmax); }
00153    /**
00154       add a range [xmin,xmax] for the first and [ymin,ymax] for the second coordinate
00155     */
00156    void AddRange(double xmin, double xmax, double ymin, double ymax ) { AddRange(0,xmin,xmax); AddRange(1,ymin,ymax); }
00157    /**
00158       add a range [xmin,xmax] for the first and [ymin,ymax] for the second coordinate and 
00159       [zmin,zmax] for the third coordinate
00160     */
00161    void AddRange(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax ) { 
00162       AddRange(0,xmin,xmax); AddRange(1,ymin,ymax); AddRange(2,zmin,zmax); }
00163 
00164    /**
00165       set a range [xmin,xmax] for the new coordinate icoord 
00166       If more range exists for other coordinates, delete the existing one and use it the new one
00167       Use Add range if want to keep the union of the existing ranges 
00168     */
00169    void SetRange(unsigned  int  icoord , double xmin, double xmax ); 
00170 
00171    /**
00172       set a range [xmin,xmax] for the first coordinate icoord 
00173     */
00174    void SetRange(double xmin, double xmax ) { SetRange(0,xmin,xmax); }
00175    /**
00176       set a range [xmin,xmax] for the first and [ymin,ymax] for the second coordinate
00177     */
00178    void SetRange(double xmin, double xmax, double ymin, double ymax ) { SetRange(0,xmin,xmax); SetRange(1,ymin,ymax); }
00179    /**
00180       set a range [xmin,xmax] for the first and [ymin,ymax] for the second coordinate and 
00181       [zmin,zmax] for the third coordinate
00182     */
00183    void SetRange(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax ) { 
00184       SetRange(0,xmin,xmax); SetRange(1,ymin,ymax); SetRange(2,zmin,zmax); }
00185 
00186    /**
00187       clear all ranges in one coordinate (is now -inf, +inf)
00188     */
00189    void Clear (unsigned  int  icoord = 0 );
00190 
00191    /**
00192       check if a point is inside the range for the given coordinate
00193     */
00194    bool IsInside(double x, unsigned int icoord = 0) const; 
00195 
00196 protected: 
00197    /** 
00198        internal function to remove all the existing ranges between xmin and xmax 
00199        called when a new range is inserted
00200    */
00201    void CleanRangeSet(unsigned int icoord, double xmin, double xmax); 
00202 
00203    // get the full range (-inf, +inf)
00204    static void GetInfRange(double &x1, double &x2);
00205 
00206 private: 
00207 
00208    RangeIntervals fRanges;  // list of all ranges
00209 
00210 
00211 }; 
00212 
00213    } // end namespace Fit
00214 
00215 } // end namespace ROOT
00216 
00217 
00218 #endif /* ROOT_Fit_DataRange */

Generated on Tue Jul 5 14:24:59 2011 for ROOT_528-00b_version by  doxygen 1.5.1