Running RootFitTools macros

Location of examples and data files:

To get RooFitMacros, go to release directory and

> addpkg RooFitMacros V00-00-17

Starting with RooFitTools

Declaring a variable - three different forms:

RooRealVar
    zero("zero","The number zero",0),                                          // Single number means this is a fixed constant
    dt("dt","B0 Decay Time Difference",-8,8,"ps"),                   // Two number define the range this variable can assume
    bfrac("bfrac","B0 vs B+ fraction, sideband",0.75,0.0,1.0);  // Three numbers give initial starting point for fit + range

The string in the first " " must match the variable name, the second string can be any descriptive phrase.  The "ps" is optional and will show up on histograms in certain cases.  The range is treated like a cut when you are reading in data, but not during the fitting process.  To make the range apply to the fitting process add a line like:

  dt.setLimits();
  bfrac.setLimits();


Category - if you have some discrete variable like tagging category or mixing status, you can use categories.  See BAD #18 for complete description.

RooCategory cat("cat","Tagging Category");
   cat.defineType("Unmixed Tag",+1);
   cat.defineType("Mixed Tag",-1);


Reading in data:

//  Reading in data from a simple text file - the order of variables must match the columns in the text file
RooDataSet *data = RooDataSet::read("Inputfile.dat",dt,dt_error,dmass,cat);
 

// Load in TTrees from output root file - names must match names in TTree, order doesn't matter
  TFile file("genericB.root");
  TTree *dataTree      = (TTree*)file.Get("dataTree");
  RooDataSet *signal_data = new RooDataSet("signal_data",dataTree,dt,cat,"tag_cat==2");

The last thing in " " is a cut on the data being read in.  You can have several cuts or leave it blank, for example:

  RooDataSet *signal_data = new RooDataSet("signal_data",dataTree,dt,cat);
  RooDataSet *signal_data = new RooDataSet("signal_data",dataTree,dt,cat,"(tag_cat==2)&&(abs(dt)<15)&&(D0_type==1)");


PDF's:  There are both generic PDF's you can use as building blocks for form more complicated ones, and special pdf's which are designed for a very particular type of distribution.  Here are some examples:

Generic

Special background To figure out what you need to initialize one of these you can look at an example that uses one or go to RooFitTools and see what the constructor requires to be initialized.  Here are some examples:

  RooBMixDecay signal("signal","Mixed and unmixed signal",dt,cat,tau,dm,eta,gauss_signal);
  RooGaussian signalDeltaM("signalDeltaM","Signal Distribution",dmass,bias,width);
  RooDstarBG bgDeltaM("bgDeltaM","D* Background",dmass,piPlusMass,c);

You can take any number of pdf and add them together.

  RooAddPdf total("total","Signal + Background",signal,bg_pdf1,n0);
  RooAddPdf total("total","Signal + Background",signal,bg_pdf1,bg_pdf2,bg_pdf3,n0,n1,n2);

signal and bg_pdf are pdf's, n0 (n1, n2 ...) are the fractions associated with that pdf.  The fraction for the last pdf is = (1 - n0 -n1 ...) thus the number of fractions is always one smaller than the number of pdfs.  There are other operations like multiply and convolution (see the BAD for these).


Fitting for results - once you have defined your pdf and you have loaded in a data set, you can fit the data with your pdf as follows:
 

  RooDataSet *signal_data = new RooDataSet("signal_data",dataTree,dt,cat,"tag_cat==2");
  RooAddPdf total("total","All backgrounds + signal", sideband_comb, sideband_fake,
    sideband_flip, prompt_ccbar, signal, comb_bg, fake_bg, flip_bg, ccbar_bg);

  total.fitTo(signal_data,"mh");   // fit the data to the pdf total.  "mh" are option sent to MINUIT for fitting.


Plotting results -

  // Create a nice plot: first the data points
  TH1F* dataplot= data->Plot(dmass, "", 38);
  dataplot->Draw("e");