Setting GaussIntegrator relative tolerance for use in binned TH1 fits?

Dear ROOT Experts:

To fit a histogram, a TF1 is created

TF1 *myDplusFit = new TF1(“myDplusFit”,“fit0p5MeV_GaussianPlusCBWithExp”,1800.,1940.,9);

and then it is used

hist->Fit("myDplusFit","QRLI"); 

where “I” indicates that it should integrate the fit function over each bin rather than using the function value at the center. This is pretty consistently generating a message

Warning in ROOT::Math::ROOT::Math::GaussIntegrator: Failed to reach the desired tolerance ; maxtol = 1e-09

Despite the warnings, the fits are excellent – better than without invoking the “I” option. But at some point the program hangs, perhaps because it has printed too many warnings. So I’d like to change the tolerance.

It seems like it should be possible to use the ROOT::Math:Integrator SetRelTolerance method to reset the default 1e-09 to another value. There some examples on the web using WrappedTF1 objects, but these don’t seem to “do the trick” (probably because I misunderstand the technology.

Specifically,

TF1 *myDplusFit = new TF1("myDplusFit","fit0p5MeV_GaussianPlusCBWithExp",1800.,1940.,9);
ROOT::Math::WrappedTF1 wf(myDplusFit);
ROOT::Math::GaussIntegrator ig;
ig.SetFunction(wf, false);
ig.SetRelTolerance(0.0001);

leads to exactly the same warnings indicating that maxtol = 1e-09, as above. myDplusFit is a TF1 *, not a TF1 (which is what sample code uses), but ROOT did not complain, so I am guessing WrappedTF1 can take either as an argument. I had hoped this magic incantation would somehow set the tolerance in myDplusFit. What should I be doing instead?

Many thanks,
Mike

Dear Experts:

I made some progress, and solved the “immediate problem” of changing the relative tolerance. Unfortunately, ROOT quits after fitting several histograms successfully and producing a multitude of warning messages. The current version of the code is

TF1 *myDplusFit = new TF1(“myDplusFit”,“fit0p5MeV_GaussianPlusCBWithExp”,1800.,1940.,9);

// the following code successfully resets the default tolerance
// values from 1.e-06 --< 1.e-04; but does not eliminate the
// warnings during execution
ROOT::Math::IntegratorOneDimOptions::SetDefaultAbsTolerance(1.E-4);
ROOT::Math::IntegratorOneDimOptions::SetDefaultRelTolerance(1.E-2);

// the following line did not stop the GausIntegrator warnings
ROOT::Math::MinimizerOptions::SetDefaultPrintLevel(-1);

I guess my question now is how to turn off printing the warning messages produced inside the integrator code.

Thanks for any advice,
Mike

What are these warnings ?

The warnings are of the form

Warning in ROOT::Math::ROOT::Math::GaussIntegrator: Failed to reach the desired tolerance ; maxtol = 1e-09

with the 1e-09 replaced by whatever value is set using

ROOT::Math::IntegratorOneDimOptions::SetDefaultRelTolerance(1.E-2);

The bit of code which generates this message appears to be line 155 in

https://root.cern.ch/doc/master/GaussIntegrator_8cxx_source.html

Any advice on how to suppress such warnings will be appreciated.

Mike

One more item, perhaps of some relevance – the code does about 150 fits, integrating over 280 bins in each fit, before ROOT hangs up. Each histogram is fit at least twice before the plot is written to the TCanvas, and occasionally more. And 75 plots are successfully generated.

Perhaps there is a maximum number of warnings allowed.

Mike

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