本文整理汇总了Python中tdrstyle.setTDRStyle函数的典型用法代码示例。如果您正苦于以下问题:Python setTDRStyle函数的具体用法?Python setTDRStyle怎么用?Python setTDRStyle使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setTDRStyle函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_canvas
def get_canvas(cname):
tdrstyle.setTDRStyle()
CMS_lumi.lumi_8TeV = "19.7 fb^{-1}"
CMS_lumi.writeExtraText = 1
CMS_lumi.extraText = "Preliminary"
iPos = 0
if( iPos==0 ): CMS_lumi.relPosX = 0.16
H_ref = 800;
W_ref = 800;
W = W_ref
H = H_ref
T = 0.08*H_ref
B = 0.12*H_ref
L = 0.12*W_ref
R = 0.04*W_ref
canvas = ROOT.TCanvas(cname,cname,50,50,W,H)
canvas.SetFillColor(0)
canvas.SetBorderMode(0)
canvas.SetFrameFillStyle(0)
canvas.SetFrameBorderMode(0)
canvas.SetLeftMargin( L/W+0.02 )
canvas.SetRightMargin( R/W )
canvas.SetTopMargin( T/H )
canvas.SetBottomMargin( B/H )
canvas.SetGrid()
canvas.SetLogy()
return canvas
示例2: get_canvas
def get_canvas(text):
tdrstyle.setTDRStyle()
CMS_lumi.lumi_13TeV = "2.1 fb^{-1}," + text
CMS_lumi.writeExtraText = 1
CMS_lumi.extraText = ""
iPos = 0
if( iPos==0 ): CMS_lumi.relPosX = 0.12
H_ref = 600
W_ref = 800
W = W_ref
H = H_ref
T = 0.08*H_ref
B = 0.12*H_ref
L = 0.12*W_ref
R = 0.04*W_ref
canvas = ROOT.TCanvas("c2","c2",50,50,W,H)
canvas.SetFillColor(0)
canvas.SetBorderMode(0)
canvas.SetFrameFillStyle(0)
canvas.SetFrameBorderMode(0)
canvas.SetLeftMargin( L/W+0.01 )
canvas.SetRightMargin( R/W+0.03 )
canvas.SetTopMargin( T/H )
canvas.SetBottomMargin( B/H+0.03 )
canvas.SetGrid()
canvas.SetLogy()
return canvas
示例3: get_canvas
def get_canvas():
tdrstyle.setTDRStyle()
CMS_lumi.lumi_13TeV = "13 TeV"
CMS_lumi.writeExtraText = 0
CMS_lumi.extraText = "Preliminary"
iPos = 0
if( iPos==0 ): CMS_lumi.relPosX = 0.07
H_ref = 600;
W_ref = 800;
W = W_ref
H = H_ref
T = 0.08*H_ref
B = 0.12*H_ref
L = 0.12*W_ref
R = 0.04*W_ref
#canvas = ROOT.TCanvas("c2","c2",50,50,W,H)
canvas = ROOT.TCanvas("c2","c2",W,H)
canvas.SetFillColor(0)
canvas.SetBorderMode(0)
canvas.SetFrameFillStyle(0)
canvas.SetFrameBorderMode(0)
canvas.SetLeftMargin( L/W )
canvas.SetRightMargin( R/W )
canvas.SetTopMargin( T/H )
canvas.SetBottomMargin( B/H )
canvas.SetTickx()
canvas.SetTicky()
return canvas
示例4: get_canvas
def get_canvas(cname,lumi8,lumi13):
tdrstyle.setTDRStyle()
CMS_lumi.lumi_13TeV = "%s fb^{-1}"%lumi13
CMS_lumi.lumi_8TeV = "%s fb^{-1}"%lumi8
CMS_lumi.writeExtraText = 1
CMS_lumi.extraText = "Preliminary"
CMS_lumi.lumi_sqrtS = "13 TeV" # used with iPeriod = 0, e.g. for simulation-only plots (default is an empty string)
iPos = 0
if( iPos==0 ): CMS_lumi.relPosX = 0.13
iPeriod=4
H_ref = 630
W_ref = 600
W = W_ref
H = H_ref
T = 0.08*H_ref
B = 0.12*H_ref
L = 0.12*W_ref
R = 0.04*W_ref
canvas = ROOT.TCanvas(cname,cname,50,50,W,H)
canvas.SetFillColor(0)
canvas.SetBorderMode(0)
canvas.SetFrameFillStyle(0)
canvas.SetFrameBorderMode(0)
canvas.SetLeftMargin( L/W+0.01 )
canvas.SetRightMargin( R/W+0.03 )
canvas.SetTopMargin( 0.07 ) #/T/H
canvas.SetBottomMargin( B/H )
#canvas.SetGrid()
canvas.SetLogy()
return canvas
示例5: get_canvas
def get_canvas(cname):
tdrstyle.setTDRStyle()
iPos = 0
if( iPos==0 ): CMS_lumi.relPosX = 0.13
iPeriod=4
H_ref = 500
W_ref = 500
W = W_ref
H = H_ref
T = 0.08*H_ref
B = 0.12*H_ref
L = 0.12*W_ref
R = 0.04*W_ref
canvas = ROOT.TCanvas(cname,cname,50,50,W,H)
canvas.SetFillColor(0)
canvas.SetBorderMode(0)
canvas.SetFrameFillStyle(0)
canvas.SetFrameBorderMode(0)
canvas.SetLeftMargin( 0.35 )
canvas.SetRightMargin( 0.02 )
canvas.SetTopMargin( 0.01 ) #/T/H
canvas.SetBottomMargin( B/H )
return canvas
示例6: __init__
def __init__(self, OutDir):
self.OutDir = OutDir
if not os.path.isdir(self.OutDir):
try:
os.makedirs(self.OutDir)
except OSError:
pass
self.lumi = Lumi
tdrstyle.setTDRStyle()
self.canvas = self.CreatCanvas()
示例7: setTDRStyle
def setTDRStyle(canvas, luminosity, energy, printCMS):
tdrstyle.setTDRStyle()
if printCMS == "right" or printCMS == "left":
if energy == 13:
CMS_lumi.lumi_13TeV = "%s fb^{-1}" % luminosity
if printCMS == "left":
iPos = 11
else:
iPos = 13
CMS_lumi.writeExtraText = 1
CMS_lumi.extraText = "Very Preliminary"
CMS_lumi.CMS_lumi(canvas, 4, iPos)
示例8: __init__
def __init__(self):
'''
Set up PlotStyle, set gStyle for things we always want no matter what.
'''
# CMS-approved everything
tdrstyle.setTDRStyle()
### Differences from TDR standard:
# Big canvas (can always shrink later)
gStyle.SetCanvasDefH(1200)
gStyle.SetCanvasDefW(1200)
# Tick marks on all sides
gStyle.SetPadTickX(1)
gStyle.SetPadTickY(1)
# Everything has white backgrounds
gStyle.SetLegendFillColor(0)
# Colors that don't suck
gStyle.SetPalette(1)
# Make axis title and labels just a little smaller and (for Y) closer to the axis
gStyle.SetTitleSize(0.048, "X")
gStyle.SetTitleSize(0.044, "YZ")
gStyle.SetLabelSize(0.033, "XYZ")
gStyle.SetTitleYOffset(1.15)
gStyle.SetTitleXOffset(0.86)
gStyle.SetPadLeftMargin(0.1)
gStyle.SetPadRightMargin(0.025)
gStyle.SetPadBottomMargin(0.095)
gStyle.SetTitleAlign(12)
# Apply changes
gROOT.ForceStyle()
# Force exponentials when axes are over 3 digits
TGaxis.SetMaxDigits(3)
TGaxis.SetExponentOffset(-0.060, 0.008, "y")
TGaxis.SetExponentOffset(-0.055, -0.062, "x") # will overlap with title unless title is centered
示例9: DrawPUperFile
def DrawPUperFile(filedir, l1seed, key=None):
global mcdf
allfiles = glob.glob(filedir)
if not os.path.exists("plots"):
os.mkdir("plots")
tdrstyle.setTDRStyle()
ROOT.gStyle.SetOptStat(000000000)
df = pd.DataFrame()
flist = [ ]
for file_ in allfiles:
df_ = pd.read_csv(file_, index_col=None, header=0)
flist.append(df_)
df = pd.concat(flist)
mcdf = GetMCDataFrame(allfiles)
if l1seed == "All":
for seed in pd.unique(df.L1Seed):
DrawPU(df, seed)
else:
return DrawPU(df, l1seed, key)
示例10: makeComparisonPlots
def makeComparisonPlots(patTuple_list, ntuple_l1recoMuonTree, label, handle,
plottingVariables):
ROOT.gROOT.SetBatch() # don't pop up canvases
ROOT.gStyle.SetErrorX(0)
tdrstyle.setTDRStyle()
muonHists_patTree = plotMuQuantities_pat(patTuple_list, label, handle,
plottingVariables)
muonHists_l1muRecoTree = plotMuQuantities_l1(ntuple_l1recoMuonTree,
plottingVariables)
for muonHist_patTree, muonHist_l1muRecoTree, plotVar in izip(muonHists_patTree,
muonHists_l1muRecoTree,
plottingVariables):
# Draw histograms
c1 = ROOT.TCanvas("", "", 1024, 786)
muonHist_l1muRecoTree.SetLineColor(ROOT.kBlue)
muonHist_l1muRecoTree.DrawCopy("E1HIST")
muonHist_patTree.SetLineColor(ROOT.kRed)
muonHist_patTree.DrawCopy("E1HISTSAME")
c1.Print(plotVar.title + ".pdf")
示例11: drawPlots_tdrstyle
def drawPlots_tdrstyle(data, signal, signalSF, signalName, background, backgroundSF, backgroundName, xlo, xhi, name, xaxisLabel, axisMin, axisMax, doLogy):
tdrstyle.setTDRStyle()
CMS_lumi.lumi_8TeV = '19.7 fb^{-1}'
CMS_lumi.extraText = 'Preliminary'
CMS_lumi.writeExtraText = 1
CMS_lumi.lumi_sqrtS = '8 TeV'
iPos = 11
H = 600
W = 800
# iPeriod = 1*(0/1 7 TeV) + 2*(0/1 8 TeV) + 4*(0/1 13 TeV)
iPeriod = 2
# references for T, B, L, R
T = 0.08*H
B = 0.12*H
L = 0.12*W
R = 0.04*W
can = ROOT.TCanvas('can', 'plot', 50, 50, W, H)
padFraction = 0.3
padhi = ROOT.TPad('padhi', 'padhi', 0, padFraction, 1, 1)
padhi.SetLeftMargin( L/W )
padhi.SetRightMargin( R/W )
padhi.SetTopMargin(T/H/(1.0 - padFraction))
padhi.SetBottomMargin(0)
padhi.SetTickx(0)
padhi.SetTicky(0)
padhi.SetLogy(doLogy)
padlo = ROOT.TPad('padlo', 'padlo', 0, 0, 1, padFraction)
padlo.SetLeftMargin( L/W )
padlo.SetRightMargin( R/W )
padlo.SetTopMargin(0)
padlo.SetBottomMargin(B/H/padFraction)
padlo.SetTickx(0)
padlo.SetTicky(0)
padhi.Draw()
padlo.Draw()
signal.Scale(signalSF)
background.Scale(backgroundSF)
background.SetFillColor(8)
sumHist = signal.Clone('sumHist')
sumHist.Add(background)
sumHist.SetFillColor(ROOT.kGray)
sumHist.GetXaxis().SetRangeUser(xlo, xhi)
sumHist.GetYaxis().SetRangeUser(axisMin, axisMax)
sumHist.GetYaxis().SetTitle('Events / 10 GeV')
ratio = data.Clone('ratio')
ratio.Reset()
for ibin in range(ratio.GetNbinsX()):
if(sumHist.GetBinContent(ibin+1) == 0):
continue
ratio.SetBinContent(ibin+1, data.GetBinContent(ibin+1) / sumHist.GetBinContent(ibin+1))
ratio.SetBinError(ibin+1, data.GetBinError(ibin+1) / sumHist.GetBinContent(ibin+1))
ratio.GetYaxis().SetRangeUser(0.45, 1.55)
ratio.GetYaxis().SetTitle('Data / Background')
ratio.GetYaxis().SetLabelSize(0.06)
ratio.GetYaxis().SetTitleSize(0.06)
ratio.GetYaxis().SetTitleOffset(0.5)
#ratio.GetYaxis().SetNdivisions(512)
ratio.GetXaxis().SetRangeUser(xlo, xhi)
ratio.GetXaxis().SetTitle(xaxisLabel)
ratio.GetXaxis().SetLabelSize(0.10)
ratio.GetXaxis().SetTitleSize(0.12)
ratio.GetXaxis().SetTitleOffset(1.2)
oneLine = ROOT.TLine(xlo, 1.0, xhi + 10.0, 1.0)
oneLine.SetLineStyle(2)
reqtitle = ''
if 'ele_bjj' in name or 'ele_jjj' in name:
if 'z_mass' in name:
reqtitle = 'ee'
else:
reqtitle = 'e#gamma'
else:
if 'z_mass' in name:
reqtitle = '#mu#mu'
else:
reqtitle = '#mu#gamma'
if 'bjj' in name:
reqtitle = reqtitle + '+bjj'
else:
reqtitle = reqtitle + '+jjj'
#leg = ROOT.TLegend(0.7, 0.6, 0.85, 0.85, '', 'brNDC')
leg = ROOT.TLegend(0.72, 0.6, 0.89, 0.85, '', 'brNDC')
leg.SetFillColor(0)
#.........这里部分代码省略.........
示例12: DrawPU
def DrawPU(f, l1seed, key=None):
df = f[(f.L1Seed == l1seed )]
RetVar = None
for i in range(0, len(pubins) -1):
pumap[pubins[i]] = []
pumap[pubins[i]].append(df[np.logical_and(df.PileUp > pubins[i], df.PileUp <= pubins[i+1])].Fired.sum())
pumap[pubins[i]].append(df[np.logical_and(df.PileUp > pubins[i], df.PileUp <= pubins[i+1])].Total.sum())
# # No merging
# PileUp = pd.unique(df.PileUp)
# for i in PileUp:
# pumap[i] = []
# pumap[i].append(df[df.PileUp == i].Fired.sum())
# pumap[i].append(df[df.PileUp == i].Total.sum())
x = []
y = []
yerr = []
for k, v in pumap.iteritems():
if v[1] != 0:
x.append(k)
if unit == "Hz":
y.append(float(v[0])/v[1] * freq * nBunches )
yerr.append( math.sqrt(float(v[0]))/v[1] * freq * nBunches )
if unit == "kHz":
y.append(float(v[0])/v[1] * freq * nBunches / 1000)
yerr.append( math.sqrt(float(v[0]))/v[1] * freq * nBunches / 1000)
## Draw the plot
graph = ROOT.TGraphErrors(len(x))
minx = min(x)
maxx = 31
for i, (xx, yy, yee) in enumerate(zip(x, y, yerr)):
graph.SetPoint(i, xx, yy)
graph.SetPointError(i, 0, yee)
c1 = ROOT.TCanvas("fd","Fdf", 600, 500)
ROOT.gStyle.SetOptStat(000000000)
tdrstyle.setTDRStyle()
graph.Draw("AP")
graph.SetTitle(l1seed)
graph.GetXaxis().SetTitle("PileUp")
graph.GetXaxis().SetLimits(0, 50)
if unit == "Hz":
graph.GetYaxis().SetTitle("Rate (nBunches = %d) [Hz]" % nBunches)
if unit == "kHz":
graph.GetYaxis().SetTitle("Rate (nBunches = %d) [kHz]" % nBunches)
leg = ROOT.TLegend(0.7432886,0.1733615,0.9949664,0.3530655)
leg.SetFillColor(0)
leg.SetBorderSize(0)
leg.SetBorderSize(0)
leg.SetFillStyle(0)
leg.SetTextFont(62)
leg.AddEntry(graph, "Data", "p")
## Get Stage1
s1fun = GetStage1Fun(l1seed)
if DrawStage1 and s1fun is not None:
s1fun.SetLineColor(ROOT.kGreen+2)
s1fun.SetLineWidth(2)
s1fun.Draw("same")
tex = ROOT.TLatex(0.19, 0.81, s1fun.GetName())
tex.SetNDC()
tex.SetTextAlign(13)
tex.SetTextFont(61)
tex.SetTextSize(0.04)
tex.SetTextColor(ROOT.kGreen+2)
tex.SetLineWidth(2)
tex.Draw()
tex = ROOT.TLatex(0.19, 0.9, l1seed)
tex.SetNDC()
tex.SetTextAlign(13)
tex.SetTextFont(61)
tex.SetTextSize(0.05)
tex.SetTextColor(ROOT.kBlack)
tex.SetLineWidth(2)
tex.Draw()
## Pol2
fitname = "pol2"
graph.Fit("pol2", "QF", "", minx, maxx)
f2 = graph.GetFunction(fitname).Clone()
f2.SetLineColor(ROOT.kBlue)
f2.SetLineWidth(2)
fun = "f2 = %.2f + %.2f*x + %.3f*x^2" % (f2.GetParameter(0), f2.GetParameter(1), f2.GetParameter(2) )
RetVar = f2.GetParameter(2)
tex = ROOT.TLatex(0.19, 0.75, fun)
f2.Draw("same")
tex.SetNDC()
tex.SetTextAlign(13)
tex.SetTextFont(61)
tex.SetTextSize(0.04)
tex.SetTextColor(ROOT.kBlue)
tex.SetLineWidth(2)
tex.Draw()
## Pol1
#.........这里部分代码省略.........
示例13: DrawPU
def DrawPU(canvas, f, l1seed, count, key=None):
df = f[(f.L1Seed == l1seed )]
RetVar = None
for i in range(0, len(pubins) -1):
pumap[pubins[i]] = []
pumap[pubins[i]].append(df[np.logical_and(df.PileUp > pubins[i], df.PileUp <= pubins[i+1])].Fired0.sum())
pumap[pubins[i]].append(df[np.logical_and(df.PileUp > pubins[i], df.PileUp <= pubins[i+1])].Total.sum())
x = []
y = []
yerr = []
for k, v in pumap.iteritems():
if v[1] != 0:
x.append(k)
if unit == "Hz":
y.append(float(v[0])/v[1] * freq * nBunches )
yerr.append( math.sqrt(float(v[0]))/v[1] * freq * nBunches )
if unit == "kHz":
y.append(float(v[0])/v[1] * freq * nBunches / 1000)
yerr.append( math.sqrt(float(v[0]))/v[1] * freq * nBunches / 1000)
## Draw the plot
graph = ROOT.TGraphErrors(len(x))
for i, (xx, yy, yee) in enumerate(zip(x, y, yerr)):
# if yy != 0 and yee/yy >0.3:
# continue
#if i == 22 or i == 23 or i == 24:
# continue
graph.SetPoint(i, xx, yy)
#print (i,xx,yy,yee)
#print "h1->SetBinContent( %d, %f);" %(xx,yy)
#print "h1->SetBinError( %d, %f);" %(xx,yee)
graph.SetPointError(i, 0, yee)
graph.SetMarkerStyle(20+count)
graph.SetMarkerSize(1.5)
graph.SetMarkerColor(1+count)
graph.SetLineColor(1+count)
graph.SetLineWidth(2)
tdrstyle.setTDRStyle()
canvas.cd()
canvas.Update()
if count == 0:
graph.Draw("AP")
graph.GetXaxis().SetTitle("PileUp")
graph.GetXaxis().SetLimits(plot_min, maxx)
graph.GetYaxis().SetRangeUser(0, maxy)
graph.GetYaxis().SetTitle("Rate (nBunches = %d) [%s]" % (nBunches, unit))
else:
graph.Draw("P")
canvas.Update()
leg.AddEntry(graph, l1seed, "p")
result_ptr = graph.Fit(fitname, "SQ", "", fit_min, fit_max)
error_vec = result_ptr.GetConfidenceIntervals()
print ("error vec size = %d, fitted PU = %d" % (error_vec.size(), fit_max - fit_min + 1))
f2 = graph.GetFunction("fitname").Clone()
#f2 = graph.GetFunction(fitname).Clone()
f2.SetLineColor(1+count)
f2.SetLineWidth(2)
f2.SetRange(plot_min, fit_min)
f2.SetLineStyle(5)
minChi = f2.GetChisquare() / f2.GetNDF()
#fun = "Fit = %.2f + %.2f*x + %.3f*x^2" % (f2.GetParameter(0), f2.GetParameter(1), f2.GetParameter(2) )
#fun = "Fit = %f*x + %f*x^2" % (f2.GetParameter(0), f2.GetParameter(1) )
#print fun
f2.Draw("same")
f2_2 = f2.Clone("dashline2")
f2_2.SetRange(fit_max, plot_max)
f2_2.Draw("same")
if config == 2017:
if PU <= fit_max: key = "Rate(PU=%d): %.2f +- %.2f, chi2/NDF=%.2f" %(PU, f2_2.Eval(PU), error_vec.at(PU-fit_min), minChi)
else: key = "Rate(PU=%d): %.2f +- %.2f, chi2/NDF=%.2f" %(PU, f2_2.Eval(PU), error_vec.back(), minChi)
if config == 2018:
#key = ""
key = "Rate: %.2f +- %.2f @PU50, %.2f +- %.2f @PU56, %.2f +- %.2f @PU62" %(f2_2.Eval(50), error_vec.at(50-fit_min), f2_2.Eval(56), error_vec.at(56-fit_min), f2_2.Eval(62), error_vec.at(62-fit_min))
if key is not None:
tex = ROOT.TLatex(0.2, 0.85, key)
tex.SetNDC()
tex.SetTextFont(61)
tex.SetTextSize(0.055)
tex.SetTextColor(ROOT.kGreen+2)
tex.SetLineWidth(2)
tex.Draw()
canvas.Update()
示例14: PlotDataMCPAS
def PlotDataMCPAS(hdictlist_bg, hdict_data, hdictlist_sig=0, legdict=0
, outputdir="plots", outfile=0, cname="canvas", plotinfo="Selection X"
, ratiotitle="ratio", logscale=False, scale="No", scalefactor=1, intlumi=19.7, style="CMS"):
# CMS style plots
if style == "CMS":
tdrstyle.setTDRStyle()
# First do some checks on the input
if outfile == 0:
print "You did not pass me a root file to store the plots. I will only produce pdf files."
if not os.path.isdir(outputdir):
print "Output directory doesn't exist yet. \nWill create directory %s" % (outputdir)
os.makedirs(outputdir)
# Get clones of all the mc histograms and put them in a list
hQCD_index = -1 # will need this if we want to scale QCD only
histos = []
for i,hdict in enumerate(hdictlist_bg):
# first check that the histogram exists
if not hdict["histogram"]:
print "Histogram for sample", hdict["name"], "and canvas", cname, "doesn't exist, will stop making this plot now"
return
h = hdict["histogram"].Clone()
h.Sumw2()
h.SetFillColor(hdict["color"])
h.SetLineColor(hdict["color"])
h.GetYaxis().SetTitle(hdict["ytitle"])
h.GetXaxis().SetTitle(hdict["xtitle"])
h.SetTitle(hdict["title"])
histos.append(h)
if "QCD" in hdict["name"]:
hQCD_index = i
# Get data histogram
hdata = 0
if hdict_data == 0:
print "Will make plots without data"
else:
if not hdict_data["histogram"]:
print hdict["name"], "doesn't exist, will stop making this plot now"
return
hdata = hdict_data["histogram"].Clone()
hdata.Sumw2()
hdata.SetMarkerStyle(hdict_data["markerstyle"])
hdata.SetLineColor(hdict_data["color"])
hdata.GetYaxis().SetTitle(hdict_data["ytitle"])
hdata.SetTitle(hdict_data["title"])
# Get signal histograms
hsignal = []
if hdictlist_sig != 0:
for hdict in hdictlist_sig:
if not hdict["histogram"]:
print hdict["name"], "doesn't exist, will stop making this plot now"
return
h = hdict["histogram"].Clone()
h.Sumw2()
h.SetFillColor(hdict["color"])
h.SetLineColor(hdict["color"])
hsignal.append(h)
# make a stack of all the mc, will use the reverse order of the list
mc = rt.THStack()
for h in reversed(histos):
mc.Add(h,"hist")
for h in hsignal:
mc.Add(h,"hist")
# make the total mc histogram, used for the ratio plot
htotal = histos[0].Clone()
for h in histos[1:]:
htotal.Add(h)
# scale MC to data if required
if scale == "Yes" and hdata != 0:
sf = scalefactor
if sf == 1: # we should rescale to match data
mc_int = htotal.Integral(0,htotal.GetNbinsX()+1)
if mc_int == 0:
mc_int = 1.
data_int = hdata.Integral()
sf = data_int/mc_int
for h in histos:
h.Scale(sf)
print "Scaled all histograms by factor", sf
# Scale everything according to the bin width
if scale == "Width":
for h in histos:
h.Scale(scalefactor,"width")
if hdata != 0:
hdata.Scale(scalefactor,"width")
for h in hsignal:
h.Scale(scalefactor,"width")
print "Will plot per bin width"
# scale only QCD to match data in the first non-empty bin
if scale == "QCD" and hdata != 0:
sf = scalefactor
#.........这里部分代码省略.........
示例15: Plot2DPAS
def Plot2DPAS(hdict,outputdir="plots",outfile=0,cname="canvas"
,logscale=False,scale="No",lumitext="Preliminary"):
# CMS style plots
tdrstyle.setTDRStyle()
# First do some checks on the input
if outfile == 0:
print "You did not pass me a root file to store the plots. I will only produce pdf files."
if not os.path.isdir(outputdir):
print "Output directory doesn't exist yet"
print "Will create directory %s" % (outputdir)
os.makedirs(outputdir)
# placeholder for draw objects
rootEvil = []
# Make the canvas
canvas = rt.TCanvas(cname,"",50,50,800,600)
CMS_lumi.lumi_8TeV = "19.7 fb^{-1}"
CMS_lumi.writeExtraText = 1
CMS_lumi.extraText = lumitext
iPos = 0#11
if( iPos==0 ): CMS_lumi.relPosX = 0.12
iPeriod = 2
H_ref = 600
W_ref = 800
W = W_ref
H = H_ref
# references for T, B, L, R
T = 0.08*H_ref
B = 0.12*H_ref
L = 0.12*W_ref
R = 0.12*W_ref
canvas.SetLeftMargin( L/W )
canvas.SetRightMargin( R/W )
canvas.SetTopMargin( T/H )
canvas.SetBottomMargin( B/H )
#canvas.SetLeftMargin(0.13)
#canvas.SetRightMargin(0.17)
#canvas.SetBottomMargin(0.13)
if logscale:
canvas.SetLogz(1)
canvas.cd()
# Get histogram from dictionary, and plot it
print "Getting histogram"
h = hdict["histogram"] # Get the histogram
if scale == "Yes":
sf = h.Integral(0,h.GetNbinsX()+1,0,h.GetNbinsY()+1)
h.Scale(1./sf)
if scale == "Width":
h.Scale(1,"width")
if scale == "Yes":
h.GetZaxis().SetTitle("A.U.")
else:
h.GetZaxis().SetTitle("Events")
maxi = h.GetMaximum()
if logscale:
h.SetMaximum(maxi*2)
else:
h.SetMaximum(maxi*1.2)
if scale == "Yes":
h.SetMaximum(1)
h.GetXaxis().SetTitle(hdict["xtitle"])
h.GetXaxis().SetTitleSize(0.05)
h.GetXaxis().SetTitleOffset(1.05)
h.GetXaxis().SetLabelSize(0.04)
h.GetYaxis().SetTitle(hdict["ytitle"])
h.GetYaxis().SetTitleSize(0.05)
h.GetYaxis().SetTitleOffset(1.05)
h.GetYaxis().SetLabelSize(0.04)
#h.GetZaxis().SetTitleSize(0.05)
#h.GetZaxis().SetTitleOffset(1.1)
#h.GetZaxis().SetLabelSize(0.04)
h.SetTitle(hdict["title"])
drawoption = hdict["drawoption"]
palette = hdict["palette"]
if "colz" in drawoption and palette == "SMS":
print "change color palette"
SetColorPaletteSMS()
if "colz" in drawoption and palette == "2DRatio":
SetColorPalette2DRatio()
rootEvil.append(h.DrawClone(drawoption))
print "Drew histogram"
print hdict["name"]
if hdict["name"] != "":
t = '#scale[1.1]{%s}' % (hdict["name"])
if len(hdict["name"]) > 20:
tex = rt.TLatex(0.45,0.82,t)
#.........这里部分代码省略.........