2D histogram fit

Dear Rooters,

I’d like to fit the 2D histogram in attachment. I tried to fit it with a 2D gaussian like show in the example fit2dHist.C : root.cern.ch/doc/master/fit2dHist_8C.html.

This example was adapted to my situation (see the code in attachment). It works ( :smiley: ) but ( :frowning: ) I don’t achieve to a good fit (I change all parameters several times).

Maybe I should not use a 2D gaussian fit for this situation. I think of not being so far from the good fit, I hope though :cry:
If you have any idea about this fit-fail I’ll take it…

2DFitOriginal.C (3.84 KB)
c1.pdf (83.8 KB)

I cannot run you macro:

Processing fit2dHist.C...
Error in <TFile::TFile>: file my2dplot.root does not exist

Hello !

I’m sorry I have forgotten to join the “.root” file… Find it in attachment

my2dplot.root (196 KB)

Yes I get:

Processing fit2dHist.C...
Warning in <Fit>: Abnormal termination of minimization.
 FCN=16080 FROM MIGRAD    STATUS=FAILED        404 CALLS         405 TOTAL
                     EDM=2.70496    STRATEGY= 1  ERROR MATRIX UNCERTAINTY 100.0 per cent
  EXT PARAMETER                APPROXIMATE        STEP         FIRST   
  NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE 
   1  p0           1.00000e+02   1.41421e+00  -0.00000e+00   0.00000e+00
   2  p1           1.00000e+02   1.12943e+02   0.00000e+00  -1.45620e-02
   3  p2           6.00000e+00   2.13372e+06  -0.00000e+00   2.44806e-12
   4  p3           4.00000e+01   1.41421e+00  -0.00000e+00   0.00000e+00
   5  p4           1.00000e+01   1.41421e+00  -0.00000e+00   0.00000e+00
   6  p5           5.50000e+01   7.53705e+06  -0.00000e+00   6.31644e-12

I let fit experts have a look…


The code is fine, the problem is your histogram. It looks to be filled in a strange way, like there is some background offset value, but only in some part of the histogram.
It is difficult in this case to simply fit with just a 2d gaussian


Hello !

Thanks for your answers !

Ok I understand… But moneta, I don’t understand what do you mean by “like there is some background offset value, but only in some part of the histogram” :blush: . Actually this histogram is fill with chi square results.
I’d like to fit this histogram to have the values of the minimum on the X and Y axis.

Thanks !

OK, but what the histogram represents ? It does not seems to me to be just a 2d gaussian, for this reason the fit fails. You should use a function which is representative of the histogram


Hello ! :slight_smile:

This histogram is a chi square test between a reference cross section and other cross sections computed for differents mass and width of the W boson.
To fill it, I computed the cross section for fixed values of (M, width) and I compared it with a reference cross section (obtained with PDG value of M and width). On the X axis is represented the mass variations and on Y axis the width variations. By minimization I’d like to access at the minimum value on X and Y axis (without projections in order to preserve the correlation).
I haven’t a function which represents this histogram or I don’t know how to find it.

It’s not necessarily a 2D-gaussian, it was just an idea because I don’t find how to fit that…

Thanks :slight_smile:


What would you like to get exactly from the histogram ? If you are interested only in finding the minimum, then you can just use the function GetMinimumBin


Hello :slight_smile:

I’d like to get the coordinates of the minimum and the 1-sigma uncertainty on this values. I think the fit is mandatory in this case, isn’t it?

Thanks for help !



A fit is not mandatory. You can just find the minimum and have also a rough estimate of the error (e.g. standard deviation/sqrt(n) )


Hi Lorenzo,

Thanks for answering :slight_smile:

Find the minimum and estimate the errors is equal to project on X and Y axis, isn’t it?


No projecting in something else. The minimum x-value of the X projection of the histogram can be different than the one non projected