51 namespace HFitInterface {
56 if (func ==0)
return false;
79 void ExamineRange(
const TAxis * axis, std::pair<double,double> range,
int &hxfirst,
int &hxlast) {
82 double xlow = range.first;
83 double xhigh = range.second;
85 std::cout <<
"xlow " << xlow <<
" xhigh = " << xhigh << std::endl;
90 if (ilow > hxlast || ihigh < hxfirst) {
91 Warning(
"ROOT::Fit::FillData",
"fit range is outside histogram range, no fit data for %s",axis->
GetName());
94 hxfirst = std::min( std::max( ilow, hxfirst), hxlast+1) ;
95 hxlast = std::max( std::min( ihigh, hxlast), hxfirst-1) ;
97 if (hxfirst < hxlast) {
142 if (range.
Size(0) != 0) {
144 if (range.
Size(0) > 1 ) {
145 Warning(
"ROOT::Fit::FillData",
"support only one range interval for X coordinate");
151 if (range.
Size(1) > 1 )
152 Warning(
"ROOT::Fit::FillData",
"support only one range interval for Y coordinate");
157 if (range.
Size(2) > 1 )
158 Warning(
"ROOT::Fit::FillData",
"support only one range interval for Z coordinate");
162 int n = (hxlast-hxfirst+1)*(hylast-hyfirst+1)*(hzlast-hzfirst+1);
165 std::cout <<
"THFitInterface: ifirst = " << hxfirst <<
" ilast = " << hxlast
166 <<
" total bins " << n
176 if (func !=0 && func->
GetNdim() == hdim-1) ndim = hdim-1;
194 for ( binx = hxfirst; binx <= hxlast; ++binx) {
203 for ( biny = hyfirst; biny <= hylast; ++biny) {
211 for ( binz = hzfirst; binz <= hzlast; ++binz) {
229 double error = hfit->
GetBinError(binx, biny, binz);
232 if (ndim == hdim -1) {
236 if (hdim == 2) dv.
Add( x, x[1], yaxis->
GetBinWidth(biny) / error );
237 if (hdim == 3) dv.
Add( x, x[2], zaxis->
GetBinWidth(binz) / error );
239 dv.
Add( x, value, error );
247 std::cout <<
"bin " << binx <<
" add point " << x[0] <<
" " << hfit->
GetBinContent(binx) << std::endl;
256 std::cout <<
"THFitInterface::FillData: Hist FitData size is " << dv.
Size() << std::endl;
266 unsigned int n = data.
Size();
273 double valxmax = valxmin;
275 for (
unsigned int i = 1; i <
n; ++ i) {
289 if (valxmin <= 0 && valxmax > 0 ) valxmin = valxmax;
290 else if (valxmax <=0 && valxmin > 0) valxmax = valxmin;
291 else if (valxmin <=0 && valxmax <= 0) { valxmin = 1; valxmax = 1; }
293 double slope =
std::log( valxmax/valxmin) / (xmax -
xmin);
306 static const double sqrtpi = 2.506628;
309 unsigned int n = data.
Size();
315 double rangex = data.
Coords(n-1)[0] - data.
Coords(0)[0];
318 if ( rangex > 0) binwidth = rangex;
320 for (
unsigned int i = 0; i <
n; ++ i) {
326 if (val > valmax) valmax = val;
329 if (dx < binwidth) binwidth = dx;
334 if (allcha <= 0)
return;
335 double mean = sumx/allcha;
336 double rms = sumx2/allcha - mean*mean;
355 double constant = 0.5*(valmax+ binwidth*allcha/(sqrtpi*rms));
376 std::cout <<
"Gaussian initial par values" << constant <<
" " << mean <<
" " << rms << std::endl;
388 static const double sqrtpi = 2.506628;
391 unsigned int n = data.
Size();
393 double sumx = 0, sumy = 0;
394 double sumx2 = 0, sumy2 = 0;
397 double rangex = data.
Coords(n-1)[0] - data.
Coords(0)[0];
398 double rangey = data.
Coords(n-1)[1] - data.
Coords(0)[1];
400 double binwidthx = 1, binwidthy = 1;
401 if ( rangex > 0) binwidthx = rangex;
402 if ( rangey > 0) binwidthy = rangey;
403 double x0 = 0, y0 = 0;
404 for (
unsigned int i = 0; i <
n; ++i) {
406 const double *coords = data.
GetPoint(i,val);
407 double x = coords[0],
y = coords[1];
413 if (val > valmax) valmax = val;
416 if (dx < binwidthx) binwidthx = dx;
418 if (dy < binwidthy) binwidthy = dy;
424 if (allcha <= 0)
return;
425 double meanx = sumx/allcha, meany = sumy/allcha;
426 double rmsx = sumx2/allcha - meanx*meanx;
427 double rmsy = sumy2/allcha - meany*meany;
433 rmsx = binwidthx*n/4;
438 rmsy = binwidthy*n/4;
448 double constant = 0.5 * (valmax+ binwidthx*allcha/(sqrtpi*rmsx))*
449 (valmax+ binwidthy*allcha/(sqrtpi*rmsy));
460 std::cout <<
"2D Gaussian initial par values" 484 if (fitOpt.
fErrors1 || ( ey == 0 && ( eyl == 0 || eyh == 0 ) ) ) {
498 else if ( ( eyl != 0 && eyh != 0) && fitOpt.
fAsymErrors) {
501 bool zeroErrorX =
true;
502 bool zeroErrorY =
true;
503 while (i < gr->GetN() && (zeroErrorX || zeroErrorY)) {
505 double e2Y = eyl[i] + eyh[i];
506 zeroErrorX &= (e2X <= 0);
507 zeroErrorY &= (e2Y <= 0);
510 if (zeroErrorX && zeroErrorY)
512 else if (!zeroErrorX && zeroErrorY)
514 else if (zeroErrorX && !zeroErrorY) {
526 bool zeroError =
true;
527 while (i < gr->GetN() && zeroError) {
528 if (ey[i] > 0) zeroError =
false;;
536 std::cout <<
"type is " << type <<
" graph type is " << gr->IsA()->
GetName() << std::endl;
546 double *ez = gr->
GetEZ();
565 std::cout <<
"type is " << type <<
" graph2D type is " << gr->IsA()->
GetName() << std::endl;
580 int nPoints = gr->
GetN();
581 double *gx = gr->
GetX();
582 double *gy = gr->
GetY();
585 bool useRange = ( range.
Size(0) > 0);
593 std::cout <<
"DoFillData: graph npoints = " << nPoints <<
" type " << type << std::endl;
595 double a1,a2; func->
GetRange(a1,a2); std::cout <<
"func range " << a1 <<
" " << a2 << std::endl;
600 for (
int i = 0; i < nPoints; ++i) {
605 if (useRange && ( x[0] < xmin || x[0] > xmax) )
continue;
617 dv.
Add( gx[i], gy[i] );
626 dv.
Add( gx[i], gy[i], errorY );
629 std::cout <<
"Point " << i <<
" " << gx[i] <<
" " << gy[i] <<
" " << errorY << std::endl;
644 double errorY = std::max(gr->
GetErrorY(i), 0.);
649 if ( errorX <=0 && errorY <= 0 )
continue;
658 dv.
Add( gx[i], gy[i], errorX, errorY );
665 std::cout <<
"TGraphFitInterface::FillData Graph FitData size is " << dv.
Size() << std::endl;
673 std::vector<double> min(dim);
674 std::vector<double> max(dim);
677 for (
int i = 0; i < ncells; ++i ) {
717 std::vector<double> min(dim);
718 std::vector<double> max(dim);
719 std::vector<Int_t> coord(dim);
722 for (
ULong64_t i = 0; i < nEntries; i++ )
725 if ( !value )
continue;
730 bool insertBox =
true;
731 for (
int j = 0; j < dim && insertBox; ++j )
761 std::vector<double>
xmin(ndim);
762 std::vector<double>
xmax(ndim);
763 for (
unsigned int i = 0; i < ndim; ++i ) {
809 if (dv.
Size() > 0 && dv.
NDim() == 1 ) {
812 Error(
"FillData",
"Inconsistent TGraph with previous data set- skip all graph data");
833 std::cout <<
"multi-graph list of graps: " << std::endl;
834 while ((obj = itr())) {
835 std::cout << obj->IsA()->
GetName() << std::endl;
848 while ((gr = (
TGraph*) next())) {
850 if (t > type ) type = t;
859 std::cout <<
"Fitting MultiGraph of type " << type << std::endl;
864 while ((gr = (
TGraph*) next())) {
869 std::cout <<
"TGraphFitInterface::FillData MultiGraph FitData size is " << dv.
Size() << std::endl;
888 int nPoints = gr->
GetN();
889 double *gx = gr->
GetX();
890 double *gy = gr->
GetY();
891 double *gz = gr->
GetZ();
901 bool useRangeX = ( range.Size(0) > 0);
902 bool useRangeY = ( range.Size(1) > 0);
907 range.GetRange(xmin,xmax,ymin,ymax);
911 for (
int i = 0; i < nPoints; ++i) {
917 if (useRangeX && (
x[0] < xmin ||
x[0] > xmax) )
continue;
918 if (useRangeY && (
x[1] < ymin ||
x[1] > ymax) )
continue;
937 dv.
Add(
x, gz[i], errorZ );
942 dv.
Add(
x, gz[i],
ex, errorZ );
948 std::cout <<
"Point " << i <<
" " << gx[i] <<
" " << gy[i] <<
" " << errorZ << std::endl;
954 std::cout <<
"THFitInterface::FillData Graph2D FitData size is " << dv.
Size() << std::endl;
963 Error(
"GetConfidenceIntervals",
"Invalid object used for storing confidence intervals");
970 double * ci = gr->
GetEY();
973 for (
unsigned int ipoint = 0; ipoint < d.
NPoints(); ++ipoint) {
974 const double *
x = d.
Coords(ipoint);
976 gr->
SetPoint(ipoint, x[0], (*func)(x) );
Double_t GetBinError(const Int_t *idx) const
virtual const char * GetName() const
Returns name of object.
virtual Int_t GetNcells() const
virtual Double_t GetErrorYhigh(Int_t bin) const
This function is called by GraphFitChisquare.
virtual void SetParameters(const Double_t *params)
virtual Double_t * GetEX() const
Bool_t IsBinUnderflow(Int_t bin, Int_t axis=0) const
Return true if the bin is underflow.
Int_t GetFirst() const
Return first bin on the axis i.e.
virtual Double_t GetErrorZ(Int_t bin) const
This function is called by Graph2DFitChisquare.
virtual Double_t GetErrorY(Int_t bin) const
This function is called by GraphFitChisquare.
Namespace for new ROOT classes and functions.
Bool_t IsBinOverflow(Int_t bin, Int_t axis=0) const
Return true if the bin is overflow.
virtual Long64_t GetNbins() const =0
ErrorType GetErrorType() const
retrieve the errortype
virtual Double_t GetBinLowEdge(Int_t bin) const
Return low edge of bin.
virtual Double_t * GetEYlow() const
void GetConfidenceIntervals(unsigned int n, unsigned int stride1, unsigned int stride2, const double *x, double *ci, double cl=0.95, bool norm=false) const
get confidence intervals for an array of n points x.
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Double_t GetBinContent(const Int_t *idx) const
A TMultiGraph is a collection of TGraph (or derived) objects.
virtual Double_t * GetEY() const
virtual void GetBinXYZ(Int_t binglobal, Int_t &binx, Int_t &biny, Int_t &binz) const
Return binx, biny, binz corresponding to the global bin number globalbin see TH1::GetBin function abo...
void ExamineRange(const TAxis *axis, std::pair< double, double > range, int &hxfirst, int &hxlast)
const IModelFunction * FittedFunction() const
fitting quantities
void AddBinUpEdge(const double *xup)
add the bin width data, a pointer to an array with the bin upper edge information.
virtual Double_t GetErrorYlow(Int_t bin) const
This function is called by GraphFitChisquare.
static constexpr double mg
bool GetConfidenceIntervals(const TH1 *h1, const ROOT::Fit::FitResult &r, TGraphErrors *gr, double cl=0.95)
compute confidence intervals at level cl for a fitted histogram h1 in a TGraphErrors gr ...
virtual Double_t GetBinUpEdge(Int_t bin) const
Return up edge of bin.
const double * Coords(unsigned int ipoint) const
return a pointer to the coordinates data for the given fit point
const double * GetPoint(unsigned int ipoint, double &value) const
retrieve at the same time a pointer to the coordinate data and the fit value More efficient than call...
virtual Int_t GetDimension() const
void GetRange(unsigned int irange, unsigned int icoord, double &xmin, double &xmax) const
get the i-th range for given coordinate.
virtual Double_t * GetEY() const
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
void Initialize(unsigned int newPoints, unsigned int dim=1, ErrorType err=kValueError)
bool AdjustError(const DataOptions &option, double &error, double value=1)
virtual Int_t GetNdim() const
virtual Double_t * GetEZ() const
unsigned int Size() const
return number of fit points
virtual Double_t GetErrorY(Int_t bin) const
This function is called by Graph2DFitChisquare.
void InitGaus(const ROOT::Fit::BinData &data, TF1 *f1)
compute initial parameter for gaussian function given the fit data Set the sigma limits for zero top ...
virtual void SetParLimits(Int_t ipar, Double_t parmin, Double_t parmax)
Set limits for parameter ipar.
virtual Double_t GetErrorXlow(Int_t bin) const
This function is called by GraphFitChisquare.
void FillData(BinData &dv, const TH1 *hist, TF1 *func=0)
fill the data vector from a TH1.
TAxis * GetAxis(Int_t dim) const
BinData::ErrorType GetDataType(const TGraph *gr, DataOptions &fitOpt)
DataOptions : simple structure holding the options on how the data are filled.
Int_t GetLast() const
Return last bin on the axis i.e.
Class to manage histogram axis.
void DoFillData(BinData &dv, const TGraph *gr, BinData::ErrorType type, TF1 *func)
unsigned int Size(unsigned int icoord=0) const
return range size for coordinate icoord (starts from zero) Size == 0 indicates no range is present [-...
void GetBinDataIntegral(BinData &) const
const DataOptions & Opt() const
access to options
static void RejectPoint(Bool_t reject=kTRUE)
Static function to set the global flag to reject points the fgRejectPoint global flag is tested by al...
Class describing the binned data sets : vectors of x coordinates, y values and optionally error on y ...
void InitExpo(const ROOT::Fit::BinData &data, TF1 *f1)
compute initial parameter for an exponential function given the fit data Set the constant and slope a...
void Warning(const char *location, const char *msgfmt,...)
virtual Double_t * GetEX() const
class containg the result of the fit and all the related information (fitted parameter values...
class describing the range in the coordinates it supports multiple range in a coordinate.
void Init2DGaus(const ROOT::Fit::BinData &data, TF1 *f1)
compute initial parameter for 2D gaussian function given the fit data Set the sigma limits for zero t...
void Add(double x, double y)
add one dim data with only coordinate and values
TFitResultPtr Fit(FitObject *h1, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption, const char *goption, ROOT::Fit::DataRange &range)
unsigned long long ULong64_t
static constexpr double s
virtual Double_t GetErrorX(Int_t bin) const
This function is called by Graph2DFitChisquare.
Int_t GetNdimensions() const
Mother of all ROOT objects.
virtual Int_t FindFixBin(Double_t x) const
Find bin number corresponding to abscissa x.
you should not use this method at all Int_t Int_t z
virtual Bool_t IsInside(const Double_t *x) const
return kTRUE if the point is inside the function range
virtual Double_t GetBinWidth(Int_t bin) const
Return bin width.
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
Set x and y values for point number i.
TList * GetListOfGraphs() const
static Bool_t RejectedPoint()
See TF1::RejectPoint above.
bool IsPointOutOfRange(const TF1 *func, const double *x)
virtual void GetRange(Double_t *xmin, Double_t *xmax) const
Return range of a generic N-D function.
A Graph is a graphics object made of two arrays X and Y with npoints each.
A TGraphErrors is a TGraph with error bars.
Multidimensional histogram base.
virtual void SetParameter(Int_t param, Double_t value)
unsigned int NPoints() const
return number of fit points
unsigned int NDim() const
return coordinate data dimension
const DataRange & Range() const
access to range
virtual Double_t * GetEYhigh() const
const Bool_t kIterBackward
Graphics object made of three arrays X, Y and Z with the same number of points each.
virtual const char * GetName() const
Returns name of object.
virtual void Set(Int_t n)
Set number of points in the graph Existing coordinates are preserved New coordinates above fNpoints a...
virtual Double_t GetErrorXhigh(Int_t bin) const
This function is called by GraphFitChisquare.
void Add(std::vector< double > &min, std::vector< double > &max, const double content, const double error=1.0)
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
void Error(ErrorHandler_t func, int code, const char *va_(fmt),...)
Write error message and call a handler, if required.
virtual Double_t GetBinError(Int_t bin) const
Return value of error associated to bin number bin.