SPlot tutorial.
This tutorial shows an example of using SPlot to unfold two distributions. The physics context for the example is that we want to know the isolation distribution for real electrons from Z events and fake electrons from QCD. Isolation is our 'control' variable To unfold them, we need a model for an uncorrelated variable that discriminates between Z and QCD. To do this, we use the invariant mass of two electrons. We model the Z with a Gaussian and the QCD with a falling exponential.
Note, since we don't have real data in this tutorial, we need to generate toy data. To do that we need a model for the isolation variable for both Z and QCD. This is only used to generate the toy data, and would not be needed if we had real data.
Processing /builddir/build/BUILD/root-6.10.00/tutorials/roostats/rs301_splot.C...
[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:
import model
[#1] INFO:ObjectHandling -- RooWorkspace::import(myWS) importing RooProdPdf::zModel
[#1] INFO:ObjectHandling -- RooWorkspace::import(myWS) importing RooRealVar::invMass
[#1] INFO:ObjectHandling -- RooWorkspace::import(myWS) importing RooRealVar::sigmaZ
[#1] INFO:ObjectHandling -- RooWorkspace::import(myWS) importing RooRealVar::isolation
[#1] INFO:ObjectHandling -- RooWorkspace::import(myWS) importing RooRealVar::zYield
[#1] INFO:ObjectHandling -- RooWorkspace::import(myWS) importing RooExponential::qcdMassModel
[#1] INFO:ObjectHandling -- RooWorkspace::import(myWS) importing RooExponential::qcdIsolationModel
[#1] INFO:ObjectHandling -- RooWorkspace::import(myWS) importing RooRealVar::qcdYield
make data set and
import to workspace
[#1] INFO:ObjectHandling -- RooWorkSpace::import(myWS) changing name of dataset from modelData to data
Calculate sWeights
[#1]
INFO:Minization -- The following expressions have been identified
as constant and will be precalculated and cached: (zIsolationModel,qcdIsolationModel)
[#1]
INFO:Minization -- The following expressions will be evaluated in cache-and-track mode: (mZModel,qcdMassModel)
**********
**********
**********
**********
PARAMETER DEFINITIONS:
NO. NAME VALUE STEP SIZE LIMITS
1 qcdMassDecayConst -1.00000e-02 2.00000e+01 -1.00000e+02 1.00000e+02
2 qcdYield 1.00000e+02 5.00000e+01 0.00000e+00 1.00000e+03
3 sigmaZ 2.00000e+00 1.00000e+00 0.00000e+00 1.00000e+01
4 zYield 5.00000e+01 2.50000e+01 0.00000e+00 1.00000e+03
**********
**********
**********
**********
**********
**********
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=1901.86 FROM MIGRAD STATUS=INITIATE 18 CALLS 19 TOTAL
EDM= unknown STRATEGY= 1 NO
ERROR MATRIX
EXT PARAMETER CURRENT GUESS STEP FIRST
NO. NAME VALUE
ERROR SIZE DERIVATIVE
1 qcdMassDecayConst -1.00000e-02 2.00000e+01 2.01358e-01 -1.06814e+05
2 qcdYield 1.00000e+02 5.00000e+01 1.72186e-01 -1.57317e+03
3 sigmaZ 2.00000e+00 1.00000e+00 2.57889e-01 3.62916e+01
4 zYield 5.00000e+01 2.50000e+01 1.18625e-01 -1.41930e+03
ERR DEF= 0.5
MIGRAD MINIMIZATION HAS CONVERGED.
MIGRAD WILL VERIFY CONVERGENCE AND
ERROR MATRIX.
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=849.923 FROM MIGRAD STATUS=CONVERGED 110 CALLS 111 TOTAL
EDM=3.1409e-06 STRATEGY= 1
ERROR MATRIX ACCURATE
EXT PARAMETER STEP FIRST
NO. NAME VALUE
ERROR SIZE DERIVATIVE
1 qcdMassDecayConst -9.30176e-03 7.55562e-04 1.52115e-07 2.51004e+01
2 qcdYield 6.22140e+02 2.52789e+01 1.04861e-03 -1.45735e-02
3 sigmaZ 1.95257e+00 8.09927e-02 4.09416e-04 -7.77193e-02
4 zYield 3.77836e+02 1.98770e+01 8.24140e-04 -6.51095e-03
ERR DEF= 0.5
EXTERNAL
ERROR MATRIX. NDIM= 25 NPAR= 4 ERR DEF=0.5
5.709e-07 1.999e-04 -1.007e-06 -1.999e-04
1.999e-04 6.396e+02 -9.256e-02 -1.747e+01
-1.007e-06 -9.256e-02 6.561e-03 9.257e-02
-1.999e-04 -1.747e+01 9.257e-02 3.953e+02
PARAMETER CORRELATION COEFFICIENTS
NO. GLOBAL 1 2 3 4
1 0.02260 1.000 0.010 -0.016 -0.013
2 0.05626 0.010 1.000 -0.045 -0.035
3 0.07351 -0.016 -0.045 1.000 0.057
4 0.06697 -0.013 -0.035 0.057 1.000
**********
**********
**********
**********
**********
** 9 **HESSE 2000
**********
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=849.923 FROM HESSE STATUS=OK 23 CALLS 134 TOTAL
EDM=3.13931e-06 STRATEGY= 1
ERROR MATRIX ACCURATE
EXT PARAMETER INTERNAL INTERNAL
NO. NAME VALUE
ERROR STEP SIZE VALUE
1 qcdMassDecayConst -9.30176e-03 7.55563e-04 3.04229e-08 -9.30176e-05
2 qcdYield 6.22140e+02 2.52790e+01 2.09721e-04 2.46778e-01
3 sigmaZ 1.95257e+00 8.09935e-02 8.18832e-05 -6.55413e-01
4 zYield 3.77836e+02 1.98772e+01 1.64828e-04 -2.46827e-01
ERR DEF= 0.5
EXTERNAL
ERROR MATRIX. NDIM= 25 NPAR= 4 ERR DEF=0.5
5.709e-07 2.002e-04 -1.009e-06 -2.002e-04
2.002e-04 6.396e+02 -9.273e-02 -1.749e+01
-1.009e-06 -9.273e-02 6.561e-03 9.273e-02
-2.002e-04 -1.749e+01 9.273e-02 3.953e+02
PARAMETER CORRELATION COEFFICIENTS
NO. GLOBAL 1 2 3 4
1 0.02264 1.000 0.010 -0.016 -0.013
2 0.05634 0.010 1.000 -0.045 -0.035
3 0.07364 -0.016 -0.045 1.000 0.058
4 0.06707 -0.013 -0.035 0.058 1.000
[#1]
INFO:Minization -- The following expressions have been identified
as constant and will be precalculated and cached: (zModel,qcdModel)
[#1]
INFO:
Eval -- Checking Likelihood normalization:
[#1]
INFO:
Eval -- Yield of specie
Sum of Row in Matrix Norm
[#1]
INFO:
Eval -- 377.841 377.842 0.999999
[#1]
INFO:
Eval -- 622.16 622.16 0.999999
Check SWeights:
Yield of Z is 377.841. From sWeights it is 377.841
Yield of QCD is 622.16. From sWeights it is 622.16
import new dataset with sWeights
[#1]
INFO:
ObjectHandling -- RooWorkSpace::import(myWS) changing name of dataset from data to dataWithSWeights
[#1] INFO:ObjectHandling -- RooWorkspace::import(myWS) importing RooRealVar::zYield_sw
[#1] INFO:ObjectHandling -- RooWorkspace::import(myWS) importing RooRealVar::qcdYield_sw
[#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: (zIsolationModel,qcdIsolationModel)
[#1]
INFO:Minization -- The following expressions will be evaluated in cache-and-track mode: (mZModel,qcdMassModel)
[#1] INFO:Plotting -- RooAbsPdf::plotOn(model) directly selected PDF components: (zModel)
[#1] INFO:Plotting -- RooAbsReal::plotOn(model) plot on invMass integrates over variables (isolation)
[#1] INFO:Plotting -- RooAbsPdf::plotOn(model) indirectly selected PDF components: (qcdMassModel,qcdIsolationModel)
using namespace RooFit;
using namespace RooStats;
void rs301_splot()
{
AddModel(wspace);
AddData(wspace);
DoSPlot(wspace);
MakePlots(wspace);
delete wspace;
}
Double_t lowRange = 00, highRange = 200;
RooRealVar invMass(
"invMass",
"M_{inv}", lowRange, highRange,
"GeV");
RooRealVar isolation(
"isolation",
"isolation", 0., 20.,
"GeV");
std::cout << "make z model" << std::endl;
RooRealVar mZ(
"mZ",
"Z Mass", 91.2, lowRange, highRange);
RooRealVar sigmaZ(
"sigmaZ",
"Width of Gaussian", 2,0,10,
"GeV");
RooGaussian mZModel(
"mZModel",
"Z+jets Model", invMass, mZ, sigmaZ);
mZ.setConstant();
"z isolation decay constant", -1);
RooExponential zIsolationModel(
"zIsolationModel",
"z isolation model",
isolation, zIsolDecayConst);
std::cout << "make qcd model" << std::endl;
"Decay const for QCD mass spectrum",
-0.01, -100, 100,"1/GeV");
invMass, qcdMassDecayConst);
"Et resolution constant", -.1);
RooExponential qcdIsolationModel(
"qcdIsolationModel",
"QCD isolation model",
isolation, qcdIsolDecayConst);
RooProdPdf qcdModel(
"qcdModel",
"2-d model for QCD",
RooRealVar zYield(
"zYield",
"fitted yield for Z",50 ,0.,1000) ;
RooRealVar qcdYield(
"qcdYield",
"fitted yield for QCD", 100 ,0.,1000) ;
std::cout << "make full model" << std::endl;
std::cout << "import model" << std::endl;
}
std::cout << "make data set and import to workspace" << std::endl;
}
std::cout << "Calculate sWeights" << std::endl;
std::cout << "Check SWeights:" << std::endl;
std::cout << std::endl << "Yield of Z is "
<< zYield->
getVal() <<
". From sWeights it is "
std::cout << "Yield of QCD is "
<< qcdYield->
getVal() <<
". From sWeights it is "
<< std::endl;
for(
Int_t i=0; i < 10; i++)
{
std::cout <<
"z Weight " << sData->
GetSWeight(i,
"zYield")
<<
" qcd Weight " << sData->
GetSWeight(i,
"qcdYield")
<< std::endl;
}
std::cout << std::endl;
std::cout << "import new dataset with sWeights" << std::endl;
}
std::cout << "make plots" << std::endl;
frame->
SetTitle(
"Fit of model to discriminating variable");
frame2->
SetTitle(
"isolation distribution for Z");
frame2->Draw() ;
frame3->
SetTitle(
"isolation distribution for QCD");
frame3->Draw() ;
}