Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
19namespace ROOT {
20
21 namespace Fit
22 {
23
24 BinData::BinData(unsigned int maxpoints, unsigned int dim,
25 ErrorType err ) :
26 FitData( maxpoints, dim ),
27 fErrorType( err ),
28 fDataPtr( nullptr ),
29 fDataErrorPtr( nullptr ), fDataErrorHighPtr( nullptr ), fDataErrorLowPtr( nullptr ),
30 fpTmpCoordErrorVector( nullptr ), fpTmpBinEdgeVector( nullptr )
31 {
34 }
35
36
37 /**
38 constructor from option and default range
39 */
40 BinData::BinData (const DataOptions & opt, unsigned int maxpoints,
41 unsigned int dim, ErrorType err ) :
42 FitData( opt, maxpoints, dim ),
43 fErrorType( err ),
44 fDataPtr( nullptr ),
45 fDataErrorPtr( nullptr ), fDataErrorHighPtr( nullptr ), fDataErrorLowPtr( nullptr ),
46 fpTmpCoordErrorVector( nullptr ), fpTmpBinEdgeVector( nullptr )
47 {
50 }
51
52 /**
53 constructor from options and range
54 efault is 1D and value errors
55 */
56 BinData::BinData (const DataOptions & opt, const DataRange & range,
57 unsigned int maxpoints, unsigned int dim, ErrorType err ) :
58 FitData( opt, range, maxpoints, dim ),
59 fErrorType( err ),
60 fDataPtr( nullptr ),
61 fDataErrorPtr( nullptr ), fDataErrorHighPtr( nullptr ), fDataErrorLowPtr( nullptr ),
62 fpTmpCoordErrorVector( nullptr ), fpTmpBinEdgeVector( nullptr )
63 {
66 }
67
68 /** constructors using external data */
69
70 /**
71 constructor from external data for 1D with errors on coordinate and value
72 */
73 BinData::BinData (unsigned int n, const double * dataX, const double * val,
74 const double * ex , const double * eval ) :
75 FitData( n, dataX ),
76 fDataPtr( nullptr ),
77 fDataErrorPtr( nullptr ), fDataErrorHighPtr( nullptr ), fDataErrorLowPtr( nullptr ),
78 fpTmpCoordErrorVector( nullptr ), fpTmpBinEdgeVector( nullptr )
79 {
80 assert( val );
81 fDataPtr = val;
82
83 if ( nullptr != eval )
84 {
85 fDataErrorPtr = eval;
86
88
89 if ( nullptr != ex )
90 {
91 fCoordErrorsPtr.resize( 1 );
92
94
96 }
97 }
98 else
99 {
101 }
102
103 fpTmpCoordErrorVector = new double [ fDim ];
104
105 ComputeSums();
106 }
107
108 /**
109 constructor from external data for 2D with errors on coordinate and value
110 */
111 BinData::BinData(unsigned int n, const double * dataX, const double * dataY,
112 const double * val, const double * ex , const double * ey,
113 const double * eval ) :
114 FitData( n, dataX, dataY ),
115 fDataErrorPtr( nullptr ), fDataErrorHighPtr( nullptr ), fDataErrorLowPtr( nullptr ),
116 fpTmpCoordErrorVector( nullptr ), fpTmpBinEdgeVector( nullptr )
117 {
118 assert( val );
119 fDataPtr = val;
120
121 if ( nullptr != eval )
122 {
123 fDataErrorPtr = eval;
124
126
127 if ( nullptr != ex || nullptr != ey )
128 {
129 fCoordErrorsPtr.resize( 2 );
130
131 fCoordErrorsPtr[0] = ex;
132 fCoordErrorsPtr[1] = ey;
133
135 }
136 }
137 else
138 {
140 }
141
142 fpTmpCoordErrorVector = new double [ fDim ];
143 ComputeSums();
144 }
145
146 /**
147 constructor from external data for 3D with errors on coordinate and value
148 */
149 BinData::BinData(unsigned int n, const double * dataX, const double * dataY,
150 const double * dataZ, const double * val, const double * ex ,
151 const double * ey , const double * ez , const double * eval ) :
152 FitData( n, dataX, dataY, dataZ ),
153 fDataErrorPtr( nullptr ), fDataErrorHighPtr( nullptr ), fDataErrorLowPtr( nullptr ),
154 fpTmpCoordErrorVector( nullptr ), fpTmpBinEdgeVector( nullptr )
155 {
156 assert( val );
157 fDataPtr = val;
158
159 if ( nullptr != eval )
160 {
161 fDataErrorPtr = eval;
162
164
165 if ( nullptr != ex || nullptr != ey || nullptr != ez )
166 {
167 fCoordErrorsPtr.resize( 3 );
168
169 fCoordErrorsPtr[0] = ex;
170 fCoordErrorsPtr[1] = ey;
171 fCoordErrorsPtr[2] = ez;
172
174 }
175 }
176 else
177 {
179 }
180
181 fpTmpCoordErrorVector = new double [ fDim ];
182 ComputeSums();
183 }
184
185 /**
186 destructor
187 */
189 {
190 assert( fMaxPoints == 0 || fWrapped == fData.empty() );
191
192 assert( kValueError == fErrorType || kCoordError == fErrorType ||
194 assert( fMaxPoints == 0 || fDataError.empty() || &fDataError.front() == fDataErrorPtr );
195 assert( fMaxPoints == 0 || fDataErrorHigh.empty() || &fDataErrorHigh.front() == fDataErrorHighPtr );
196 assert( fMaxPoints == 0 || fDataErrorLow.empty() || &fDataErrorLow.front() == fDataErrorLowPtr );
197 assert( fMaxPoints == 0 || fDataErrorLow.empty() == fDataErrorHigh.empty() );
198 assert( fMaxPoints == 0 || fData.empty() || &fData.front() == fDataPtr );
199
200 for ( unsigned int i=0; i < fDim; i++ )
201 {
202 assert( fCoordErrors.empty() || &fCoordErrors[i].front() == fCoordErrorsPtr[i] );
203 }
204
205 if ( fpTmpBinEdgeVector )
206 {
207 delete[] fpTmpBinEdgeVector;
208 fpTmpBinEdgeVector= nullptr;
209 }
210
212 {
213 delete[] fpTmpCoordErrorVector;
214 fpTmpCoordErrorVector = nullptr;
215 }
216 }
217
218 /**
219 copy constructors
220 */
222 : FitData(rhs),
223 fDataPtr(nullptr),
224 fDataErrorPtr(nullptr), fDataErrorHighPtr(nullptr), fDataErrorLowPtr(nullptr),
225 fpTmpCoordErrorVector(nullptr), fpTmpBinEdgeVector(nullptr)
226 {
227 *this = rhs;
228 }
229
231 {
232 FitData::operator=( rhs );
233
234 if ( fpTmpBinEdgeVector )
235 {
236 assert(HasBinEdges());
237
238 delete[] fpTmpBinEdgeVector;
239 fpTmpBinEdgeVector= nullptr;
240 }
241
243 {
244 delete[] fpTmpCoordErrorVector;
245 fpTmpCoordErrorVector = nullptr;
246 }
247
248 fDataPtr = nullptr;
250
253 fBinEdge = rhs.fBinEdge;
254
255 if ( fWrapped )
256 {
257 fData.clear();
258 fCoordErrors.clear();
259 fDataError.clear();
260 fDataErrorHigh.clear();
261 fDataErrorLow.clear();
262
263 fDataPtr = rhs.fDataPtr;
268 }
269 else
270 {
271 // copy data vector and set correct pointer
272 fData = rhs.fData;
273 if ( !fData.empty() )
274 fDataPtr = &fData.front();
275
276 // copy coordinate errors and set correct pointers
278 if (!fCoordErrors.empty()) {
280 fCoordErrorsPtr.resize(fDim);
281 for (unsigned int i = 0; i < fDim; i++) {
282 fCoordErrorsPtr[i] = fCoordErrors[i].empty() ? nullptr : &fCoordErrors[i].front();
283 }
284 }
285 // copy data error
287 if (!fDataError.empty()) {
289 fDataErrorPtr = &fDataError.front();
290 }
291 // copy the asymmetric data error
294 // both error low and high should be empty or not
295 assert( fDataErrorLow.empty() == fDataErrorHigh.empty()) ;
296 if (!fDataErrorHigh.empty() && !fDataErrorLow.empty()) {
297 assert(kAsymError == fErrorType);
300 }
301 }
302
303 fpTmpCoordErrorVector= new double[ fDim ];
304
305 if ( HasBinEdges() )
306 fpTmpBinEdgeVector = new double[ fDim ];
307
308 return *this;
309 }
310
311
312 /**
313 preallocate a data set with given size , dimension and error type (to get the full point size)
314 If the data set already exists and it is having the compatible point size space for the new points
315 is created in the data sets, while if not compatible the old data are erased and new space of
316 new size is allocated.
317 (i.e if exists initialize is equivalent to a resize( NPoints() + maxpoints)
318 */
319
320 void BinData::Append( unsigned int newPoints, unsigned int dim , ErrorType err )
321 {
322 assert( !fWrapped );
323 assert( fMaxPoints == 0 || fWrapped == fData.empty() );
324
325 assert( kValueError == fErrorType || kCoordError == fErrorType ||
327 assert( fMaxPoints == 0 || fDataError.empty() || &fDataError.front() == fDataErrorPtr );
328 assert( fMaxPoints == 0 || fDataErrorHigh.empty() || &fDataErrorHigh.front() == fDataErrorHighPtr );
329 assert( fMaxPoints == 0 || fDataErrorLow.empty() || &fDataErrorLow.front() == fDataErrorLowPtr );
330 assert( fMaxPoints == 0 || fDataErrorLow.empty() == fDataErrorHigh.empty() );
331 assert( fMaxPoints == 0 || fData.empty() || &fData.front() == fDataPtr );
332
333 FitData::Append( newPoints, dim );
334
335 fErrorType = err;
336
339 }
340
341
342 /**
343 apply a Log transformation of the data values
344 can be used for example when fitting an exponential or gaussian
345 Transform the data in place need to copy if want to preserve original data
346 The data sets must not contain negative values. IN case it does,
347 an empty data set is returned
348 */
350 { // apply log transform on the bin data values
351
352 if ( fWrapped )
353 {
354 UnWrap();
355 }
356
357 if ( kNoError == fErrorType )
358 {
360 fDataErrorPtr = fDataError.empty() ? nullptr : &fDataError.front();
361 }
362
363 for ( unsigned int i=0; i < fNPoints; i++ )
364 {
365 double val = fData[i];
366
367 if ( val <= 0 )
368 {
369 MATH_ERROR_MSG("BinData::TransformLog","Some points have negative values - cannot apply a log transformation");
370 return *this;
371 }
372
373 fData[i] = std::log( val );
374
375 if( kNoError == fErrorType )
376 {
377 fDataError[i] = val;
378 }
379 else if ( kValueError == fErrorType )
380 {
381 fDataError[i]*= val;
382 }
383 else if ( kCoordError == fErrorType )
384 {
385 fDataError[i]/= val;
386 }
387 else if ( kAsymError == fErrorType )
388 {
389 fDataErrorHigh[i]/= val;
390 fDataErrorLow[i]/= val;
391 }
392 else
393 assert(false);
394 }
395
396 if ( kNoError == fErrorType )
397 {
399 }
400
401 return *this;
402 }
403
404
405 /**
406 add one dim data with only coordinate and values
407 */
408 void BinData::Add( double x, double y )
409 {
410 assert( kNoError == fErrorType );
411
412 assert( !fData.empty() && fDataPtr );
413 assert( fDataErrorHigh.empty() && !fDataErrorHighPtr );
414 assert( fDataErrorLow.empty() && !fDataErrorLowPtr );
415 assert( fDataError.empty() && !fDataErrorPtr );
416 assert( fCoordErrors.empty() && fCoordErrorsPtr.empty() );
417
418 fData[ fNPoints ] = y;
419
420 FitData::Add( x );
421 fSumContent += y;
422 }
423
424 /**
425 add one dim data with no error in the coordinate (x)
426 in this case store the inverse of the error in the value (y)
427 */
428 void BinData::Add( double x, double y, double ey )
429 {
430 assert( kValueError == fErrorType );
431 assert( !fData.empty() && fDataPtr );
432 assert( fDataErrorHigh.empty() && !fDataErrorHighPtr );
433 assert( fDataErrorLow.empty() && !fDataErrorLowPtr );
434 assert( !fDataError.empty() && fDataErrorPtr );
435 assert( fCoordErrors.empty() && fCoordErrorsPtr.empty() );
436
437 fData[ fNPoints ] = y;
438 fDataError[ fNPoints ] = (ey != 0.0) ? 1.0/ey : 0.0;
439
440 FitData::Add( x );
441 fSumContent += y;
442 if (y != 0 || ey != 1.0) fSumError2 += ey*ey;
443 // set the weight flag checking if error^2 != y
444 if (!fIsWeighted)
445 if (y != 0 && std::abs( ey*ey/y - 1.0) > 1.E-12) fIsWeighted = true;
446 }
447
448 /**
449 add one dim data with error in the coordinate (x)
450 in this case store the value (y) error and not the inverse
451 */
452 void BinData::Add( double x, double y, double ex, double ey )
453 {
454 assert( kCoordError == fErrorType );
455 assert( !fData.empty() && fDataPtr );
456 assert( !fDataError.empty() && fDataErrorPtr );
457 assert( fDataErrorHigh.empty() && !fDataErrorHighPtr );
458 assert( fDataErrorLow.empty() && !fDataErrorLowPtr );
459 assert( !fCoordErrors.empty() && fCoordErrors.size() == 1 );
460 assert( !fCoordErrorsPtr.empty() && fCoordErrorsPtr.size() == 1 && fCoordErrorsPtr[0] );
461 assert( &fCoordErrors[0].front() == fCoordErrorsPtr[0] );
462
463 fData[ fNPoints ] = y;
464 fCoordErrors[0][ fNPoints ] = ex;
466
467 FitData::Add( x );
468 fSumContent += y;
469 if (y != 0 || ey != 1.0) fSumError2 += ey*ey;
470 // set the weight flag checking if error^2 != y
471 if (!fIsWeighted)
472 if (y != 0 && std::abs( ey*ey/y - 1.0) > 1.E-12) fIsWeighted = true;
473 }
474
475 /**
476 add one dim data with error in the coordinate (x) and asymmetric errors in the value (y)
477 in this case store the y errors and not the inverse
478 */
479 void BinData::Add( double x, double y, double ex, double eyl, double eyh )
480 {
481 assert( kAsymError == fErrorType );
482 assert( !fData.empty() && fDataPtr );
483 assert( !fDataErrorHigh.empty() && fDataErrorHighPtr );
484 assert( !fDataErrorLow.empty() && fDataErrorLowPtr );
485 assert( fDataError.empty() && !fDataErrorPtr );
486 assert( !fCoordErrors.empty() && fCoordErrors.size() == 1 );
487 assert( !fCoordErrorsPtr.empty() && fCoordErrorsPtr.size() == 1 && fCoordErrorsPtr[0] );
488 assert( &fCoordErrors[0].front() == fCoordErrorsPtr[0] );
489
490 fData[ fNPoints ] = y;
491 fCoordErrors[0][ fNPoints ] = ex;
492 fDataErrorHigh[ fNPoints ] = eyh;
493 fDataErrorLow[ fNPoints ] = eyl;
494
495 FitData::Add( x );
496 fSumContent += y;
497 if (y != 0 || eyl != 1.0 || eyh != 1.0) fSumError2 += (eyl+eyh)*(eyl+eyh)/4;
498
499 }
500
501 /**
502 add multi-dim coordinate data with only value
503 */
504 void BinData::Add( const double* x, double val )
505 {
506 assert( kNoError == fErrorType );
507
508 assert( !fData.empty() && fDataPtr );
509 assert( fDataErrorHigh.empty() && !fDataErrorHighPtr );
510 assert( fDataErrorLow.empty() && !fDataErrorLowPtr );
511 assert( fDataError.empty() && !fDataErrorPtr );
512 assert( fCoordErrors.empty() && fCoordErrorsPtr.empty() );
513
514 fData[ fNPoints ] = val;
515
516 FitData::Add( x );
517 fSumContent += val;
518 }
519
520 /**
521 add multi-dim coordinate data with only error in value
522 The class stores internally the inverse of the error in this case
523 */
524 void BinData::Add( const double* x, double val, double eval )
525 {
526 assert( kValueError == fErrorType );
527 assert( !fData.empty() && fDataPtr );
528 assert( fDataErrorHigh.empty() && !fDataErrorHighPtr );
529 assert( fDataErrorLow.empty() && !fDataErrorLowPtr );
530 assert( !fDataError.empty() && fDataErrorPtr );
531 assert( fCoordErrors.empty() && fCoordErrorsPtr.empty() );
532
533 fData[ fNPoints ] = val;
534 fDataError[ fNPoints ] = (eval != 0.0) ? 1.0/eval : 0.0;
535
536 FitData::Add( x );
537 fSumContent += val;
538 if (val != 0 || eval != 1.0) fSumError2 += eval*eval;
539 if (!fIsWeighted)
540 if (val != 0 && std::abs( eval*eval/val - 1.0) > 1.E-12) fIsWeighted = true;
541 }
542
543 /**
544 add multi-dim coordinate data with both error in coordinates and value
545 */
546 void BinData::Add( const double* x, double val, const double* ex, double eval )
547 {
548 assert( kCoordError == fErrorType );
549 assert( !fData.empty() && fDataPtr );
550 assert( !fDataError.empty() && fDataErrorPtr );
551 assert( fDataErrorHigh.empty() && !fDataErrorHighPtr );
552 assert( fDataErrorLow.empty() && !fDataErrorLowPtr );
553 assert( fCoordErrors.size() == fDim );
554 assert( fCoordErrorsPtr.size() == fDim );
555
556 fData[ fNPoints ] = val;
557
558 for( unsigned int i=0; i<fDim; i++ )
559 {
560 assert( &fCoordErrors[i].front() == fCoordErrorsPtr[i] );
561
562 fCoordErrors[i][ fNPoints ] = ex[i];
563 }
564 // in this case we store the y error and not the inverse
565 fDataError[ fNPoints ] = eval;
566
567 FitData::Add( x );
568 fSumContent += val;
569 if (val != 0 || eval != 1.0) fSumError2 += eval*eval;
570 if (!fIsWeighted)
571 if (val != 0 && std::abs( eval*eval/val - 1.0) > 1.E-12) fIsWeighted = true;
572 }
573
574 /**
575 add multi-dim coordinate data with both error in coordinates and value
576 */
577 void BinData::Add( const double* x, double val, const double* ex, double elval, double ehval )
578 {
579 assert( kAsymError == fErrorType );
580
581 assert( !fData.empty() && fDataPtr );
582 assert( !fDataErrorHigh.empty() && fDataErrorHighPtr );
583 assert( !fDataErrorLow.empty() && fDataErrorLowPtr );
584 assert( fDataError.empty() && !fDataErrorPtr );
585 assert( fCoordErrors.size() == fDim );
586 assert( fCoordErrorsPtr.size() == fDim );
587
588 fData[ fNPoints ] = val;
589
590 for( unsigned int i=0; i<fDim; i++ )
591 {
592 assert( &fCoordErrors[i].front() == fCoordErrorsPtr[i] );
593
594 fCoordErrors[i][ fNPoints ] = ex[i];
595 }
596
597 fDataErrorLow[ fNPoints ] = elval;
598 fDataErrorHigh[ fNPoints ] = ehval;
599
600 FitData::Add( x );
601 fSumContent += val;
602 if (val != 0 || elval != 1.0 || ehval != 1.0 )
603 fSumError2 += (elval+ehval)*(elval+ehval)/4;
604 }
605
606
607 /**
608 add the bin width data, a pointer to an array with the bin upper edge information.
609 This is needed when fitting with integral or Bin volume normalization options
610 The information is added for the previously inserted point.
611 BinData::Add must be called before
612 */
613 void BinData::AddBinUpEdge( const double* xup )
614 {
615 if ( fBinEdge.empty() )
616 InitBinEdge();
617
618 assert( fBinEdge.size() == fDim );
619
620 for ( unsigned int i=0; i<fDim; i++ )
621 {
622 fBinEdge[i].push_back( xup[i] );
623
624 // check that is consistent with number of points added in the data
625 assert( fNPoints == fBinEdge[i].size() );
626 }
627
628 // compute the bin volume
629 const double* xlow = Coords( fNPoints-1 );
630
631 double binVolume = 1.0;
632 for ( unsigned int j = 0; j < fDim; j++ )
633 {
634 binVolume *= ( xup[j] - xlow[j] );
635 }
636
637 // store the minimum bin volume found as reference for future normalizations
638 if ( fNPoints == 1 )
639 fRefVolume = binVolume;
640 else if ( binVolume < fRefVolume )
641 fRefVolume = binVolume;
642 }
643
644
646 {
648 fDataPtr = fData.empty() ? nullptr : &fData.front();
649 }
650
652 {
653 assert( kValueError == fErrorType || kCoordError == fErrorType ||
655
657 {
658 delete[] fpTmpCoordErrorVector;
659 fpTmpCoordErrorVector = nullptr;
660 }
661
662 if ( kNoError == fErrorType )
663 {
664 fCoordErrors.clear();
665 fCoordErrorsPtr.clear();
666
667 fDataErrorHigh.clear();
668 fDataErrorHighPtr = nullptr;
669
670 fDataErrorLow.clear();
671 fDataErrorLowPtr = nullptr;
672
673 fDataError.clear();
674 fDataErrorPtr = nullptr;
675
676 return;
677 }
678
680 {
681 fCoordErrorsPtr.resize( fDim );
682 fCoordErrors.resize( fDim );
683 for( unsigned int i=0; i < fDim; i++ )
684 {
686
687 fCoordErrorsPtr[i] = fCoordErrors[i].empty() ? nullptr : &fCoordErrors[i].front();
688 }
689
690 fpTmpCoordErrorVector = new double[fDim];
691 }
692 else
693 {
694 fCoordErrors.clear();
695 fCoordErrorsPtr.clear();
696 }
697
699 {
701 fDataErrorPtr = fDataError.empty() ? nullptr : &fDataError.front();
702
703 fDataErrorHigh.clear();
704 fDataErrorHighPtr = nullptr;
705 fDataErrorLow.clear();
706 fDataErrorLowPtr = nullptr;
707 }
708 else if ( fErrorType == kAsymError )
709 {
711 fDataErrorHighPtr = fDataErrorHigh.empty() ? nullptr : &fDataErrorHigh.front();
712
714 fDataErrorLowPtr = fDataErrorLow.empty() ? nullptr : &fDataErrorLow.front();
715
716 fDataError.clear();
717 fDataErrorPtr = nullptr;
718 }
719 else
720 {
721 assert(false);
722 }
723 }
724
726 {
727 fBinEdge.resize( fDim );
728
729 for( unsigned int i=0; i<fDim; i++ )
730 {
732 }
733
734 if ( fpTmpBinEdgeVector )
735 {
736 delete[] fpTmpBinEdgeVector;
737 fpTmpBinEdgeVector = nullptr;
738 }
739
740 fpTmpBinEdgeVector = new double[ fDim ];
741 }
742
744 {
745 assert( fWrapped );
746 assert( kValueError == fErrorType || kCoordError == fErrorType ||
748 assert( fDataError.empty() || &fDataError.front() == fDataErrorPtr );
749 assert( fDataErrorHigh.empty() || &fDataErrorHigh.front() == fDataErrorHighPtr );
750 assert( fDataErrorLow.empty() || &fDataErrorLow.front() == fDataErrorLowPtr );
751 assert( fDataErrorLow.empty() == fDataErrorHigh.empty() );
752
753 assert( fData.empty() );
754 assert( fDataPtr );
755
756 unsigned vectorPadding = FitData::VectorPadding(fNPoints);
757 fData.resize(fNPoints + vectorPadding);
758 std::copy( fDataPtr, fDataPtr + fNPoints, fData.begin() );
759 fDataPtr = fData.empty() ? nullptr : &fData.front();
760
761 for ( unsigned int i=0; i < fDim; i++ )
762 {
763 assert( fCoordErrorsPtr[i] );
764 assert( fCoordErrors.empty() || &fCoordErrors[i].front() == fCoordErrorsPtr[i] );
765 }
766
768 {
769 assert( fDataError.empty() );
770 assert( fDataErrorPtr );
771
772 fDataError.resize(fNPoints + vectorPadding);
773 std::copy(fDataErrorPtr, fDataErrorPtr + fNPoints + vectorPadding, fDataError.begin());
774 fDataErrorPtr = fDataError.empty() ? nullptr : &fDataError.front();
775 }
776
777 if ( kValueError == fErrorType )
778 {
779 for ( unsigned int i=0; i < fNPoints; i++ )
780 {
781 fDataError[i] = 1.0 / fDataError[i];
782 }
783 }
784
786 {
787 fCoordErrors.resize( fDim );
788 for( unsigned int i=0; i < fDim; i++ )
789 {
790 assert( fCoordErrorsPtr[i] );
791 fCoordErrors[i].resize(fNPoints + vectorPadding);
792 std::copy(fCoordErrorsPtr[i], fCoordErrorsPtr[i] + fNPoints + vectorPadding, fCoordErrors[i].begin());
793 fCoordErrorsPtr[i] = fCoordErrors[i].empty() ? nullptr : &fCoordErrors[i].front();
794 }
795
796 if( kAsymError == fErrorType )
797 {
798 assert( fDataErrorHigh.empty() );
799 assert( fDataErrorLow.empty() );
801
802 fDataErrorHigh.resize(fNPoints + vectorPadding);
803 fDataErrorLow.resize(fNPoints + vectorPadding);
804 std::copy(fDataErrorHighPtr, fDataErrorHighPtr + fNPoints + vectorPadding, fDataErrorHigh.begin());
805 std::copy(fDataErrorLowPtr, fDataErrorLowPtr + fNPoints + vectorPadding, fDataErrorLow.begin());
806 fDataErrorHighPtr = fDataErrorHigh.empty() ? nullptr : &fDataErrorHigh.front();
807 fDataErrorLowPtr = fDataErrorLow.empty() ? nullptr : &fDataErrorLow.front();
808 }
809 }
810
812 }
813
815 unsigned int n = Size();
816 fSumContent = 0;
817 fSumError2 = 0;
818 if (fErrorType != kAsymError) {
819 for (unsigned int i = 0; i < n; ++i) {
820 double y = Value(i);
821 double err = Error(i);
822 fSumContent += y;
823 if (fErrorType != kNoError) {
824 if (y != 0 || err != 1.0 ) fSumError2 += err*err;
825 }
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
839 if (fErrorType != kNoError)
841 }
842
843 } // end namespace Fit
844
845} // 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:188
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:651
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:320
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:613
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:349
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:24
ErrorType fErrorType
Definition BinData.h:602
double * fpTmpCoordErrorVector
not threadsafe stuff!
Definition BinData.h:629
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:408
double fSumContent
total sum of the bin data content
Definition BinData.h:605
BinData & operator=(const BinData &rhs)
assignment operator
Definition BinData.cxx:230
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
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
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
DataOptions : simple structure holding the options on how the data are filled.
Definition DataOptions.h:28