File indexing completed on 2025-01-18 10:10:09
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
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
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046 class UnBinData : public FitData {
0047
0048 public :
0049
0050
0051
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
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
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
0090
0091 UnBinData(unsigned int n, const double * dataX ) :
0092 FitData( n, dataX ),
0093 fWeighted( false )
0094 {
0095 }
0096
0097
0098
0099
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
0110
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
0121
0122
0123
0124
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
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
0148
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
0159
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
0170
0171
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
0181 UnBinData(const UnBinData &);
0182
0183 UnBinData & operator= (const UnBinData &);
0184
0185 public:
0186
0187
0188
0189 ~UnBinData() override {
0190 }
0191
0192
0193
0194
0195 void Add(double x)
0196 {
0197 assert( !fWeighted );
0198
0199 FitData::Add( x );
0200 }
0201
0202
0203
0204
0205
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
0217
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
0229
0230 void Add( const double* x )
0231 {
0232 FitData::Add( x );
0233 }
0234
0235
0236
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
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
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 }
0299
0300 }
0301
0302
0303
0304 #endif