Logo ROOT  
Reference Guide
BinData.cxx
Go to the documentation of this file.
1// @(#)root/mathcore:$Id$
2// Author: M. Borinsky
3
4/**********************************************************************
5 * *
6 * Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT *
7 * *
8 * *
9 **********************************************************************/
10
11// Implementation file for class BinData
12
13#include "Fit/BinData.h"
14#include "Math/Error.h"
15
16#include <cassert>
17#include <cmath>
18
19using namespace std;
20
21namespace ROOT {
22
23 namespace Fit
24 {
25
26 BinData::BinData(unsigned int maxpoints, unsigned int dim,
27 ErrorType err ) :
28 FitData( maxpoints, dim ),
29 fErrorType( err ),
30 fDataPtr( nullptr ),
31 fDataErrorPtr( nullptr ), fDataErrorHighPtr( nullptr ), fDataErrorLowPtr( nullptr ),
32 fpTmpCoordErrorVector( nullptr ), fpTmpBinEdgeVector( nullptr )
33 {
36 }
37
38
39 /**
40 constructor from option and default range
41 */
42 BinData::BinData (const DataOptions & opt, unsigned int maxpoints,
43 unsigned int dim, ErrorType err ) :
44 FitData( opt, maxpoints, dim ),
45 fErrorType( err ),
46 fDataPtr( nullptr ),
47 fDataErrorPtr( nullptr ), fDataErrorHighPtr( nullptr ), fDataErrorLowPtr( nullptr ),
48 fpTmpCoordErrorVector( nullptr ), fpTmpBinEdgeVector( nullptr )
49 {
52 }
53
54 /**
55 constructor from options and range
56 efault is 1D and value errors
57 */
58 BinData::BinData (const DataOptions & opt, const DataRange & range,
59 unsigned int maxpoints, unsigned int dim, ErrorType err ) :
60 FitData( opt, range, maxpoints, dim ),
61 fErrorType( err ),
62 fDataPtr( nullptr ),
63 fDataErrorPtr( nullptr ), fDataErrorHighPtr( nullptr ), fDataErrorLowPtr( nullptr ),
64 fpTmpCoordErrorVector( nullptr ), fpTmpBinEdgeVector( nullptr )
65 {
68 }
69
70 /** constructurs using external data */
71
72 /**
73 constructor from external data for 1D with errors on coordinate and value
74 */
75 BinData::BinData (unsigned int n, const double * dataX, const double * val,
76 const double * ex , const double * eval ) :
77 FitData( n, dataX ),
78 fDataPtr( nullptr ),
79 fDataErrorPtr( nullptr ), fDataErrorHighPtr( nullptr ), fDataErrorLowPtr( nullptr ),
80 fpTmpCoordErrorVector( nullptr ), fpTmpBinEdgeVector( nullptr )
81 {
82 assert( val );
83 fDataPtr = val;
84
85 if ( nullptr != eval )
86 {
87 fDataErrorPtr = eval;
88
90
91 if ( nullptr != ex )
92 {
93 fCoordErrorsPtr.resize( 1 );
94
96
98 }
99 }
100 else
101 {
103 }
104
105 fpTmpCoordErrorVector = new double [ fDim ];
106
107 ComputeSums();
108 }
109
110 /**
111 constructor from external data for 2D with errors on coordinate and value
112 */
113 BinData::BinData(unsigned int n, const double * dataX, const double * dataY,
114 const double * val, const double * ex , const double * ey,
115 const double * eval ) :
116 FitData( n, dataX, dataY ),
117 fDataErrorPtr( nullptr ), fDataErrorHighPtr( nullptr ), fDataErrorLowPtr( nullptr ),
118 fpTmpCoordErrorVector( nullptr ), fpTmpBinEdgeVector( nullptr )
119 {
120 assert( val );
121 fDataPtr = val;
122
123 if ( nullptr != eval )
124 {
125 fDataErrorPtr = eval;
126
128
129 if ( nullptr != ex || nullptr != ey )
130 {
131 fCoordErrorsPtr.resize( 2 );
132
133 fCoordErrorsPtr[0] = ex;
134 fCoordErrorsPtr[1] = ey;
135
137 }
138 }
139 else
140 {
142 }
143
144 fpTmpCoordErrorVector = new double [ fDim ];
145 ComputeSums();
146 }
147
148 /**
149 constructor from external data for 3D with errors on coordinate and value
150 */
151 BinData::BinData(unsigned int n, const double * dataX, const double * dataY,
152 const double * dataZ, const double * val, const double * ex ,
153 const double * ey , const double * ez , const double * eval ) :
154 FitData( n, dataX, dataY, dataZ ),
155 fDataErrorPtr( nullptr ), fDataErrorHighPtr( nullptr ), fDataErrorLowPtr( nullptr ),
156 fpTmpCoordErrorVector( nullptr ), fpTmpBinEdgeVector( nullptr )
157 {
158 assert( val );
159 fDataPtr = val;
160
161 if ( nullptr != eval )
162 {
163 fDataErrorPtr = eval;
164
166
167 if ( nullptr != ex || nullptr != ey || nullptr != ez )
168 {
169 fCoordErrorsPtr.resize( 3 );
170
171 fCoordErrorsPtr[0] = ex;
172 fCoordErrorsPtr[1] = ey;
173 fCoordErrorsPtr[2] = ez;
174
176 }
177 }
178 else
179 {
181 }
182
183 fpTmpCoordErrorVector = new double [ fDim ];
184 ComputeSums();
185 }
186
187 /**
188 destructor
189 */
191 {
192 assert( fMaxPoints == 0 || fWrapped == fData.empty() );
193
194 assert( kValueError == fErrorType || kCoordError == fErrorType ||
196 assert( fMaxPoints == 0 || fDataError.empty() || &fDataError.front() == fDataErrorPtr );
197 assert( fMaxPoints == 0 || fDataErrorHigh.empty() || &fDataErrorHigh.front() == fDataErrorHighPtr );
198 assert( fMaxPoints == 0 || fDataErrorLow.empty() || &fDataErrorLow.front() == fDataErrorLowPtr );
199 assert( fMaxPoints == 0 || fDataErrorLow.empty() == fDataErrorHigh.empty() );
200 assert( fMaxPoints == 0 || fData.empty() || &fData.front() == fDataPtr );
201
202 for ( unsigned int i=0; i < fDim; i++ )
203 {
204 assert( fCoordErrors.empty() || &fCoordErrors[i].front() == fCoordErrorsPtr[i] );
205 }
206
207 if ( fpTmpBinEdgeVector )
208 {
209 delete[] fpTmpBinEdgeVector;
210 fpTmpBinEdgeVector= nullptr;
211 }
212
214 {
215 delete[] fpTmpCoordErrorVector;
216 fpTmpCoordErrorVector = nullptr;
217 }
218 }
219
220 /**
221 copy constructors
222 */
224 : FitData(rhs),
225 fDataPtr(nullptr),
226 fDataErrorPtr(nullptr), fDataErrorHighPtr(nullptr), fDataErrorLowPtr(nullptr),
227 fpTmpCoordErrorVector(nullptr), fpTmpBinEdgeVector(nullptr)
228 {
229 *this = rhs;
230 }
231
233 {
234 FitData::operator=( rhs );
235
236 if ( fpTmpBinEdgeVector )
237 {
238 assert(HasBinEdges());
239
240 delete[] fpTmpBinEdgeVector;
241 fpTmpBinEdgeVector= nullptr;
242 }
243
245 {
246 delete[] fpTmpCoordErrorVector;
247 fpTmpCoordErrorVector = nullptr;
248 }
249
250 fDataPtr = nullptr;
252
255 fBinEdge = rhs.fBinEdge;
256
257 if ( fWrapped )
258 {
259 fData.clear();
260 fCoordErrors.clear();
261 fDataError.clear();
262 fDataErrorHigh.clear();
263 fDataErrorLow.clear();
264
265 fDataPtr = rhs.fDataPtr;
270 }
271 else
272 {
273 // copy data vector and set correct pointer
274 fData = rhs.fData;
275 if ( !fData.empty() )
276 fDataPtr = &fData.front();
277
278 // copy coordinate erro and set correct pointers
280 if (!fCoordErrors.empty()) {
282 fCoordErrorsPtr.resize(fDim);
283 for (unsigned int i = 0; i < fDim; i++) {
284 fCoordErrorsPtr[i] = fCoordErrors[i].empty() ? nullptr : &fCoordErrors[i].front();
285 }
286 }
287 // copy data error
289 if (!fDataError.empty()) {
291 fDataErrorPtr = &fDataError.front();
292 }
293 // copy the asymmetric data error
296 // both error low and high should be empty or not
297 assert( fDataErrorLow.empty() == fDataErrorHigh.empty()) ;
298 if (!fDataErrorHigh.empty() && !fDataErrorLow.empty()) {
299 assert(kAsymError == fErrorType);
302 }
303 }
304
305 fpTmpCoordErrorVector= new double[ fDim ];
306
307 if ( HasBinEdges() )
308 fpTmpBinEdgeVector = new double[ fDim ];
309
310 return *this;
311 }
312
313
314 /**
315 preallocate a data set with given size , dimension and error type (to get the full point size)
316 If the data set already exists and it is having the compatible point size space for the new points
317 is created in the data sets, while if not compatible the old data are erased and new space of
318 new size is allocated.
319 (i.e if exists initialize is equivalent to a resize( NPoints() + maxpoints)
320 */
321
322 void BinData::Append( unsigned int newPoints, unsigned int dim , ErrorType err )
323 {
324 assert( !fWrapped );
325 assert( fMaxPoints == 0 || fWrapped == fData.empty() );
326
327 assert( kValueError == fErrorType || kCoordError == fErrorType ||
329 assert( fMaxPoints == 0 || fDataError.empty() || &fDataError.front() == fDataErrorPtr );
330 assert( fMaxPoints == 0 || fDataErrorHigh.empty() || &fDataErrorHigh.front() == fDataErrorHighPtr );
331 assert( fMaxPoints == 0 || fDataErrorLow.empty() || &fDataErrorLow.front() == fDataErrorLowPtr );
332 assert( fMaxPoints == 0 || fDataErrorLow.empty() == fDataErrorHigh.empty() );
333 assert( fMaxPoints == 0 || fData.empty() || &fData.front() == fDataPtr );
334
335 FitData::Append( newPoints, dim );
336
337 fErrorType = err;
338
341 }
342
343
344 /**
345 apply a Log transformation of the data values
346 can be used for example when fitting an exponential or gaussian
347 Transform the data in place need to copy if want to preserve original data
348 The data sets must not contain negative values. IN case it does,
349 an empty data set is returned
350 */
352 { // apply log transform on the bin data values
353
354 if ( fWrapped )
355 {
356 UnWrap();
357 }
358
359 if ( kNoError == fErrorType )
360 {
362 fDataErrorPtr = fDataError.empty() ? nullptr : &fDataError.front();
363 }
364
365 for ( unsigned int i=0; i < fNPoints; i++ )
366 {
367 double val = fData[i];
368
369 if ( val <= 0 )
370 {
371 MATH_ERROR_MSG("BinData::TransformLog","Some points have negative values - cannot apply a log transformation");
372 return *this;
373 }
374
375 fData[i] = std::log( val );
376
377 if( kNoError == fErrorType )
378 {
379 fDataError[i] = val;
380 }
381 else if ( kValueError == fErrorType )
382 {
383 fDataError[i]*= val;
384 }
385 else if ( kCoordError == fErrorType )
386 {
387 fDataError[i]/= val;
388 }
389 else if ( kAsymError == fErrorType )
390 {
391 fDataErrorHigh[i]/= val;
392 fDataErrorLow[i]/= val;
393 }
394 else
395 assert(false);
396 }
397
398 if ( kNoError == fErrorType )
399 {
401 }
402
403 return *this;
404 }
405
406
407 /**
408 add one dim data with only coordinate and values
409 */
410 void BinData::Add( double x, double y )
411 {
412 assert( kNoError == fErrorType );
413
414 assert( !fData.empty() && fDataPtr );
415 assert( fDataErrorHigh.empty() && !fDataErrorHighPtr );
416 assert( fDataErrorLow.empty() && !fDataErrorLowPtr );
417 assert( fDataError.empty() && !fDataErrorPtr );
418 assert( fCoordErrors.empty() && fCoordErrorsPtr.empty() );
419
420 fData[ fNPoints ] = y;
421
422 FitData::Add( x );
423 fSumContent += y;
424 }
425
426 /**
427 add one dim data with no error in the coordinate (x)
428 in this case store the inverse of the error in the value (y)
429 */
430 void BinData::Add( double x, double y, double ey )
431 {
432 assert( kValueError == fErrorType );
433 assert( !fData.empty() && fDataPtr );
434 assert( fDataErrorHigh.empty() && !fDataErrorHighPtr );
435 assert( fDataErrorLow.empty() && !fDataErrorLowPtr );
436 assert( !fDataError.empty() && fDataErrorPtr );
437 assert( fCoordErrors.empty() && fCoordErrorsPtr.empty() );
438
439 fData[ fNPoints ] = y;
440 fDataError[ fNPoints ] = (ey != 0.0) ? 1.0/ey : 0.0;
441
442 FitData::Add( x );
443 fSumContent += y;
444 if (y != 0 || ey != 1.0) fSumError2 += ey*ey;
445 // set the weight flag checking if error^2 != y
446 if (!fIsWeighted)
447 if (y != 0 && std::abs( ey*ey/y - 1.0) > 1.E-12) fIsWeighted = true;
448 }
449
450 /**
451 add one dim data with error in the coordinate (x)
452 in this case store the value (y) error and not the inverse
453 */
454 void BinData::Add( double x, double y, double ex, double ey )
455 {
456 assert( kCoordError == fErrorType );
457 assert( !fData.empty() && fDataPtr );
458 assert( !fDataError.empty() && fDataErrorPtr );
459 assert( fDataErrorHigh.empty() && !fDataErrorHighPtr );
460 assert( fDataErrorLow.empty() && !fDataErrorLowPtr );
461 assert( !fCoordErrors.empty() && fCoordErrors.size() == 1 );
462 assert( !fCoordErrorsPtr.empty() && fCoordErrorsPtr.size() == 1 && fCoordErrorsPtr[0] );
463 assert( &fCoordErrors[0].front() == fCoordErrorsPtr[0] );
464
465 fData[ fNPoints ] = y;
466 fCoordErrors[0][ fNPoints ] = ex;
468
469 FitData::Add( x );
470 fSumContent += y;
471 if (y != 0 || ey != 1.0) fSumError2 += ey*ey;
472 // set the weight flag checking if error^2 != y
473 if (!fIsWeighted)
474 if (y != 0 && std::abs( ey*ey/y - 1.0) > 1.E-12) fIsWeighted = true;
475 }
476
477 /**
478 add one dim data with error in the coordinate (x) and asymmetric errors in the value (y)
479 in this case store the y errors and not the inverse
480 */
481 void BinData::Add( double x, double y, double ex, double eyl, double eyh )
482 {
483 assert( kAsymError == fErrorType );
484 assert( !fData.empty() && fDataPtr );
485 assert( !fDataErrorHigh.empty() && fDataErrorHighPtr );
486 assert( !fDataErrorLow.empty() && fDataErrorLowPtr );
487 assert( fDataError.empty() && !fDataErrorPtr );
488 assert( !fCoordErrors.empty() && fCoordErrors.size() == 1 );
489 assert( !fCoordErrorsPtr.empty() && fCoordErrorsPtr.size() == 1 && fCoordErrorsPtr[0] );
490 assert( &fCoordErrors[0].front() == fCoordErrorsPtr[0] );
491
492 fData[ fNPoints ] = y;
493 fCoordErrors[0][ fNPoints ] = ex;
494 fDataErrorHigh[ fNPoints ] = eyh;
495 fDataErrorLow[ fNPoints ] = eyl;
496
497 FitData::Add( x );
498 fSumContent += y;
499 if (y != 0 || eyl != 1.0 || eyh != 1.0) fSumError2 += (eyl+eyh)*(eyl+eyh)/4;
500
501 }
502
503 /**
504 add multi-dim coordinate data with only value
505 */
506 void BinData::Add( const double* x, double val )
507 {
508 assert( kNoError == fErrorType );
509
510 assert( !fData.empty() && fDataPtr );
511 assert( fDataErrorHigh.empty() && !fDataErrorHighPtr );
512 assert( fDataErrorLow.empty() && !fDataErrorLowPtr );
513 assert( fDataError.empty() && !fDataErrorPtr );
514 assert( fCoordErrors.empty() && fCoordErrorsPtr.empty() );
515
516 fData[ fNPoints ] = val;
517
518 FitData::Add( x );
519 fSumContent += val;
520 }
521
522 /**
523 add multi-dim coordinate data with only error in value
524 The class stores internally the inverse of the error in this case
525 */
526 void BinData::Add( const double* x, double val, double eval )
527 {
528 assert( kValueError == fErrorType );
529 assert( !fData.empty() && fDataPtr );
530 assert( fDataErrorHigh.empty() && !fDataErrorHighPtr );
531 assert( fDataErrorLow.empty() && !fDataErrorLowPtr );
532 assert( !fDataError.empty() && fDataErrorPtr );
533 assert( fCoordErrors.empty() && fCoordErrorsPtr.empty() );
534
535 fData[ fNPoints ] = val;
536 fDataError[ fNPoints ] = (eval != 0.0) ? 1.0/eval : 0.0;
537
538 FitData::Add( x );
539 fSumContent += val;
540 if (val != 0 || eval != 1.0) fSumError2 += eval*eval;
541 if (!fIsWeighted)
542 if (val != 0 && std::abs( eval*eval/val - 1.0) > 1.E-12) fIsWeighted = true;
543 }
544
545 /**
546 add multi-dim coordinate data with both error in coordinates and value
547 */
548 void BinData::Add( const double* x, double val, const double* ex, double eval )
549 {
550 assert( kCoordError == fErrorType );
551 assert( !fData.empty() && fDataPtr );
552 assert( !fDataError.empty() && fDataErrorPtr );
553 assert( fDataErrorHigh.empty() && !fDataErrorHighPtr );
554 assert( fDataErrorLow.empty() && !fDataErrorLowPtr );
555 assert( fCoordErrors.size() == fDim );
556 assert( fCoordErrorsPtr.size() == fDim );
557
558 fData[ fNPoints ] = val;
559
560 for( unsigned int i=0; i<fDim; i++ )
561 {
562 assert( &fCoordErrors[i].front() == fCoordErrorsPtr[i] );
563
564 fCoordErrors[i][ fNPoints ] = ex[i];
565 }
566 // in this case we store the y error and not the inverse
567 fDataError[ fNPoints ] = eval;
568
569 FitData::Add( x );
570 fSumContent += val;
571 if (val != 0 || eval != 1.0) fSumError2 += eval*eval;
572 if (!fIsWeighted)
573 if (val != 0 && std::abs( eval*eval/val - 1.0) > 1.E-12) fIsWeighted = true;
574 }
575
576 /**
577 add multi-dim coordinate data with both error in coordinates and value
578 */
579 void BinData::Add( const double* x, double val, const double* ex, double elval, double ehval )
580 {
581 assert( kAsymError == fErrorType );
582
583 assert( !fData.empty() && fDataPtr );
584 assert( !fDataErrorHigh.empty() && fDataErrorHighPtr );
585 assert( !fDataErrorLow.empty() && fDataErrorLowPtr );
586 assert( fDataError.empty() && !fDataErrorPtr );
587 assert( fCoordErrors.size() == fDim );
588 assert( fCoordErrorsPtr.size() == fDim );
589
590 fData[ fNPoints ] = val;
591
592 for( unsigned int i=0; i<fDim; i++ )
593 {
594 assert( &fCoordErrors[i].front() == fCoordErrorsPtr[i] );
595
596 fCoordErrors[i][ fNPoints ] = ex[i];
597 }
598
599 fDataErrorLow[ fNPoints ] = elval;
600 fDataErrorHigh[ fNPoints ] = ehval;
601
602 FitData::Add( x );
603 fSumContent += val;
604 if (val != 0 || elval != 1.0 || ehval != 1.0 )
605 fSumError2 += (elval+ehval)*(elval+ehval)/4;
606 }
607
608
609 /**
610 add the bin width data, a pointer to an array with the bin upper edge information.
611 This is needed when fitting with integral or Bin volume normalization options
612 The information is added for the previously inserted point.
613 BinData::Add must be called before
614 */
615 void BinData::AddBinUpEdge( const double* xup )
616 {
617 if ( fBinEdge.empty() )
618 InitBinEdge();
619
620 assert( fBinEdge.size() == fDim );
621
622 for ( unsigned int i=0; i<fDim; i++ )
623 {
624 fBinEdge[i].push_back( xup[i] );
625
626 // check that is consistent with number of points added in the data
627 assert( fNPoints == fBinEdge[i].size() );
628 }
629
630 // compute the bin volume
631 const double* xlow = Coords( fNPoints-1 );
632
633 double binVolume = 1.0;
634 for ( unsigned int j = 0; j < fDim; j++ )
635 {
636 binVolume *= ( xup[j] - xlow[j] );
637 }
638
639 // store the minimum bin volume found as reference for future normalizations
640 if ( fNPoints == 1 )
641 fRefVolume = binVolume;
642 else if ( binVolume < fRefVolume )
643 fRefVolume = binVolume;
644 }
645
646
648 {
650 fDataPtr = fData.empty() ? nullptr : &fData.front();
651 }
652
654 {
655 assert( kValueError == fErrorType || kCoordError == fErrorType ||
657
659 {
660 delete[] fpTmpCoordErrorVector;
661 fpTmpCoordErrorVector = nullptr;
662 }
663
664 if ( kNoError == fErrorType )
665 {
666 fCoordErrors.clear();
667 fCoordErrorsPtr.clear();
668
669 fDataErrorHigh.clear();
670 fDataErrorHighPtr = nullptr;
671
672 fDataErrorLow.clear();
673 fDataErrorLowPtr = nullptr;
674
675 fDataError.clear();
676 fDataErrorPtr = nullptr;
677
678 return;
679 }
680
682 {
683 fCoordErrorsPtr.resize( fDim );
684 fCoordErrors.resize( fDim );
685 for( unsigned int i=0; i < fDim; i++ )
686 {
688
689 fCoordErrorsPtr[i] = fCoordErrors[i].empty() ? nullptr : &fCoordErrors[i].front();
690 }
691
692 fpTmpCoordErrorVector = new double[fDim];
693 }
694 else
695 {
696 fCoordErrors.clear();
697 fCoordErrorsPtr.clear();
698 }
699
701 {
703 fDataErrorPtr = fDataError.empty() ? nullptr : &fDataError.front();
704
705 fDataErrorHigh.clear();
706 fDataErrorHighPtr = nullptr;
707 fDataErrorLow.clear();
708 fDataErrorLowPtr = nullptr;
709 }
710 else if ( fErrorType == kAsymError )
711 {
713 fDataErrorHighPtr = fDataErrorHigh.empty() ? nullptr : &fDataErrorHigh.front();
714
716 fDataErrorLowPtr = fDataErrorLow.empty() ? nullptr : &fDataErrorLow.front();
717
718 fDataError.clear();
719 fDataErrorPtr = nullptr;
720 }
721 else
722 {
723 assert(false);
724 }
725 }
726
728 {
729 fBinEdge.resize( fDim );
730
731 for( unsigned int i=0; i<fDim; i++ )
732 {
734 }
735
736 if ( fpTmpBinEdgeVector )
737 {
738 delete[] fpTmpBinEdgeVector;
739 fpTmpBinEdgeVector = nullptr;
740 }
741
742 fpTmpBinEdgeVector = new double[ fDim ];
743 }
744
746 {
747 assert( fWrapped );
748 assert( kValueError == fErrorType || kCoordError == fErrorType ||
750 assert( fDataError.empty() || &fDataError.front() == fDataErrorPtr );
751 assert( fDataErrorHigh.empty() || &fDataErrorHigh.front() == fDataErrorHighPtr );
752 assert( fDataErrorLow.empty() || &fDataErrorLow.front() == fDataErrorLowPtr );
753 assert( fDataErrorLow.empty() == fDataErrorHigh.empty() );
754
755 assert( fData.empty() );
756 assert( fDataPtr );
757
758 unsigned vectorPadding = FitData::VectorPadding(fNPoints);
759 fData.resize(fNPoints + vectorPadding);
760 std::copy( fDataPtr, fDataPtr + fNPoints, fData.begin() );
761 fDataPtr = fData.empty() ? nullptr : &fData.front();
762
763 for ( unsigned int i=0; i < fDim; i++ )
764 {
765 assert( fCoordErrorsPtr[i] );
766 assert( fCoordErrors.empty() || &fCoordErrors[i].front() == fCoordErrorsPtr[i] );
767 }
768
770 {
771 assert( fDataError.empty() );
772 assert( fDataErrorPtr );
773
774 fDataError.resize(fNPoints + vectorPadding);
775 std::copy(fDataErrorPtr, fDataErrorPtr + fNPoints + vectorPadding, fDataError.begin());
776 fDataErrorPtr = fDataError.empty() ? nullptr : &fDataError.front();
777 }
778
779 if ( kValueError == fErrorType )
780 {
781 for ( unsigned int i=0; i < fNPoints; i++ )
782 {
783 fDataError[i] = 1.0 / fDataError[i];
784 }
785 }
786
788 {
789 fCoordErrors.resize( fDim );
790 for( unsigned int i=0; i < fDim; i++ )
791 {
792 assert( fCoordErrorsPtr[i] );
793 fCoordErrors[i].resize(fNPoints + vectorPadding);
794 std::copy(fCoordErrorsPtr[i], fCoordErrorsPtr[i] + fNPoints + vectorPadding, fCoordErrors[i].begin());
795 fCoordErrorsPtr[i] = fCoordErrors[i].empty() ? nullptr : &fCoordErrors[i].front();
796 }
797
798 if( kAsymError == fErrorType )
799 {
800 assert( fDataErrorHigh.empty() );
801 assert( fDataErrorLow.empty() );
803
804 fDataErrorHigh.resize(fNPoints + vectorPadding);
805 fDataErrorLow.resize(fNPoints + vectorPadding);
806 std::copy(fDataErrorHighPtr, fDataErrorHighPtr + fNPoints + vectorPadding, fDataErrorHigh.begin());
807 std::copy(fDataErrorLowPtr, fDataErrorLowPtr + fNPoints + vectorPadding, fDataErrorLow.begin());
808 fDataErrorHighPtr = fDataErrorHigh.empty() ? nullptr : &fDataErrorHigh.front();
809 fDataErrorLowPtr = fDataErrorLow.empty() ? nullptr : &fDataErrorLow.front();
810 }
811 }
812
814 }
815
817 unsigned int n = Size();
818 fSumContent = 0;
819 fSumError2 = 0;
820 if (fErrorType != kAsymError) {
821 for (unsigned int i = 0; i < n; ++i) {
822 double y = Value(i);
823 double err = Error(i);
824 fSumContent += y;
825 if (y != 0 || err != 1.0) fSumError2 += err*err;
826 }
827 }
828 else {
829 for (unsigned int i = 0; i < n; ++i) {
830 double y = Value(i);
831 fSumContent += y;
832 double elval,ehval = 0;
833 GetAsymError(i,elval,ehval);
834 if (y != 0 || elval != 1.0 || ehval != 1.0)
835 fSumError2 += (elval+ehval)*(elval+ehval)/4;
836 }
837 }
838 // set the weight flag
840 }
841
842 } // end namespace Fit
843
844} // end namespace ROOT
#define MATH_ERROR_MSG(loc, str)
Definition: Error.h:83
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
Class describing the binned data sets : vectors of x coordinates, y values and optionally error on y ...
Definition: BinData.h:52
const double * fDataErrorHighPtr
Definition: BinData.h:624
~BinData() override
destructor
Definition: BinData.cxx:190
const double * fDataPtr
Definition: BinData.h:613
std::vector< double > fData
Stores the data values the same way as the coordinates.
Definition: BinData.h:612
void InitializeErrors()
Definition: BinData.cxx:653
bool HasBinEdges() const
query if the data store the bin edges instead of the center
Definition: BinData.h:545
std::vector< const double * > fCoordErrorsPtr
Definition: BinData.h:616
void Append(unsigned int newPoints, unsigned int dim=1, ErrorType err=kValueError)
Equivalent to Initialize()
Definition: BinData.cxx:322
std::vector< double > fDataErrorLow
Definition: BinData.h:622
void AddBinUpEdge(const double *xup)
add the bin width data, a pointer to an array with the bin upper edge information.
Definition: BinData.cxx:615
const double * fDataErrorLowPtr
Definition: BinData.h:625
std::vector< double > fDataErrorHigh
Definition: BinData.h:621
BinData & LogTransform()
apply a Log transformation of the data values can be used for example when fitting an exponential or ...
Definition: BinData.cxx:351
BinData(unsigned int maxpoints=0, unsigned int dim=1, ErrorType err=kValueError)
constructor from dimension of point and max number of points (to pre-allocate vector) Give a zero val...
Definition: BinData.cxx:26
ErrorType fErrorType
Definition: BinData.h:602
double * fpTmpCoordErrorVector
not threadsafe stuff!
Definition: BinData.h:629
double Value(unsigned int ipoint) const
return the value for the given fit point
Definition: BinData.h:220
void InitDataVector()
Definition: BinData.cxx:647
bool fIsWeighted
flag to indicate weighted data
Definition: BinData.h:603
std::vector< std::vector< double > > fCoordErrors
Definition: BinData.h:615
void Add(double x, double y)
add one dim data with only coordinate and values
Definition: BinData.cxx:410
double fSumContent
total sum of the bin data content
Definition: BinData.h:605
BinData & operator=(const BinData &rhs)
assignment operator
Definition: BinData.cxx:232
std::vector< std::vector< double > > fBinEdge
Definition: BinData.h:631
void GetAsymError(unsigned int ipoint, double &lowError, double &highError) const
Definition: BinData.h:307
double fRefVolume
reference bin volume - used to normalize the bins in case of variable bins data
Definition: BinData.h:604
const double * fDataErrorPtr
Definition: BinData.h:623
double fSumError2
total sum square of the errors
Definition: BinData.h:606
double * fpTmpBinEdgeVector
not threadsafe stuff!
Definition: BinData.h:634
std::vector< double > fDataError
Definition: BinData.h:620
double Error(unsigned int ipoint) const
Return the error on the given point.
Definition: BinData.h:262
class describing the range in the coordinates it supports multiple range in a coordinate.
Definition: DataRange.h:35
Base class for all the fit data types: Stores the coordinates and the DataOptions.
Definition: FitData.h:56
unsigned int Size() const
return number of fit points
Definition: FitData.h:293
void Add(double x)
add one dim data with only coordinate and values
Definition: FitData.h:254
void Append(unsigned int newPoints, unsigned int dim=1)
Definition: FitData.cxx:251
unsigned int fMaxPoints
Definition: FitData.h:384
static constexpr unsigned VectorPadding(const unsigned)
If VecCore is not defined, there is no vectorization available and the SIMD vector size will always b...
Definition: FitData.h:372
unsigned int fDim
Definition: FitData.h:386
FitData & operator=(const FitData &rhs)
Definition: FitData.cxx:218
unsigned int fNPoints
Definition: FitData.h:385
const double * Coords(unsigned int ipoint) const
return a pointer to the coordinates data for the given fit point
Definition: FitData.h:236
RVec< PromoteType< T > > abs(const RVec< T > &v)
Definition: RVec.hxx:1778
RVec< PromoteType< T > > log(const RVec< T > &v)
Definition: RVec.hxx:1787
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
Double_t ey[n]
Definition: legend1.C:17
const Int_t n
Definition: legend1.C:16
Double_t ex[n]
Definition: legend1.C:17
TFitResultPtr Fit(FitObject *h1, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption, const char *goption, ROOT::Fit::DataRange &range)
Definition: HFitImpl.cxx:133
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
DataOptions : simple structure holding the options on how the data are filled.
Definition: DataOptions.h:28