2D histogram fitted with rooEllipse

Dear rooFitter,

I have some problems with my code and I hope you can help me…

I’d like to fit a 2D Chi2 distribution (it’s a 2D histogram and the distribution is an ellipse). To do that I tried many things and I have finally chosen rooEllipse but unlike to what I have think, I can’t find the solution.

My 2D histogram is named hChi2. First I have tried to import and plot the 2D histogram in rooEllipse with different technics:

  1. RooRealVar x(“x”,“x”,-0.5,60.5);
    RooRealVar y(“y”,“y”,-0.5,49.5);
    RooDataHist* roohChi2 = new RooDataHist(“roohChi2”,“hChi2 import”,RooArgSet(x,y), Import(*hChi2));

    RooPlot* frame = new RooPlot(-0.5,60.5,-0.5,49.5) ;

  2. RooAbsData* data;
    TH2* roohChi2 = x.createHistogram(“Chi2 dans roofit”, y,0,0,0,10000);
    data->fillHistogram(roohChi2, RooArgList(x,y));


  • with test 1) : The compilation is OK but I have problems in execution and an empty plot
    [#1] INFO:DataHandling – RooDataHist::adjustBinning(roohChi2): fit range of variable x expanded to nearest bin boundaries: [-0.5,60.5] --> [-0.5,60.5]
    [#1] INFO:DataHandling – RooDataHist::adjustBinning(roohChi2): fit range of variable y expanded to nearest bin boundaries: [-0.5,49.5] --> [-0.5,49.5]
    [#1] INFO:InputArguments – RooAbsData::plotOn(roohChi2) INFO: dataset has non-integer weights, auto-selecting SumW2 errors instead of Poisson errors
    [#0] ERROR:InputArguments – RooDataHist::roohChi2:plotOn: frame does not specify a plot variable

  • with test 2) : The compilation fails with error :
    error: initializing argument 6 of ‘TH2F* RooAbsRealLValue::createHistogram(const char*, const RooAbsRealLValue&, const char*, Double_t*, Double_t*, Int_t*) const’ [-fpermissive]
    TH2F *createHistogram(const char *name, const RooAbsRealLValue &yvar, const char *zAxisLabel=0,

For the frame I have also tested :

  1. RooPlot *frame = x.frame();

  2. RooPlot* yframe = y.frame(Bins(40),Title(" ")) ;
    roohChi2->plotOn(yframe) ;

Neither give good results…

After this 2D histogram import, I’d like to fit with rooEllipse. I plan to use :
RooEllipse contour(“contour”, “contour”, 50.0, 20.0, 0.01, 0.01, 0.85);
contour.fitTo(rooHisto) ;
contour.plotOn(frame) ;

I have also seen on the Internet :
RooEllipse *contour= new RooEllipse(“contour”,50.0, 20.0, 0.01, 0.01, 0.85);

Do you know the right solution?

I begin in ROOT and rooFit, if you have any idea I’ll take it !

Thank to read me :wink:


perhaps a good starting point is this tutorial: root.cern.ch/doc/master/fitCircle_8C.html
I would leave RooFit out of the equation.


Hi Danilo !

Thank for answering ! :slight_smile:

You’re absolutly right Roofit is useless here because I’d like to minimized my distribution
I tried to change my code with your example and :
homepages.physik.uni-muenchen.de … ontour.cxx

These two methods used TMinuit and TVirtualFitter respectively but none of them give something. I have for both of these methods an execution error (the same):

*** Break *** segmentation violation

There was a crash.
This is the entire stack trace of all threads:

#0 0x00007fe493e56b4c in __libc_waitpid (pid=3703, stat_loc=stat_loc
entry=0x7ffdf7ac4f40, options=options
entry=0) at …/sysdeps/unix/sysv/linux/waitpid.c:31
#1 0x00007fe493ddc2e2 in do_system (line=) at …/sysdeps/posix/system.c:148
#2 0x00007fe494b5be43 in TUnixSystem::StackTrace() () from /home/m/root/lib/libCore.so
#3 0x00007fe494b5e68c in TUnixSystem::DispatchSignals(ESignals) () from /home/m/root/lib/libCore.so
#5 0x00007fe4893794ff in TPad::PaintPolyLine(int, double*, double*, char const*) () from /home/m/root/lib/libGpad.so
#6 0x00007fe485a5b304 in ?? ()
#7 0x00007fe494e55670 in vtable for TString () from /home/m/root/lib/libCore.so
#8 0x0000000000000000 in ?? ()

The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.

#5 0x00007fe4893794ff in TPad::PaintPolyLine(int, double*, double*, char const*) () from /home/m/root/lib/libGpad.so
#6 0x00007fe485a5b304 in ?? ()
#7 0x00007fe494e55670 in vtable for TString () from /home/m/root/lib/libCore.so
#8 0x0000000000000000 in ?? ()

I searched on the Internet a mean to fix this error but I did not find anything…
I put my code in attachment, maybe it’s a stupid error :blush: .

my2dplot.root (63.9 KB)
my_test.C (4.85 KB)

I have tried your macro with ROOT 6 and ROOT 5.34.
It crashes with ROOT 6 but not with ROOT 5.34.
I will tell our fitting expert to have a look.

Hi Couet !

Thank a lot ! :slight_smile:
It’s a really strange behaviour…



I can reproduce the issue with 6.06 on lxplus.
The full stack with debugging symbols is the following:

#0  0x00007ffff62168d2 in TPad::PaintPolyLine(int, double*, double*, char const*) () from /afs/cern.ch/sw/lcg/app/releases/ROOT/6.06.04/x86_64-slc6-gcc49-opt/root/lib/libGpad.so
#1  0x0000000000401fca in fcn(int&, double*, double&, double*, int) () at my_test.C:54
#2  0x00007fffe6f17197 in TMinuit::Eval(int, double*, double&, double*, int) () from /afs/cern.ch/sw/lcg/app/releases/ROOT/6.06.04/x86_64-slc6-gcc49-opt/root/lib/libMinuit.so
#3  0x00007fffe6f184fe in TMinuit::mnamin() () from /afs/cern.ch/sw/lcg/app/releases/ROOT/6.06.04/x86_64-slc6-gcc49-opt/root/lib/libMinuit.so
#4  0x00007fffe6f1b90f in TMinuit::mnmigr() () from /afs/cern.ch/sw/lcg/app/releases/ROOT/6.06.04/x86_64-slc6-gcc49-opt/root/lib/libMinuit.so
#5  0x00007fffe6f2c9e1 in TMinuit::mnexcm(char const*, double*, int, int&) () from /afs/cern.ch/sw/lcg/app/releases/ROOT/6.06.04/x86_64-slc6-gcc49-opt/root/lib/libMinuit.so
#6  0x00007fffe6f37cbd in TFitter::ExecuteCommand(char const*, double*, int) () from /afs/cern.ch/sw/lcg/app/releases/ROOT/6.06.04/x86_64-slc6-gcc49-opt/root/lib/libMinuit.so
#7  0x00000000004022d2 in my_test(double) () at my_test.C:91
#8  0x00000000004025ab in main () at my_test.C:115

This seems related to a painting of a line which happens within the function to minimise (fcn).


The code is quite fragile.
If you remove the commented part of the macro it crashes in Eval instead in PaintPolyLine…
There is surely some memory overwriting …

Thanks both of you !

Danilo, I have the same issues… I tried to fix the problems but I don’t really find a solution…

Couet, you’re right my code is maybe quite fragile… this is my first code with TMinuit (and minmization in general) and it’s a little difficult :blush:


Lorenzo found the issue … you are casting a TCanvas to an histogram:

    h2 = (TH2F*)f->Get("c1");

:slight_smile: That is indeed fatal!

Attached a new version your macro. Note that I commented out the ellipse drawing because it has wrong coordinates and obscures completely the histogram.
my_test.C (3.09 KB)

Thanks !!! =D> =D> =D> =D> =D>

It’s fatal indeed !