Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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_code
8/// \macro_output
9///
10/// \date July 2008
11/// \author Wouter Verkerke
12
13#include "RooRealVar.h"
14#include "RooDataSet.h"
15#include "RooGaussian.h"
16#include "RooFormulaVar.h"
17#include "RooRealSumPdf.h"
18#include "RooPolyVar.h"
19#include "RooProduct.h"
20#include "TH1.h"
21#include "TCanvas.h"
22#include "TAxis.h"
23#include "RooPlot.h"
24using namespace RooFit;
25
27{
28 // 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
29 // -------------------------------------------------------
30
31 // Observables
32 RooRealVar t("t", "time", -1., 15.);
33 RooRealVar cosa("cosa", "cos(alpha)", -1., 1.);
34
35 RooRealVar tau("tau", "#tau", 1.5);
36 RooRealVar deltaGamma("deltaGamma", "deltaGamma", 0.3);
37 RooFormulaVar coshG("coshGBasis", "exp(-@0/ @1)*cosh(@0*@2/2)", {t, tau, deltaGamma});
38 RooFormulaVar sinhG("sinhGBasis", "exp(-@0/ @1)*sinh(@0*@2/2)", {t, tau, deltaGamma});
39
40 // Construct polynomial amplitudes in cos(a)
41 RooPolyVar poly1("poly1", "poly1", cosa, RooArgList{0.5, 0.2, 0.2}, 0);
42 RooPolyVar poly2("poly2", "poly2", cosa, RooArgList{1.0, -0.2, 3.0}, 0);
43
44 // Construct 2D amplitude as uncorrelated product of amp(t)*amp(cosa)
45 RooProduct ampl1("ampl1", "amplitude 1", {poly1, coshG});
46 RooProduct ampl2("ampl2", "amplitude 2", {poly2, sinhG});
47
48 // C o n s t r u c t a m p l i t u d e s u m p d f
49 // -----------------------------------------------------
50
51 // Amplitude strengths
52 RooRealVar f1("f1", "f1", 1, 0, 2);
53 RooRealVar f2("f2", "f2", 0.5, 0, 2);
54
55 // Construct pdf
56 RooRealSumPdf pdf("pdf", "pdf", RooArgList(ampl1, ampl2), RooArgList(f1, f2));
57
58 // Generate some toy data from pdf
59 std::unique_ptr<RooDataSet> data{pdf.generate({t, cosa}, 10000)};
60
61 // Fit pdf to toy data with only amplitude strength floating
62 pdf.fitTo(*data, PrintLevel(-1));
63
64 // P l o t a m p l i t u d e s u m p d f
65 // -------------------------------------------
66
67 // Make 2D plots of amplitudes
68 TH1 *hh_cos = ampl1.createHistogram("hh_cos", t, Binning(50), YVar(cosa, Binning(50)));
69 TH1 *hh_sin = ampl2.createHistogram("hh_sin", t, Binning(50), YVar(cosa, Binning(50)));
70 hh_cos->SetLineColor(kBlue);
71 hh_sin->SetLineColor(kRed);
72
73 // Make projection on t, plot data, pdf and its components
74 // Note component projections may be larger than sum because amplitudes can be negative
75 RooPlot *frame1 = t.frame();
76 data->plotOn(frame1);
77 pdf.plotOn(frame1);
78 pdf.plotOn(frame1, Components(ampl1), LineStyle(kDashed));
79 pdf.plotOn(frame1, Components(ampl2), LineStyle(kDashed), LineColor(kRed));
80
81 // Make projection on cosa, plot data, pdf and its components
82 // Note that components projection may be larger than sum because amplitudes can be negative
83 RooPlot *frame2 = cosa.frame();
84 data->plotOn(frame2);
85 pdf.plotOn(frame2);
86 pdf.plotOn(frame2, Components(ampl1), LineStyle(kDashed));
87 pdf.plotOn(frame2, Components(ampl2), LineStyle(kDashed), LineColor(kRed));
88
89 TCanvas *c = new TCanvas("rf704_amplitudefit", "rf704_amplitudefit", 800, 800);
90 c->Divide(2, 2);
91 c->cd(1);
92 gPad->SetLeftMargin(0.15);
93 frame1->GetYaxis()->SetTitleOffset(1.4);
94 frame1->Draw();
95 c->cd(2);
96 gPad->SetLeftMargin(0.15);
97 frame2->GetYaxis()->SetTitleOffset(1.4);
98 frame2->Draw();
99 c->cd(3);
100 gPad->SetLeftMargin(0.20);
101 hh_cos->GetZaxis()->SetTitleOffset(2.3);
102 hh_cos->Draw("surf");
103 c->cd(4);
104 gPad->SetLeftMargin(0.20);
105 hh_sin->GetZaxis()->SetTitleOffset(2.3);
106 hh_sin->Draw("surf");
107}
#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
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
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:237
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
A RooAbsReal implementing a polynomial in terms of a list of RooAbsReal coefficients.
Definition RooPolyVar.h:25
Represents the product of a given set of RooAbsReal objects.
Definition RooProduct.h:29
Implements a PDF constructed from a sum of functions:
Variable that can be changed from the outside.
Definition RooRealVar.h:37
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition TAttAxis.cxx:298
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:59
TAxis * GetZaxis()
Definition TH1.h:326
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3066
RooCmdArg YVar(const RooAbsRealLValue &var, const RooCmdArg &arg={})
RooCmdArg PrintLevel(Int_t code)
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 JSONIO.h:26