ROOT   Reference Guide
Searching...
No Matches
rf710_roopoly.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_roofit
3/// \notebook -js
4/// Taylor expansion of RooFit functions using the taylorExpand function with RooPolyFunc
5///
6/// \macro_image
7/// \macro_code
8/// \macro_output
9///
10/// \date December 2021
11/// \author Rahul Balasubramanian
12
13#include "RooRealVar.h"
14#include "RooPolyFunc.h"
15#include "RooAbsCollection.h"
16#include "RooPlot.h"
17#include "TCanvas.h"
18
19using namespace RooFit;
20
21void rf710_roopoly()
22{
23 // C r e a t e p o l y n o m i a l
24 // f u n c t i o n o f f o u r t h o r d e r
25 // ---------------------------------------------
26 // x^4 - 5x^3 + 5x^2 + 5x -6
27 // ---------------------------------------------
28
29 RooRealVar x("x", "x", 0, -3, 10);
30 RooPolyFunc f("f", "f", RooArgSet(x));
36
37 // C r e a t e t a y l o r e x p a n s i o n
38 // ---------------------------------------------
39 double x0 = 2.0;
40 auto taylor_o1 = RooPolyFunc::taylorExpand("taylor_o1", "taylor expansion order 1", f, {x}, 1, {x0});
41 auto taylor_o2 = RooPolyFunc::taylorExpand("taylor_o2", "taylor expansion order 2", f, {x}, 2, {x0});
42
43 // Plot polynomial with first and second order taylor expansion overlaid
44 auto frame = x.frame(Title("x^{4} - 5x^{3} + 5x^{2} + 5x - 6"));
45 auto c = new TCanvas("rf710_roopoly", "rf710_roopoly", 400, 400);
46 c->cd();
47
48 f.plotOn(frame, Name("f"));
49 taylor_o1->plotOn(frame, LineColor(kRed), LineStyle(kDashed), Name("taylor_o1"));
50 taylor_o2->plotOn(frame, LineColor(kRed - 9), LineStyle(kDotted), Name("taylor_o2"));
51
52 frame->SetMinimum(-8.0);
53 frame->SetMaximum(+8.0);
54 frame->SetYTitle("function value");
55 frame->Draw();
56
57 auto legend = new TLegend(0.53, 0.7, 0.86, 0.87);
58 legend->SetFillColor(kWhite);
59 legend->SetLineColor(kWhite);
60 legend->SetTextSize(0.02);
61 legend->AddEntry("taylor_o1", "Taylor expansion upto first order", "L");
62 legend->AddEntry("taylor_o2", "Taylor expansion upto second order", "L");
63 legend->AddEntry("f", "Polynomial of fourth order", "L");
64 legend->Draw();
65 c->Draw();
66 c->SaveAs("rf710_roopoly.png");
67}
#define f(i)
Definition RSha256.hxx:104
#define c(i)
Definition RSha256.hxx:101
@ kRed
Definition Rtypes.h:66
@ kWhite
Definition Rtypes.h:65
@ kDashed
Definition TAttLine.h:48
@ kDotted
Definition TAttLine.h:48
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
RooPolyFunc implements a polynomial function in multi-variables.
Definition RooPolyFunc.h:28
static std::unique_ptr< RooPolyFunc > taylorExpand(const char *name, const char *title, RooAbsReal &func, const RooArgList &observables, int order=1, std::vector< double > const &observableValues={}, double eps1=1e-6, double eps2=1e-3)
Taylor expanding given function in terms of observables around observableValues.
Variable that can be changed from the outside.
Definition RooRealVar.h:37
The Canvas class.
Definition TCanvas.h:23
This class displays a legend box (TPaveText) containing several legend entries.
Definition TLegend.h:23
RooCmdArg LineColor(Color_t color)
RooCmdArg LineStyle(Style_t style)
Double_t x[n]
Definition legend1.C:17
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition JSONIO.h:26
const char * Name
Definition TXMLSetup.cxx:67
const char * Title
Definition TXMLSetup.cxx:68