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

Detailed Description

View in nbviewer Open in SWAN 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
auto * m
Definition textangle.C:8
␛[1mRooFit v3.60 -- Developed by Wouter Verkerke and David Kirkby␛[0m
Copyright (C) 2000-2013 NIKHEF, University of California & Stanford University
All rights reserved, please read http://roofit.sourceforge.net/license.txt
[#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.
[#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!
[#1] INFO:Minization -- RooMinimizer::optimizeConst: activating const optimization
[#1] INFO:Minization -- The following expressions have been identified as constant and will be precalculated and cached: (sig1,sig2)
[#1] INFO:Minization -- The following expressions will be evaluated in cache-and-track mode: (bkg)
**********
** 1 **SET PRINT 1
**********
**********
** 2 **SET NOGRAD
**********
PARAMETER DEFINITIONS:
NO. NAME VALUE STEP SIZE LIMITS
1 a0 5.00000e-01 1.00000e-01 0.00000e+00 1.00000e+00
2 a1 2.00000e-01 1.00000e-01 0.00000e+00 1.00000e+00
3 bkgfrac 5.00000e-01 1.00000e-01 0.00000e+00 1.00000e+00
4 sig1frac 8.00000e-01 1.00000e-01 0.00000e+00 1.00000e+00
**********
** 3 **SET ERR 0.5
**********
**********
** 4 **SET PRINT 1
**********
**********
** 5 **SET STR 1
**********
NOW USING STRATEGY 1: TRY TO BALANCE SPEED AGAINST RELIABILITY
**********
** 6 **MIGRAD 2000 1
**********
FIRST CALL TO USER FUNCTION AT NEW START POINT, WITH IFLAG=4.
START MIGRAD MINIMIZATION. STRATEGY 1. CONVERGENCE WHEN EDM .LT. 1.00e-03
FCN=1962.68 FROM MIGRAD STATUS=INITIATE 10 CALLS 11 TOTAL
EDM= unknown STRATEGY= 1 NO ERROR MATRIX
EXT PARAMETER CURRENT GUESS STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 a0 5.00000e-01 1.00000e-01 2.01358e-01 5.55984e+00
2 a1 2.00000e-01 1.00000e-01 2.57889e-01 -1.57464e+00
3 bkgfrac 5.00000e-01 1.00000e-01 2.01358e-01 1.16417e+00
4 sig1frac 8.00000e-01 1.00000e-01 2.57889e-01 -2.02114e+00
ERR DEF= 0.5
MIGRAD MINIMIZATION HAS CONVERGED.
MIGRAD WILL VERIFY CONVERGENCE AND ERROR MATRIX.
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=1962.27 FROM MIGRAD STATUS=CONVERGED 77 CALLS 78 TOTAL
EDM=2.21873e-05 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 a0 4.41621e-01 7.31971e-02 4.49448e-03 -2.95364e-02
2 a1 2.01070e-01 1.18164e-01 5.76018e-03 4.48544e-03
3 bkgfrac 5.04184e-01 3.60469e-02 1.24368e-03 -2.15278e-02
4 sig1frac 8.37334e-01 1.17186e-01 6.00443e-03 1.16304e-03
ERR DEF= 0.5
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 4 ERR DEF=0.5
5.397e-03 1.212e-03 -3.088e-04 -1.017e-03
1.212e-03 1.439e-02 -3.249e-03 -9.741e-03
-3.088e-04 -3.249e-03 1.302e-03 3.287e-03
-1.017e-03 -9.741e-03 3.287e-03 1.422e-02
PARAMETER CORRELATION COEFFICIENTS
NO. GLOBAL 1 2 3 4
1 0.14102 1.000 0.138 -0.117 -0.116
2 0.77022 0.138 1.000 -0.751 -0.681
3 0.82636 -0.117 -0.751 1.000 0.764
4 0.78133 -0.116 -0.681 0.764 1.000
**********
** 7 **SET ERR 0.5
**********
**********
** 8 **SET PRINT 1
**********
**********
** 9 **HESSE 2000
**********
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=1962.27 FROM HESSE STATUS=OK 23 CALLS 101 TOTAL
EDM=2.21633e-05 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER INTERNAL INTERNAL
NO. NAME VALUE ERROR STEP SIZE VALUE
1 a0 4.41621e-01 7.31875e-02 8.98897e-04 -1.17025e-01
2 a1 2.01070e-01 1.17637e-01 2.30407e-04 -6.40829e-01
3 bkgfrac 5.04184e-01 3.59091e-02 2.48735e-04 8.36870e-03
4 sig1frac 8.37334e-01 1.16852e-01 2.40177e-04 7.40515e-01
ERR DEF= 0.5
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 4 ERR DEF=0.5
5.396e-03 1.199e-03 -3.049e-04 -1.005e-03
1.199e-03 1.426e-02 -3.211e-03 -9.629e-03
-3.049e-04 -3.211e-03 1.292e-03 3.259e-03
-1.005e-03 -9.629e-03 3.259e-03 1.414e-02
PARAMETER CORRELATION COEFFICIENTS
NO. GLOBAL 1 2 3 4
1 0.14012 1.000 0.137 -0.116 -0.115
2 0.76777 0.137 1.000 -0.748 -0.678
3 0.82488 -0.116 -0.748 1.000 0.763
4 0.77985 -0.115 -0.678 0.763 1.000
[#1] INFO:Minization -- RooMinimizer::optimizeConst: 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)
0x7fff3ced4b50 RooAddPdf::model = 0.898624 [Auto,Dirty]
0x7fff3ced6140/V- RooChebychev::bkg = 0.79893 [Auto,Dirty]
0x7fff3ced80f0/V- RooRealVar::x = 5
0x7fff3ced6960/V- RooRealVar::a0 = 0.441621 +/- 0.0731875
0x7fff3ced65f0/V- RooRealVar::a1 = 0.20107 +/- 0.117637
0x7fff3ced51e8/V- RooRealVar::bkgfrac = 0.504184 +/- 0.0359091
0x7fff3ced5648/V- RooAddPdf::sig = 1 [Auto,Dirty]
0x7fff3ced71b0/V- RooGaussian::sig1 = 1 [Auto,Dirty]
0x7fff3ced80f0/V- RooRealVar::x = 5
0x7fff3ced7d80/V- RooRealVar::mean = 5
0x7fff3ced7a00/V- RooRealVar::sigma1 = 0.5
0x7fff3ced5ce0/V- RooRealVar::sig1frac = 0.837334 +/- 0.116852
0x7fff3ced6cd0/V- RooGaussian::sig2 = 1 [Auto,Dirty]
0x7fff3ced80f0/V- RooRealVar::x = 5
0x7fff3ced7d80/V- RooRealVar::mean = 5
0x7fff3ced7690/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: ()
0x7fff3ced3bc0 RooAddPdf::model = 0.898624 [Auto,Dirty]
0x7fff3ced6140/V- RooChebychev::bkg = 0.79893 [Auto,Dirty]
0x7fff3ced80f0/V- RooRealVar::x = 5
0x7fff3ced6960/V- RooRealVar::a0 = 0.441621 +/- 0.0731875
0x7fff3ced65f0/V- RooRealVar::a1 = 0.20107 +/- 0.117637
0x7fff3ced51e8/V- RooRealVar::bkgfrac = 0.504184 +/- 0.0359091
0x7fff3ced71b0/V- RooGaussian::sig1 = 1 [Auto,Dirty]
0x7fff3ced80f0/V- RooRealVar::x = 5
0x7fff3ced7d80/V- RooRealVar::mean = 5
0x7fff3ced7a00/V- RooRealVar::sigma1 = 0.5
0x563ca27e0c40/V- RooRecursiveFraction::model_recursive_fraction_sig1 = 0.415163 [Auto,Clean]
0x7fff3ced5ce0/V- RooRealVar::sig1frac = 0.837334 +/- 0.116852
0x7fff3ced51e8/V- RooRealVar::bkgfrac = 0.504184 +/- 0.0359091
0x7fff3ced6cd0/V- RooGaussian::sig2 = 1 [Auto,Dirty]
0x7fff3ced80f0/V- RooRealVar::x = 5
0x7fff3ced7d80/V- RooRealVar::mean = 5
0x7fff3ced7690/V- RooRealVar::sigma2 = 1
0x563ca1e1ae10/V- RooRecursiveFraction::model_recursive_fraction_sig2 = 0.0806524 [Auto,Clean]
0x563ca046cdc0/V- RooConstVar::1 = 1
0x7fff3ced5ce0/V- RooRealVar::sig1frac = 0.837334 +/- 0.116852
0x7fff3ced51e8/V- RooRealVar::bkgfrac = 0.504184 +/- 0.0359091
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooChebychev.h"
#include "RooAddPdf.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
RooDataSet *data = model.generate(x, 1000);
// Fit model to data
model.fitTo(*data);
// 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), kTRUE);
// 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);
gPad->SetLeftMargin(0.15);
xframe->GetYaxis()->SetTitleOffset(1.4);
xframe->Draw();
}
const Bool_t kTRUE
Definition RtypesCore.h:91
@ kRed
Definition Rtypes.h:66
@ kDashed
Definition TAttLine.h:48
@ kDotted
Definition TAttLine.h:48
#define gPad
virtual RooPlot * plotOn(RooPlot *frame, const RooCmdArg &arg1=RooCmdArg::none(), const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none()) const
RooAddPdf is an efficient implementation of a sum of PDFs of the form.
Definition RooAddPdf.h:32
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:21
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:29
Chebychev polynomial p.d.f.
RooDataSet is a container class to hold unbinned data.
Definition RooDataSet.h:33
Plain Gaussian p.d.f.
Definition RooGaussian.h:24
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition RooPlot.h:44
TAxis * GetYaxis() const
Definition RooPlot.cxx:1263
static RooPlot * frame(const RooAbsRealLValue &var, Double_t xmin, Double_t xmax, Int_t nBins)
Create a new frame for a given variable in x.
Definition RooPlot.cxx:249
virtual void Print(Option_t *options=0) const
Print TNamed name and title.
Definition RooPlot.h:134
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition RooPlot.cxx:691
RooRealVar represents a variable that can be changed from the outside.
Definition RooRealVar.h:39
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition TAttAxis.cxx:293
The Canvas class.
Definition TCanvas.h:23
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Date
July 2008
Author
Wouter Verkerke

Definition in file rf201_composite.C.