eek in the Woods 2005
RooFit Introduction
Week in the Woods
2005.6.14
jeremy gogos
my gogos
eek in the Woods 2005
Documentation
RooFit Homepage
http://roofit.sourceforge.net
Three tutorial talks by Wouter Verkerke available at
http://roofit.sourceforge.net/docs/tutorial/index.html
This talk relies heavily on the documentation from the website.
my gogos
eek in the Woods 2005
Overview
• RooFit Objective
• Design Philosophy
• Implementation
• Basic RooFit Classes
• RooFit PDF Classes
• Fitting and Generating
• RooNeuOsc PDF
my gogos
eek in the Woods 2005
Objective
RooFit aims to provide an object oriented framework which extends ROOT’s functionality
for fitting, minimization, and the generation of toy monte carlo.
Theory predicts distribution of observables ~
x in terms of
• Physical parameters p~ (∆m2 , for example)
• Parameters ~q to describe detector effects
These go into a probability distribution function F (~
x|~
p, ~q)
RooFit connects these concepts
my gogos
eek in the Woods 2005
Design Philosophy
Object oriented - everything represented by C++ object
• variables
• data points
• integrals
• PDF
All are classes
my gogos
eek in the Woods 2005
Implementation
• Add on to ROOT
• Two distinct RooFit packages, RooFitCore and RooFitModels (∼ 2.5M B code)
• Compile, create libRooFitCore.so, libRooFitModels.so
• RooFit objects persistable
my gogos
eek in the Woods 2005
Basic RooFit Objects
RooFit has its own basic types which
• are self documenting
• can carry errors, units . . .
• are manipulable like basic types
my gogos
eek in the Woods 2005
Basic RooFit Objects
RooFit’s basic types include
• RooAbsArg - the base class for all value-storing classes
• RooRealVar - usual Double precision type
• RooPolyVar - polynomial
• RooRealIntegral - class to represent integral of function over variable(s)
• RooCategory - class for discrete variables
• RooAbsPdf - base class for PDFs
my gogos
eek in the Woods 2005
Basic RooFit Objects (continued)
Also included are classes which make managing data sets easy
• RooArgSet - no repeat elements, no ordering
• RooArgList - repeated elements ok, order maintained
• RooDataSet - a collection of identical RooArgSets/RooArgLists (unbinned)
• RooDataHist - similar to RooDataSet, but binned
The usual iterator, access via element name, numEntries() stuff implemented
my gogos
eek in the Woods 2005
RooFit PDFs
RooAbsPDF is base class from which all PDF classes inherit. It provides the framework for
• Automatic Normalization (even for Dim > 1)
• Parameter or Observable Interpretation
• Plotting
• Generating Observables
• Fitting
Also RooGenericPdf for quick PDF construction
my gogos
eek in the Woods 2005
RooFit PDFs (continued)
A list of the current PDFs
Roo2DKeysPdf
RooArgusBG
RooBCPEffDecay
RooBCPGenDecay
RooBDecay
RooBMixDecay
RooBifurGauss
RooBlindTools
RooBreitWigner
RooBukinPdf
RooCBShape
RooChebychev
RooDecay
RooDstD0BG
RooExponential
RooGExpModel
RooGaussModel
RooGaussian
RooKeysPdf
RooLandau
RooNonCPEigenDecay
RooNovosibirsk
RooParametricStepFunction
RooPolynomial
RooUnblindCPAsymVar
RooUnblindOffset
RooUnblindPrecision
RooUnblindUniform
RooVoigtian
I am working on RooNeuOsc
my gogos
eek in the Woods 2005
RooFit PDFs (continued)
RooFit PDFs can be used to create more realistic models via
• Addition
• Multiplication
• Composition
• Convolution
my gogos
eek in the Woods 2005
Fitting and Generating
With a PDF in hand, fitting and generating are very simple.
• Declare variables
RooRealVar x("x","x",-10.,10.);
RooRealVar sigma("sigma","sigma",0.,10.);
RooRealVar mean("mean","mean",-10.,10.);
sigma.setVal(1.5);
mean.setVal(0.);
• Declare PDF
my gogos
RooGaussian *gauss
= new RooGaussian("gauss","gauss",x,mean,sigma);
eek in the Woods 2005
Fitting and Generating (continued)
• Generate and Fit
RooDataSet *data = gauss.generate(x,10000);
gauss.fitTo(*data);
RooPlot *xframe = x.frame();
data->plotOn(xframe);
gauss.plotOn(xframe);
xframe->Draw();
• Also have RooMCStudy class which manages ensemble of ToyMC
my gogos
RooMCStudy manager(gauss,gauss,x,‘‘’’,‘‘mhv’’);
manager.generateandFit(1000,100);
RooMCStudy::run: Generating and fitting sample 999
RooMCStudy::run: Generating and fitting sample 999
.
.
.
eek in the Woods 2005
Fitting Example - RooNeuOsc PDF
First, generate fake “beam” data sample
• 500 events with a flat energy spectrum, 0 < E < 10GeV
• L = 700km, ∆m2 = 2.5 × 10−3 eV 2 , sin2 (2θ) = 1
• Oscillate away neutrinos based on usual P (νµ → ντ ), which leaves 341 events
htemp
P4Neu[3]
my gogos
Entries
341
Mean
5.99
RMS
2.562
Underflow
0
Overflow
0
Integral
341
10
8
6
4
2
0
0
2
4
6
8
10
eek in the Woods 2005
RooNeuOsc PDF (continued)
gSystem->Load("$CODEDIR/RooFit/RooFitCore/tmp/libRooFitCore.so");
gSystem->Load("$CODEDIR/RooFit/RooFitModels/tmp/libRooFitModels.so");
//reading in neutrino information
TFile f("truneus");
TTree *datatree = (TTree*)(f.Get("neutree"));
TBranch *P4Neu = datatree->GetBranch("P4Neu");
Float_t p4neu[4];
P4Neu->SetAddress(p4neu);
RooRealVar
RooRealVar
RooRealVar
RooRealVar
sin2theta("sin2theta","mixing angle term",0.,1.);
delmsqr("delmsqr","mass squared difference",0.,1.);
L("L","Length of Flight",0.,13000.); // km
E("E","Neutrino Energy",0.,10.); // GeV
RooArgSet neuargs(L,E,"Neuargs");
RooDataSet neudataset("neudataset","neudataset",neuargs);
for(int i=0;i<datatree->GetEntries();i++){
datatree->GetEvent(i);
L.setVal(700.);
E = p4neu[3];
neudataset.add(neuargs,1.0);
}
RooNeuOsc *oscpdf =
new RooNeuOsc("oscpdf","oscpdf", sin2theta, delmsqr, L, E);
RooArgSet *depSet = (RooArgSet*)(oscpdf->getDependents(neuargs));
RooArgSet *paramSet = (RooArgSet*)(oscpdf->getParameters(neuargs));
my gogos
eek in the Woods 2005
RooNeuOsc PDF (continued)
depSet->Print("v");
paramSet->Print("v");
RooFitResult *fitres = (RooFitResult*)(oscpdf->fitTo(neudataset,"rsv"));
fitres->Print();
TFile *outfile = new TFile("outfile","RECREATE");
outfile->cd();
fitres->Write();
outfile->Close();
The output...
OBJ: TStyle
videoStyle
Video Style : 0 at: 0xae49e80
Processing macros/fit_macro.C...
RooFit v1.92 -- Developed by Wouter Verkerke and David Kirkby
Copyright (C) 2000-2005 University of California & Stanford University
All rights reserved, please read http://roofit.sourceforge.net/license.txt
RooDataSet::neuinfoD: "neuinfoD"
Contains 341 entries
RooArgSet::dependents:
1) RooRealVar::L : 700.00 L(0 - 13000)
2) RooRealVar::E : 8.6804 L(0 - 10)
RooArgSet::parameters:
1) RooRealVar::delmsqr
: 0.50000 L(0 - 1)
2) RooRealVar::sin2theta : 0.50000 L(0 - 1)
RooMinuit::optimizeConst: activating const optimization
my gogos
eek in the Woods 2005
RooNeuOsc PDF (continued)
RooAbsOptGoodnessOfFit::constOptimize(nll) Action=Activate
RooAbsReal::optimizeConst: The following unused tree branches are
deactivated: (L,E)
RooMinuit::synchronize: WARNING: no initial error estimate available for
delmsqr: using 0.1
RooMinuit::synchronize: WARNING: no initial error estimate available for
sin2theta: using 0.1
.
.
.
RooFitResult: minimized FCN value: 3801.43, estimated distance to minimum: 1.30497e-08
coviarance matrix quality: Full, accurate covariance matrix
Floating Parameter
-------------------delmsqr
sin2theta
my gogos
FinalValue +/- Error
-------------------------2.2850e-03 +/- 3.01e-08
1.0000e-00 +/- 1.00e-03
eek in the Woods 2005
RooNeuOsc PDF (continued)
energy (GeV)
my gogos
2
1.5
1
0.5
0
0
2
4
6
8
10
eek in the Woods 2005
Conclusions
• RooFit basic operations (e.g. gaussian) easy to learn and fast
• Fitting with my RooNeuOsc PDF slow (several hours for 341 events), but room for
optimization
• Documentation worsens as operations become more complex, but support available
• Worth learning, in my humble opinion
my gogos
© Copyright 2026 Paperzz