ROOT   Reference Guide
Searching...
No Matches
rf201_composite.C File Reference

## Detailed Description

Addition and convolution: composite pdf with signal and background component

pdf = f_bkg * bkg(x,a0,a1) + (1-fbkg) * (f_sig1 * sig1(x,m,s1 + (1-f_sig1) * sig2(x,m,s2)))
#define s1(x)
Definition RSha256.hxx:91
Double_t x[n]
Definition legend1.C:17
TMarker m
Definition textangle.C:8
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooChebychev.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "RooPlot.h"
using namespace RooFit;
{
// S e t u p c o m p o n e n t p d f s
// ---------------------------------------
// Declare observable x
RooRealVar x("x", "x", 0, 10);
// Create two Gaussian PDFs g1(x,mean1,sigma) anf g2(x,mean2,sigma) and their parameters
RooRealVar mean("mean", "mean of gaussians", 5);
RooRealVar sigma1("sigma1", "width of gaussians", 0.5);
RooRealVar sigma2("sigma2", "width of gaussians", 1);
RooGaussian sig1("sig1", "Signal component 1", x, mean, sigma1);
RooGaussian sig2("sig2", "Signal component 2", x, mean, sigma2);
// Build Chebychev polynomial pdf
RooRealVar a0("a0", "a0", 0.5, 0., 1.);
RooRealVar a1("a1", "a1", 0.2, 0., 1.);
RooChebychev bkg("bkg", "Background", x, RooArgSet(a0, a1));
// ---------------------------------------------
// M E T H O D 1 - T w o R o o A d d P d f s
// =============================================
// A d d s i g n a l c o m p o n e n t s
// ------------------------------------------
// Sum the signal components into a composite signal pdf
RooRealVar sig1frac("sig1frac", "fraction of component 1 in signal", 0.8, 0., 1.);
RooAddPdf sig("sig", "Signal", RooArgList(sig1, sig2), sig1frac);
// A d d s i g n a l a n d b a c k g r o u n d
// ------------------------------------------------
// Sum the composite signal and background
RooRealVar bkgfrac("bkgfrac", "fraction of background", 0.5, 0., 1.);
RooAddPdf model("model", "g1+g2+a", RooArgList(bkg, sig), bkgfrac);
// S a m p l e , f i t a n d p l o t m o d e l
// ---------------------------------------------------
// Generate a data sample of 1000 events in x from model
std::unique_ptr<RooDataSet> data{model.generate(x, 1000)};
// Fit model to data
model.fitTo(*data, PrintLevel(-1));
// Plot data and PDF overlaid
RooPlot *xframe = x.frame(Title("Example of composite pdf=(sig1+sig2)+bkg"));
data->plotOn(xframe);
model.plotOn(xframe);
// Overlay the background component of model with a dashed line
model.plotOn(xframe, Components(bkg), LineStyle(kDashed));
// Overlay the background+sig2 components of model with a dotted line
model.plotOn(xframe, Components(RooArgSet(bkg, sig2)), LineStyle(kDotted));
// Print structure of composite pdf
model.Print("t");
// ---------------------------------------------------------------------------------------------
// M E T H O D 2 - O n e R o o A d d P d f w i t h r e c u r s i v e f r a c t i o n s
// =============================================================================================
// Construct sum of models on one go using recursive fraction interpretations
//
// model2 = bkg + (sig1 + sig2)
//
RooAddPdf model2("model", "g1+g2+a", RooArgList(bkg, sig1, sig2), RooArgList(bkgfrac, sig1frac), true);
// NB: Each coefficient is interpreted as the fraction of the
// left-hand component of the i-th recursive sum, i.e.
//
// sum4 = A + ( B + ( C + D) with fraction fA, fB and fC expands to
//
// sum4 = fA*A + (1-fA)*(fB*B + (1-fB)*(fC*C + (1-fC)*D))
// P l o t r e c u r s i v e a d d i t i o n m o d e l
// ---------------------------------------------------------
model2.plotOn(xframe, LineColor(kRed), LineStyle(kDashed));
model2.plotOn(xframe, Components(RooArgSet(bkg, sig2)), LineColor(kRed), LineStyle(kDashed));
model2.Print("t");
// Draw the frame on the canvas
new TCanvas("rf201_composite", "rf201_composite", 600, 600);
xframe->GetYaxis()->SetTitleOffset(1.4);
xframe->Draw();
}
@ kRed
Definition Rtypes.h:66
@ kDashed
Definition TAttLine.h:48
@ kDotted
Definition TAttLine.h:48
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Efficient implementation of a sum of PDFs of the form.
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:55
Chebychev polynomial p.d.f.
Plain Gaussian p.d.f.
Definition RooGaussian.h:24
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
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
The Canvas class.
Definition TCanvas.h:23
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition JSONIO.h:26
[#0] WARNING:InputArguments -- The parameter 'sigma1' with range [-inf, inf] of the RooGaussian 'sig1' exceeds the safe range of (0, inf). Advise to limit its range.
[#0] WARNING:InputArguments -- The parameter 'sigma2' with range [-inf, inf] of the RooGaussian 'sig2' exceeds the safe range of (0, inf). Advise to limit its range.
[#1] INFO:Fitting -- RooAbsPdf::fitTo(model) fixing normalization set for coefficient determination to observables in data
[#1] INFO:Fitting -- using CPU computation library compiled with -mavx2
[#1] INFO:Fitting -- RooAddition::defaultErrorLevel(nll_model_modelData) Summation contains a RooNLLVar, using its error level
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: activating const optimization
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: deactivating const optimization
[#1] INFO:Plotting -- RooAbsPdf::plotOn(model) directly selected PDF components: (bkg)
[#1] INFO:Plotting -- RooAbsPdf::plotOn(model) indirectly selected PDF components: ()
[#1] INFO:Plotting -- RooAbsPdf::plotOn(model) directly selected PDF components: (bkg,sig2)
[#1] INFO:Plotting -- RooAbsPdf::plotOn(model) indirectly selected PDF components: (sig)
0x7ffc3b8bc438/V- RooChebychev::bkg = 0.79893 [Auto,Dirty]
0x7ffc3b8bc968/V- RooRealVar::x = 5
0x7ffc3b8ba438/V- RooRealVar::a0 = 0.441621 +/- 0.0731875
0x7ffc3b8ba820/V- RooRealVar::a1 = 0.20107 +/- 0.117637
0x7ffc3b8bbaf8/V- RooRealVar::bkgfrac = 0.504184 +/- 0.0359091
0x7ffc3b8b9710/V- RooGaussian::sig1 = 1 [Auto,Dirty]
0x7ffc3b8bc968/V- RooRealVar::x = 5
0x7ffc3b8bb328/V- RooRealVar::mean = 5
0x7ffc3b8b9c68/V- RooRealVar::sigma1 = 0.5
0x7ffc3b8bb710/V- RooRealVar::sig1frac = 0.837334 +/- 0.116852
0x7ffc3b8bbee0/V- RooGaussian::sig2 = 1 [Auto,Dirty]
0x7ffc3b8bc968/V- RooRealVar::x = 5
0x7ffc3b8bb328/V- RooRealVar::mean = 5
0x7ffc3b8ba050/V- RooRealVar::sigma2 = 1
[#1] INFO:Plotting -- RooAbsPdf::plotOn(model) directly selected PDF components: (bkg,sig2)
[#1] INFO:Plotting -- RooAbsPdf::plotOn(model) indirectly selected PDF components: ()
0x7ffc3b8bc438/V- RooChebychev::bkg = 0.79893 [Auto,Dirty]
0x7ffc3b8bc968/V- RooRealVar::x = 5
0x7ffc3b8ba438/V- RooRealVar::a0 = 0.441621 +/- 0.0731875
0x7ffc3b8ba820/V- RooRealVar::a1 = 0.20107 +/- 0.117637
0x7ffc3b8bbaf8/V- RooRealVar::bkgfrac = 0.504184 +/- 0.0359091
0x7ffc3b8b9710/V- RooGaussian::sig1 = 1 [Auto,Dirty]
0x7ffc3b8bc968/V- RooRealVar::x = 5
0x7ffc3b8bb328/V- RooRealVar::mean = 5
0x7ffc3b8b9c68/V- RooRealVar::sigma1 = 0.5
0x55a026f03da0/V- RooRecursiveFraction::model_recursive_fraction_sig1_2 = 0.415163 [Auto,Clean]
0x7ffc3b8bb710/V- RooRealVar::sig1frac = 0.837334 +/- 0.116852
0x7ffc3b8bbaf8/V- RooRealVar::bkgfrac = 0.504184 +/- 0.0359091
0x7ffc3b8bbee0/V- RooGaussian::sig2 = 1 [Auto,Dirty]
0x7ffc3b8bc968/V- RooRealVar::x = 5
0x7ffc3b8bb328/V- RooRealVar::mean = 5
0x7ffc3b8ba050/V- RooRealVar::sigma2 = 1
0x55a026f655b0/V- RooRecursiveFraction::model_recursive_fraction_sig2_3 = 0.0806524 [Auto,Clean]
0x55a0249e2440/V- RooConstVar::1 = 1
0x7ffc3b8bb710/V- RooRealVar::sig1frac = 0.837334 +/- 0.116852
0x7ffc3b8bbaf8/V- RooRealVar::bkgfrac = 0.504184 +/- 0.0359091
Date
July 2008

Definition in file rf201_composite.C.