Using Contour() to make contour plot with ROOT::Fit::FitResult

I’m performing a combined fit of two histograms based on the root example ROOT: tutorials/fit/combinedFit.C File Reference.

I’m able to get the correlation matrix between fit parameters via ROOT::Fit::FitResult result; and result.GetCorrelationMatrix(mtrx);

But I can’t figure how to make a contour plot between pairs of parameters, via something like result.Contour(1,2,100).

Thanks, Tim.

I think @moneta can help, but did you have a look athe ROOT: ROOT::Fit::FitResult Class Reference ?

Hi bellenot,
I did look at ROOT: ROOT::Fit::FitResult Class Reference and saw the Contour() method. But when it tried to use the method it didnt seem to recognize it.
For example
root -l
root [0] ROOT::Fit::FitResult result;

root [1] result.Chi2() // if I type result.Chi and tab it completes to Chi2()

root [2] result.Contour() // if I type Cont it soesn;t complete to Contour( args )

Best, Tim.

Here is what I get:

root [0] ROOT::Fit::FitResult result;
root [1] result.
Chi2
Contour
Correlation
CovMatri
CovMatrixStatus
Edm
Error
Errors
FillResult
FitResult
FittedBinData
FittedFunction
GetConfidenceIntervals
GetErrors
GetParameterName
GetParams
GlobalCC
HasMinosError
Index
IsEmpty
IsParameterBound
IsParameterFixed
IsValid
LowerError
MinFcnValue
MinimizerType
NCalls
NFreeParameters
NPar
NTotalParameters
Ndf
NormalizeErrors
NormalizedErrors
ParError
ParName
Parameter
ParameterBounds
Parameters
Print
PrintCovMatrix
Prob
Scan
SetMinosError
Status
Update
UpperError
Value
operator=
~FitResult
root [1] result.Co
Contour
Correlation
CovMatrix
CovMatrixStatus
root [1] result.Contour(
bool Contour(unsigned int ipar, unsigned int jpar, unsigned int& npoints, double* pntsx, double* pntsy, double confLevel = 0.68300000000000005)
root [1] result.Contour(

Hi,
You have the pass the right parameters to the Contour method.
It is also more convenient to use the method re-implemented in TFitResult that uses directly a TGraph. Here is an example:

 auto h1 = new TH1D("h1","h1",100,-3,3);
   h1->FillRandom("gaus");
   auto result = h1->Fit("gaus","S");
   TGraph * gr = new TGraph(50);
  // make contour of parameter 2 (sigma) vs 1 (mean)
   result->Contour(1,2,gr);
   gr->Draw("AL");

Hi bellenot,

That’s interesting i got

[gorringe@muon Analysis]$ root -l
root [0] ROOT::Fit::FitResult result;
root [1] result.Co

Correlation
CovMatrix
CovMatrixStatus

i.e. no Contour. i tried it on root v6.22/00 and v6.06/06.

Best, Tim.

Hi Lorenzo,

Thanks for suggestion. I tried it but got the following error
when compiling

root [0] .L timedistribution.C
In file included from input_line_8:1:
/tmp_mnt/home72/home48/phy/gorringe/Experiments/pienu/Analysis/timedistribution.C:866:11: error: no member named ‘Contour’ in
‘ROOT::Fit::FitResult’
result.Contour(1,2,gr);


The previous line in my code

result.GetCorrelationMatrix(mat);

compiles / works fine,

Best, Tim.

Which version of ROOT? Which OS? Which compiler?

I tried it with

root v6.06 on CentOS Linux release 7.9.2009 w/ gcc.x86_64 4.8.5-44.el7 and gcc-c++.x86_64 4.8.5-44.el7

root v6.22 on MAC OS X 10.15.7 w/ clang 12.0.0

Best, Tim.

So 6.06 doesn’t have it, but I think 6.22 should have it (see ROOT: ROOT::Fit::FitResult Class Reference).

thanks so much! 6.22 and getting the arguments of Contour correct did the trick,
Best, Tim

1 Like

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