Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:09

0001 // @(#)root/mathcore:$Id$
0002 // Author: L. Moneta Wed Aug 30 11:15:23 2006
0003 
0004 /**********************************************************************
0005  *                                                                    *
0006  * Copyright (c) 2006  LCG ROOT Math Team, CERN/PH-SFT                *
0007  *                                                                    *
0008  *                                                                    *
0009  **********************************************************************/
0010 
0011 // Header file for class UnBinData
0012 
0013 #ifndef ROOT_Fit_UnBinData
0014 #define ROOT_Fit_UnBinData
0015 
0016 #include "Fit/FitData.h"
0017 #include "Math/Error.h"
0018 
0019 #include <vector>
0020 
0021 namespace ROOT {
0022 
0023    namespace Fit {
0024 
0025 
0026 //___________________________________________________________________________________
0027 /**
0028    Class describing the un-binned data sets (just x coordinates values) of any dimensions
0029 
0030   There is the option to construct UnBindata copying the data inside
0031   (in the base FitData class) or using a pointer to external data, depending on which
0032   constructor of the UnBinData class is used.
0033   It is recommended to copy the input data inside, since this will be more efficient and
0034   less error prone, since the input provided data will have to be kept alive for all the time the
0035   Fit classes will be used.
0036   In case of really large data sets for limiting memory consumption then the other option can be used
0037   with special care.
0038   Specialized constructor exists for using external data up to 3 dimensions.
0039 
0040   When the data are copying in the number of points can be set later (or re-set) using Initialize and
0041   the data are inserted one by one using the Add method.
0042   It is mandatory to set the size before using the Add method.
0043 
0044   @ingroup FitData
0045 */
0046 class UnBinData : public FitData {
0047 
0048 public :
0049 
0050   /**
0051     constructor from dimension of point  and max number of points (to pre-allocate vector)
0052   */
0053 
0054   explicit UnBinData( unsigned int maxpoints = 0, unsigned int dim = 1,
0055     bool isWeighted = false ) :
0056     FitData( maxpoints, isWeighted ? dim + 1 : dim ),
0057     fWeighted(isWeighted)
0058   {
0059     assert( dim >= 1 );
0060     assert( !fWeighted || dim >= 2 );
0061   }
0062 
0063 
0064   /**
0065     constructor from range and default option
0066   */
0067   explicit UnBinData ( const DataRange & range, unsigned int maxpoints = 0,
0068     unsigned int dim = 1, bool isWeighted = false ) :
0069     FitData( range, maxpoints, isWeighted ? dim + 1 : dim ),
0070     fWeighted(isWeighted)
0071   {
0072     assert( dim >= 1 );
0073     assert( !fWeighted || dim >= 2 );
0074   }
0075 
0076   /**
0077     constructor from options and range
0078   */
0079   UnBinData (const DataOptions & opt, const DataRange & range,
0080     unsigned int maxpoints = 0, unsigned int dim = 1, bool isWeighted = false ) :
0081     FitData( opt, range, maxpoints, isWeighted ? dim + 1 : dim ),
0082     fWeighted(isWeighted)
0083   {
0084     assert( dim >= 1 );
0085     assert( !fWeighted || dim >= 2 );
0086   }
0087 
0088   /**
0089     constructor for 1D external data (data are not copied inside)
0090   */
0091   UnBinData(unsigned int n, const double * dataX ) :
0092     FitData( n, dataX ),
0093     fWeighted( false )
0094   {
0095   }
0096 
0097   /**
0098     constructor for 2D external data (data are not copied inside)
0099     or 1D data with a weight (if isWeighted = true)
0100   */
0101   UnBinData(unsigned int n, const double * dataX, const double * dataY,
0102     bool isWeighted = false ) :
0103     FitData( n, dataX, dataY ),
0104     fWeighted( isWeighted )
0105   {
0106   }
0107 
0108   /**
0109     constructor for 3D external data (data are not copied inside)
0110     or 2D data with a weight (if isWeighted = true)
0111   */
0112   UnBinData(unsigned int n, const double * dataX, const double * dataY,
0113     const double * dataZ, bool isWeighted = false ) :
0114     FitData( n, dataX, dataY, dataZ ),
0115     fWeighted( isWeighted )
0116   {
0117   }
0118 
0119   /**
0120     constructor for multi-dim external data (data are not copied inside)
0121     Uses as argument an iterator of a list (or vector) containing the const double * of the data
0122     An example could be the std::vector<const double *>::begin
0123     In case of weighted data, the external data must have a dim+1 lists of data
0124     The passed dim refers just to the coordinate size
0125   */
0126   template<class Iterator>
0127   UnBinData(unsigned int n, unsigned int dim, Iterator dataItr,
0128     bool isWeighted = false ) :
0129     FitData( n, isWeighted ? dim + 1 : dim, dataItr ),
0130     fWeighted( isWeighted )
0131   {
0132     assert( dim >= 1 );
0133     assert( !fWeighted || dim >= 2 );
0134   }
0135 
0136   /**
0137     constructor for 1D data and a range (data are copied inside according to the given range)
0138   */
0139   UnBinData(unsigned int maxpoints, const double * dataX, const DataRange & range) :
0140     FitData( range, maxpoints, dataX ),
0141     fWeighted( false )
0142   {
0143   }
0144 
0145 
0146   /**
0147     constructor for 2D data and a range (data are copied inside according to the given range)
0148     or 1 1D data set + weight. If is weighted  dataY is the pointer to the list of the weights
0149   */
0150   UnBinData(unsigned int maxpoints, const double * dataX, const double * dataY,
0151     const DataRange & range, bool isWeighted = false) :
0152     FitData( range, maxpoints, dataX, dataY ),
0153     fWeighted( isWeighted )
0154   {
0155   }
0156 
0157   /**
0158     constructor for 3D data and a range (data are copied inside according to the given range)
0159     or a 2D data set + weights. If is weighted  dataZ is the pointer to the list of the weights
0160   */
0161   UnBinData(unsigned int maxpoints, const double * dataX, const double * dataY,
0162     const double * dataZ, const DataRange & range, bool isWeighted = false) :
0163     FitData( range, maxpoints, dataX, dataY, dataZ ),
0164     fWeighted( isWeighted )
0165   {
0166   }
0167 
0168   /**
0169     constructor for multi-dim external data and a range (data are copied inside according to the range)
0170     Uses as argument an iterator of a list (or vector) containing the const double * of the data
0171     An example could be the std::vector<const double *>::begin
0172   */
0173   template<class Iterator>
0174   UnBinData( unsigned int maxpoints, unsigned int dim, Iterator dataItr, const DataRange & range, bool isWeighted = false ) :
0175     FitData( range, maxpoints, dim, dataItr ),
0176     fWeighted( isWeighted )
0177   {
0178   }
0179 
0180   /// copy constructor
0181   UnBinData(const UnBinData &);
0182   /// assignment operator
0183   UnBinData & operator= (const UnBinData &);
0184 
0185 public:
0186   /**
0187     destructor, delete pointer to internal data or external data wrapper
0188   */
0189   ~UnBinData() override {
0190   }
0191 
0192   /**
0193     add one dim coordinate data (unweighted)
0194   */
0195   void Add(double x)
0196   {
0197     assert( !fWeighted );
0198 
0199     FitData::Add( x );
0200   }
0201 
0202 
0203   /**
0204     add 2-dim coordinate data
0205     can also be used to add 1-dim data with a weight
0206   */
0207   void Add(double x, double y)
0208   {
0209     assert( fDim == 2 );
0210     double dataTmp[] = { x, y };
0211 
0212     FitData::Add( dataTmp );
0213   }
0214 
0215   /**
0216     add 3-dim coordinate data
0217     can also be used to add 2-dim data with a weight
0218   */
0219   void Add(double x, double y, double z)
0220   {
0221     assert( fDim == 3 );
0222     double dataTmp[] = { x, y, z };
0223 
0224     FitData::Add( dataTmp );
0225   }
0226 
0227   /**
0228     add multi-dim coordinate data
0229   */
0230   void Add( const double* x )
0231   {
0232     FitData::Add( x );
0233   }
0234 
0235   /**
0236     add multi-dim coordinate data + weight
0237   */
0238   void Add(const double *x, double w)
0239   {
0240     assert( fWeighted );
0241 
0242     std::vector<double> tmpVec(fDim);
0243     std::copy( x, x + fDim - 1, tmpVec.begin() );
0244     tmpVec[fDim-1] = w;
0245 
0246     FitData::Add( &tmpVec.front() );
0247   }
0248 
0249   /**
0250     return weight
0251   */
0252   double Weight( unsigned int ipoint ) const
0253   {
0254     assert( ipoint < fNPoints );
0255 
0256     if ( !fWeighted ) return 1.0;
0257     return *GetCoordComponent(ipoint, fDim-1);
0258   }
0259 
0260   const double * WeightsPtr( unsigned int ipoint ) const
0261   {
0262     assert( ipoint < fNPoints );
0263 
0264     if ( !fWeighted ){
0265        MATH_ERROR_MSG("UnBinData::WeightsPtr","The function is unweighted!");
0266        return nullptr;
0267     }
0268     return GetCoordComponent(ipoint, fDim-1);
0269   }
0270 
0271 
0272   /**
0273     return coordinate data dimension
0274   */
0275   unsigned int NDim() const
0276   { return fWeighted ? fDim -1 : fDim; }
0277 
0278   bool IsWeighted() const
0279   {
0280     return fWeighted;
0281   }
0282 
0283   void Append( unsigned int newPoints, unsigned int dim = 1, bool isWeighted = false )
0284   {
0285     assert( !fWrapped );
0286 
0287     fWeighted = isWeighted;
0288 
0289     FitData::Append( newPoints, dim );
0290   }
0291 
0292 private:
0293   bool fWeighted;
0294 
0295 };
0296 
0297 
0298    } // end namespace Fit
0299 
0300 } // end namespace ROOT
0301 
0302 
0303 
0304 #endif /* ROOT_Fit_UnBinData */