Logo ROOT   6.07/09
Reference Guide
rf705_linearmorph.C File Reference

Detailed Description

View in nbviewer Open in SWAN 'SPECIAL PDFS' RooFit tutorial macro #705

Linear interpolation between p.d.f shapes using the 'Alex Read' algorithm

pict1_rf705_linearmorph.C.png
Processing /mnt/vdb/lsf/workspace/root-makedoc-v608/rootspi/rdoc/src/v6-08-00-patches/tutorials/roofit/rf705_linearmorph.C...
RooFit v3.60 -- Developed by Wouter Verkerke and David Kirkby
Copyright (C) 2000-2013 NIKHEF, University of California & Stanford University
All rights reserved, please read http://roofit.sourceforge.net/license.txt
[#1] INFO:Caching -- RooAbsCachedPdf::getCache(lmorph) creating new cache 0x3c3fd00 with pdf g1_MORPH_g2_CACHE_Obs[x] for nset (x) with code 0
[#1] INFO:Caching -- RooAbsCachedPdf::getCache(lmorph) creating new cache 0x3c3fd00 with pdf g1_MORPH_g2_CACHE_Obs[x] for nset (x) with code 0
[#1] INFO:Caching -- RooAbsCachedPdf::getCache(lmorph) creating new cache 0x3b6d9e0 with pdf g1_MORPH_g2_CACHE_Obs[x] for nset (x) with code 0
[#1] INFO:Caching -- RooAbsCachedPdf::getCache(lmorph) creating new cache 0x3b6d9e0 with pdf g1_MORPH_g2_CACHE_Obs[x] for nset (x) with code 0
[#1] INFO:Caching -- RooAbsCachedPdf::getCache(lmorph) creating new cache 0x3b6d9e0 with pdf g1_MORPH_g2_CACHE_Obs[x] for nset (x) with code 0
[#1] INFO:Caching -- RooAbsCachedPdf::getCache(lmorph) creating new cache 0x3b6d9e0 with pdf g1_MORPH_g2_CACHE_Obs[x] for nset (x) with code 0
[#1] INFO:Caching -- RooAbsCachedPdf::getCache(lmorph) creating new cache 0x3b6d9e0 with pdf g1_MORPH_g2_CACHE_Obs[x] for nset (x) with code 0
[#1] INFO:Caching -- RooAbsCachedPdf::getCache(lmorph) creating new cache 0x3894340 with pdf g1_MORPH_g2_CACHE_Obs[x] for nset (x) with code 0
[#1] INFO:Caching -- RooAbsCachedPdf::getCache(lmorph) creating new cache 0x3c35e00 with pdf g1_MORPH_g2_CACHE_Obs[x] for nset (x,alpha) with code 0 from preexisting content.
[#1] INFO:Caching -- RooAbsCachedPdf::getCache(lmorph) creating new cache 0x3894340 with pdf g1_MORPH_g2_CACHE_Obs[x] for nset (x) with code 0
[#1] INFO:Caching -- RooAbsCachedPdf::getCache(lmorph) creating new cache 0x386d770 with pdf g1_MORPH_g2_CACHE_Obs[x] for nset (x) with code 0 from preexisting content.
[#0] PROGRESS:Eval -- RooIntegralMorph::fillCacheObject(lmorph) filling multi-dimensional cache..................................................
[#1] INFO:Caching -- RooAbsCachedPdf::getCache(lmorph) creating new cache 0x3ee43f0 with pdf g1_MORPH_g2_CACHE_Obs[alpha,x] for nset (x) with code 0
[#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: (g1,g2)
[#0] WARNING:Minization -- RooMinimizerFcn::synchronize: WARNING: no initial error estimate available for alpha: using 0.1
**********
** 1 **SET PRINT 1
**********
**********
** 2 **SET NOGRAD
**********
PARAMETER DEFINITIONS:
NO. NAME VALUE STEP SIZE LIMITS
1 alpha 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 500 1
**********
FIRST CALL TO USER FUNCTION AT NEW START POINT, WITH IFLAG=4.
prevFCN = 2639.71348 START MIGRAD MINIMIZATION. STRATEGY 1. CONVERGENCE WHEN EDM .LT. 1.00e-03
alpha=0.8026,
prevFCN = 2639.370838 alpha=0.7974,
prevFCN = 2640.13986 alpha=0.8003,
prevFCN = 2639.666981 alpha=0.7997,
prevFCN = 2639.761239 FCN=2639.71 FROM MIGRAD STATUS=INITIATE 4 CALLS 5 TOTAL
EDM= unknown STRATEGY= 1 NO ERROR MATRIX
EXT PARAMETER CURRENT GUESS STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 alpha 8.00000e-01 1.00000e-01 2.57889e-01 -5.94047e+01
ERR DEF= 0.5
alpha=0.8117,
prevFCN = 2638.871739 alpha=0.812,
prevFCN = 2638.883686 alpha=0.8114,
prevFCN = 2638.861418 alpha=0.8095,
prevFCN = 2638.85007 alpha=0.8102,
prevFCN = 2638.83663 alpha=0.8104,
prevFCN = 2638.838462 alpha=0.8105,
prevFCN = 2638.840038 alpha=0.8099,
prevFCN = 2638.836678 alpha=0.8104,
prevFCN = 2638.838537 alpha=0.81,
prevFCN = 2638.835179 alpha=0.8105,
prevFCN = 2638.840049 alpha=0.8099,
prevFCN = 2638.836701 alpha=0.8099,
prevFCN = 2638.837868 alpha=0.8101,
prevFCN = 2638.835736 alpha=0.8101,
prevFCN = 2638.835493 alpha=0.8096,
prevFCN = 2638.847089 alpha=0.8098,
prevFCN = 2638.839436 alpha=0.81,
prevFCN = 2638.835865 alpha=0.81,
prevFCN = 2638.835182 alpha=0.81,
prevFCN = 2638.835414 alpha=0.81,
prevFCN = 2638.835066 alpha=0.8102,
prevFCN = 2638.83647 alpha=0.8099,
prevFCN = 2638.838806 alpha=0.8101,
prevFCN = 2638.835704 alpha=0.8099,
prevFCN = 2638.836348 alpha=0.8101,
prevFCN = 2638.835616 alpha=0.81,
prevFCN = 2638.835153 alpha=0.81,
prevFCN = 2638.835081 alpha=0.81,
prevFCN = 2638.835068 alpha=0.81,
prevFCN = 2638.835066 MIGRAD FAILS TO FIND IMPROVEMENT
MIGRAD MINIMIZATION HAS CONVERGED.
MIGRAD WILL VERIFY CONVERGENCE AND ERROR MATRIX.
alpha=0.81,
prevFCN = 2638.835066 alpha=0.8101,
prevFCN = 2638.835704 alpha=0.8099,
prevFCN = 2638.836348 alpha=0.81,
prevFCN = 2638.835184 alpha=0.81,
prevFCN = 2638.834951 alpha=0.81,
prevFCN = 2638.835089 alpha=0.81,
prevFCN = 2638.835043 COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=2638.84 FROM MIGRAD STATUS=CONVERGED 41 CALLS 42 TOTAL
EDM=0.00017663 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 alpha 8.10030e-01 1.85998e-03 2.07772e-04 2.80295e+00
ERR DEF= 0.5
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 1 ERR DEF=0.5
3.460e-06
alpha=0.81, **********
** 7 **SET ERR 0.5
**********
**********
** 8 **SET PRINT 1
**********
**********
** 9 **HESSE 500
**********
prevFCN = 2638.835066 alpha=0.81,
prevFCN = 2638.835089 alpha=0.81,
prevFCN = 2638.835043 alpha=0.8104,
prevFCN = 2638.838366 alpha=0.8097,
prevFCN = 2638.844002 alpha=0.8134,
prevFCN = 2638.957145 alpha=0.8066,
prevFCN = 2638.998648 alpha=0.8172,
prevFCN = 2639.32881 alpha=0.8027,
prevFCN = 2639.353813 alpha=0.8102,
prevFCN = 2638.83663 alpha=0.8098,
prevFCN = 2638.839285 alpha=0.8101,
prevFCN = 2638.835335 alpha=0.81,
prevFCN = 2638.835043 COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=2638.84 FROM HESSE STATUS=OK 13 CALLS 55 TOTAL
EDM=0.0028007 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER INTERNAL INTERNAL
NO. NAME VALUE ERROR STEP SIZE VALUE
1 alpha 8.10030e-01 7.20341e-03 1.84784e-02 6.68818e-01
ERR DEF= 0.5
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 1 ERR DEF=0.5
5.190e-05
alpha=0.81, [#1] INFO:Minization -- RooMinimizer::optimizeConst: deactivating const optimization
[#1] INFO:Caching -- RooAbsCachedPdf::getCache(lmorph) creating new cache 0x44affd0 with pdf g1_MORPH_g2_CACHE_Obs[alpha,x] for nset (x) with code 0 from preexisting content.
[#1] INFO:Caching -- RooAbsCachedPdf::getCache(lmorph) creating new cache 0x3976b10 with pdf g1_MORPH_g2_CACHE_Obs[alpha,x] for nset (x) with code 0 from preexisting content.
[#1] INFO:Caching -- RooAbsCachedPdf::getCache(lmorph) creating new cache 0x3875020 with pdf g1_MORPH_g2_CACHE_Obs[alpha,x] for nset (x) with code 0 from preexisting content.
[#1] INFO:Caching -- RooAbsCachedPdf::getCache(lmorph) creating new cache 0x3875020 with pdf g1_MORPH_g2_CACHE_Obs[alpha,x] for nset (x) with code 0 from preexisting content.
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooConstVar.h"
#include "RooPolynomial.h"
#include "RooNLLVar.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "RooPlot.h"
#include "TH1.h"
using namespace RooFit ;
void rf705_linearmorph()
{
// C r e a t e e n d p o i n t p d f s h a p e s
// ------------------------------------------------------
// Observable
RooRealVar x("x","x",-20,20) ;
// Lower end point shape: a Gaussian
RooRealVar g1mean("g1mean","g1mean",-10) ;
RooGaussian g1("g1","g1",x,g1mean,RooConst(2)) ;
// Upper end point shape: a Polynomial
RooPolynomial g2("g2","g2",x,RooArgSet(RooConst(-0.03),RooConst(-0.001))) ;
// C r e a t e i n t e r p o l a t i n g p d f
// -----------------------------------------------
// Create interpolation variable
RooRealVar alpha("alpha","alpha",0,1.0) ;
// Specify sampling density on observable and interpolation variable
x.setBins(1000,"cache") ;
alpha.setBins(50,"cache") ;
// Construct interpolating pdf in (x,a) represent g1(x) at a=a_min
// and g2(x) at a=a_max
RooIntegralMorph lmorph("lmorph","lmorph",g1,g2,x,alpha) ;
// P l o t i n t e r p o l a t i n g p d f a t v a r i o u s a l p h a
// -----------------------------------------------------------------------------
// Show end points as blue curves
RooPlot* frame1 = x.frame() ;
g1.plotOn(frame1) ;
g2.plotOn(frame1) ;
// Show interpolated shapes in red
alpha.setVal(0.125) ;
lmorph.plotOn(frame1,LineColor(kRed)) ;
alpha.setVal(0.25) ;
lmorph.plotOn(frame1,LineColor(kRed)) ;
alpha.setVal(0.375) ;
lmorph.plotOn(frame1,LineColor(kRed)) ;
alpha.setVal(0.50) ;
lmorph.plotOn(frame1,LineColor(kRed)) ;
alpha.setVal(0.625) ;
lmorph.plotOn(frame1,LineColor(kRed)) ;
alpha.setVal(0.75) ;
lmorph.plotOn(frame1,LineColor(kRed)) ;
alpha.setVal(0.875) ;
lmorph.plotOn(frame1,LineColor(kRed)) ;
alpha.setVal(0.95) ;
lmorph.plotOn(frame1,LineColor(kRed)) ;
// S h o w 2 D d i s t r i b u t i o n o f p d f ( x , a l p h a )
// -----------------------------------------------------------------------
// Create 2D histogram
TH1* hh = lmorph.createHistogram("hh",x,Binning(40),YVar(alpha,Binning(40))) ;
hh->SetLineColor(kBlue) ;
// F i t p d f t o d a t a s e t w i t h a l p h a = 0 . 8
// -----------------------------------------------------------------
// Generate a toy dataset at alpha = 0.8
alpha=0.8 ;
RooDataSet* data = lmorph.generate(x,1000) ;
// Fit pdf to toy data
lmorph.setCacheAlpha(kTRUE) ;
lmorph.fitTo(*data,Verbose(kTRUE)) ;
// Plot fitted pdf and data overlaid
RooPlot* frame2 = x.frame(Bins(100)) ;
data->plotOn(frame2) ;
lmorph.plotOn(frame2) ;
// S c a n - l o g ( L ) v s a l p h a
// -----------------------------------------
// Show scan -log(L) of dataset w.r.t alpha
RooPlot* frame3 = alpha.frame(Bins(100),Range(0.1,0.9)) ;
// Make 2D pdf of histogram
RooNLLVar nll("nll","nll",lmorph,*data) ;
nll.plotOn(frame3,ShiftToZero()) ;
lmorph.setCacheAlpha(kFALSE) ;
TCanvas* c = new TCanvas("rf705_linearmorph","rf705_linearmorph",800,800) ;
c->Divide(2,2) ;
c->cd(1) ; gPad->SetLeftMargin(0.15) ; frame1->GetYaxis()->SetTitleOffset(1.6) ; frame1->Draw() ;
c->cd(2) ; gPad->SetLeftMargin(0.20) ; hh->GetZaxis()->SetTitleOffset(2.5) ; hh->Draw("surf") ;
c->cd(3) ; gPad->SetLeftMargin(0.15) ; frame3->GetYaxis()->SetTitleOffset(1.4) ; frame3->Draw() ;
c->cd(4) ; gPad->SetLeftMargin(0.15) ; frame2->GetYaxis()->SetTitleOffset(1.4) ; frame2->Draw() ;
}
Author
07/2008 - Wouter Verkerke

Definition in file rf705_linearmorph.C.