Rf 2 0 5_Compplot¶

Addition and convolution: options for plotting components of composite pdfs.

Author: Wouter Verkerke
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Wednesday, January 19, 2022 at 10:13 AM.

In :
%%cpp -d
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooChebychev.h"
#include "RooExponential.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "RooPlot.h"
In :
%%cpp -d
// This is a workaround to make sure the namespace is used inside functions
using namespace RooFit;

Setup composite pdf¶

Declare observable x

In :
RooRealVar x("x", "x", 0, 10);
RooFit v3.60 -- Developed by Wouter Verkerke and David Kirkby
Copyright (C) 2000-2013 NIKHEF, University of California & Stanford University

Create two gaussian pdfs g1(x,mean1,sigma) anf g2(x,mean2,sigma) and their parameters

In :
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);
[#0] WARNING:InputArguments -- The parameter 'sigma1' with range [-1e+30, 1e+30] of the RooGaussian 'sig1' exceeds the safe range of (0, inf). Advise to limit its range.
[#0] WARNING:InputArguments -- The parameter 'sigma2' with range [-1e+30, 1e+30] of the RooGaussian 'sig2' exceeds the safe range of (0, inf). Advise to limit its range.

Sum the signal components into a composite signal pdf

In :
RooRealVar sig1frac("sig1frac", "fraction of component 1 in signal", 0.8, 0., 1.);
RooAddPdf sig("sig", "Signal", RooArgList(sig1, sig2), sig1frac);

Build chebychev polynomial pdf

In :
RooRealVar a0("a0", "a0", 0.5, 0., 1.);
RooRealVar a1("a1", "a1", 0.2, 0., 1.);
RooChebychev bkg1("bkg1", "Background 1", x, RooArgSet(a0, a1));

Build exponential pdf

In :
RooRealVar alpha("alpha", "alpha", -1);
RooExponential bkg2("bkg2", "Background 2", x, alpha);

Sum the background components into a composite background pdf

In :
RooRealVar bkg1frac("sig1frac", "fraction of component 1 in background", 0.2, 0., 1.);
RooAddPdf bkg("bkg", "Signal", RooArgList(bkg1, bkg2), sig1frac);

Sum the composite signal and background

In :
RooRealVar bkgfrac("bkgfrac", "fraction of background", 0.5, 0., 1.);
RooAddPdf model("model", "g1+g2+a", RooArgList(bkg, sig), bkgfrac);

Setup basic plot with data and full pdf¶

Generate a data sample of 1000 events in x from model

In :
RooDataSet *data = model.generate(x, 1000);
[#0] WARNING:Eval -- Evaluating RooAddPdf without a defined normalization set. This can lead to ambiguos coefficients definition and incorrect results. Use RooAddPdf::fixCoefNormalization(nset) to provide a normalization set for defining uniquely RooAddPdf coefficients!
[#0] WARNING:Eval -- Evaluating RooAddPdf without a defined normalization set. This can lead to ambiguos coefficients definition and incorrect results. Use RooAddPdf::fixCoefNormalization(nset) to provide a normalization set for defining uniquely RooAddPdf coefficients!

Plot data and complete pdf overlaid

In :
RooPlot *xframe = x.frame(Title("Component plotting of pdf=(sig1+sig2)+(bkg1+bkg2)"));
data->plotOn(xframe);
model.plotOn(xframe);
input_line_61:3:1: error: reference to 'data' is ambiguous
data->plotOn(xframe);
^
input_line_60:2:14: note: candidate found by name lookup is '__cling_N528::data'
RooDataSet *data = model.generate(x, 1000);
^
/usr/include/c++/9/bits/range_access.h:318:5: note: candidate found by name lookup is 'std::data'
data(initializer_list<_Tp> __il) noexcept
^
/usr/include/c++/9/bits/range_access.h:289:5: note: candidate found by name lookup is 'std::data'
data(_Container& __cont) noexcept(noexcept(__cont.data()))
^
/usr/include/c++/9/bits/range_access.h:299:5: note: candidate found by name lookup is 'std::data'
data(const _Container& __cont) noexcept(noexcept(__cont.data()))
^
/usr/include/c++/9/bits/range_access.h:309:5: note: candidate found by name lookup is 'std::data'
data(_Tp (&__array)[_Nm]) noexcept
^

Clone xframe for use below

In :
RooPlot *xframe2 = (RooPlot *)xframe->Clone("xframe2");
input_line_63:2:14: error: use of undeclared identifier 'xframe'
((RooPlot *)xframe->Clone("xframe2"))
^
Error in <HandleInterpreterException>: Error evaluating expression ((RooPlot *)xframe->Clone("xframe2"))
Execution of your code was aborted.

Make component by object reference¶

Plot single background component specified by object reference

In :
model.plotOn(xframe, Components(bkg), LineColor(kRed));
input_line_64:2:50: error: cannot take the address of an rvalue of type 'EColor'
model.plotOn(xframe, Components(bkg), LineColor(kRed));
^~~~
Error while creating dynamic expression for:
model.plotOn(xframe, Components(bkg), LineColor(kRed))

Plot single background component specified by object reference

In :
model.plotOn(xframe, Components(bkg2), LineStyle(kDashed), LineColor(kRed));
input_line_65:2:51: error: cannot take the address of an rvalue of type 'ELineStyle'
model.plotOn(xframe, Components(bkg2), LineStyle(kDashed), LineColor(kRed));
^~~~~~~
Error while creating dynamic expression for:
model.plotOn(xframe, Components(bkg2), LineStyle(kDashed), LineColor(kRed))

Plot multiple background components specified by object reference Note that specified components may occur at any level in object tree (e.g bkg is component of 'model' and 'sig2' is component 'sig')

In :
model.plotOn(xframe, Components(RooArgSet(bkg, sig2)), LineStyle(kDotted));
input_line_66:2:67: error: cannot take the address of an rvalue of type 'ELineStyle'
model.plotOn(xframe, Components(RooArgSet(bkg, sig2)), LineStyle(kDotted));
^~~~~~~
Error while creating dynamic expression for:
model.plotOn(xframe, Components(RooArgSet(bkg, sig2)), LineStyle(kDotted))

Make component by name / regexp¶

Plot single background component specified by name

In :
model.plotOn(xframe2, Components("bkg"), LineColor(kCyan));
[#0] ERROR:Plotting -- RooAddPdf::model:plotOn: frame is null

Plot multiple background components specified by name

In :
model.plotOn(xframe2, Components("bkg1,sig2"), LineStyle(kDotted), LineColor(kCyan));
[#0] ERROR:Plotting -- RooAddPdf::model:plotOn: frame is null

Plot multiple background components specified by regular expression on name

In :
model.plotOn(xframe2, Components("sig*"), LineStyle(kDashed), LineColor(kCyan));
[#0] ERROR:Plotting -- RooAddPdf::model:plotOn: frame is null

Plot multiple background components specified by multiple regular expressions on name

In :
model.plotOn(xframe2, Components("bkg1,sig*"), LineStyle(kDashed), LineColor(kYellow), Invisible());
[#0] ERROR:Plotting -- RooAddPdf::model:plotOn: frame is null

Draw the frame on the canvas

In :
TCanvas *c = new TCanvas("rf205_compplot", "rf205_compplot", 800, 400);
c->Divide(2);
c->cd(1);
xframe->GetYaxis()->SetTitleOffset(1.4);
xframe->Draw();
c->cd(2);