Logo ROOT  
Reference Guide
rf704_amplitudefit.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_roofit
3/// \notebook
4/// Special pdf's: using a pdf defined by a sum of real-valued amplitude components
5///
6/// \macro_image
7/// \macro_output
8/// \macro_code
9///
10/// \date July 2008
11/// \author Wouter Verkerke
12
13#include "RooRealVar.h"
14#include "RooDataSet.h"
15#include "RooGaussian.h"
16#include "RooTruthModel.h"
17#include "RooFormulaVar.h"
18#include "RooRealSumPdf.h"
19#include "RooPolyVar.h"
20#include "RooProduct.h"
21#include "TH1.h"
22#include "TCanvas.h"
23#include "TAxis.h"
24#include "RooPlot.h"
25using namespace RooFit;
26
28{
29 // S e t u p 2 D a m p l i t u d e f u n c t i o n s
30 // -------------------------------------------------------
31
32 // Observables
33 RooRealVar t("t", "time", -1., 15.);
34 RooRealVar cosa("cosa", "cos(alpha)", -1., 1.);
35
36 // Use RooTruthModel to obtain compiled implementation of sinh/cosh modulated decay functions
37 RooRealVar tau("tau", "#tau", 1.5);
38 RooRealVar deltaGamma("deltaGamma", "deltaGamma", 0.3);
39 RooTruthModel truthModel("tm", "tm", t);
40 RooFormulaVar coshGBasis("coshGBasis", "exp(-@0/ @1)*cosh(@0*@2/2)", RooArgList(t, tau, deltaGamma));
41 RooFormulaVar sinhGBasis("sinhGBasis", "exp(-@0/ @1)*sinh(@0*@2/2)", RooArgList(t, tau, deltaGamma));
42 RooAbsReal *coshGConv = truthModel.convolution(&coshGBasis, &t);
43 RooAbsReal *sinhGConv = truthModel.convolution(&sinhGBasis, &t);
44
45 // Construct polynomial amplitudes in cos(a)
46 RooPolyVar poly1("poly1", "poly1", cosa, RooArgList(0.5, 0.2, 0.2), 0);
47 RooPolyVar poly2("poly2", "poly2", cosa, RooArgList(1.0, -0.2, 3.0), 0);
48
49 // Construct 2D amplitude as uncorrelated product of amp(t)*amp(cosa)
50 RooProduct ampl1("ampl1", "amplitude 1", RooArgSet(poly1, *coshGConv));
51 RooProduct ampl2("ampl2", "amplitude 2", RooArgSet(poly2, *sinhGConv));
52
53 // C o n s t r u c t a m p l i t u d e s u m p d f
54 // -----------------------------------------------------
55
56 // Amplitude strengths
57 RooRealVar f1("f1", "f1", 1, 0, 2);
58 RooRealVar f2("f2", "f2", 0.5, 0, 2);
59
60 // Construct pdf
61 RooRealSumPdf pdf("pdf", "pdf", RooArgList(ampl1, ampl2), RooArgList(f1, f2));
62
63 // Generate some toy data from pdf
64 RooDataSet *data = pdf.generate(RooArgSet(t, cosa), 10000);
65
66 // Fit pdf to toy data with only amplitude strength floating
67 pdf.fitTo(*data);
68
69 // P l o t a m p l i t u d e s u m p d f
70 // -------------------------------------------
71
72 // Make 2D plots of amplitudes
73 TH1 *hh_cos = ampl1.createHistogram("hh_cos", t, Binning(50), YVar(cosa, Binning(50)));
74 TH1 *hh_sin = ampl2.createHistogram("hh_sin", t, Binning(50), YVar(cosa, Binning(50)));
75 hh_cos->SetLineColor(kBlue);
76 hh_sin->SetLineColor(kRed);
77
78 // Make projection on t, plot data, pdf and its components
79 // Note component projections may be larger than sum because amplitudes can be negative
80 RooPlot *frame1 = t.frame();
81 data->plotOn(frame1);
82 pdf.plotOn(frame1);
83 pdf.plotOn(frame1, Components(ampl1), LineStyle(kDashed));
84 pdf.plotOn(frame1, Components(ampl2), LineStyle(kDashed), LineColor(kRed));
85
86 // Make projection on cosa, plot data, pdf and its components
87 // Note that components projection may be larger than sum because amplitudes can be negative
88 RooPlot *frame2 = cosa.frame();
89 data->plotOn(frame2);
90 pdf.plotOn(frame2);
91 pdf.plotOn(frame2, Components(ampl1), LineStyle(kDashed));
92 pdf.plotOn(frame2, Components(ampl2), LineStyle(kDashed), LineColor(kRed));
93
94 TCanvas *c = new TCanvas("rf704_amplitudefit", "rf704_amplitudefit", 800, 800);
95 c->Divide(2, 2);
96 c->cd(1);
97 gPad->SetLeftMargin(0.15);
98 frame1->GetYaxis()->SetTitleOffset(1.4);
99 frame1->Draw();
100 c->cd(2);
101 gPad->SetLeftMargin(0.15);
102 frame2->GetYaxis()->SetTitleOffset(1.4);
103 frame2->Draw();
104 c->cd(3);
105 gPad->SetLeftMargin(0.20);
106 hh_cos->GetZaxis()->SetTitleOffset(2.3);
107 hh_cos->Draw("surf");
108 c->cd(4);
109 gPad->SetLeftMargin(0.20);
110 hh_sin->GetZaxis()->SetTitleOffset(2.3);
111 hh_sin->Draw("surf");
112}
#define c(i)
Definition: RSha256.hxx:101
@ kRed
Definition: Rtypes.h:66
@ kBlue
Definition: Rtypes.h:66
@ kDashed
Definition: TAttLine.h:48
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
#define gPad
Definition: TVirtualPad.h:288
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:62
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:22
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:56
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:55
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
Definition: RooFormulaVar.h:30
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition: RooPlot.h:43
static RooPlot * frame(const RooAbsRealLValue &var, double xmin, double xmax, Int_t nBins)
Create a new frame for a given variable in x.
Definition: RooPlot.cxx:239
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1276
void Draw(Option_t *options=nullptr) override
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:649
Class RooPolyVar is a RooAbsReal implementing a polynomial in terms of a list of RooAbsReal coefficie...
Definition: RooPolyVar.h:28
A RooProduct represents the product of a given set of RooAbsReal objects.
Definition: RooProduct.h:29
The class RooRealSumPdf implements a PDF constructed from a sum of functions:
Definition: RooRealSumPdf.h:24
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:40
RooTruthModel is an implementation of RooResolution model that provides a delta-function resolution m...
Definition: RooTruthModel.h:21
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition: TAttAxis.cxx:301
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
The Canvas class.
Definition: TCanvas.h:23
TH1 is the base class of all histogram classes in ROOT.
Definition: TH1.h:58
TAxis * GetZaxis()
Definition: TH1.h:324
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition: TH1.cxx:3060
RooCmdArg YVar(const RooAbsRealLValue &var, const RooCmdArg &arg=RooCmdArg::none())
RooCmdArg Components(Args_t &&... argsOrArgSet)
RooCmdArg Binning(const RooAbsBinning &binning)
RooCmdArg LineColor(Color_t color)
RooCmdArg LineStyle(Style_t style)
TF1 * f1
Definition: legend1.C:11
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition: Common.h:18