Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 ///
6 /// This an example of a fit with an acceptance that changes per-event
7 ///
8 /// pdf = exp(-t/tau) with t[tmin,5]
9 ///
10 /// where t and tmin are both observables in the dataset
11 ///
12 /// \macro_image
13 /// \macro_output
14 /// \macro_code
15 /// \author 07/2008 - Wouter Verkerke
16 
17 #include "RooRealVar.h"
18 #include "RooDataSet.h"
19 #include "RooGaussian.h"
20 #include "RooConstVar.h"
21 #include "RooExponential.h"
22 #include "TCanvas.h"
23 #include "TAxis.h"
24 #include "RooPlot.h"
25 #include "RooFitResult.h"
26 
27 using namespace RooFit;
28 
29 void rf314_paramfitrange()
30 {
31 
32  // 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
33  // ---------------------------------------------------------------
34 
35  // Declare observables
36  RooRealVar t("t", "t", 0, 5);
37  RooRealVar tmin("tmin", "tmin", 0, 0, 5);
38 
39  // Make parametrized range in t : [tmin,5]
40  t.setRange(tmin, RooConst(t.getMax()));
41 
42  // Make pdf
43  RooRealVar tau("tau", "tau", -1.54, -10, -0.1);
44  RooExponential model("model", "model", t, tau);
45 
46  // C r e a t e i n p u t d a t a
47  // ------------------------------------
48 
49  // Generate complete dataset without acceptance cuts (for reference)
50  RooDataSet *dall = model.generate(t, 10000);
51 
52  // Generate a (fake) prototype dataset for acceptance limit values
53  RooDataSet *tmp = RooGaussian("gmin", "gmin", tmin, RooConst(0), RooConst(0.5)).generate(tmin, 5000);
54 
55  // Generate dataset with t values that observe (t>tmin)
56  RooDataSet *dacc = model.generate(t, ProtoData(*tmp));
57 
58  // 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
59  // -----------------------------------------------------------------------
60 
61  RooFitResult *r = model.fitTo(*dacc, Save());
62 
63  // 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
64  // ---------------------------------------------------------------------------------
65 
66  // Make plot frame, add datasets and overlay model
67  RooPlot *frame = t.frame(Title("Fit to data with per-event acceptance"));
68  dall->plotOn(frame, MarkerColor(kRed), LineColor(kRed));
69  model.plotOn(frame);
70  dacc->plotOn(frame);
71 
72  // Print fit results to demonstrate absence of bias
73  r->Print("v");
74 
75  new TCanvas("rf314_paramranges", "rf314_paramranges", 600, 600);
76  gPad->SetLeftMargin(0.15);
77  frame->GetYaxis()->SetTitleOffset(1.6);
78  frame->Draw();
79 
80  return;
81 }