Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
rf314_paramfitrange.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_roofit
3/// \notebook -js
4/// Multidimensional models: working with parametrized ranges in a fit.
5/// This an example of a fit with an acceptance that changes per-event
6///
7/// `pdf = exp(-t/tau)` with `t[tmin,5]`
8///
9/// where `t` and `tmin` are both observables in the dataset
10///
11/// \macro_image
12/// \macro_output
13/// \macro_code
14///
15/// \date July 2008
16/// \author Wouter Verkerke
17
18#include "RooRealVar.h"
19#include "RooDataSet.h"
20#include "RooGaussian.h"
21#include "RooConstVar.h"
22#include "RooExponential.h"
23#include "TCanvas.h"
24#include "TAxis.h"
25#include "RooPlot.h"
26#include "RooFitResult.h"
27
28using namespace RooFit;
29
31{
32
33 // D e f i n e o b s e r v a b l e s a n d d e c a y p d f
34 // ---------------------------------------------------------------
35
36 // Declare observables
37 RooRealVar t("t", "t", 0, 5);
38 RooRealVar tmin("tmin", "tmin", 0, 0, 5);
39
40 // Make parametrized range in t : [tmin,5]
41 t.setRange(tmin, RooConst(t.getMax()));
42
43 // Make pdf
44 RooRealVar tau("tau", "tau", -1.54, -10, -0.1);
45 RooExponential model("model", "model", t, tau);
46
47 // C r e a t e i n p u t d a t a
48 // ------------------------------------
49
50 // Generate complete dataset without acceptance cuts (for reference)
51 RooDataSet *dall = model.generate(t, 10000);
52
53 // Generate a (fake) prototype dataset for acceptance limit values
54 RooDataSet *tmp = RooGaussian("gmin", "gmin", tmin, RooConst(0), RooConst(0.5)).generate(tmin, 5000);
55
56 // Generate dataset with t values that observe (t>tmin)
57 RooDataSet *dacc = model.generate(t, ProtoData(*tmp));
58
59 // F i t p d f t o d a t a i n a c c e p t a n c e r e g i o n
60 // -----------------------------------------------------------------------
61
62 RooFitResult *r = model.fitTo(*dacc, Save());
63
64 // P l o t f i t t e d p d f o n f u l l a n d a c c e p t e d d a t a
65 // ---------------------------------------------------------------------------------
66
67 // Make plot frame, add datasets and overlay model
68 RooPlot *frame = t.frame(Title("Fit to data with per-event acceptance"));
69 dall->plotOn(frame, MarkerColor(kRed), LineColor(kRed));
70 model.plotOn(frame);
71 dacc->plotOn(frame);
72
73 // Print fit results to demonstrate absence of bias
74 r->Print("v");
75
76 new TCanvas("rf314_paramranges", "rf314_paramranges", 600, 600);
77 gPad->SetLeftMargin(0.15);
78 frame->GetYaxis()->SetTitleOffset(1.6);
79 frame->Draw();
80
81 return;
82}
ROOT::R::TRInterface & r
Definition Object.C:4
@ kRed
Definition Rtypes.h:66
#define gPad
virtual RooPlot * plotOn(RooPlot *frame, const RooCmdArg &arg1=RooCmdArg::none(), const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none()) const
RooDataSet * generate(const RooArgSet &whatVars, Int_t nEvents, const RooCmdArg &arg1, const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none())
See RooAbsPdf::generate(const RooArgSet&,const RooCmdArg&,const RooCmdArg&,const RooCmdArg&,...
Definition RooAbsPdf.h:58
RooDataSet is a container class to hold unbinned data.
Definition RooDataSet.h:33
Exponential PDF.
RooFitResult is a container class to hold the input and output of a PDF fit to a dataset.
Plain Gaussian p.d.f.
Definition RooGaussian.h:24
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition RooPlot.h:44
TAxis * GetYaxis() const
Definition RooPlot.cxx:1263
static RooPlot * frame(const RooAbsRealLValue &var, Double_t xmin, Double_t xmax, Int_t nBins)
Create a new frame for a given variable in x.
Definition RooPlot.cxx:249
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition RooPlot.cxx:691
RooRealVar represents a variable that can be changed from the outside.
Definition RooRealVar.h:39
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition TAttAxis.cxx:293
The Canvas class.
Definition TCanvas.h:23
virtual void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
Definition TObject.cxx:552
RooConstVar & RooConst(Double_t val)
RooCmdArg Save(Bool_t flag=kTRUE)
RooCmdArg ProtoData(const RooDataSet &protoData, Bool_t randomizeOrder=kFALSE, Bool_t resample=kFALSE)
RooCmdArg MarkerColor(Color_t color)
RooCmdArg LineColor(Color_t color)
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
const char * Title
Definition TXMLSetup.cxx:68