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

Detailed Description

View in nbviewer Open in SWAN
Multidimensional models: use of tailored pdf as conditional pdfs.s

pdf = gauss(x,f(y),sx | y ) with f(y) = a0 + a1*y

#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooDataHist.h"
#include "RooGaussian.h"
#include "RooPolyVar.h"
#include "RooProdPdf.h"
#include "RooPlot.h"
#include "TRandom.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "TH1.h"
using namespace RooFit;
RooDataSet *makeFakeDataXY();
{
// S e t u p c o m p o s e d m o d e l g a u s s ( x , m ( y ) , s )
// -----------------------------------------------------------------------
// Create observables
RooRealVar x("x", "x", -10, 10);
RooRealVar y("y", "y", -10, 10);
// Create function f(y) = a0 + a1*y
RooRealVar a0("a0", "a0", -0.5, -5, 5);
RooRealVar a1("a1", "a1", -0.5, -1, 1);
RooPolyVar fy("fy", "fy", y, RooArgSet(a0, a1));
// Create gauss(x,f(y),s)
RooRealVar sigma("sigma", "width of gaussian", 0.5, 0.1, 2.0);
RooGaussian model("model", "Gaussian with shifting mean", x, fy, sigma);
// Obtain fake external experimental dataset with values for x and y
RooDataSet *expDataXY = makeFakeDataXY();
// G e n e r a t e d a t a f r o m c o n d i t i o n a l p . d . f m o d e l ( x | y )
// ---------------------------------------------------------------------------------------------
// Make subset of experimental data with only y values
RooDataSet *expDataY = (RooDataSet *)expDataXY->reduce(y);
// Generate 10000 events in x obtained from _conditional_ model(x|y) with y values taken from experimental data
RooDataSet *data = model.generate(x, ProtoData(*expDataY));
data->Print();
// F i t c o n d i t i o n a l p . d . f m o d e l ( x | y ) t o d a t a
// ---------------------------------------------------------------------------------------------
model.fitTo(*expDataXY, ConditionalObservables(y), PrintLevel(-1));
// P r o j e c t c o n d i t i o n a l p . d . f o n x a n d y d i m e n s i o n s
// ---------------------------------------------------------------------------------------------
// Plot x distribution of data and projection of model on x = 1/Ndata sum(data(y_i)) model(x;y_i)
RooPlot *xframe = x.frame();
expDataXY->plotOn(xframe);
model.plotOn(xframe, ProjWData(*expDataY));
// Speed up (and approximate) projection by using binned clone of data for projection
RooAbsData *binnedDataY = expDataY->binnedClone();
model.plotOn(xframe, ProjWData(*binnedDataY), LineColor(kCyan), LineStyle(kDotted));
// Show effect of projection with too coarse binning
((RooRealVar *)expDataY->get()->find("y"))->setBins(5);
RooAbsData *binnedDataY2 = expDataY->binnedClone();
model.plotOn(xframe, ProjWData(*binnedDataY2), LineColor(kRed));
// Make canvas and draw RooPlots
new TCanvas("rf303_conditional", "rf303_conditional", 600, 460);
gPad->SetLeftMargin(0.15);
xframe->GetYaxis()->SetTitleOffset(1.2);
xframe->Draw();
}
RooDataSet *makeFakeDataXY()
{
RooRealVar x("x", "x", -10, 10);
RooRealVar y("y", "y", -10, 10);
RooArgSet coord(x, y);
RooDataSet *d = new RooDataSet("d", "d", RooArgSet(x, y));
for (int i = 0; i < 10000; i++) {
double tmpy = gRandom->Gaus(0, 10);
double tmpx = gRandom->Gaus(0.5 * tmpy, 1);
if (fabs(tmpy) < 10 && fabs(tmpx) < 10) {
x.setVal(tmpx);
y.setVal(tmpy);
d->add(coord);
}
}
return d;
}
#define d(i)
Definition RSha256.hxx:102
PrintLevel
Definition RooMinuit.h:6
@ kRed
Definition Rtypes.h:66
@ kCyan
Definition Rtypes.h:66
@ kDotted
Definition TAttLine.h:48
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
R__EXTERN TRandom * gRandom
Definition TRandom.h:62
#define gPad
RooAbsArg * find(const char *name) const
Find object with given name in list.
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition RooAbsData.h:59
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
RooAbsData * reduce(const RooCmdArg &arg1, const RooCmdArg &arg2=RooCmdArg(), const RooCmdArg &arg3=RooCmdArg(), const RooCmdArg &arg4=RooCmdArg(), const RooCmdArg &arg5=RooCmdArg(), const RooCmdArg &arg6=RooCmdArg(), const RooCmdArg &arg7=RooCmdArg(), const RooCmdArg &arg8=RooCmdArg())
Create a reduced copy of this dataset.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
RooPlot * plotOn(RooPlot *frame, PlotOpt o) const override
Back end function to plotting functionality.
RooDataSet is a container class to hold unbinned data.
Definition RooDataSet.h:57
const RooArgSet * get(Int_t index) const override
Return RooArgSet with coordinates of event 'index'.
RooDataHist * binnedClone(const char *newName=nullptr, const char *newTitle=nullptr) const
Return binned clone of this dataset.
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:43
static RooPlot * frame(const RooAbsRealLValue &var, double xmin, double xmax, Int_t nBins)
Create a new frame for a given variable in x.
Definition RooPlot.cxx:239
TAxis * GetYaxis() const
Definition RooPlot.cxx:1276
void Draw(Option_t *options=nullptr) override
Draw this plot and all of the elements it contains.
Definition RooPlot.cxx:649
Class RooPolyVar is a RooAbsReal implementing a polynomial in terms of a list of RooAbsReal coefficie...
Definition RooPolyVar.h:25
RooRealVar represents a variable that can be changed from the outside.
Definition RooRealVar.h:40
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition TAttAxis.cxx:298
The Canvas class.
Definition TCanvas.h:23
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
Definition TRandom.cxx:274
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 Common.h:18
RooDataSet::modelData[x,y] = 6850 entries
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: activating const optimization
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: deactivating const optimization
[#1] INFO:Plotting -- RooAbsReal::plotOn(model) plot on x averages using data variables (y)
[#1] INFO:Plotting -- RooDataWeightedAverage::ctor(modelDataWgtAvg) constructing data weighted average of function model_Norm[x] over 6850 data points of (y) with a total weight of 6850
.........................................................................................................................................................................................................
[#1] INFO:Plotting -- RooAbsReal::plotOn(model) plot on x averages using data variables (y)
[#1] INFO:Plotting -- RooDataWeightedAverage::ctor(modelDataWgtAvg) constructing data weighted average of function model_Norm[x] over 100 data points of (y) with a total weight of 6850
.........................................................................................................................................................................................................
[#1] INFO:Plotting -- RooAbsReal::plotOn(model) plot on x averages using data variables (y)
[#1] INFO:Plotting -- RooDataWeightedAverage::ctor(modelDataWgtAvg) constructing data weighted average of function model_Norm[x] over 5 data points of (y) with a total weight of 6850
.................................................................................................................................................................................................................................................
Date
July 2008
Author
Wouter Verkerke

Definition in file rf303_conditional.C.