Fit function between specific y values

Hi, I have a TGraphAsymmErrors object, to which I added a sigmoid fit. Since I am only interested in a specific y range of that function, I would like to add my fit only to that y range (so that that range is being fitted more precisely), but I am not sure how to do that… Thanks!

${ROOTSYS}/tutorials/fit/fitExclude.C

Thanks! That tutorial is able to set the x range of the fit, but how would I make it work for the y range?

@moneta @couet I’m afraid I have forgotten how to easily extract the current “y” value (for the current “x”) from inside of the fit function.

I have already answered to this question in Fit function uses initial parameter values

@evdv it is not efficient to open different posts for the same problem. Please refrain to do it, It just creates confusion

yes, you’re right, I’m sorry

@moneta I think it would still be nice to learn how one can get the actual “y”, for the actual “x”, inside of the fit function (i.e. each time it is called and gets its new “Double_t *x” set).

I am sorry I don’t understand what do you mean exactly. To get y value given x, just call TF1::Eval(x), but I think you refer to something else

The question is:

Double_t fline(Double_t *x, Double_t *par)
{
  // how to get the current (to be fitted) data point's "y" for the current "x[0]"
}

This is not a question for the function, but for the data used for fitting. And from each data object (TH1, TGraph, etc…) you can get this information given the x value, or vice versa, find x given y

Lorenzo

This is a question for the ROOT’s fitter / minimizer. It calls the user provided “FCN” fit function when calculating the ch^2 or the likelihood (for each data point separately). This function gets the “Double_t *x” but inside I also want to know what is the (experimental) data point’s “value” (i.e. “y” for 1D data objects and “z” for 2D objects) for this particular point. This should work regardless of the data object type (the “FCN” fit function should not depend on the actual type, i.e. regardless if one does “graph->Fit(FCN)” or “histo->Fit(FCN)” it should look the same).

If I remember well, I once used TVirtualFitter::GetFitter() to gain access to it’s settings inside of the “FCN” fit function (but there were some problems and I don’t remember now how I got around them).

Hi,

It is up to you as you implement the function. In the ps you could use the static Fitter instance to get access to the data, it is true. Now there is no existing global fitter instance, it is up to the user to get this information from the data object itself. One for example can use a lambda function to build a TF1 and have access directly to the fitted histogram when implementing the fit user function. This is similar with what you get in the past with TVirtulFitter::GetFitter()->GetObjectFit()

If you want to get more lower level information there is always the way of using instead of TH1::Fit the Fitter class.

Lorenzo

Lorenzo

Well, this reminds me the first problem. In the beginning, during fitting, inside of the “FCN” fit function, TVirtualFitter::GetFitter() returns 0 (and first AFTER the fit completes, it returns some valid pointer).

Hi,

This is correct ! There is a global TVirtualFitter instance created only after fitting. This was introduced mainly for backward compatibility butit should not be used anymore now. Also, when running with ROOT IMT support (multi-threading mode) this instance is not created even after fitting !
We should probably add a deprecated warning message when calling TVirtualFitter::GetFitter()

Lorenzo

So the question is again … from inside of the “FCN”, how can I get the actual (experimental) data point’s “value” (i.e. “y” for 1D data objects and “z” for 2D objects) for this particular point (for which this function has been called)?
Or, how can I get access to the object being fitted (without writing object specific lambda functions).

One thing to clarify, FCN is a jargon used (from Minuit) to call the objective function (chi2, likelihood, etc…) and not your fitting model function that you pass in TH1::Fit

Concerning your question, no there is no static function to access the data object that you can use within your TF1 implementation.
But it is not needed, you can create the TF1 from a C++ object (a lambda, a functor, etc…) and pass the data object pointer or reference or you can always make your data object a global one and be visible inside the TF1 user implementation.
I can provide a simple example for this if you need
I hope this answers your question

Lorenzo

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.