RooDataHist chi2fit problem

Hello,

I’ve been trying to fit a RooDataHist created from a TH1F. The problem is that RooFit tells me that bin 0 has zero error… which is weird since when I print the RooDataHist I don’t get the same thing.

Here’s some code to illustrate what I mean:

    gSystem->Load("libRooFit") ; 

Setting up the histogram:

    TH1* h= (TH1*)DiLcMass_pKpi_pKpi->Clone("hnew");
    RooMsgService::instance().Print();
    // Declare variables x,mean,sigma with associated name, title, initial value and allowed range
    Double_t xmin=h->GetXaxis()->GetXmin();
    Double_t xmax=h->GetXaxis()->GetXmax();
    Double_t delta;
    delta=.1*(xmax-xmin);
    cout<<"The histogram ranges from ["<<xmin<<","<<xmax<<"]\n";
    RooRealVar x("x","x",xmin+delta,xmax-delta);
    // Create a binned dataset that imports contents of TH1 and associates its contents to observable 'x'
    RooDataHist dh("dh","dh",RooArgSet(x),Import(*DiLcMass_pKpi_pKpi)) ;

Which prints:

Printing the RooDataHist:

for (int i=0;i<dh.numEntries();i++)
    {
        dh.get(i);
        dh.weightError(RooAbsData::SumW2);
        cout<<"Bin "<<i<<" x="<<dh.get(i)->getRealValue("x")<<" Weight="<<dh.weight()<<" Weight Error= "<<dh.weightError(RooAbsData::SumW2)<<endl;
    }

Which prints:

The original histogram prints (in the same range):

Then I declare the gaussian:

    RooRealVar mean("mean","mean of gaussian",3,0,5) ;
    RooRealVar sigma("sigma","width of gaussian",1,0,2) ;
    // Build gaussian p.d.f in terms of x,mean and sigma
    RooGaussian gauss("gauss","gaussian PDF",x,mean,sigma) ;

Then I fit (That’s where the fun begins):

    RooChi2Var chi2("chi2","chi2",gauss,dh) ;
    RooMinuit m2(chi2) ;
    m2.migrad() ;
    m2.hesse() ;

And here’s the output:

gauss.chi2FitTo(dh) has the same problem.

Does anyone know what I’m doing wrong?

Hi,
RooChi2Var uses the expected error , i.e. squre root of the pdf value in the bin. It seems you have a pdf which evaluates to zero and this gives the problem. Try to avoid that the sigma of your gaussian gets too small

Lorenzo