TTree to define model roofit

Hi all,
Is is possible to use the contents of a TTree to define a PDF in Roofit? I have an experimental data set accessed (as per the manual):

TFile *f_exp = TFile::Open(expFileName);
TTree expTree=(TTree)f_exp->Get(“myTree”);
RooRealVar x(“x”,“x”,-10,10);
RooDataSet ds(“ds”,“ds”,RooArgSet(x),Import(*expTree));

Is there an analogous way of defining a model? My model is too complex for a functional representation–it needs to come from a simulation program (geant). Maybe some option like the code like below exists?

TFile *f_sim = TFile::Open(simFileName);
TTree sig1=(TTree)f_sim->Get(“sig1”);
RooAbsPdf xs(“xs”,“xs”,x,Import(*sig1));

TTree bkg1=(TTree)f_sim->Get(“bkg1”);
RooAbsPdf xb(“xb”,“xb”,x,Import(*bkg1));

The parameter extraction method is extended maximum likelihood–there are no internal parameters to the model, only relative rates.


You cannot use directly the TTRee, but you can use either a RooHistPdf obtained by binning the data or a kernel pdf, like RooKeysPdf obtained using the vector of all data points (e.g. from a RooDataSet obtained from the TTree) which uses kernel density estimation

Best Regards


Many thanks!

I have a follow-up question. I will be using a multi-dimensional PDF to compare to experiment. If I import multiple variables from the experiment tree then can I compare this directly to a multi-dimensional PDF? In other words, would the code below work?

  RooDataSet ds("ds","ds",RooArgSet(x,y,z),Import(*expTree));

// Create signal pdf gauss(x)*gauss(y)*gauss(z) 
  RooGaussian gx("gx","gx",x,RooConst(0),RooConst(1)) ;
  RooGaussian gy("gy","gy",y,RooConst(0),RooConst(1)) ;
  RooGaussian gz("gz","gz",z,RooConst(0),RooConst(1)) ;
  RooProdPdf sig("sig","sig",RooArgSet(gx,gy,gz)) ;

  // Create background pdf poly(x)*poly(y)*poly(z) 
  RooPolynomial px("px","px",x,RooArgSet(RooConst(-0.1),RooConst(0.004))) ;
  RooPolynomial py("py","py",y,RooArgSet(RooConst(0.1),RooConst(-0.004))) ;
  RooPolynomial pz("pz","pz",z) ;
  RooProdPdf bkg("bkg","bkg",RooArgSet(px,py,pz)) ;

  // Create composite pdf sig+bkg
  RooRealVar fsig("fsig","signal fraction",0.1,0.,1.) ;
  RooAddPdf model("model","model",RooArgList(sig,bkg),fsig) ;
  model.fitTo(ds,Save()) ;

Or must I explicitly construct a multi-dimensional data set for experiment as well as model?

Yes, this should work !
Best Regards