I am getting this fit when I fit the combined model to the data.

this fit looks good to me but when I print the chi square value it always prints -1.

can you please correct my code?

roomodel.cpp (1.7 KB)

I am getting this fit when I fit the combined model to the data.

this fit looks good to me but when I print the chi square value it always prints -1.

can you please correct my code?

roomodel.cpp (1.7 KB)

Hello,

How did you compute the chisquare ? Using `RooPlot::chiSquare`

?

See also How exactly does RooPlot::chisquare() compute the result? - #4 by Xuli

Lorenzo

Thanks for your suggestion, I just corrected my code a bit, and it gives Chi Sq = 142.046.

I did not use `RooPlot::chiSquare`

I just used

double chiSquare = frame->chiSquare()

One more thing, that confuses me is that when I write

double chiSquare = frame->chiSquare(any integer)

it gives me little different ChiSq value.

What is the significance of this argument??

@moneta also If i increase the no. of bins to 10000 .

I get ChiSq = 23.18 , but my fit looks like this-

is there anything wrong in this?

Thanks.

Hi,

yes, you are using `RooPlot::chiSquare`

(see the ROOT: RooPlot Class Reference), by calling `frame->chiSquare, since `

frame` is a RooPlot object instance.

The function returns the reduced chiSquare (i.e. chisquare divided by the number of bins). If it is after a fit you should provide to the function the number of first parameters.

In addition, when you are not passing a curve name and a data name, `RooPlot::chiSquare`

will compute the chi-square for the last curve you have plotted, in your case I think is the `sig3`

. You should then provide the name of the data hist and of the curve. For doing this just ad this code to find these names:

```
for (int i = 0; i < frame->numItems(); i++) {
std::cout << "component " << frame->nameOf(i) << " is a " << frame->getObject(i)->IsA()->GetName() << std::endl;
}
```

and then call the correct one in `frame->chiSquare`

, probably it should be: the data are the first (index 0) and the full pdf is second (with index 1) since this is the order how you have plotted them.

```
frame->chiSquare((frame->nameOf(1),frame->nameOf(0), numberOfFitParamters)
```

The number of fit parameters seems to be 6, looking at your code.

If you increase the number of bins, since the function is returning the reduce chi-square it should still give a results around 1 if the fit is good.

Best,

Lorenzo

Dear @moneta

this is what it prints if I add your code and when I write

`frame->chiSquare((frame->model_Norm[X],frame->h_dh, numberOfFitParamters)`

it says these items are not in the RooPlot.

I am confused What exactly I should add to my code in order to get the chiSq value of **model**(not sig1 sig 2 sig3) fitted to the histogram.

I am sorry for the inconvenience

Im new to all these.

roomodel.cpp (2.1 KB)

Dear @Subhu18,

Let me start with a disclaimer: I am clueless about RooFit but …

Fitting two Gaussians at the same position but different widths is a very difficult task for any fitter; and it shows in your correlation matrix with off-diagonal elements close to 1 and even one negative diagonal element.

The chi-square of exactly -1 means probably that the underlying optimization algorithm bailed out because some matrix was not positive definite.

How would one distinguish between 2 Gaussians (allowing a fatter tail) and a Hyper-Gaussian shape (see for description )

-Eddy

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