Fit a contour of TH2F with ellipse

Hi,

I have a TH2F (like the one on the picture) and I need to fit the elliptical part with an ellipse. I tried to make a contour around it (second plot) using a list of one contour, but for some reason the “CONT LIST” draw option doesn’t work and I cannot retrieve the contour in a graph to fit it (I used “cont3 same” for drawing the contour). When I try the “CONT LIST” I don’t get any errors but the canvas is blank.

Could someone please tell me what would be the easiest way (procedure) to fit the circular part of this TH2F to an ellipse?

Thanks a lot!



If the ellipse were not just the border, you could try a bivariate normal gaus fit.

See sft.its.cern.ch/jira/browse/ROOT-8022

For only the countour, look for ellipse equations and type it eg. in the fit panel.

The LIST option used with the option CONT build a list of contours. As graphs. To retrieve them you can proceed like in this example: root.cern.ch/doc/master/ContourList_8C.html

If you want to fit an ellipse to a set of data points from a TGraph, see “${ROOTSYS}/tutorials/fit/fitEllipseTGraphRMM.cxx” and “${ROOTSYS}/tutorials/fit/fitEllipseTGraphDLSF.cxx”.

[quote=“couet”][quote]
When I try the “CONT LIST” I don’t get any errors but the canvas is blank.
[/quote]

The LIST option used with the option CONT build a list of contours. As graphs. To retrieve them you can proceed like in this example: root.cern.ch/doc/master/ContourList_8C.html[/quote]

Hi,

thanks, I have seen this example and actually tried to retrieve the TGraphs. My concern is that I cannot even obtain the number of contours (which is 1 in my case), by implementing the piece of code below. I get TotalConts = 0.

TObjArray conts = (TObjArray)gROOT->GetListOfSpecials()->FindObject(“contours”);
TList* contLevel = NULL;
TGraph* curv = NULL;
TGraph* gc = NULL;

Int_t nGraphs = 0;
Int_t TotalConts = 0;

if (conts == NULL){
printf("*** No Contours Were Extracted!\n");
TotalConts = 0;
return;
} else {
TotalConts = conts->GetSize();
}

printf(“TotalConts = %d\n”, TotalConts);

We would need a running example to understand the problem you have with the LIST option.

I removed the “return” and I get the value 1 for the TotalConts . Trying to retrieve the Graph now. Thanks a lot!

Thanks a lot for these! I want to try the one uses the “ROOT::Math::Minimizer” interface, but when I try to execute it (as it is, no modifications) i get an error: Error: Can’t call Minimizer::SetVariableLimits(0,xmin,xmax) in current scope EllipseTGraphRMM.cxx:186:
Possible candidates are…
Error: class,struct,union or type Minimizer not defined EllipseTGraphRMM.cxx:186:

Would you know why?

Thanks!

No idea what it can be.
I have just checked ROOT 5.34/34 and 6.06/00 and in both cases both macros run fine.

[quote=“Pepe Le Pew”]No idea what it can be.
I have just checked ROOT 5.34/34 and 6.06/00 and in both cases both macros run fine.[/quote]

Hmm, I have a 5.34/00 version from 2012. Looks like it’s time for update!

Thanks!

If you compile it yourself, take the head of the “v5-34-00-patches” branch.

Works now! Thanks!