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

Detailed Description

View in nbviewer Open in SWAN
Addition and convolution: tools and utilities for manipulation of composite objects

#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooChebychev.h"
#include "RooExponential.h"
#include "RooAddPdf.h"
#include "RooPlot.h"
#include "RooCustomizer.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "TH1.h"
using namespace RooFit;
{
// S e t u p c o m p o s i t e p d f, d a t a s e t
// --------------------------------------------------------
// 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 sigma("sigma", "width of gaussians", 0.5);
RooGaussian sig("sig", "Signal component 1", x, mean, sigma);
// Build Chebychev polynomial pdf
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
RooRealVar alpha("alpha", "alpha", -1);
RooExponential bkg2("bkg2", "Background 2", x, alpha);
// Sum the background components into a composite background pdf
RooRealVar bkg1frac("bkg1frac", "fraction of component 1 in background", 0.2, 0., 1.);
RooAddPdf bkg("bkg", "Signal", RooArgList(bkg1, bkg2), bkg1frac);
// 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);
// Create dummy dataset that has more observables than the above pdf
RooRealVar y("y", "y", -10, 10);
RooDataSet data("data", "data", RooArgSet(x, y));
// ---------------------------------------------------
// B a s i c i n f o r m a t i o n r e q u e s t s
// ===================================================
// G e t l i s t o f o b s e r v a b l e s
// ---------------------------------------------
// Get list of observables of pdf in context of a dataset
//
// Observables are define each context as the variables
// shared between a model and a dataset. In this case
// that is the variable 'x'
std::unique_ptr<RooArgSet> model_obs{model.getObservables(data)};
model_obs->Print("v");
// G e t l i s t o f p a r a m e t e r s
// -------------------------------------------
// Get list of parameters, given list of observables
std::unique_ptr<RooArgSet> model_params{model.getParameters(x)};
model_params->Print("v");
// Get list of parameters, given a dataset
// (Gives identical results to operation above)
std::unique_ptr<RooArgSet> model_params2{model.getParameters(data)};
model_params2->Print();
// G e t l i s t o f c o m p o n e n t s
// -------------------------------------------
// Get list of component objects, including top-level node
std::unique_ptr<RooArgSet> model_comps{model.getComponents()};
model_comps->Print("v");
// -------------------------------------------------------------------------------
// M o d i f i c a t i o n s t o s t r u c t u r e o f c o m p o s i t e s
// ===============================================================================
// Create a second Gaussian
RooRealVar sigma2("sigma2", "width of gaussians", 1);
RooGaussian sig2("sig2", "Signal component 1", x, mean, sigma2);
// Create a sum of the original Gaussian plus the new second Gaussian
RooRealVar sig1frac("sig1frac", "fraction of component 1 in signal", 0.8, 0., 1.);
RooAddPdf sigsum("sigsum", "sig+sig2", RooArgList(sig, sig2), sig1frac);
// Construct a customizer utility to customize model
RooCustomizer cust(model, "cust");
// Instruct the customizer to replace node 'sig' with node 'sigsum'
cust.replaceArg(sig, sigsum);
// Build a clone of the input pdf according to the above customization
// instructions. Each node that requires modified is clone so that the
// original pdf remained untouched. The name of each cloned node is that
// of the original node suffixed by the name of the customizer object
//
// The returned head node own all nodes that were cloned as part of
// the build process so when cust_clone is deleted so will all other
// nodes that were created in the process.
RooAbsPdf *cust_clone = (RooAbsPdf *)cust.build(true);
// Print structure of clone of model with sig->sigsum replacement.
cust_clone->Print("t");
delete cust_clone;
}
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
void Print(Option_t *options=nullptr) const override
Print the object to the defaultPrintStream().
Definition RooAbsArg.h:320
Abstract interface for all probability density functions.
Definition RooAbsPdf.h:40
Efficient implementation of a sum of PDFs of the form.
Definition RooAddPdf.h:33
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.
RooCustomizer is a factory class to produce clones of a prototype composite PDF object with the same ...
Container class to hold unbinned data.
Definition RooDataSet.h:57
Exponential PDF.
Plain Gaussian p.d.f.
Definition RooGaussian.h:24
Variable that can be changed from the outside.
Definition RooRealVar.h:37
const Double_t sigma
Double_t y[n]
Definition legend1.C:17
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
[#0] WARNING:InputArguments -- The parameter 'sigma' with range [-inf, inf] of the RooGaussian 'sig' exceeds the safe range of (0, inf). Advise to limit its range.
1) 0x7ffe77c09620 RooRealVar:: x = 5 L(0 - 10) "x"
1) 0x7ffe77c057c0 RooRealVar:: a0 = 0.5 L(0 - 1) "a0"
2) 0x7ffe77c05ba8 RooRealVar:: a1 = 0.2 L(0 - 1) "a1"
3) 0x7ffe77c05f90 RooRealVar:: alpha = -1 C L(-INF - +INF) "alpha"
4) 0x7ffe77c06378 RooRealVar:: bkg1frac = 0.2 L(0 - 1) "fraction of component 1 in background"
5) 0x7ffe77c06760 RooRealVar:: bkgfrac = 0.5 L(0 - 1) "fraction of background"
6) 0x7ffe77c07ba8 RooRealVar:: mean = 5 C L(-INF - +INF) "mean of gaussians"
7) 0x7ffe77c053d8 RooRealVar:: sigma = 0.5 C L(-INF - +INF) "width of gaussians"
RooArgSet::parameters = (a0,a1,alpha,bkg1frac,bkgfrac,mean,sigma)
1) 0x7ffe77c089a8 RooAddPdf:: model[ bkgfrac * bkg + [%] * sig ] = 0.582695/1 "g1+g2+a"
2) 0x7ffe77c07488 RooAddPdf:: bkg[ bkg1frac * bkg1 + [%] * bkg2 ] = 0.16539/1 "Signal"
3) 0x7ffe77c049b0 RooChebychev:: bkg1[ x=x coefficients=(a0,a1) ] = 0.8 "Background 1"
4) 0x7ffe77c04ee0 RooExponential:: bkg2[ x=x c=alpha ] = 0.00673795 "Background 2"
5) 0x7ffe77c06f30 RooGaussian:: sig[ x=x mean=mean sigma=sigma ] = 1 "Signal component 1"
[#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:ObjectHandling -- RooCustomizer::build(model): tree node sig will be replaced by sigsum
[#1] INFO:ObjectHandling -- RooCustomizer::build(model) Branch node RooAddPdf::model cloned: depends on a replaced parameter
[#1] INFO:ObjectHandling -- RooCustomizer::build(model) Branch node sig is already replaced
0x55b082036030 RooAddPdf::model_cust = 0.582695/1 [Auto,Clean]
0x7ffe77c07488/V- RooAddPdf::bkg = 0.16539/1 [Auto,Clean]
0x7ffe77c049b0/V- RooChebychev::bkg1 = 0.8 [Auto,Dirty]
0x7ffe77c09620/V- RooRealVar::x = 5
0x7ffe77c057c0/V- RooRealVar::a0 = 0.5
0x7ffe77c05ba8/V- RooRealVar::a1 = 0.2
0x7ffe77c06378/V- RooRealVar::bkg1frac = 0.2
0x7ffe77c04ee0/V- RooExponential::bkg2 = 0.00673795 [Auto,Dirty]
0x7ffe77c09620/V- RooRealVar::x = 5
0x7ffe77c05f90/V- RooRealVar::alpha = -1
0x7ffe77c06760/V- RooRealVar::bkgfrac = 0.5
0x7ffe77c09a08/V- RooAddPdf::sigsum = 1/1 [Auto,Clean]
0x7ffe77c06f30/V- RooGaussian::sig = 1 [Auto,Dirty]
0x7ffe77c09620/V- RooRealVar::x = 5
0x7ffe77c07ba8/V- RooRealVar::mean = 5
0x7ffe77c053d8/V- RooRealVar::sigma = 0.5
0x7ffe77c08378/V- RooRealVar::sig1frac = 0.8
0x7ffe77c090c8/V- RooGaussian::sig2 = 1 [Auto,Dirty]
0x7ffe77c09620/V- RooRealVar::x = 5
0x7ffe77c07ba8/V- RooRealVar::mean = 5
0x7ffe77c07f90/V- RooRealVar::sigma2 = 1
Date
July 2008
Author
Wouter Verkerke

Definition in file rf207_comptools.C.