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
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( Opt().fIntegral );
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 ( Opt().fIntegral )
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 void BinData::Initialize( unsigned int newPoints, unsigned int dim, ErrorType err )
344 {
345 Append( newPoints, dim, err );
346 }
347
348
349
350 /**
351 apply a Log transformation of the data values
352 can be used for example when fitting an exponential or gaussian
353 Transform the data in place need to copy if want to preserve original data
354 The data sets must not contain negative values. IN case it does,
355 an empty data set is returned
356 */
358 { // apply log transform on the bin data values
359
360 if ( fWrapped )
361 {
362 UnWrap();
363 }
364
365 if ( kNoError == fErrorType )
366 {
368 fDataErrorPtr = fDataError.empty() ? nullptr : &fDataError.front();
369 }
370
371 for ( unsigned int i=0; i < fNPoints; i++ )
372 {
373 double val = fData[i];
374
375 if ( val <= 0 )
376 {
377 MATH_ERROR_MSG("BinData::TransformLog","Some points have negative values - cannot apply a log transformation");
378 return *this;
379 }
380
381 fData[i] = std::log( val );
382
383 if( kNoError == fErrorType )
384 {
385 fDataError[i] = val;
386 }
387 else if ( kValueError == fErrorType )
388 {
389 fDataError[i]*= val;
390 }
391 else if ( kCoordError == fErrorType )
392 {
393 fDataError[i]/= val;
394 }
395 else if ( kAsymError == fErrorType )
396 {
397 fDataErrorHigh[i]/= val;
398 fDataErrorLow[i]/= val;
399 }
400 else
401 assert(false);
402 }
403
404 if ( kNoError == fErrorType )
405 {
407 }
408
409 return *this;
410 }
411
412
413 /**
414 add one dim data with only coordinate and values
415 */
416 void BinData::Add( double x, double y )
417 {
418 assert( kNoError == fErrorType );
419
420 assert( !fData.empty() && fDataPtr );
421 assert( fDataErrorHigh.empty() && !fDataErrorHighPtr );
422 assert( fDataErrorLow.empty() && !fDataErrorLowPtr );
423 assert( fDataError.empty() && !fDataErrorPtr );
424 assert( fCoordErrors.empty() && fCoordErrorsPtr.empty() );
425
426 fData[ fNPoints ] = y;
427
428 FitData::Add( x );
429 fSumContent += y;
430 }
431
432 /**
433 add one dim data with no error in the coordinate (x)
434 in this case store the inverse of the error in the value (y)
435 */
436 void BinData::Add( double x, double y, double ey )
437 {
438 assert( kValueError == fErrorType );
439 assert( !fData.empty() && fDataPtr );
440 assert( fDataErrorHigh.empty() && !fDataErrorHighPtr );
441 assert( fDataErrorLow.empty() && !fDataErrorLowPtr );
442 assert( !fDataError.empty() && fDataErrorPtr );
443 assert( fCoordErrors.empty() && fCoordErrorsPtr.empty() );
444
445 fData[ fNPoints ] = y;
446 fDataError[ fNPoints ] = (ey != 0.0) ? 1.0/ey : 0.0;
447
448 FitData::Add( x );
449 fSumContent += y;
450 if (y != 0 || ey != 1.0) fSumError2 += ey*ey;
451 // set the weight flag checking if error^2 != y
452 if (!fIsWeighted)
453 if (y != 0 && std::abs( ey*ey/y - 1.0) > 1.E-12) fIsWeighted = true;
454 }
455
456 /**
457 add one dim data with error in the coordinate (x)
458 in this case store the value (y) error and not the inverse
459 */
460 void BinData::Add( double x, double y, double ex, double ey )
461 {
462 assert( kCoordError == fErrorType );
463 assert( !fData.empty() && fDataPtr );
464 assert( !fDataError.empty() && fDataErrorPtr );
465 assert( fDataErrorHigh.empty() && !fDataErrorHighPtr );
466 assert( fDataErrorLow.empty() && !fDataErrorLowPtr );
467 assert( !fCoordErrors.empty() && fCoordErrors.size() == 1 );
468 assert( !fCoordErrorsPtr.empty() && fCoordErrorsPtr.size() == 1 && fCoordErrorsPtr[0] );
469 assert( &fCoordErrors[0].front() == fCoordErrorsPtr[0] );
470
471 fData[ fNPoints ] = y;
472 fCoordErrors[0][ fNPoints ] = ex;
474
475 FitData::Add( x );
476 fSumContent += y;
477 if (y != 0 || ey != 1.0) fSumError2 += ey*ey;
478 // set the weight flag checking if error^2 != y
479 if (!fIsWeighted)
480 if (y != 0 && std::abs( ey*ey/y - 1.0) > 1.E-12) fIsWeighted = true;
481 }
482
483 /**
484 add one dim data with error in the coordinate (x) and asymmetric errors in the value (y)
485 in this case store the y errors and not the inverse
486 */
487 void BinData::Add( double x, double y, double ex, double eyl, double eyh )
488 {
489 assert( kAsymError == fErrorType );
490 assert( !fData.empty() && fDataPtr );
491 assert( !fDataErrorHigh.empty() && fDataErrorHighPtr );
492 assert( !fDataErrorLow.empty() && fDataErrorLowPtr );
493 assert( fDataError.empty() && !fDataErrorPtr );
494 assert( !fCoordErrors.empty() && fCoordErrors.size() == 1 );
495 assert( !fCoordErrorsPtr.empty() && fCoordErrorsPtr.size() == 1 && fCoordErrorsPtr[0] );
496 assert( &fCoordErrors[0].front() == fCoordErrorsPtr[0] );
497
498 fData[ fNPoints ] = y;
499 fCoordErrors[0][ fNPoints ] = ex;
500 fDataErrorHigh[ fNPoints ] = eyh;
501 fDataErrorLow[ fNPoints ] = eyl;
502
503 FitData::Add( x );
504 fSumContent += y;
505 if (y != 0 || eyl != 1.0 || eyh != 1.0) fSumError2 += (eyl+eyh)*(eyl+eyh)/4;
506
507 }
508
509 /**
510 add multi-dim coordinate data with only value
511 */
512 void BinData::Add( const double* x, double val )
513 {
514 assert( kNoError == fErrorType );
515
516 assert( !fData.empty() && fDataPtr );
517 assert( fDataErrorHigh.empty() && !fDataErrorHighPtr );
518 assert( fDataErrorLow.empty() && !fDataErrorLowPtr );
519 assert( fDataError.empty() && !fDataErrorPtr );
520 assert( fCoordErrors.empty() && fCoordErrorsPtr.empty() );
521
522 fData[ fNPoints ] = val;
523
524 FitData::Add( x );
525 fSumContent += val;
526 }
527
528 /**
529 add multi-dim coordinate data with only error in value
530 The class stores internally the inverse of the error in this case
531 */
532 void BinData::Add( const double* x, double val, double eval )
533 {
534 assert( kValueError == fErrorType );
535 assert( !fData.empty() && fDataPtr );
536 assert( fDataErrorHigh.empty() && !fDataErrorHighPtr );
537 assert( fDataErrorLow.empty() && !fDataErrorLowPtr );
538 assert( !fDataError.empty() && fDataErrorPtr );
539 assert( fCoordErrors.empty() && fCoordErrorsPtr.empty() );
540
541 fData[ fNPoints ] = val;
542 fDataError[ fNPoints ] = (eval != 0.0) ? 1.0/eval : 0.0;
543
544 FitData::Add( x );
545 fSumContent += val;
546 if (val != 0 || eval != 1.0) fSumError2 += eval*eval;
547 if (!fIsWeighted)
548 if (val != 0 && std::abs( eval*eval/val - 1.0) > 1.E-12) fIsWeighted = true;
549 }
550
551 /**
552 add multi-dim coordinate data with both error in coordinates and value
553 */
554 void BinData::Add( const double* x, double val, const double* ex, double eval )
555 {
556 assert( kCoordError == fErrorType );
557 assert( !fData.empty() && fDataPtr );
558 assert( !fDataError.empty() && fDataErrorPtr );
559 assert( fDataErrorHigh.empty() && !fDataErrorHighPtr );
560 assert( fDataErrorLow.empty() && !fDataErrorLowPtr );
561 assert( fCoordErrors.size() == fDim );
562 assert( fCoordErrorsPtr.size() == fDim );
563
564 fData[ fNPoints ] = val;
565
566 for( unsigned int i=0; i<fDim; i++ )
567 {
568 assert( &fCoordErrors[i].front() == fCoordErrorsPtr[i] );
569
570 fCoordErrors[i][ fNPoints ] = ex[i];
571 }
572 // in this case we store the y error and not the inverse
573 fDataError[ fNPoints ] = eval;
574
575 FitData::Add( x );
576 fSumContent += val;
577 if (val != 0 || eval != 1.0) fSumError2 += eval*eval;
578 if (!fIsWeighted)
579 if (val != 0 && std::abs( eval*eval/val - 1.0) > 1.E-12) fIsWeighted = true;
580 }
581
582 /**
583 add multi-dim coordinate data with both error in coordinates and value
584 */
585 void BinData::Add( const double* x, double val, const double* ex, double elval, double ehval )
586 {
587 assert( kAsymError == fErrorType );
588
589 assert( !fData.empty() && fDataPtr );
590 assert( !fDataErrorHigh.empty() && fDataErrorHighPtr );
591 assert( !fDataErrorLow.empty() && fDataErrorLowPtr );
592 assert( fDataError.empty() && !fDataErrorPtr );
593 assert( fCoordErrors.size() == fDim );
594 assert( fCoordErrorsPtr.size() == fDim );
595
596 fData[ fNPoints ] = val;
597
598 for( unsigned int i=0; i<fDim; i++ )
599 {
600 assert( &fCoordErrors[i].front() == fCoordErrorsPtr[i] );
601
602 fCoordErrors[i][ fNPoints ] = ex[i];
603 }
604
605 fDataErrorLow[ fNPoints ] = elval;
606 fDataErrorHigh[ fNPoints ] = ehval;
607
608 FitData::Add( x );
609 fSumContent += val;
610 if (val != 0 || elval != 1.0 || ehval != 1.0 )
611 fSumError2 += (elval+ehval)*(elval+ehval)/4;
612 }
613
614
615 /**
616 add the bin width data, a pointer to an array with the bin upper edge information.
617 This is needed when fitting with integral options
618 The information is added for the previously inserted point.
619 BinData::Add must be called before
620 */
621 void BinData::AddBinUpEdge( const double* xup )
622 {
623 if ( fBinEdge.empty() )
624 InitBinEdge();
625
626 assert( fBinEdge.size() == fDim );
627
628 for ( unsigned int i=0; i<fDim; i++ )
629 {
630 fBinEdge[i].push_back( xup[i] );
631
632 // check that is consistent with number of points added in the data
633 assert( fNPoints == fBinEdge[i].size() );
634 }
635
636 // compute the bin volume
637 const double* xlow = Coords( fNPoints-1 );
638
639 double binVolume = 1.0;
640 for ( unsigned int j = 0; j < fDim; j++ )
641 {
642 binVolume *= ( xup[j] - xlow[j] );
643 }
644
645 // store the minimum bin volume found as reference for future normalizations
646 if ( fNPoints == 1 )
647 fRefVolume = binVolume;
648 else if ( binVolume < fRefVolume )
649 fRefVolume = binVolume;
650 }
651
652
654 {
656 fDataPtr = fData.empty() ? nullptr : &fData.front();
657 }
658
660 {
661 assert( kValueError == fErrorType || kCoordError == fErrorType ||
663
665 {
666 delete[] fpTmpCoordErrorVector;
667 fpTmpCoordErrorVector = nullptr;
668 }
669
670 if ( kNoError == fErrorType )
671 {
672 fCoordErrors.clear();
673 fCoordErrorsPtr.clear();
674
675 fDataErrorHigh.clear();
676 fDataErrorHighPtr = nullptr;
677
678 fDataErrorLow.clear();
679 fDataErrorLowPtr = nullptr;
680
681 fDataError.clear();
682 fDataErrorPtr = nullptr;
683
684 return;
685 }
686
688 {
689 fCoordErrorsPtr.resize( fDim );
690 fCoordErrors.resize( fDim );
691 for( unsigned int i=0; i < fDim; i++ )
692 {
694
695 fCoordErrorsPtr[i] = fCoordErrors[i].empty() ? nullptr : &fCoordErrors[i].front();
696 }
697
698 fpTmpCoordErrorVector = new double[fDim];
699 }
700 else
701 {
702 fCoordErrors.clear();
703 fCoordErrorsPtr.clear();
704 }
705
707 {
709 fDataErrorPtr = fDataError.empty() ? nullptr : &fDataError.front();
710
711 fDataErrorHigh.clear();
712 fDataErrorHighPtr = nullptr;
713 fDataErrorLow.clear();
714 fDataErrorLowPtr = nullptr;
715 }
716 else if ( fErrorType == kAsymError )
717 {
719 fDataErrorHighPtr = fDataErrorHigh.empty() ? nullptr : &fDataErrorHigh.front();
720
722 fDataErrorLowPtr = fDataErrorLow.empty() ? nullptr : &fDataErrorLow.front();
723
724 fDataError.clear();
725 fDataErrorPtr = nullptr;
726 }
727 else
728 {
729 assert(false);
730 }
731 }
732
734 {
735 fBinEdge.resize( fDim );
736
737 for( unsigned int i=0; i<fDim; i++ )
738 {
740 }
741
742 if ( fpTmpBinEdgeVector )
743 {
744 delete[] fpTmpBinEdgeVector;
745 fpTmpBinEdgeVector = nullptr;
746 }
747
748 fpTmpBinEdgeVector = new double[ fDim ];
749 }
750
752 {
753 assert( fWrapped );
754 assert( kValueError == fErrorType || kCoordError == fErrorType ||
756 assert( fDataError.empty() || &fDataError.front() == fDataErrorPtr );
757 assert( fDataErrorHigh.empty() || &fDataErrorHigh.front() == fDataErrorHighPtr );
758 assert( fDataErrorLow.empty() || &fDataErrorLow.front() == fDataErrorLowPtr );
759 assert( fDataErrorLow.empty() == fDataErrorHigh.empty() );
760
761 assert( fData.empty() );
762 assert( fDataPtr );
763
764 unsigned vectorPadding = FitData::VectorPadding(fNPoints);
765 fData.resize(fNPoints + vectorPadding);
766 std::copy( fDataPtr, fDataPtr + fNPoints, fData.begin() );
767 fDataPtr = fData.empty() ? nullptr : &fData.front();
768
769 for ( unsigned int i=0; i < fDim; i++ )
770 {
771 assert( fCoordErrorsPtr[i] );
772 assert( fCoordErrors.empty() || &fCoordErrors[i].front() == fCoordErrorsPtr[i] );
773 }
774
776 {
777 assert( fDataError.empty() );
778 assert( fDataErrorPtr );
779
780 fDataError.resize(fNPoints + vectorPadding);
781 std::copy(fDataErrorPtr, fDataErrorPtr + fNPoints + vectorPadding, fDataError.begin());
782 fDataErrorPtr = fDataError.empty() ? nullptr : &fDataError.front();
783 }
784
785 if ( kValueError == fErrorType )
786 {
787 for ( unsigned int i=0; i < fNPoints; i++ )
788 {
789 fDataError[i] = 1.0 / fDataError[i];
790 }
791 }
792
794 {
795 fCoordErrors.resize( fDim );
796 for( unsigned int i=0; i < fDim; i++ )
797 {
798 assert( fCoordErrorsPtr[i] );
799 fCoordErrors[i].resize(fNPoints + vectorPadding);
800 std::copy(fCoordErrorsPtr[i], fCoordErrorsPtr[i] + fNPoints + vectorPadding, fCoordErrors[i].begin());
801 fCoordErrorsPtr[i] = fCoordErrors[i].empty() ? nullptr : &fCoordErrors[i].front();
802 }
803
804 if( kAsymError == fErrorType )
805 {
806 assert( fDataErrorHigh.empty() );
807 assert( fDataErrorLow.empty() );
809
810 fDataErrorHigh.resize(fNPoints + vectorPadding);
811 fDataErrorLow.resize(fNPoints + vectorPadding);
812 std::copy(fDataErrorHighPtr, fDataErrorHighPtr + fNPoints + vectorPadding, fDataErrorHigh.begin());
813 std::copy(fDataErrorLowPtr, fDataErrorLowPtr + fNPoints + vectorPadding, fDataErrorLow.begin());
814 fDataErrorHighPtr = fDataErrorHigh.empty() ? nullptr : &fDataErrorHigh.front();
815 fDataErrorLowPtr = fDataErrorLow.empty() ? nullptr : &fDataErrorLow.front();
816 }
817 }
818
820 }
821
823 unsigned int n = Size();
824 fSumContent = 0;
825 fSumError2 = 0;
826 if (fErrorType != kAsymError) {
827 for (unsigned int i = 0; i < n; ++i) {
828 double y = Value(i);
829 double err = Error(i);
830 fSumContent += y;
831 if (y != 0 || err != 1.0) fSumError2 += err*err;
832 }
833 }
834 else {
835 for (unsigned int i = 0; i < n; ++i) {
836 double y = Value(i);
837 fSumContent += y;
838 double elval,ehval = 0;
839 GetAsymError(i,elval,ehval);
840 if (y != 0 || elval != 1.0 || ehval != 1.0)
841 fSumError2 += (elval+ehval)*(elval+ehval)/4;
842 }
843 }
844 // set the weight flag
846 }
847
848 } // end namespace Fit
849
850} // end namespace ROOT
#define MATH_ERROR_MSG(loc, str)
Definition Error.h:83
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:612
const double * fDataPtr
Definition BinData.h:601
std::vector< double > fData
Stores the data values the same way as the coordinates.
Definition BinData.h:600
void InitializeErrors()
Definition BinData.cxx:659
std::vector< const double * > fCoordErrorsPtr
Definition BinData.h:604
void Append(unsigned int newPoints, unsigned int dim=1, ErrorType err=kValueError)
preallocate a data set with given size , dimension and error type (to get the full point size) If the...
Definition BinData.cxx:322
std::vector< double > fDataErrorLow
Definition BinData.h:610
void AddBinUpEdge(const double *xup)
add the bin width data, a pointer to an array with the bin upper edge information.
Definition BinData.cxx:621
const double * fDataErrorLowPtr
Definition BinData.h:613
std::vector< double > fDataErrorHigh
Definition BinData.h:609
BinData & LogTransform()
apply a Log transformation of the data values can be used for example when fitting an exponential or ...
Definition BinData.cxx:357
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
virtual ~BinData()
destructor
Definition BinData.cxx:190
ErrorType fErrorType
Definition BinData.h:590
double * fpTmpCoordErrorVector
Definition BinData.h:617
std::vector< std::vector< double > > fCoordErrors
Definition BinData.h:603
void Add(double x, double y)
add one dim data with only coordinate and values
Definition BinData.cxx:416
void Initialize(unsigned int newPoints, unsigned int dim=1, ErrorType err=kValueError)
Definition BinData.cxx:343
BinData & operator=(const BinData &rhs)
Definition BinData.cxx:232
std::vector< std::vector< double > > fBinEdge
Definition BinData.h:619
void GetAsymError(unsigned int ipoint, double &lowError, double &highError) const
Definition BinData.h:295
const double * fDataErrorPtr
Definition BinData.h:611
double * fpTmpBinEdgeVector
Definition BinData.h:622
std::vector< double > fDataError
Definition BinData.h:608
double Error(unsigned int ipoint) const
Definition BinData.h:250
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:66
unsigned int Size() const
return number of fit points
Definition FitData.h:303
void Add(double x)
add one dim data with only coordinate and values
Definition FitData.h:264
void Append(unsigned int newPoints, unsigned int dim=1)
Definition FitData.cxx:250
unsigned int fMaxPoints
Definition FitData.h:394
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:382
unsigned int fDim
Definition FitData.h:396
FitData & operator=(const FitData &rhs)
Definition FitData.cxx:218
unsigned int fNPoints
Definition FitData.h:395
const DataOptions & Opt() const
access to options
Definition FitData.h:319
const double * Coords(unsigned int ipoint) const
return a pointer to the coordinates data for the given fit point
Definition FitData.h:246
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
Double_t ey[n]
Definition legend1.C:17
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