# RooMinuit and RooMinimizer difference

Dear experts,
I don’t know if this is the right place for this post but I’ll explain my problem shortly.

I’m running several ToyMC of a background (parametrized with Exponentials “E" or 4th degree Bernstein polynomial “B”) + a signal pdf (for simplicity a gaussian function) and fitting them with a bkg+signal pdf of the same kind.

The fitting is achieved by means of RooChi2Var and RooMinuit, calling migrad, hesse and minos in succession.

``````RooChi2Var *Chi2=new RooChi2Var(“Chi2”,”Chi2”,*fitting_pdf,data_simulation,Extended());
RooMinuit *minuit=new RooMinuit(*Chi2);
int result_hesse=minuit->hesse();
int result_minos=minuit->minos();``````

When I run the simulation Minos status always says PROBLEMS and I obtain

result_hesse=0
result_minos=6 (what does 6 mean?)

The problem disappear when I use RooMinimizer instead of RooMinuit.

``````RooChi2Var *Chi2=new RooChi2Var(“Chi2”,”Chi2”,*fitting_pdf,data_simulation,Extended());
RooMinimizer *minuit=new RooMinimizer(*Chi2);
int result_hesse=minuit->hesse();
int result_minos=minuit->minos();``````

Obtaining a Minos status which says SUCCESSFUL and

result_hesse=0
result_minos=0

Am I doing something wrong?
Can anyone tell me why this is happening or, in other words, what are the differences between RooMinuit and RooMinimizer that produce this phenomenon?
And finally, if I switch from RooMinuit to RooMinimizer, how my results (errors estimate in particular) will be affected?

Cheers,
Carlo

1 Like

HI,

In principle both of them should give the same result. It could be the difference is due to some defaults initial step sizes or tolerance of the minimisation. If you have a running code reproducing the problem I could investigate.
Anyway you should look at the result with the lowest minimum function value, this is the one to choose. You can also try to use with the RooMinimizer Minuit2.

Best Regards

Lorenzo

Dear Lorenzo,
thanks for your reply. I’ll put in attachment the files. Thanks for you help!
I have a question actually: is there a way to use “Minuit2” as algorithm in RooMinuit? In RooMinimizer is very easy but I couldn’t find a way with RooMinuit.

Best regards,
Carlo
generateSimulation.h (2.05 KB)
RooMinuit_RooMinimizer.cpp (3.3 KB)

Hi,
I also would like to use Minuit2 with RooMinuit,
but I can’t figure out how to do it.

Many thanks,

• Mauro.

In principle you should not use RooMinuit. Just use RooMinimizer, where you can switch to the minimisation algorithm you prefer (TMinuit, Minuit2, GSL minimisation algorithms and what-ever else is supported by ROOT.

If you still observe a difference in the fit switching from RooMinuit to RooMinimizer, still using TMinuit, please let me know

Best Regards

Lorenzo

Many thanks Lorenzo.
How would you do it with RooMinimizer ?

I’m trying with:

RooAbsReal* NLL;
NLL = (*TotalPDF)->createNLL(*dataSet,Extended(true),ExternalConstraints(*vecConstr));

``````      RooMinimizer RooMin(*NLL);
RooMin.setMinimizerType("Minuit2");
RooPlot* myFrameNLL = RooMin.contour(*GetVar(*TotalPDF,"AfbS"),*GetVar(*TotalPDF,"FlS"),1.0,2.0,3.0);
``````

It crashes at RooMin.contour.

• Mauro.

HI,

The code seems fine, it should not crash. I have just tried with a small example and it does not crash for me, using latest ROOT 5.34.
There is a problem in drawing the 2 and 3-sigma’s contours, see sft.its.cern.ch/jira/browse/ROOT-7290
but this is now fixed.

Lorenzo

Hi Lorenzo,
many thanks for checking this.

I can tell you that this works for me:

RooAbsReal* NLL;
NLL = (*TotalPDF)->createNLL(*dataSet,Extended(true),ExternalConstraints(*vecConstr));

RooMinuit RooMin(NLL);
// RooMin.setMinimizerType(“Minuit2”);
RooPlot
myFrameNLL = RooMin.contour(*GetVar(*TotalPDF,“AfbS”),*GetVar(*TotalPDF,“FlS”),1.0,2.0,3.0);

Which is exactly the same as before but instead of RooMinimizer, I use RooMinuit (and of course I remove RooMin.setMinimizerType).

Do you have an idea on what is going wrong with RooMinimizer ?
Do you have a suggestion on what to look for as culprit ?
Many thanks,

• Mauro.

Hi,
I don’t understand why you are getting a crash. Please attach your workspace, including the dataset, so I can check it

Thanks

Lorenzo

Hi Lorenzo,
I’ve saved the status of the program with the lines:

RooWorkspace w(“w”);
w.import(**TotalPDF);
w.importClassCode();
w.import(*dataSet);
w.writeToFile(“Dinardo.root”);

Right after those lines in my code I have:

RooAbsReal* NLL = (TotalPDF)->createNLL(dataSet,Extended(true));
RooMinimizer RooMin(NLL);
RooMin.setMinimizerType(“Minuit2”);
RooPlot
myFrameNLL = RooMin.contour(
((RooRealVar
)(TotalPDF)->getVariables()->find(“FlS”)),((RooRealVar*)(*TotalPDF)->getVariables()->find(“AfbS”)),1.0,2.0,3.0);

As we said, the code crashes at “RooMin.contour” with the error:

*** Break *** segmentation violation
Generating stack trace…
0x0000000104a40f97 in IterativeMass2AnglesFitq2Bins(RooDataSet*, bool, double, double, double, RooRealVar*, RooRealVar*, RooRealVar*, int, unsigned int, std::__1::vector<TH1D*, std::__1::allocator<TH1D*> >*, std::__1::vect
0x0000000104a4c185 in main (in ExtractYield) + 26485
0x00007fff949bb5c9 in start (in libdyld.dylib) + 1
ExtractYield(67927,0x7fff796de300) malloc: *** error for object 0x7fa0fc981410: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6

Will you be able with these information to debug the problem ?
Many thanks,

Unfortunately I cannot read your workspace because it contains a pdf based on a functor , a RooFunctorPdfBinding, which cannot be stored.
I would need then the full code creating the pdf in this case to run your program.

However, why you say the code crashes in contour. I see the crash in IterativeMass2AnglesFitq2Bins.
It looks like there is a double delete somewhere in your code.

Ciao
Lorenzo

Hi Lorenzo,
I might have figured out what’s the problem:

digging into the RooMinimizer code it seems to me that BEFORE performing the "RooMin.contour"
operation I MUST run the fitter. Which I do, but not with RooMinimizer, with “RooFit” instead.

Which means with the line:
fitResult = (*TotalPDF)->fitTo(*dataSet,Extended(true),Save(true),Minos(true),Minimizer(“Minui2”));

Therefore the sequence that I’m currently using is pretty much this one:

fitResult = (*TotalPDF)->fitTo(dataSet,Extended(true),Save(true),Minos(true),Minimizer(“Minui2”));

RooAbsReal
NLL = (*TotalPDF)->createNLL(*dataSet,Extended(true));
RooMinimizer RooMin(NLL);
RooMin.setMinimizerType(“Minuit2”);
RooPlot
myFrameNLL = RooMin.contour(*GetVar(*TotalPDF,“AfbS”),*GetVar(*TotalPDF,“FlS”),1.0,2.0,3.0);
and the crash occurs at “RooMin.contour”.

Do you think this is a reasonable diagnosis ?
If yes, do you have suggestions on how to solve it,
but keep using “fitTo” member function ?

Many thanks.

• Mauro.

Hi Mauro,

If you create a RooMinimizer, you can use it directly. So you don;t really need fitTO, but you can do

RooMin.minimize(“Minuit2”)

I woould add those lines also if you are using fitTo, to be sure you have a valid minimum before running the contour. If you are already at the minimum, the overhead of re-doing a minimisation is very small.

Lorenzo

A check has been added inside RooMinimizer::contour that a minimization (Migrad() ) is run before as it is currently done in RooMinimizer::minos.

Running fitTo before is not sufficient because a different RooMinimizer instance is used.

Lorenzo

Ciao Lorenzo,
due to instabilities in my fit, whose final result depend upon
the fit starting values, I really need to make the contour from
the pdf that is obtained from the fitTo step.

Is there a way, or a trick, that I can use in order to use the same
pdf ?

It’s really important.
Many thanks.

• Mauro.

I guess you mean nll and not pdf.
In this case don’t use fitTo, but directly createNll. You have the same options

Lorenzo