Roofit Tutorial Plot
Roofit Tutorial Plot
RooDataSet(x,y,z)
- Binning
- Projection (x,y,z)
(x)
- Normalization
RooAbsPdf(x,y,z)
1-Dimensional plots
The basics
Title of RooRealVar
// Alternate frame() methods // change default range, binning RooPlot* xframe = x.frame(-5,5) ; RooPlot* xframe = x.frame(40) ;
// Adding a dataset also updates // the set of normalization observables frame->getNormVars()->Print(1) ; (x,y,z)
PDFs added after this dataset that depend on y,z will be normalized & projected over y,z
Wouter Verkerke, UCSB
(Re)define manually which of the // Enter custom definition of observables PDF variables xframe->updateNormVars(RooArgSet(x,y,z)) ; are observables p->plotOn(xframe) ;
Curve/histogram 2 calculation
frame->chiSquare() ; frame->chiSquare(curveName,histName) ;
Wouter Verkerke, UCSB
Projection via Integration Projecting discrete vs real observables Projection via data averaging Mixing projection methods
Pf ( x) =
f ( x, p) dp
f ( x, p) dxdp
Plotted observables
Wouter Verkerke, UCSB
Pp ( x) =
p( x, y)dxdy p( x, y)dx
p( x, y)dy
Pp ( y ) =
p( x, y)dxdy
Wouter Verkerke, UCSB
g ( x) g ( y )dy
g ( x) g ( y )dy
g ( x) g ( x )dx
g ( x) g ( y )dx
Pp (t ) =
Use summation instead of integration for discrete states
= =
Expand summation
pmixed (t ) + punmixed (t )
mixed
mS
Pp ( x) =
p( x, y)dxdy
p( x, y) dy
1 Pp ( x) = N
i =1, N
p( x, y )dx
i
p ( x, yi )
Can be used to cancel the effect of a disagreement between data and PDF in a projected observable
Example: per-event errors: PDF is usually flat in dtErr, distribution in data is usually peaked.
// Plot bmixPdf, projecting dterr with data bmixPdf->plotOn(dtframe,ProjWData(dterr,projData)) ; RooAbsReal::plotOn(bmixPdf) plot on dt integrates over variables (mixState) RooAbsReal::plotOn(bmixPdf) plot on dt averages using data variables (dtErr)
ProjWData only controls how observables are projected. It does not override which observables are projected
Wouter Verkerke, UCSB
Projecting per-event errors with data RooPlot* dtFrame = dt.frame() ; data->plotOn(dtFrame) ; bmixPdf.plotOn(dtFrame, ProjWData(dterr,projData)); dtFrame->Draw() ; OK
Choosing data averaging instead of integration changes the meaning of the projected function
The theoretical model / experimental data distinction is blurred: the plotted curve takes part of its behavior from the dataset Often applied to non-physics observables (e.g. per-event errors)
Shape of per-event error distribution irrelevant to physics and may be hard to model correctly in a PDF
Can also to applied to well-modeled physics observable: Example: plot t distribution of B-mixing PDF while
projecting the mix state via integration True model/experimental data comparison projecting the mix state with data averaging Compare only dt shape aspect of model with data Any effects that purely arise from PDF/data discrepancy in B 0/B0 Wouter Verkerke, UCSB counter are taken out
Projections with large datasets can be accelerated enormously by using binned projection data sets
Works the same way, just provide a binned dataset RooPlot* dtFrame = dt.frame() ; data->plotOn(dtFrame) ; dterr.setFitBins(50) ; RooDataHist projData(projData,projData,dtErr,data) ; bmixPdf.plotOn(dtFrame,ProjWData(projData)); Minor loss of precision may occur, but with sufficient data and a prudent binning net loss may be less than plotting precision Example: unbinned projection with 20K events: 51.2 sec binned projection with 100 bins: 0.2 sec
Any projected PDF observable may be averaged with data instead of integrated Final projection may be combination of data-averaging & integration
Slice in y
Slice in x
y = y.getVal()
x = x.getVal()
Slicing can be done in real and discrete dimensions Slice set can have an any number of dimensions
Wouter Verkerke, UCSB
Pf (t , M )dt 1
Ntotal
The RooAbsData::plotOn() function with cut gives the full (uncut) number of events to the RooPlot so that the final normalization comes out as
The normalization of the PDF slice curve reflects the PDFs prediction of the slice fraction Wouter Verkerke, UCSB
Example plot:
RooPlot* dtframe = dt.frame() ; data->plotOn(dtframe) ; // not a slice dtErr=0.1 ; bmix.plotOn(dtframe,Slice(dtErr)) ; dtErr=0.5 ; bmix.plotOn(dtframe,Slice(dtErr)) ; dtErr=1.0 ; bmix.plotOn(dtframe,Slice(dtErr)) ; dtframe->Draw() ;
1) 2) 3)
Generate a sufficiently large ToyMC sample to be plotted Reduce the ToyMC data to the band to be plotted Plot the PDF the usual way, projecting out all unplotted observables via data averaging. Use the reduce ToyMC set as weighting dataset
Wouter Verkerke, UCSB
RooDataSet* mbSliceData = data->reduce("mb>5.27") ; mbSliceData->plotOn(dtframe2, "mixState==mixState::mixed) RooDataSet *toyMC = model.generate( RooArgSet(dt,mixState,tagFlav,mB), 80000); RooDataSet* mbSliceToyMC = toyMC->reduce(mb>5.27); model.plotOn(dtframe2,Slice(mixState), ProjWData(mb,mbSliceToyMC))
Reduce the toyMC data to the band to be plotted Plot the PDF the usual way, projecting out all unplotted observables via data averaging.
Integrated projection of data/PDF on X doesnt reflect signal/background discrimination power of PDF in y,z
Wouter Verkerke, UCSB
The createProjection() method create a RooPlot* pframe = nll->frame(4.5,7.5,100) ; data->plotOn(pframe) ; projection of sum over x, with (y,z) as observables:
RooDataSet* sliceData =r data->reduce(RooArgSet(x,y,z),"nll<5.2") ;
sum.plotOn(xframe2,"L",1.0, RooAbsReal::Relative,sliceData) ;
g ( x, p r
Reduce ToyMC projection dataset with RooPlot* pframe = nll->frame(4.5,7.5,100) ; cut on per-event likelihood
data->plotOn(pframe) ; RooDataSet* sliceData = data->reduce(RooArgSet(x,y,z),"nll<5.2") ; RooPlot* xframe2 = x.frame(40) ; sliceData->plotOn(xframe2) ; sum.plotOn(xframe2,ProjWData(sliceData)) ;
Component plotting
+
RooProdPdf sig RooProdPdf bkg
*
RooGaussian sigDE RooGaussian sigMB
*RooAddPdf RooGaussian
bkgDE bkgMB
+
RooGaussian bkgMBpeak RooGaussian bkgMBcont
Wouter Verkerke, UCSB
RooAddPdf model
2 Implicit selection
+
RooProdPdf sig
*
RooGaussian sigDE RooGaussian sigMB
RooProdPdf bkg
* RooGaussian
bkgDE
RooAddPdf bkgMB
+
RooGaussian bkgMBpeak RooGaussian bkgMBcont
Wouter Verkerke, UCSB
RooAddPdf model
2 Implicit selection
+
RooProdPdf sig
*
RooGaussian sigDE RooGaussian sigMB
RooProdPdf bkg
*
RooGaussian bkgDE RooAddPdf bkgMB
+
RooGaussian bkgMBpeak RooGaussian bkgMBcont
Wouter Verkerke, UCSB
+
RooProdPdf sig RooProdPdf bkg
RooGaussian sigDE
* RooGaussian
sigMB
RooGaussian bkgDE
* RooAddPdf
bkgMB
+
pdf->plotOn(frame,Components(bkg)) ; RooAbsPdf::plotCompOn(model) directly selected PDF components: (bkg) RooAbsPdf::plotCompOn(model) indirectly selected PDF components: (bkgMBPeak,bkgMBCont,bkg,model)
RooGaussian bkgMBpeak RooGaussian bkgMBcont
RooSimultaneous
View of RooSimultaneous in 2D
Ro oS im
ind ex ca te go ry
Why does plotSliceOn() need data? Normalization works like in regular plotSliceOn()
RooAbsData::plotOn(frame,Cut(cutExpr)) stores total number of events without cut RooAbsPdf::plotOn(frame,Slice()) normalizes projection to 1 * fslice RooSimultaneous needs projection dataset to calculate fslice
Wouter Verkerke, UCSB
Ro oS im
ind ex
ca te go ry
index = Kaon
Apparent problem: need 2 projection dataset with different sizes Solution: RooSimultaneous::plotOn automatically trims the dataset when passing it on to the components plotOn()
Wouter Verkerke, UCSB
RooSimultaneous index projection uses entire dataset Component dterr projection uses subset of dataset with cat==A
Wouter Verkerke, UCSB
Miscellaneous
Asymmetry plots
RooFit supports generic asymmetry plotting in any RooCategory with (+1,-1) or (+1,0,-1) states
Example: mixState asymmetry of BMixing PDF & data RooPlot* dtframe = dt.frame(40) ; data->plotOn(dtframe,Asymmetry(mixState)) ; bmix->plotOn(dtframe,Asymmetry(mixState), ProjWData(dterr,data)) ; Can be combined with other plot arguments
RooAbsReal::plotOn(Asymmetry())
All regular PDF projection techniques work:
Projection via integration Projection with data averaging Slice plotting ToyMC region plotting
Adaptive NLL sampling used (standard for all RooPlot curves). Explicit control over resolution tunes CPU/precision tradeoff Optional automatic baseline shift to zero
prod.plotNLLContours(data,meanx,sigmax) ;