RooFIt, the first steps

Dear rooters,

I tried to estimate the backgroung by a 2nd order Chebychev polynom (only as learning step)
I dont get usable result.
What I am doing wrong?

Thanx,
k.


Fit(const char* filename){
gROOT->Reset();
gSystem->Load(“libRooFit”);
// gSystem->Load(“libRooFitModels.so”);
using namespace RooFit;

TFile* file = new TFile(filename);

if(file){

  TH1D* h0 = (TH1D*) file->Get("h0");

  if(h0){
     RooRealVar x("x", "x", 0, 50000);
     x.setRange("Range1",20000, 40000);
     RooDataHist data("data", "data", x, h0);


     RooRealVar Par1("Par1", "Par1", -1e16, 1e16);
     RooRealVar Par2("Par2", "Par2", -100000, 100000);

     RooChebychev Cheby5("Cheby5", "Chebychev Bacground",x, RooArgList(Par1,  
                                                                                                                         Par2));
     Cheby5.fitTo(data, "", "" ,"Range1");
     Par1.Print();
  }

}
}
fileout.root (4.64 KB)

Hi,

I don’t see what you have concluded has gone wrong in the fit, based on the value of Par1. Note that the parameters of RooChebychev are defined such that they run between [-1,1] so any fit make will result in chebychev coefficients in that range. Making a plot is usually more instructive to see if the fit has converged or not, e.g.

RooPlot* frame = x.frame() ;
data.plotOn(frame) ;
Cheby5.plotOn(frame) ;
frame->Draw() ;

Having said that, I have recently discovered that RooChebychev has an outstanding issue with the correct calculation of normalization integrals over sub-ranges that might also affect you here. To work around that you can either use a regular polynomial class for the moment, e.g.

RooRealVar p1(“p1”, “p1”,-0.0003,-0.01,0.003) ;
RooRealVar p2(“p2”, “p2”,0,-1e-5,1e-5) ;
RooPolynomial Cheby5(“Cheby5”, “Chebychev Background”,x,RooArgList(p1,p2));

or set the correct fit range upfront when you import the TH1 and then do not specify
a range when fitting e.g.

RooRealVar x(“x”, “x”, 10000, 40000);
RooDataHist data(“data”, “data”, x, h0);

Cheby5.fitTo(data) ;

I will of course fix the RooChebychev class a.s.a.p.

Wouter

Thank you Wouter,

After setting the correct range of the parameters it works properly …

However I have a problem with the “Range” operation.
If I set a range on the x (x.setRange(“Range1”,20000, 40000):wink: than I would like to fit only on this range (Cheby5.fitTo(data, “”, “” ,“Range1”):wink: I get a very bad fit, while with defining the x on the same range instead of the usage of the SetRange (RooRealVar x(“x”, “x”, 20000, 40000):wink: the fit is perfect …
My conclusion is the SetRange has effect on the visualisation, but not on the fit

Is it right?

Thanx,
k.


Fit(const char* filename){
   gROOT->Reset();
   gSystem->Load("libRooFit");
   // gSystem->Load("libRooFitModels.so");
   using namespace RooFit;

   TFile* file = new TFile(filename);

   if(file){

      TH1D* h0 = (TH1D*) file->Get("h0");

      if(h0){
         RooRealVar x("x", "x", 20000, 40000);
//         RooRealVar x("x", "x", 0, 50000);
//          x.setRange("Range1",20000, 40000);
         RooDataHist data("data", "data", x, h0);


         RooRealVar Par1("Par1", "Par1", .5,  -1, 1);
         RooRealVar Par2("Par2", "Par2", 0.2, -1, 1);
         RooRealVar Par3("Par3", "Par3", .5,  -1, 1);
         RooRealVar Par4("Par4", "Par4", 0.2, -1, 1);
         RooRealVar Par5("Par5", "Par5", 0.2, -1, 1);
         RooRealVar Par6("Par6", "Par6", 0.2, -1, 1);

         RooChebychev Cheby5("Cheby5", "Chebychev Bacground",x, RooArgList(Par1,
                                                                           Par2,
                                                                           Par3,
                                                                           Par4,
                                                                           Par5,
                                                                           Par6));
//         Cheby5.fitTo(data, "", "" ,"");
         Cheby5.fitTo(data, "", "" ,"Range1");
         Par1.Print();
         Par2.Print();
         Par3.Print();
         Par4.Print();

         RooPlot* frame = x.frame() ;
         data.plotOn(frame) ;
         Cheby5.plotOn(frame) ;
         frame->Draw() ;
      }
   }
}

fit2.ps (43.8 KB)
fit1.ps (61 KB)

Hi,

There seems to be some residual problem and I am investigating this. I will get back to
you by the end of the week.

Wouter