Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
rf710_roopoly.C File Reference

Detailed Description

View in nbviewer Open in SWAN
Taylor expansion of RooFit functions using the taylorExpand function with RooPolyFunc

#include "RooRealVar.h"
#include "RooPolyFunc.h"
#include "RooPlot.h"
#include "TCanvas.h"
using namespace RooFit;
{
// C r e a t e p o l y n o m i a l
// f u n c t i o n o f f o u r t h o r d e r
// ---------------------------------------------
// x^4 - 5x^3 + 5x^2 + 5x -6
// ---------------------------------------------
RooRealVar x("x", "x", 0, -3, 10);
RooPolyFunc f("f", "f", RooArgSet(x));
f.addTerm(+1, x, 4);
f.addTerm(-5, x, 3);
f.addTerm(+5, x, 2);
f.addTerm(+5, x, 1);
f.addTerm(-6, x, 0);
// C r e a t e t a y l o r e x p a n s i o n
// ---------------------------------------------
double x0 = 2.0;
auto taylor_o1 = RooPolyFunc::taylorExpand("taylor_o1", "taylor expansion order 1", f, {x}, 1, {x0});
auto taylor_o2 = RooPolyFunc::taylorExpand("taylor_o2", "taylor expansion order 2", f, {x}, 2, {x0});
// Plot polynomial with first and second order taylor expansion overlaid
auto frame = x.frame(Title("x^{4} - 5x^{3} + 5x^{2} + 5x - 6"));
auto c = new TCanvas("rf710_roopoly", "rf710_roopoly", 400, 400);
c->cd();
f.plotOn(frame, Name("f"));
taylor_o1->plotOn(frame, LineColor(kRed), LineStyle(kDashed), Name("taylor_o1"));
taylor_o2->plotOn(frame, LineColor(kRed - 9), LineStyle(kDotted), Name("taylor_o2"));
frame->SetMinimum(-8.0);
frame->SetMaximum(+8.0);
frame->SetYTitle("function value");
frame->Draw();
auto legend = new TLegend(0.53, 0.7, 0.86, 0.87);
legend->SetFillColor(kWhite);
legend->SetLineColor(kWhite);
legend->SetTextSize(0.02);
legend->AddEntry("taylor_o1", "Taylor expansion upto first order", "L");
legend->AddEntry("taylor_o2", "Taylor expansion upto second order", "L");
legend->AddEntry("f", "Polynomial of fourth order", "L");
legend->Draw();
c->Draw();
c->SaveAs("rf710_roopoly.png");
}
#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.
RooRealVar represents a 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
Date
December 2021
Author
Rahul Balasubramanian

Definition in file rf710_roopoly.C.