Skip to content

Instantly share code, notes, and snippets.

@ram1123
Last active June 7, 2023 04:53
Show Gist options
  • Save ram1123/42e5e95952f13abbe5d5e3adc65d7315 to your computer and use it in GitHub Desktop.
Save ram1123/42e5e95952f13abbe5d5e3adc65d7315 to your computer and use it in GitHub Desktop.
rooFit Scripts
# (RooFit) Read Histogram from root file and fit using RooFit
import ROOT as r
from ROOT import RooErfExpPdf
fin = r.TFile.Open("root://cmseos.fnal.gov//store/user/rasharma/SecondStep/WWTree_2018_01_07_12h02/HaddedFiles/Hadds_for_BkgEstimation/WWTree_WJets.root")
treeIn = fin.Get("otree")
c1 = r.TCanvas("c1","c1",800,600)
h1 = r.TH1F("h1","",22,40,150)
treeIn.Draw("PuppiAK8_jet_mass_so>>h1",cutString)
x = r.RooRealVar("x","AK8 invariant mass",40,150);
offset = r.RooRealVar("offset","offset",60.,30.,120);
width = r.RooRealVar("width","width",30.,10, 60.);
model_pdf = r.RooGaussian("model_pdf","gaussian function",x, offset, width)
print "Entries from MC = ",h1.GetEntries(),h1.Integral()
dh = r.RooDataHist("dh","plotOn test data with x",r.RooArgList(x),h1)
model_pdf.fitTo(dh)
rfresult = model_pdf.createIntegral(r.RooArgSet(x))
print rfresult.getVal()
frame = rrv_x.frame()
dh.plotOn(frame)
dh.statOn(frame); #this will display hist stat on canvas
model_pdf.plotOn(frame)
model_pdf.paramOn(frame);
frame.Draw()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment