Difference: SWGuideRooFitExamples (3 vs. 4)

Revision 42009-05-27 - LucaLista

Line: 1 to 1
<!-- PDFSTART -->

RooFit Examples in CMSSW

Complete: 2
Complete: 3


This page is intended to provide examples with RooFit that are usable within CMSSW.

The presented examples can be installed and compiled under CMSSW using the following recipe:

cmsrel CMSSW_3_1_0_pre7
cd CMSSW_3_1_0_pre7/src
addpkg PhysicsTools/CandExamples V02-00-00
cd PhysicsTools/CandExamples
scram b 
$CMSSW_BASE/test/slc4_ia32_gcc345/<name of the application<

Building RooFit applications in CMSSW

Before using the following examples, you should first understand how to build
Line: 109 to 121

Complete example


Multi-dimensional fits

RooFit does not distinguish, conceptually, multi-dimensional PDFs from one-dimensional ones. The only difference is that the support for plotting via RooPlot is limited to a single dimension, and in the case of multi-dimensional PDFs works with one-dimensional projectons.

The following example shows how to define a two-dimensional PDF using RooProdPdf as the product of independend one-dimensional PDFs, and how to project PDFs and data sets to a single dimension using RooPlot, or as two-dimensional standard ROOT contour plots:

  RooRealVar x("x", "x", -10, 10);
  RooRealVar y("y", "y", -10, 10);
  RooRealVar mux("mux", "average-x'", 0, -1, 1);
  RooRealVar sigmax("sigmax", "sigma-x'", 0.5, 0, 5);
  RooGaussian gaussx("gaussx","gaussian PDF x'", x, mux, sigmax);
  RooRealVar muy("muy", "average-y'", 0, -1, 1);
  RooRealVar sigmay("sigmay", "sigma-y'", 1.5, 0, 5);
  RooGaussian gaussy("gaussy","gaussian PDF y'", y, muy, sigmay);
  RooProdPdf gaussxy("gaussxy", "gaussxy", RooArgSet(gaussx, gaussy));

  RooRealVar lambdax("lambdax", "log-slope x", -0.1, -5., 0.);
  RooExponential expox("expox", "exponential PDF x", x, lambdax);
  RooRealVar lambday("lambday", "log-slope y", -0.1, -5., 0.);
  RooExponential expoy("expoy", "exponential PDF y", y, lambday);
  RooProdPdf expoxy("expoxy", "expoxy", RooArgSet(expox, expoy));

  RooRealVar s("s", "signal yield", 50, 0, 10000);
  RooRealVar b("b", "background yield", 200, 0, 10000);

  RooAddPdf sum("sum", "gaussian plus exponential PDF",
                RooArgList(gaussxy, expoxy), RooArgList(s, b));
  RooDataSet * data = sum.generate(RooArgSet(x,y), 250);
  RooFitResult* result = sum.fitTo(*data, RooFit::Extended(), RooFit::Minos(), RooFit::Save());
  assert(result != 0);

  RooPlot * xFrame = x.frame() ;
  data->plotOn(xFrame) ;
  sum.plotOn(xFrame) ;
  sum.plotOn(xFrame, RooFit::Components(expoxy), RooFit::LineStyle(kDashed)) ;

  RooPlot * yFrame = y.frame() ;
  data->plotOn(yFrame) ;
  sum.plotOn(yFrame) ;
  sum.plotOn(yFrame, RooFit::Components(expoxy), RooFit::LineStyle(kDashed)) ;

  TCanvas c;
  TH2 * surf = dynamic_cast<TH2*>(sum.createHistogram("surf", x,
                                                      RooFit::YVar(y, RooFit::Binning(100))));
  TH2 * surfData = data->createHistogram(x, y, 100, 100, "", "surfData");

Complete example


More examples

You can find more examples in the following pages:
This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback