Physics Analysis Tools: CMS.RooFit at CMS

Complete: 1

Introduction to RooFit

RooFit is a toolkit integrated with ROOT that performs different kinds of binned and un-binned fits and Toy Monte Carlo generations based on user-defined models of Probability Density Functions (PDF).

Documentation about RooFit can be found in:

The following section contains documentation and examples of how to use RooFit in CMSSW.

Using RooFit in CMSSW

RooFit Tips, Tricks, and Quirks

RooFit is a very powerful tool, and there are usually three solutions to a given problem. This section will outline some tips and tricks to may RooFitting a pleasurable and fun experience for everyone.

Reading and Writing RooFit

Saving RooFit objects is fairly easy to do, and uses the fairly standard syntax:
TFile f("myOutputFile.root","RECREATE");
RooRealVar x("x","myVar x",0,1,"myUnit");
RooDataSet MyData("MyData" "A toy dataset",RooArgSet(x));
RooDataSet.Write();
f.Write();
f.Close();
This was simple enough, but retrieving the dataset from the resulting rootfile is not obvious:
TFile f("myOutputFile.root");
f.ls();
This will give a listing of the available TKeys in the file. Then you need to do something like this:
RooDataSet* myData = (RooDataSet*) f.FindObject("dataname");
If this doesn't work (ie myData==NULL) then try:
RooDataSet* myData = (RooDataSet*) f.FindAnyObject("dataname");
Where dataname comes from the TKeys listing from f.ls() -- DavidBjergaard - 28 May 2009

Booking a standard Histogram from a RooDataSet

It may be that you generate/create a RooDataSet from some source (ie PAT-tuple) and then want to create a standard root histogram instead of a RooPlot. This section explains how to do that.
//assumes that RooDataSet *data; RooRealVar var1, var2; and someHist; exist
for(unsigned int i=0; i < data->numEntries(); i++)
{
   //retrieves the ith event
   data->get(i);
   Double_t var1_val = var1.getVal();
   Double_t var2_val = var2.getVal();
   someHist->Fill(var1_val);
   //if you have a 2-D histo (or 3-D) you can fill similarly
   //... Do other operations with var1_val etc.
}
-- DavidBjergaard - 12 Jun 2009
Edit | Attach | Watch | Print version | History: r6 < r5 < r4 < r3 < r2 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r6 - 2009-07-24 - AnthonyDiChiara
 
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    CMSPublic All webs login

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