m_tag = some RooCategory with 2 states (+/-1)
RooPlot*m_t_frame_asym = m_t->frame(0.,15.);
RooDataSet* m_data = some data where m_tag is filled properly;
m_data->plotOn(m_t_frame_asym,RooFit::Asymmetry(*m_tag)
,RooFit::Name("totdata"));
RooAbsPdf m_total_pdf = somepdf;
m_total_pdf->plotOn(m_t_frame_asym,
RooFit::Asymmetry(*m_tag)
,RooFit::Name("totpdf"));
This is plotted very nicely.
Now I want to get the chi2, so I use
double chi2 = m_t_frame_asym->chiSquare("totpdf",
"totdata");
But at this point, the code fails to find “totpdf”, as the Name property is not passed to plotAsymOn. I guess this is a bug somehow.
But anyway, I used the final plot and got the curve’s name by right click,
double chi2 = m_t_frame_asym->chiSquare("curve_Total pdfAsymmetry[tag]",
"totdata");
But there, chi2 = nan
Where did I make a mistake ?
What version of ROOT/RooFit are you using (this code handling this was recently changed)? Also. can attach a ROOT file with your RooPlot? Then I can have a look
at the NaN issue.
I found something in the RooCurve::chiSquare.
In case of an asymmetry plot, it is very convenient to use a RooBinning, to have variable bin sizes. In the method above, which is called by RooPlot::chiSquare, the bin size is not taken into account. The bin width is taken as follows :
I would say this is not the best in case of variable bin size…
I’d rather use something like
[code]Double_t exl,exh;
for (i=0 ; i<np ; i++) {
// Retrieve histogram contents
((RooHist&)hist).GetPoint(i,x,y) ;
// Check if point is in range of curve
if (x<xstart || x>xstop) continue ;
nbin++ ;
eyl = hist.GetEYlow()[i] ;
eyh = hist.GetEYhigh()[i] ;
exl = hist.GetEXlow()[i] ;
exh = hist.GetEXhigh()[i] ;
// Integrate function over this bin
Double_t avg = average(x-exl,x+exh) ;
// Add pull^2 to chisq
if (y!=0) {
Double_t pull = (y>avg) ? ((y-avg)/eyl) : ((y-avg)/eyh) ;
chisq += pull*pull ;
}
}
[/code]
The problem seems to come from the fact that some bins have eyh = nan and/or eyl = nan. So pull = nan. Is there a way to check that ?
What version of ROOT/RooFit are you using (this code handling this was recently changed)? Also. can attach a ROOT file with your RooPlot? Then I can have a look
at the NaN issue.