13 #ifndef ROOT_Fit_BinData
14 #define ROOT_Fit_BinData
53 class BinData :
public FitData {
57 enum ErrorType { kNoError, kValueError, kCoordError, kAsymError };
64 explicit BinData(
unsigned int maxpoints = 0,
unsigned int dim = 1,
65 ErrorType err = kValueError);
71 explicit BinData (
const DataOptions & opt,
unsigned int maxpoints = 0,
72 unsigned int dim = 1, ErrorType err = kValueError);
78 BinData (
const DataOptions & opt,
const DataRange & range,
79 unsigned int maxpoints = 0,
unsigned int dim = 1, ErrorType err = kValueError );
86 BinData(
unsigned int n,
const double * dataX,
const double * val,
87 const double * ex ,
const double * eval );
92 BinData(
unsigned int n,
const double * dataX,
const double * dataY,
93 const double * val,
const double * ex ,
const double * ey,
94 const double * eval );
99 BinData(
unsigned int n,
const double * dataX,
const double * dataY,
100 const double * dataZ,
const double * val,
const double * ex ,
101 const double * ey ,
const double * ez ,
const double * eval );
111 BinData(
const BinData & rhs);
113 BinData & operator= (
const BinData & rhs );
124 void Append(
unsigned int newPoints,
unsigned int dim = 1, ErrorType err = kValueError );
126 void Initialize(
unsigned int newPoints,
unsigned int dim = 1, ErrorType err = kValueError );
131 bool HaveCoordErrors()
const {
132 assert ( fErrorType == kNoError ||
133 fErrorType == kValueError ||
134 fErrorType == kCoordError ||
135 fErrorType == kAsymError );
137 return fErrorType == kCoordError;
143 bool HaveAsymErrors()
const {
144 assert ( fErrorType == kNoError ||
145 fErrorType == kValueError ||
146 fErrorType == kCoordError ||
147 fErrorType == kAsymError );
149 return fErrorType == kAsymError;
160 BinData & LogTransform();
166 void Add(
double x,
double y );
172 void Add(
double x,
double y,
double ey );
178 void Add(
double x,
double y,
double ex,
double ey );
184 void Add(
double x,
double y,
double ex,
double eyl,
double eyh );
189 void Add(
const double* x,
double val );
194 void Add(
const double* x,
double val,
double eval );
199 void Add(
const double* x,
double val,
const double* ex,
double eval );
204 void Add(
const double* x,
double val,
const double* ex,
double elval,
double ehval );
212 void AddBinUpEdge(
const double* xup );
217 double Value(
unsigned int ipoint )
const
219 assert( ipoint < fMaxPoints );
221 assert( fData.empty() || &fData.front() == fDataPtr );
223 return fDataPtr[ipoint];
229 const double *ValuePtr(
unsigned int ipoint )
const
231 return &fDataPtr[ipoint];
240 const double * ErrorPtr(
unsigned int ipoint)
const{
241 assert( ipoint < fMaxPoints );
242 assert( kValueError == fErrorType || kCoordError == fErrorType ||
243 kAsymError == fErrorType || kNoError == fErrorType );
245 if ( fErrorType == kNoError )
248 return &fDataErrorPtr[ ipoint ];
251 double Error(
unsigned int ipoint )
const
253 assert( ipoint < fMaxPoints );
254 assert( kValueError == fErrorType || kCoordError == fErrorType ||
255 kAsymError == fErrorType || kNoError == fErrorType );
257 if ( fErrorType == kNoError )
259 assert( !fDataErrorPtr && !fDataErrorHighPtr && !fDataErrorLowPtr );
260 assert( fDataError.empty() && fDataErrorHigh.empty() && fDataErrorLow.empty() );
264 if ( fErrorType == kValueError )
266 assert( fDataErrorPtr && !fDataErrorHighPtr && !fDataErrorLowPtr );
267 assert( fDataErrorHigh.empty() && fDataErrorLow.empty() );
268 assert( fDataError.empty() || &fDataError.front() == fDataErrorPtr );
270 double eval = fDataErrorPtr[ ipoint ];
275 return (eval != 0.0) ? 1.0/eval : 0.0;
278 if ( fErrorType == kAsymError )
280 assert( !fDataErrorPtr && fDataErrorHighPtr && fDataErrorLowPtr );
281 assert( fDataError.empty() );
282 assert( fDataErrorHigh.empty() || &fDataErrorHigh.front() == fDataErrorHighPtr );
283 assert( fDataErrorLow.empty() || &fDataErrorLow.front() == fDataErrorLowPtr );
284 assert( fDataErrorLow.empty() == fDataErrorHigh.empty() );
286 double eh = fDataErrorHighPtr[ ipoint ];
287 double el = fDataErrorLowPtr[ ipoint ];
289 return (el+eh) / 2.0;
292 assert( fErrorType == kCoordError );
293 return fDataErrorPtr[ ipoint ];
296 void GetAsymError(
unsigned int ipoint,
double& lowError,
double& highError )
const
298 assert( fErrorType == kAsymError );
299 assert( !fDataErrorPtr && fDataErrorHighPtr && fDataErrorLowPtr );
300 assert( fDataError.empty() );
301 assert( fDataErrorHigh.empty() || &fDataErrorHigh.front() == fDataErrorHighPtr );
302 assert( fDataErrorLow.empty() || &fDataErrorLow.front() == fDataErrorLowPtr );
303 assert( fDataErrorLow.empty() == fDataErrorHigh.empty() );
305 lowError = fDataErrorLowPtr[ ipoint ];
306 highError = fDataErrorHighPtr[ ipoint ];
314 double InvError(
unsigned int ipoint )
const
316 assert( ipoint < fMaxPoints );
317 assert( kValueError == fErrorType || kCoordError == fErrorType ||
318 kAsymError == fErrorType || kNoError == fErrorType );
320 if ( fErrorType == kNoError )
322 assert( !fDataErrorPtr && !fDataErrorHighPtr && !fDataErrorLowPtr );
323 assert( fDataError.empty() && fDataErrorHigh.empty() && fDataErrorLow.empty() );
327 if ( fErrorType == kValueError )
329 assert( fDataErrorPtr && !fDataErrorHighPtr && !fDataErrorLowPtr );
330 assert( fDataErrorHigh.empty() && fDataErrorLow.empty() );
331 assert( fDataError.empty() || &fDataError.front() == fDataErrorPtr );
333 double eval = fDataErrorPtr[ ipoint ];
340 return (eval != 0.0) ? eval : 0.0;
343 if ( fErrorType == kAsymError ) {
345 assert( !fDataErrorPtr && fDataErrorHighPtr && fDataErrorLowPtr );
346 assert( fDataError.empty() );
347 assert( fDataErrorHigh.empty() || &fDataErrorHigh.front() == fDataErrorHighPtr );
348 assert( fDataErrorLow.empty() || &fDataErrorLow.front() == fDataErrorLowPtr );
349 assert( fDataErrorLow.empty() == fDataErrorHigh.empty() );
351 double eh = fDataErrorHighPtr[ ipoint ];
352 double el = fDataErrorLowPtr[ ipoint ];
354 return 2.0 / (el+eh);
357 assert( fErrorType == kCoordError );
359 return 1.0 / fDataErrorPtr[ ipoint ];
370 const double * GetPoint(
unsigned int ipoint,
double & value )
const
372 assert( ipoint < fMaxPoints );
373 value = Value( ipoint );
375 return Coords( ipoint );
384 double GetCoordErrorComponent(
unsigned int ipoint,
unsigned int icoord )
const
386 assert( ipoint < fMaxPoints );
387 assert( icoord < fDim );
388 assert( fCoordErrorsPtr.size() == fDim );
389 assert( fCoordErrorsPtr[icoord] );
390 assert( fCoordErrors.empty() || &fCoordErrors[icoord].front() == fCoordErrorsPtr[icoord] );
392 return fCoordErrorsPtr[icoord][ipoint];
401 const double* CoordErrors(
unsigned int ipoint )
const
403 assert( ipoint < fMaxPoints );
404 assert( fpTmpCoordErrorVector );
405 assert( fErrorType == kCoordError || fErrorType == kAsymError );
407 for (
unsigned int i=0; i < fDim; i++ )
409 assert( fCoordErrorsPtr[i] );
410 assert( fCoordErrors.empty() || &fCoordErrors[i].front() == fCoordErrorsPtr[i] );
412 fpTmpCoordErrorVector[i] = fCoordErrorsPtr[i][ipoint];
415 return fpTmpCoordErrorVector;
428 const double* GetPoint(
unsigned int ipoint,
double & value,
double & invError )
const
430 assert( ipoint < fMaxPoints );
431 assert( fErrorType == kNoError || fErrorType == kValueError );
433 double e = Error( ipoint );
438 invError = ( e != 0.0 ) ? 1.0/e : 1.0;
440 return GetPoint( ipoint, value );
451 const double* GetPointError(
unsigned int ipoint,
double & errvalue)
const
453 assert( ipoint < fMaxPoints );
454 assert( fErrorType == kCoordError || fErrorType == kAsymError );
456 errvalue = Error( ipoint );
457 return CoordErrors( ipoint );
469 const double* GetPointError(
unsigned int ipoint,
double & errlow,
double & errhigh)
const
471 assert( ipoint < fMaxPoints );
472 assert( fErrorType == kAsymError );
473 assert( !fDataErrorPtr && fDataErrorHighPtr && fDataErrorLowPtr );
474 assert( fDataError.empty() );
475 assert( fDataErrorHigh.empty() || &fDataErrorHigh.front() == fDataErrorHighPtr );
476 assert( fDataErrorLow.empty() || &fDataErrorLow.front() == fDataErrorLowPtr );
477 assert( fDataErrorLow.empty() == fDataErrorHigh.empty() );
479 errhigh = fDataErrorHighPtr[ ipoint ];
480 errlow = fDataErrorLowPtr[ ipoint ];
482 return CoordErrors( ipoint );
491 double GetBinUpEdgeComponent(
unsigned int ipoint,
unsigned int icoord )
const
493 assert( icoord < fDim );
494 assert( !fBinEdge.empty() );
495 assert( ipoint < fBinEdge.front().size() );
497 return fBinEdge[icoord][ipoint];
508 const double* BinUpEdge(
unsigned int ipoint )
const
510 if ( fBinEdge.empty() || ipoint > fBinEdge.front().size() )
513 assert( fpTmpBinEdgeVector );
514 assert( !fBinEdge.empty() );
515 assert( ipoint < fMaxPoints );
517 for (
unsigned int i=0; i < fDim; i++ )
519 fpTmpBinEdgeVector[i] = fBinEdge[i][ ipoint ];
522 return fpTmpBinEdgeVector;
528 bool HasBinEdges()
const {
529 return fBinEdge.size() == fDim && fBinEdge[0].size() > 0;
535 double RefVolume()
const {
return fRefVolume; }
540 void SetRefVolume(
double value) { fRefVolume = value; }
545 ErrorType GetErrorType( )
const
554 double SumOfContent()
const {
return fSumContent; }
560 double SumOfError2()
const {
return fSumError2;}
567 bool IsWeighted()
const {
572 void InitDataVector ();
574 void InitializeErrors();
585 ErrorType fErrorType;
586 bool fIsWeighted =
false;
588 double fSumContent = 0;
589 double fSumError2 = 0;
595 std::vector< double > fData;
596 const double* fDataPtr;
598 std::vector< std::vector< double > > fCoordErrors;
599 std::vector< const double* > fCoordErrorsPtr;
603 std::vector< double > fDataError;
604 std::vector< double > fDataErrorHigh;
605 std::vector< double > fDataErrorLow;
606 const double* fDataErrorPtr;
607 const double* fDataErrorHighPtr;
608 const double* fDataErrorLowPtr;
612 double* fpTmpCoordErrorVector;
614 std::vector< std::vector< double > > fBinEdge;
617 double* fpTmpBinEdgeVector;