本文整理汇总了Python中ROOT.RooAddPdf.createIntegral方法的典型用法代码示例。如果您正苦于以下问题:Python RooAddPdf.createIntegral方法的具体用法?Python RooAddPdf.createIntegral怎么用?Python RooAddPdf.createIntegral使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ROOT.RooAddPdf
的用法示例。
在下文中一共展示了RooAddPdf.createIntegral方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: doDataFit
# 需要导入模块: from ROOT import RooAddPdf [as 别名]
# 或者: from ROOT.RooAddPdf import createIntegral [as 别名]
#.........这里部分代码省略.........
leg.AddEntry(0,'N_{2}/N_{1} = '+str(Ratio)+' #pm '+str(s_Ratio),'')
if printSigReso: # Add Significance
Sig = numChib.calcSignificance()
s_Sig = numChib.calcSignificanceError()
Sig, s_Sig = roundPair(Sig, s_Sig)
leg.AddEntry(0,'Sig = '+str(Sig)+' #pm '+str(s_Sig),'')
if(Chib1_parameters.sigma>Chib2_parameters.sigma):
Reso = Chib1_parameters.sigma * 1000 # So it's in MeV and not in GeV
s_Reso = Chib1_parameters.s_sigma * 1000 # So it's in MeV and not in GeV
else:
Reso = Chib2_parameters.sigma * 1000 # So it's in MeV and not in GeV
s_Reso = Chib2_parameters.s_sigma * 1000 # So it's in MeV and not in GeV
Reso, s_Reso =roundPair(Reso, s_Reso)
leg.AddEntry(0,'Reso = '+str(Reso)+' #pm '+str(s_Reso)+' MeV','')
#N1 = numChib.numChib1
#s_N1 = numChib.s_numChib1
#N1, s_N1 = roundPair(N1, s_N1)
#leg.AddEntry(0,'N_{1} = '+str(N1)+' #pm '+str(s_N1),'')
#N2 = numChib.numChib2
#s_N2 = numChib.s_numChib2
#N2, s_N2 = roundPair(N2, s_N2)
#leg.AddEntry(0,'N_{2} = '+str(N2)+' #pm '+str(s_N2),'')
frame.addObject(leg)
if legendOnPlot: # < pT <
legend = TLegend(.06,.75,.53,.93)
legend.SetFillStyle(0)
legend.SetBorderSize(0)
#legend.AddEntry(0,'CMS','')
legend.AddEntry(0,str(cuts.upsilon_pt_lcut)+' GeV < p_{T}(#Upsilon) < '+str(cuts.upsilon_pt_hcut)+' GeV','')
#legend.AddEntry(0,'p_{T}(#Upsilon)<'+str(cuts.upsilon_pt_hcut),'')
frame.addObject(legend)
if titleOnPlot:
titleLegend = TLegend(.06,.4,.55,.73)
#titleLegend.SetTextSize(0.03)
titleLegend.SetFillStyle(0)
titleLegend.SetBorderSize(0)
titleLegend.AddEntry(0,plotTitle,'')
frame.addObject(titleLegend)
if cmsOnPlot:
if printLegend:
pvtxt = TPaveText(.1,.55,.55,.73,"NDC")
else:
pvtxt = TPaveText(0.5,0.75,0.97,0.9,"NDC") #(.06,.4,.55,.73)
pvtxt.AddText('CMS Preliminary')
pvtxt.AddText('pp, #sqrt{s} = 8 TeV')
pvtxt.AddText('L = 20.7 fb^{-1}')
pvtxt.SetFillStyle(0)
pvtxt.SetBorderSize(0)
pvtxt.SetTextSize(0.04)
frame.addObject(pvtxt)
# Canvas
c1=TCanvas('Chib12_1P'+output_suffix+ptBin_label,'Chib12_1P'+output_suffix+ptBin_label)
frame.Draw()
if drawPulls:
#c1=TCanvas(output_name+output_suffix,output_name+output_suffix,700, 625)
hpull = frame.pullHist()
framePulls = x.frame()
framePulls.SetTitle(';;Pulls')
framePulls.GetYaxis().SetLabelSize(0.18)
framePulls.GetYaxis().SetTitle('Pulls')
framePulls.GetYaxis().SetTitleSize(0.18)
framePulls.GetYaxis().SetTitleOffset(0.15)
framePulls.GetYaxis().SetNdivisions(005)
framePulls.GetXaxis().SetLabelSize(0.16)
framePulls.GetXaxis().SetTitle('')
line0 = TLine(9.7, 0, 10.1, 0)
line0.SetLineColor(ROOT.kBlue)
line0.SetLineWidth(2)
framePulls.addObject(line0)
framePulls.addPlotable(hpull,"P")
framePulls.SetMaximum(5)
framePulls.SetMinimum(-5)
pad1 = TPad("pad1", "The pad 80% of the height",0.0,0.2,1.0,1.0)
pad1.cd()
frame.Draw()
pad2 = TPad("pad2", "The pad 20% of the height",0.0,0.01,1.0,0.2)
pad2.cd()
framePulls.Draw()
c1.cd()
pad1.Draw()
pad2.Draw()
#c1.SaveAs('Chib12_1P'+output_suffix+'.png')
print 'Chi2 = '+str(frame.chiSquare())
# print ratio background/all in the signal refion
signal_region = x.setRange("signal_region",9.87,9.92)
pdf_integral = modelPdf.createIntegral(RooArgSet(x), RooFit.Range('signal_region')).getVal() * (n_chib.getVal() + n_background.getVal())
bkg_integral = background.createIntegral(RooArgSet(x), RooFit.Range('signal_region')).getVal() * n_background.getVal()
print 'Ratio bkg/all in signal region = '+str(bkg_integral/pdf_integral)
return numChib, c1
示例2: main
# 需要导入模块: from ROOT import RooAddPdf [as 别名]
# 或者: from ROOT.RooAddPdf import createIntegral [as 别名]
#.........这里部分代码省略.........
if args.widefit:
mframew = mjj.frame()
rooDataHist2.plotOn(mframew, ROOT.RooFit.Name("data"))
res6 = model.fitTo(rooDataHist2, RooFit.Save(kTRUE), RooFit.Strategy(args.fitStrategy))
model.plotOn(mframew, ROOT.RooFit.Name("model1"), ROOT.RooFit.LineStyle(1), ROOT.RooFit.LineWidth(1), ROOT.RooFit.LineColor(ROOT.EColor.kRed))
res7 = model2.fitTo(rooDataHist2, RooFit.Save(kTRUE), RooFit.Strategy(args.fitStrategy))
model2.plotOn(mframew, ROOT.RooFit.Name("model2"), ROOT.RooFit.LineStyle(1), ROOT.RooFit.LineWidth(1), ROOT.RooFit.LineColor(ROOT.EColor.kOrange))
res8 = model3.fitTo(rooDataHist2, RooFit.Save(kTRUE), RooFit.Strategy(args.fitStrategy))
model3.plotOn(mframew, ROOT.RooFit.Name("model3"), ROOT.RooFit.LineStyle(1), ROOT.RooFit.LineWidth(1), ROOT.RooFit.LineColor(ROOT.EColor.kGreen))
res9 = model4.fitTo(rooDataHist2, RooFit.Save(kTRUE), RooFit.Strategy(args.fitStrategy))
model4.plotOn(mframew, ROOT.RooFit.Name("model4"), ROOT.RooFit.LineStyle(1), ROOT.RooFit.LineWidth(1), ROOT.RooFit.LineColor(ROOT.EColor.kBlue))
res10 = model5.fitTo(rooDataHist2, RooFit.Save(kTRUE), RooFit.Strategy(args.fitStrategy))
model5.plotOn(mframew, ROOT.RooFit.Name("model5"), ROOT.RooFit.LineStyle(1), ROOT.RooFit.LineWidth(1), ROOT.RooFit.LineColor(ROOT.EColor.kViolet))
if args.pyes:
c = TCanvas("c","c",800,800)
mframew.SetAxisRange(300.,1300.)
c.SetLogy()
# mframew.SetMaximum(10)
# mframew.SetMinimum(1)
mframew.Draw()
fitname = args.pdir+'/5funcfittowide_m'+str(mass)+fstr+'.pdf'
c.SaveAs(fitname)
cpull = TCanvas("cpull","cpull",800,800)
pulls = mframew.pullHist("data","model1")
pulls.Draw("ABX")
pullname = args.pdir+'/pullwidefit_m'+str(mass)+fstr+'.pdf'
cpull.SaveAs(pullname)
if args.chi2:
fullInt = model.createIntegral(RooArgSet(mjj))
norm = dataInt/fullInt.getVal()
chi1 = 0.
fullInt2 = model2.createIntegral(RooArgSet(mjj))
norm2 = dataInt2/fullInt2.getVal()
chi2 = 0.
fullInt3 = model3.createIntegral(RooArgSet(mjj))
norm3 = dataInt3/fullInt3.getVal()
chi3 = 0.
fullInt4 = model4.createIntegral(RooArgSet(mjj))
norm4 = dataInt4/fullInt4.getVal()
chi4 = 0.
fullInt5 = model5.createIntegral(RooArgSet(mjj))
norm5 = dataInt5/fullInt5.getVal()
chi5 = 0.
for i in range(args.massMin, args.massMax):
new = 0
new2 = 0
new3 = 0
new4 = 0
new5 = 0
height = hData.GetBinContent(i)
xLow = hData.GetXaxis().GetBinLowEdge(i)
xUp = hData.GetXaxis().GetBinLowEdge(i+1)
obs = height*(xUp-xLow)
mjj.setRange("intrange",xLow,xUp)
integ = model.createIntegral(RooArgSet(mjj),ROOT.RooFit.NormSet(RooArgSet(mjj)),ROOT.RooFit.Range("intrange"))
exp = integ.getVal()*norm
new = pow(exp-obs,2)/exp
chi1 = chi1 + new
integ2 = model2.createIntegral(RooArgSet(mjj),ROOT.RooFit.NormSet(RooArgSet(mjj)),ROOT.RooFit.Range("intrange"))
exp2 = integ2.getVal()*norm2
new2 = pow(exp2-obs,2)/exp2
示例3: alpha
# 需要导入模块: from ROOT import RooAddPdf [as 别名]
# 或者: from ROOT.RooAddPdf import createIntegral [as 别名]
#.........这里部分代码省略.........
X_mass.setRange("X_reasonable_range", XBINMIN, XBINMAX)
# Set RooArgSets once for all, see https://root.cern.ch/phpBB3/viewtopic.php?t=11758
jetMassArg = RooArgSet(J_mass)
#*******************************************************#
# #
# V+jets normalization #
# #
#*******************************************************#
# Variables for V+jets
constVjet = RooRealVar("constVjet", "slope of the exp", -0.020, -1., 0.)
offsetVjet = RooRealVar("offsetVjet", "offset of the erf", 30., -50., 200.)
widthVjet = RooRealVar("widthVjet", "width of the erf", 100., 1., 200.)
offsetVjet.setConstant(True)
a0Vjet = RooRealVar("a0Vjet", "width of the erf", -0.1, -5, 0)
a1Vjet = RooRealVar("a1Vjet", "width of the erf", 0.6, 0, 5)
a2Vjet = RooRealVar("a2Vjet", "width of the erf", -0.1, -1, 1)
# Define V+jets model
if fitFuncVjet == "ERFEXP": modelVjet = RooErfExpPdf("modelVjet", "error function for V+jets mass", J_mass, constVjet, offsetVjet, widthVjet)
elif fitFuncVjet == "EXP": modelVjet = RooExponential("modelVjet", "exp for V+jets mass", J_mass, constVjet)
elif fitFuncVjet == "POL": modelVjet = RooChebychev("modelVjet", "polynomial for V+jets mass", J_mass, RooArgList(a0Vjet, a1Vjet, a2Vjet))
elif fitFuncVjet == "POW": modelVjet = RooGenericPdf("modelVjet", "powerlaw for X mass", "@0^@1", RooArgList(J_mass, a0Vjet))
else:
print " ERROR! Pdf", fitFuncVjet, "is not implemented for Vjets"
exit()
# fit to main bkg in MC (whole range)
frVjet = modelVjet.fitTo(setVjet, RooFit.SumW2Error(True), RooFit.Range("h_reasonable_range"), RooFit.Strategy(2), RooFit.Minimizer("Minuit2"), RooFit.Save(1), RooFit.PrintLevel(1 if VERBOSE else -1))
# integrals and number of events
iSBVjet = modelVjet.createIntegral(jetMassArg, RooFit.NormSet(jetMassArg), RooFit.Range("LSBrange,HSBrange"))
iLSBVjet = modelVjet.createIntegral(jetMassArg, RooFit.NormSet(jetMassArg), RooFit.Range("LSBrange"))
iHSBVjet = modelVjet.createIntegral(jetMassArg, RooFit.NormSet(jetMassArg), RooFit.Range("HSBrange"))
iSRVjet = modelVjet.createIntegral(jetMassArg, RooFit.NormSet(jetMassArg), RooFit.Range("SRrange"))
iVRVjet = modelVjet.createIntegral(jetMassArg, RooFit.NormSet(jetMassArg), RooFit.Range("VRrange"))
# Do not remove the following lines, integrals are computed here
iALVjet = modelVjet.createIntegral(jetMassArg, RooFit.NormSet(jetMassArg))
nSBVjet = iSBVjet.getVal()/iALVjet.getVal()*setVjet.sumEntries(SBcut)
nLSBVjet = iLSBVjet.getVal()/iALVjet.getVal()*setVjet.sumEntries(LSBcut)
nHSBVjet = iHSBVjet.getVal()/iALVjet.getVal()*setVjet.sumEntries(HSBcut)
nSRVjet = iSRVjet.getVal()/iALVjet.getVal()*setVjet.sumEntries(SRcut)
drawPlot("JetMass_Vjet", channel, J_mass, modelVjet, setVjet, binsJmass, frVjet)
if VERBOSE: print "********** Fit result [JET MASS Vjets] *"+"*"*40, "\n", frVjet.Print(), "\n", "*"*80
#*******************************************************#
# #
# VV, VH normalization #
# #
#*******************************************************#
# Variables for VV
# Error function and exponential to model the bulk
constVV = RooRealVar("constVV", "slope of the exp", -0.030, -0.1, 0.)
offsetVV = RooRealVar("offsetVV", "offset of the erf", 90., 1., 300.)
widthVV = RooRealVar("widthVV", "width of the erf", 50., 1., 100.)
erfrVV = RooErfExpPdf("baseVV", "error function for VV jet mass", J_mass, constVV, offsetVV, widthVV)
expoVV = RooExponential("baseVV", "error function for VV jet mass", J_mass, constVV)
# gaussian for the V mass peak
meanVV = RooRealVar("meanVV", "mean of the gaussian", 90., 60., 100.)
sigmaVV = RooRealVar("sigmaVV", "sigma of the gaussian", 10., 6., 30.)
fracVV = RooRealVar("fracVV", "fraction of gaussian wrt erfexp", 3.2e-1, 0., 1.)
示例4: alpha
# 需要导入模块: from ROOT import RooAddPdf [as 别名]
# 或者: from ROOT.RooAddPdf import createIntegral [as 别名]
#.........这里部分代码省略.........
if VERBOSE:
print "********** Fit result [JET MASS DATA] **" + "*" * 40, "\n", frMass.Print(), "\n", "*" * 80
frMass2 = BkgMass2.fitTo(
setDataSB,
RooFit.SumW2Error(True),
RooFit.Extended(True),
RooFit.Range("LSBrange,HSBrange"),
RooFit.Strategy(2),
RooFit.Minimizer("Minuit"),
RooFit.Save(1),
RooFit.PrintLevel(1 if VERBOSE else -1),
)
if VERBOSE:
print "********** Fit result [JET MASS DATA] **" + "*" * 40, "\n", frMass2.Print(), "\n", "*" * 80
# if SCAN:
# likelihoodScan(VjetMass, setVjet, [constVjet, offsetVjet, widthVjet])
# Fix normalization and parameters of V+jets after the fit to data
nVjet.setConstant(True)
nVjet2.setConstant(True)
constVjet.setConstant(True)
offsetVjet.setConstant(True)
widthVjet.setConstant(True)
a0Vjet.setConstant(True)
a1Vjet.setConstant(True)
a2Vjet.setConstant(True)
# integrals for global normalization
# do not integrate the composte model: results have no sense
# integral for normalization in the SB
iSBVjet = VjetMass.createIntegral(jetMassArg, RooFit.NormSet(jetMassArg), RooFit.Range("LSBrange,HSBrange"))
iSBVV = VVMass.createIntegral(jetMassArg, RooFit.NormSet(jetMassArg), RooFit.Range("LSBrange,HSBrange"))
iSBTop = TopMass.createIntegral(jetMassArg, RooFit.NormSet(jetMassArg), RooFit.Range("LSBrange,HSBrange"))
# integral for normalization in the SR
iSRVjet = VjetMass.createIntegral(jetMassArg, RooFit.NormSet(jetMassArg), RooFit.Range("SRrange"))
iSRVV = VVMass.createIntegral(jetMassArg, RooFit.NormSet(jetMassArg), RooFit.Range("SRrange"))
iSRTop = TopMass.createIntegral(jetMassArg, RooFit.NormSet(jetMassArg), RooFit.Range("SRrange"))
# integral for normalization in the VR
iVRVjet = VjetMass.createIntegral(jetMassArg, RooFit.NormSet(jetMassArg), RooFit.Range("VRrange"))
iVRVV = VVMass.createIntegral(jetMassArg, RooFit.NormSet(jetMassArg), RooFit.Range("VRrange"))
iVRTop = TopMass.createIntegral(jetMassArg, RooFit.NormSet(jetMassArg), RooFit.Range("VRrange"))
# formual vars
SByield = RooFormulaVar(
"SByield", "extrapolation to SR", "@0*@1 + @2*@3 + @4*@5", RooArgList(iSBVjet, nVjet, iSBVV, nVV, iSBTop, nTop)
)
VRyield = RooFormulaVar(
"VRyield", "extrapolation to VR", "@0*@1 + @2*@3 + @4*@5", RooArgList(iVRVjet, nVjet, iVRVV, nVV, iVRTop, nTop)
)
SRyield = RooFormulaVar(
"SRyield", "extrapolation to SR", "@0*@1 + @2*@3 + @4*@5", RooArgList(iSRVjet, nVjet, iSRVV, nVV, iSRTop, nTop)
)
# fractions
fSBVjet = RooRealVar(
"fVjet", "Fraction of Vjet events in SB", iSBVjet.getVal() * nVjet.getVal() / SByield.getVal(), 0.0, 1.0
)
fSBVV = RooRealVar(
"fSBVV", "Fraction of VV events in SB", iSBVV.getVal() * nVV.getVal() / SByield.getVal(), 0.0, 1.0
)
fSBTop = RooRealVar(