-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add all examples up to 111, update README
- Loading branch information
Showing
9 changed files
with
658 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
##################################### | ||
# | ||
# 'BASIC FUNCTIONALITY' RooFit tutorial macro #105 | ||
# | ||
# Demonstration of binding ROOT Math functions as RooFit functions | ||
# and pdfs | ||
# | ||
# 07/2008 - Wouter Verkerke | ||
# | ||
####################################/ | ||
|
||
from ROOT import * | ||
|
||
def rf105_funcbinding(): | ||
|
||
# B i n d T M a t h : : E r f C f u n c t i o n | ||
# --------------------------------------------------- | ||
|
||
# Bind one-dimensional TMath.Erf function as RooAbsReal function | ||
x = RooRealVar("x","x",-3,3) | ||
erf = RooFit.bindFunction("erf",TMath.Erf,x) | ||
|
||
# Print erf definition | ||
erf.Print() | ||
|
||
# Plot erf on frame | ||
frame1 = x.frame(RooFit.Title("TMath.Erf bound as RooFit function")) | ||
erf.plotOn(frame1) | ||
|
||
|
||
# B i n d R O O T : : M a t h : : b e t a _ p d f C f u n c t i o n | ||
# ----------------------------------------------------------------------- | ||
|
||
# Bind pdf ROOT.Math.Beta with three variables as RooAbsPdf function | ||
x2 = RooRealVar("x2","x2",0,0.999) | ||
a = RooRealVar("a","a",5,0,10) | ||
b = RooRealVar("b","b",2,0,10) | ||
beta = RooFit.bindPdf("beta",ROOT.Math.beta_pdf,x2,a,b) | ||
|
||
# Perf beta definition | ||
beta.Print() | ||
|
||
# Generate some events and fit | ||
data = beta.generate(RooArgSet(x2),10000) | ||
beta.fitTo(*data) | ||
|
||
# Plot data and pdf on frame | ||
frame2 = x2.frame(RooFit.Title("ROOT.Math.Beta bound as RooFit pdf")) | ||
data.plotOn(frame2) | ||
beta.plotOn(frame2) | ||
|
||
|
||
|
||
# B i n d R O O T T F 1 a s R o o F i t f u n c t i o n | ||
# --------------------------------------------------------------- | ||
|
||
# Create a ROOT TF1 function | ||
fa1 = TF1("fa1","sin(x)/x",0,10) | ||
|
||
# Create an observable | ||
x3 = RooRealVar("x3","x3",0.01,20) | ||
|
||
# Create binding of TF1 object to above observable | ||
rfa1 = bindFunction(fa1,x3) | ||
|
||
# Print rfa1 definition | ||
rfa1.Print() | ||
|
||
# Make plot frame in observable, TF1 binding function | ||
frame3 = x3.frame(RooFit.Title("TF1 bound as RooFit function")) | ||
rfa1.plotOn(frame3) | ||
|
||
|
||
|
||
c = TCanvas("rf105_funcbinding","rf105_funcbinding",1200,400) | ||
c.Divide(3) | ||
c.cd(1) ; gPad.SetLeftMargin(0.15) ; frame1.GetYaxis().SetTitleOffset(1.6) ; frame1.Draw() | ||
c.cd(2) ; gPad.SetLeftMargin(0.15) ; frame2.GetYaxis().SetTitleOffset(1.6) ; frame2.Draw() | ||
c.cd(3) ; gPad.SetLeftMargin(0.15) ; frame3.GetYaxis().SetTitleOffset(1.6) ; frame3.Draw() | ||
|
||
c.SaveAs("rf105_funcbinding.png") | ||
|
||
if __name__ == "__main__": | ||
rf105_funcbinding() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
##################################### | ||
# | ||
# 'BASIC FUNCTIONALITY' RooFit tutorial macro #106 | ||
# | ||
# Adding boxes with parameters, to RooPlots. | ||
# Decorating RooPlots with arrows, etc... | ||
# | ||
# | ||
# 07/2008 - Wouter Verkerke | ||
# | ||
####################################/ | ||
|
||
|
||
from ROOT import * | ||
|
||
|
||
def rf106_plotdecoration(): | ||
|
||
# S e t u p m o d e l | ||
# --------------------- | ||
|
||
# Create observables | ||
x = RooRealVar("x","x",-10,10) | ||
|
||
# Create Gaussian | ||
sigma = RooRealVar("sigma","sigma",1,0.1,10) | ||
mean = RooRealVar("mean","mean",-3,-10,10) | ||
gauss = RooGaussian("gauss","gauss",x,mean,sigma) | ||
|
||
# Generate a sample of 1000 events with sigma=3 | ||
data = gauss.generate(RooArgSet(x),1000) | ||
|
||
# Fit pdf to data | ||
gauss.fitTo(data) | ||
|
||
|
||
# P l o t p . d . f a n d d a t a | ||
# ------------------------------------- | ||
|
||
# Overlay projection of gauss on data | ||
frame = x.frame(RooFit.Name("xframe"),RooFit.Title("RooPlot with decorations"),RooFit.Bins(40)) | ||
data.plotOn(frame) | ||
gauss.plotOn(frame) | ||
|
||
|
||
# A d d b o x w i t h p d f p a r a m e t e r s | ||
# ----------------------------------------------------- | ||
|
||
# Left edge of box starts at 55% of Xaxis) | ||
gauss.paramOn(frame,RooFit.Layout(0.55)) | ||
|
||
|
||
# A d d b o x w i t h d a t a s t a t i s t i c s | ||
# ------------------------------------------------------- | ||
|
||
# X size of box is from 55% to 99% of Xaxis range, of box is at 80% of Yaxis range) | ||
data.statOn(frame,RooFit.Layout(0.55,0.99,0.8)) | ||
|
||
|
||
# A d d t e x t a n d a r r o w | ||
# ----------------------------------- | ||
|
||
# Add text to frame | ||
txt = TText(2,100,"Signal") | ||
txt.SetTextSize(0.04) | ||
txt.SetTextColor(kRed) | ||
frame.addObject(txt) | ||
|
||
# Add arrow to frame | ||
arrow = TArrow(2,100,-1,50,0.01,"|>") | ||
arrow.SetLineColor(kRed) | ||
arrow.SetFillColor(kRed) | ||
arrow.SetLineWidth(3) | ||
frame.addObject(arrow) | ||
|
||
|
||
# P e r s i s t f r a m e w i t h a l l d e c o r a t i o n s i n R O O T f i l e | ||
# --------------------------------------------------------------------------------------------- | ||
|
||
f = TFile("rf106_plotdecoration.root","RECREATE") | ||
frame.Write() | ||
f.Close() | ||
|
||
# To read back and plot frame with all decorations in clean root session do | ||
# root> TFile f("rf106_plotdecoration.root") | ||
# root> xframe.Draw() | ||
|
||
c = TCanvas("rf106_plotdecoration","rf106_plotdecoration",600,600) | ||
gPad.SetLeftMargin(0.15) ; frame.GetYaxis().SetTitleOffset(1.6) ; frame.Draw() | ||
|
||
c.SaveAs("rf106_plotdecoration.png") | ||
|
||
if __name__ == "__main__": | ||
rf106_plotdecoration() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
##################################### | ||
# | ||
# 'BASIC FUNCTIONALITY' RooFit tutorial macro #107 | ||
# | ||
# Demonstration of various plotting styles of data, functions | ||
# in a RooPlot | ||
# | ||
# 07/2008 - Wouter Verkerke | ||
# | ||
####################################/ | ||
|
||
from ROOT import * | ||
|
||
|
||
def rf107_plotstyles(): | ||
|
||
# S e t u p m o d e l | ||
# --------------------- | ||
|
||
# Create observables | ||
x = RooRealVar("x","x",-10,10) | ||
|
||
# Create Gaussian | ||
sigma = RooRealVar("sigma","sigma",3,0.1,10) | ||
mean = RooRealVar("mean","mean",-3,-10,10) | ||
gauss = RooGaussian("gauss","gauss",x,mean,sigma) | ||
|
||
# Generate a sample of 100 events with sigma=3 | ||
data = gauss.generate(RooArgSet(x),100) | ||
|
||
# Fit pdf to data | ||
gauss.fitTo(data) | ||
|
||
|
||
|
||
# M a k e p l o t f r a m e s | ||
# ------------------------------- | ||
|
||
# Make four plot frames to demonstrate various plotting features | ||
frame1 = x.frame(RooFit.Name("xframe"),RooFit.Title("Red Curve / SumW2 Histo errors"),RooFit.Bins(20)) | ||
frame2 = x.frame(RooFit.Name("xframe"),RooFit.Title("Dashed Curve / No XError bars"),RooFit.Bins(20)) | ||
frame3 = x.frame(RooFit.Name("xframe"),RooFit.Title("Filled Curve / Blue Histo"),RooFit.Bins(20)) | ||
frame4 = x.frame(RooFit.Name("xframe"),RooFit.Title("Partial Range / Filled Bar chart"),RooFit.Bins(20)) | ||
|
||
|
||
|
||
# D a t a p l o t t i n g s t y l e s | ||
# --------------------------------------- | ||
|
||
# Use sqrt(sum(weights^2)) error instead of Poisson errors | ||
data.plotOn(frame1,RooFit.DataError(RooAbsData.SumW2)) | ||
|
||
# Remove horizontal error bars | ||
data.plotOn(frame2,RooFit.XErrorSize(0)) | ||
|
||
# Blue markers and error bors | ||
data.plotOn(frame3,RooFit.MarkerColor(kBlue),RooFit.LineColor(kBlue)) | ||
|
||
# Filled bar chart | ||
data.plotOn(frame4,RooFit.DrawOption("B"),RooFit.DataError(RooAbsData.None),RooFit.XErrorSize(0),RooFit.FillColor(kGray)) | ||
|
||
|
||
|
||
# F u n c t i o n p l o t t i n g s t y l e s | ||
# ----------------------------------------------- | ||
|
||
# Change line color to red | ||
gauss.plotOn(frame1,RooFit.LineColor(kRed)) | ||
|
||
# Change line style to dashed | ||
gauss.plotOn(frame2,RooFit.LineStyle(kDashed)) | ||
|
||
# Filled shapes in green color | ||
gauss.plotOn(frame3,RooFit.DrawOption("F"),RooFit.FillColor(kOrange),RooFit.MoveToBack()) | ||
|
||
# | ||
gauss.plotOn(frame4,RooFit.Range(-8,3),RooFit.LineColor(kMagenta)) | ||
|
||
|
||
|
||
c = TCanvas("rf107_plotstyles","rf107_plotstyles",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.15) ; frame2.GetYaxis().SetTitleOffset(1.6) ; frame2.Draw() | ||
c.cd(3) ; gPad.SetLeftMargin(0.15) ; frame3.GetYaxis().SetTitleOffset(1.6) ; frame3.Draw() | ||
c.cd(4) ; gPad.SetLeftMargin(0.15) ; frame4.GetYaxis().SetTitleOffset(1.6) ; frame4.Draw() | ||
|
||
c.SaveAs("rf107_plotstyles.png") | ||
|
||
if __name__ == "__main__": | ||
rf107_plotstyles() | ||
|
||
|
||
|
Oops, something went wrong.