本文整理汇总了Python中ROOT.TPad.cd方法的典型用法代码示例。如果您正苦于以下问题:Python TPad.cd方法的具体用法?Python TPad.cd怎么用?Python TPad.cd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ROOT.TPad
的用法示例。
在下文中一共展示了TPad.cd方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: makeTwoScalesGraph
# 需要导入模块: from ROOT import TPad [as 别名]
# 或者: from ROOT.TPad import cd [as 别名]
def makeTwoScalesGraph(file):
print(file)
ch1 = OPData.fromPath('../data/part3/%s' % file, 1)
ch2 = OPData.fromPath('../data/part3/%s' % file, 2)
print('make canvas + pad')
c = TCanvas('c-%s' % file, '', 1280, 720)
pad = TPad('pad-%s' % file, '', 0, 0, 1, 1)
pad.Draw()
pad.cd()
print('frame')
frame = pad.DrawFrame(0, min(ch1.getY()) * 1.1, 0.051, max(ch1.getY()) * 1.1)
frame.SetXTitle('Zeit t / s')
frame.GetXaxis().CenterTitle()
frame.SetYTitle('Spannung Spule 2: U_{2} / V')
frame.GetYaxis().CenterTitle()
frame.GetYaxis().SetLabelColor(4)
frame.GetYaxis().SetTitleColor(4)
print('g1')
g1 = ch1.makeGraph('g1-%s' % file)
prepareGraph(g1)
g1.Draw('PX')
print('overlay')
c.cd()
overlay = TPad('overlay-%s' % file, '', 0, 0, 1, 1)
overlay.SetFillStyle(4000) # transparent
overlay.SetFillColor(0) # white
overlay.SetFrameFillStyle(4000) # transparent
overlay.Draw()
overlay.cd()
print('g2')
g2 = ch2.makeGraph('g2-%s' % file)
prepareGraph(g2, 2)
g2ymin = min(ch2.getY())
xmin = pad.GetUxmin()
xmax = pad.GetUxmax()
ymin = 1.1 * g2ymin
ymax = abs(ymin)
if file == '07.tab': # same scale like 06.tab
ymin, ymax = -0.07128, 0.07128
oframe = overlay.DrawFrame(xmin, ymin, xmax, ymax)
oframe.GetXaxis().SetLabelOffset(99)
oframe.GetYaxis().SetLabelOffset(99)
oframe.GetYaxis().SetTickLength(0)
g2.Draw('PX')
print('axis')
axis = TGaxis(xmax, ymin, xmax, ymax, ymin, ymax, 510, "+L")
axis.SetTitle('Spannung Photodiode: U_{ph} / V')
axis.CenterTitle()
axis.SetTitleOffset(1.2)
axis.Draw()
print('print')
c.Update()
c.Print('../img/part3/%s.pdf' % file[:-4], 'pdf')
示例2: overlayAndRatio
# 需要导入模块: from ROOT import TPad [as 别名]
# 或者: from ROOT.TPad import cd [as 别名]
def overlayAndRatio(canvas, min_ratio, max_ratio, h1, h2):
canvas.ResetAttPad()
canvas.Clear()
pad = TPad("main","main", 0, 0.3, 1, 1)
pad.SetBottomMargin(0.05);
pad.Draw()
pad.cd()
h1.Draw()
h2.SetLineColor(kOrange+10)
h2.Draw('SAME')
canvas.cd()
ratio = TPad("ratio","ratio", 0, 0.05, 1, 0.3);
ratio.SetTopMargin(0.05);
ratio.Draw()
ratio.cd()
if isinstance(h1, TProfile) and isinstance(h2, TProfile):
h1_p = h1.ProjectionX()
h2_p = h2.ProjectionX()
h1_p.Divide(h2_p)
h1_p.SetMaximum(max_ratio)
h1_p.SetMinimum(min_ratio)
h1_p.SetMarkerStyle(kFullCircle)
h1_p.SetMarkerSize(0.6)
h1_p.SetTitle('')
h1_p.GetXaxis().SetLabelFont(42)
h1_p.GetXaxis().SetLabelSize(0.1)
h1_p.GetYaxis().SetLabelFont(42)
h1_p.GetYaxis().SetLabelSize(0.1)
h1_p.GetYaxis().SetNdivisions(505)
equality = TLine()
h1_p.Draw("SAME HIST P")
equality.SetLineColor(kOrange+10)
equality.DrawLine(h1_p.GetXaxis().GetXmin(), 1, h1_p.GetXaxis().GetXmax(), 1)
示例3: draw_histos
# 需要导入模块: from ROOT import TPad [as 别名]
# 或者: from ROOT.TPad import cd [as 别名]
def draw_histos(self):
for i in range(self.planes):
self.histos.append([])
self.pads.append([])
self.canvas.cd(i+1)
name = 'ROC' + str(i)
p = TPad('name','',0,0,1,1)
p.SetRightMargin(0.15)
self.pads[i].append(p)
p.Draw()
p.cd()
th2 = TH2F(name, name, self.data[i].shape[0],
0, 53, self.data[i].shape[1], 0, 81)
th2.SetStats(False)
th2.SetDirectory(0)
th2.SetMarkerSize(10)
th2.GetXaxis().SetTitle('pixels x')
th2.GetYaxis().SetTitle('pixels y')
th2.GetYaxis().SetTitleOffset(1.2)
th2.GetYaxis().CenterTitle()
th2.GetXaxis().CenterTitle()
th2.GetZaxis().SetTitle('pulse height')
th2.GetZaxis().SetTitleOffset(1.2)
th2.GetZaxis().CenterTitle()
th2.SetDrawOption('COLZ')
self.histos[i].append(th2)
for ix, x in enumerate(self.data[i]):
for iy, y in enumerate(x):
th2.SetBinContent(ix, iy, y)
th2.Draw('COLZ')
self.canvas.Update()
示例4: main
# 需要导入模块: from ROOT import TPad [as 别名]
# 或者: from ROOT.TPad import cd [as 别名]
def main():
f = TFile("ScanXsec.root","recreate")
c1 = TCanvas( 'c1', 'A Simple Graph', 200, 10, 1600, 900 )
c1.SetGrid(0,0)
gStyle.SetPaintTextFormat(".2e")
gStyle.SetOptStat(0)
gStyle.SetMarkerSize(0.9)
hAList30 = gethAList(hA_files30)
hAList34 = gethAList(hA_files34)
histo_hA030 = TH2F('xsec1','Xsec(gz=0.8, tb=1.0) pdf setting 263000',17,500,4100,6,250,850)
histo_hA034 = TH2F('xsec2','Cross-Section(pb) with PDF Setting: 263400(CMS), 263000(ATLAS and containing b quarks) and #DeltaCS',17,500,4100,6,250,850)
histo_hA0Rate = TH2F('xsec3','Xsec(gz=0.8, tb=1.0) Rate',17,500,4100,6,250,850)
histo_hA034.SetXTitle("M_{Zp} (GeV)")
histo_hA034.SetYTitle("M_{A0} (GeV)")
for a in hAList30:
histo_hA030.Fill(a.zpMass,a.ma0Mass,a.weight)
for b in hAList34:
if (a.zpMass==b.zpMass and a.ma0Mass==b.ma0Mass):
histo_hA034.Fill(b.zpMass,b.ma0Mass,b.weight)
a.rate = a.weight/b.weight
b.rate = b.weight/a.weight
histo_hA0Rate.Fill(b.zpMass,b.ma0Mass,abs(a.rate-1))
histo_hA034.SetBarOffset(0.2)
histo_hA0Rate.SetBarOffset(-0.2)
histo_hA034.GetYaxis().SetTickLength(0.)
histo_hA034.Draw("colztext")
histo_hA030.Draw("textsame")
histo_hA0Rate.Draw("textsame")
p = TPad("p","p",0.,0.,1.,1.)
p.SetFillStyle(0)
p.Draw("same")
p.cd()
pt1 = TPaveText(0.574,0.55,0.8,0.75)
pt2 = TPaveText(0.795,0.55,0.897,0.75)
pt1.SetTextSize(0.02)
pt1.AddText("Each bin contains 3 values,")
pt1.AddText("they are the cross-section (CS)")
pt1.AddText("with pdf = 263400(CMS), 263000+b(ATLAS)")
pt1.AddText("and the difference between 2 pdf settings,")
pt1.AddText(" #DeltaCS = |CS_{CMS} - CS_{ATLAS}|/CS_{CMS}")
pt2.SetTextSize(0.02)
pt2.AddText("#scale[1.3]{CS_{CMS}}")
pt2.AddText("#scale[1.3]{CS_{ATLAS}}")
pt2.AddText("#scale[1.3]{#DeltaCS}")
pt2.AddText("( 2% < #DeltaCS < 7% )")
pt1.Draw()
pt2.Draw()
c1.SaveAs("pdfDiff.png")
c1.Print("pdfDiff.pdf")
f.Write()
f.Close()
c1.Update()
示例5: draw
# 需要导入模块: from ROOT import TPad [as 别名]
# 或者: from ROOT.TPad import cd [as 别名]
def draw(self, title):
'''
draws regression and residuals in one canvas
'''
self.residuals()
from ROOT import TCanvas, TPad, TLine
from random import randint
from sys import maxint
random_name = randint(0,maxint)
self.canvas = TCanvas("canvas{}".format( random_name), "Linear Regression", 1300, 800)
self.canvas.SetBatch()
hPad = TPad("fitPad{}".format( random_name ), "Fit", 0, 0.3, 1, 1)
hPad.SetFillStyle(4000)
hPad.SetBorderSize(0)
hPad.SetBottomMargin(0)
hPad.Draw()
hPad.cd()
self.graph.SetTitle( title )
self.resgraph.GetXaxis().SetTitle("")
self.graph.Draw("ap")
self.canvas.cd()
residualPad = TPad("resPad{}".format( random_name ), "Residuals", 0, 0, 1, 0.3)
residualPad.SetFillStyle(4000)
residualPad.SetFrameFillStyle(4000)
residualPad.SetBorderSize(0)
residualPad.Draw()
residualPad.cd()
# get y-label for residuals
from re import match
try:
splittitle = title.split(';')
val, unit = match( '(.*)\[(.*)\]', splittitle[2] ).groups()
restitle = splittitle[0] + ';' + splittitle[1] + ';' + val + '- fit [' + unit + ']'
self.resgraph.SetTitle( restitle )
except:
self.resgraph.SetTitle( title + ' - fit' )
xaxis = self.resgraph.GetXaxis()
xaxis.SetTitleSize(.15)
xaxis.SetTitleOffset(.3)
xaxis.SetLabelSize(.1)
self.resgraph.GetYaxis().SetNdivisions( 8,0 ,0 )
self.resgraph.GetYaxis().SetTitleSize(.18)
self.resgraph.GetYaxis().SetTitleOffset(.23)
self.resgraph.GetYaxis().SetLabelSize(.2)
self.resgraph.Draw("ap")
self.line = TLine( xaxis.GetXmin(), 0, xaxis.GetXmax(), 0 )
self.line.Draw()
示例6: drawCanvas2
# 需要导入模块: from ROOT import TPad [as 别名]
# 或者: from ROOT.TPad import cd [as 别名]
def drawCanvas2():
c1 = TCanvas("c1", "c1", 700, 700)
pad1 = TPad("pad1", "top pad" , 0.0, 0.3, 1.0, 1.0)
pad1.SetBottomMargin(0.0)
pad1.SetNumber(1)
pad1.Draw()
pad1.cd()
c1.cd()
pad2 = TPad("pad2", "bottom pad", 0.0, 0.0, 1.0, 0.3)
pad2.SetTopMargin(0.0)
pad2.SetBottomMargin(0.35)
pad2.SetNumber(2)
pad2.Draw()
pad2.cd()
c1.cd()
return c1
示例7: make_KLZ_spectral_plot
# 需要导入模块: from ROOT import TPad [as 别名]
# 或者: from ROOT.TPad import cd [as 别名]
def make_KLZ_spectral_plot(image_name,
stack,
legend):
"""
:param image_name: name of output image (ext. ".png" will be added)
:type image_name: str
:param stack: stack of histograms to plot
:type stack: THStack
:param legend: legend to accompany histograms in stack
:type legend: TLegend
"""
ROOT.gROOT.SetStyle("Plain")
gStyle.SetCanvasBorderMode(0)
gStyle.SetPadBorderMode(0)
gStyle.SetPadColor(0)
gStyle.SetCanvasColor(0)
gStyle.SetOptTitle(0)
gStyle.SetLabelSize(0.06, "xyz")
gStyle.SetTitleSize(0.06, "xyz")
c1 = TCanvas("canvas", "canvas", 1200, 600)
c1.cd()
p1 = TPad("p1", "Full Spectrum", 0.0, 0.0, 1.0, 1.0, 0)
p1.SetBottomMargin(0.15)
p1.SetLeftMargin(0.15)
p1.Draw()
p2 = TPad("p2", "Key", 0.5, 0.6, 0.9, 0.9, 0)
p2.SetBottomMargin(0.2)
p2.SetTopMargin(0.2)
p2.Draw()
p2.cd()
legend.SetTextSize(0.08)
legend.SetNColumns(2)
legend.SetEntrySeparation(0.01)
legend.Draw()
p1.cd()
gStyle.SetOptStat(0)
p1.SetLogy()
stack.Draw("nostack")
stack.GetXaxis().SetTitle("E (MeV)")
stack.GetYaxis().SetTitle("Events/(0.05 MeV)")
stack.SetMinimum(0.1)
c1.Draw()
image_path = image_name + ".png"
c1.Print(image_path)
raw_input("RETURN to exit")
示例8: plot_data_vs_refold
# 需要导入模块: from ROOT import TPad [as 别名]
# 或者: from ROOT.TPad import cd [as 别名]
def plot_data_vs_refold(args, regularisation_settings, tau):
'''
Plot the differences between the unfolded and refolded distributions
TODO Include also with best tau - redo unfolding with best tau then come here
'''
tau = str(tau).replace('.', 'p')
# data = hist_to_value_error_tuplelist(regularisation_settings.h_data)
# measured = hist_to_value_error_tuplelist(regularisation_settings.h_measured)
variable = regularisation_settings.variable
channel = regularisation_settings.channel
plot_outpath = regularisation_settings.outpath.replace('tables/', 'plots/')+variable+'/'
make_folder_if_not_exists(plot_outpath)
outfile = plot_outpath+channel+'_unfold_refold_test_tau_'+tau+'.pdf'
if args.run_measured_as_data:
outfile = plot_outpath+channel+'_run_measured_as_data_tau_'+tau+'.pdf'
c = TCanvas('c1','c1',600,400)
c.SetFillColor(2);
p1 = TPad("pad1", "p1",0.0,0.2,1.0,1.0,21)
p2 = TPad("pad2", "p2",0.0,0.0,1.0,0.2,22)
p1.SetFillColor(0);
p2.SetFillColor(0);
p1.Draw()
p2.Draw()
p1.cd()
regularisation_settings.h_refolded.SetMarkerStyle(10);
regularisation_settings.h_refolded.SetMarkerColor(4);
# regularisation_settings.h_refolded.SetMarkerSize(10);
regularisation_settings.h_refolded.Draw()
regularisation_settings.h_data.SetFillColor(3);
regularisation_settings.h_data.Draw("hist same");
p2.cd()
h_ratio = regularisation_settings.h_data.Clone()
h_ratio.Divide(regularisation_settings.h_refolded)
h_ratio.SetMarkerSize(0.1);
h_ratio.Draw()
c.SaveAs(outfile)
c.Delete()
return
示例9: make_spectral_plot
# 需要导入模块: from ROOT import TPad [as 别名]
# 或者: from ROOT.TPad import cd [as 别名]
def make_spectral_plot(image_name,
stack,
legend):
"""
:param image_name: name of output image (ext. ".png" will be added)
:type image_name: str
:param stack: stack of histograms to plot
:type stack: THStack
:param legend: legend to accompany histograms in stack
:type legend: TLegend
"""
ROOT.gROOT.SetStyle("Plain")
gStyle.SetCanvasBorderMode(0)
gStyle.SetPadBorderMode(0)
gStyle.SetPadColor(0)
gStyle.SetCanvasColor(0)
gStyle.SetOptTitle(0)
gStyle.SetLabelSize(0.06, "xyz")
gStyle.SetTitleSize(0.06, "xyz")
gStyle.SetOptStat("")
c1 = TCanvas("canvas", "canvas", 1200, 900)
c1.cd()
p1 = TPad("p1", "Region of Interest", 0.0, 0.5, 0.7, 1.0, 0)
p1.SetBottomMargin(0.15)
p1.SetLeftMargin(0.15)
p1.Draw()
p2 = TPad("p2", "Key", 0.7, 0.5, 1.0, 1.0, 0)
p2.SetBottomMargin(0.15)
p2.SetTopMargin(0.15)
p2.SetLeftMargin(0.05)
p2.SetRightMargin(0.05)
p2.Draw()
p3 = TPad("p3", "Full Spectrum", 0.0, 0.0, 1.0, 0.5, 0)
p3.SetBottomMargin(0.15)
p3.SetLeftMargin(0.15)
p3.Draw()
p3.cd()
gStyle.SetOptStat(0)
p3.SetLogy()
stack.Draw("nostack")
stack.GetXaxis().SetTitle("E (MeV)")
stack.GetYaxis().SetTitle("Events/(0.02 MeV)")
stack.SetMinimum(0.1)
p1.cd()
gStyle.SetOptStat(0)
p1.SetLogy()
stack_zoomed = stack.Clone()
x_axis = stack_zoomed.GetXaxis()
bin_width = x_axis.GetBinWidth(0) # assume uniform
e_lo = 2.0 # MeV
e_hi = 3.5 # MeV
x_axis.SetRange(int(e_lo/bin_width), int(e_hi/bin_width))
stack_zoomed.SetMaximum(5e3)
stack_zoomed.Draw("nostack")
p2.cd()
legend.Draw()
c1.Draw()
image_path = image_name + ".png"
c1.Print(image_path)
raw_input("RETURN to exit")
示例10: savePlot
# 需要导入模块: from ROOT import TPad [as 别名]
# 或者: from ROOT.TPad import cd [as 别名]
def savePlot(plot,plotPull,filename,longPlot=True):
if plotPull:
plotPull.GetYaxis().SetRangeUser(-5,5)
plotPull.SetMarkerStyle(2)
cNorm.Clear()
cLong.Clear()
plotPullTh1 = False
tmpLogy = False
tmpLogx = False
plot.GetXaxis().SetDecimals(True)
plot.GetXaxis().SetLabelOffset(0.023)
if plotPull:
tmpLogy = gPad.GetLogy()
tmpLogx = gPad.GetLogx()
gPad.SetLogy(False)
gPad.SetLogx(False)
pNorm1 = TPad("pNorm1","pNorm1",0,0.28,1,1)
pNorm2 = TPad("pNorm2","pNorm2",0,0,1,0.28)
cNorm.cd()
pNorm1.Draw()
pNorm2.Draw()
pNorm1.SetFillColor(0)
pNorm2.SetFillColor(0)
pNorm2.SetBottomMargin(0.33)
pNorm1.SetLogy(tmpLogy)
pNorm1.SetLogx(tmpLogx)
pNorm2.SetLogx(tmpLogx)
#pNorm1.SetBottomMargin(0.00001)
pNorm1.SetBottomMargin(0.025)
pNorm1.SetBorderMode(0)
pNorm2.SetTopMargin(0.01)
#pNorm2.SetTopMargin(0.05)
#pNorm2.SetBottomMargin(0.1)
pNorm2.SetBorderMode(0)
plot.GetXaxis().SetLabelOffset(0.023)
plot.GetXaxis().SetLabelSize(0.06)
plot.GetXaxis().SetTitleOffset(1.1)
plot.GetYaxis().SetLabelSize(0.06)
plot.GetXaxis().SetNdivisions(511)
pNorm1.SetLeftMargin(0.13)
pNorm2.SetLeftMargin(0.13)
pxa = plot.GetXaxis()
plotPullTh1 = TH1D("plotPullTh1","plotPullTh1",100,pxa.GetBinLowEdge(pxa.GetFirst()),pxa.GetBinUpEdge(pxa.GetLast()))
plotPullTh1.SetStats(False)
plotPullTh1.GetXaxis().SetDecimals(True)
if plotPull:
plotPullTh1.GetYaxis().SetRangeUser(-5,5)
plotPullTh1.GetXaxis().SetTitle(plot.GetXaxis().GetTitle())
plotPullTh1.GetXaxis().SetNdivisions(511)
plotPullTh1.GetXaxis().SetTickLength(0.1)
plotPullTh1.GetYaxis().SetTitle("Pull / #sigma")
plotPullTh1.GetYaxis().SetTitleFont(132)
plotPullTh1.GetYaxis().SetNdivisions(205)
plotPullTh1.GetXaxis().SetLabelSize(0.15)
plotPullTh1.GetXaxis().SetLabelOffset(0.022)
plotPullTh1.GetXaxis().SetTitleSize(0.18)
plotPullTh1.GetXaxis().SetTitleOffset(0.78)
plotPullTh1.GetXaxis().SetTitleFont(132)
plotPullTh1.GetYaxis().SetLabelSize(0.15)
plotPullTh1.GetYaxis().SetLabelOffset(0.009)
plotPullTh1.GetYaxis().SetTitleSize(0.17)
plotPullTh1.GetYaxis().SetTitleOffset(0.32)
##plotPull.GetZaxis().SetLabelSize(0.05)
##plotPull.GetZaxis().SetTitleSize(0.06)
##plotPull.GetZaxis().SetTitleFont(42)
plot.GetYaxis().SetTitleOffset(1)
plot.GetXaxis().SetTitleSize(0.06)
plot.GetYaxis().SetTitleSize(0.06)
plot.GetXaxis().SetTitleFont(132)
plot.GetYaxis().SetTitleFont(132)
plot.GetXaxis().SetLabelFont(132)
plot.GetYaxis().SetLabelFont(132)
tl = False
#if "asym" not in filename and "data" not in filename and "nll" not in filename:
#tl = genLegend(plot)
cNorm.cd()
#.........这里部分代码省略.........
示例11: plotEfficiencyForPt
# 需要导入模块: from ROOT import TPad [as 别名]
# 或者: from ROOT.TPad import cd [as 别名]
def plotEfficiencyForPt(folder,pt):
if(DEBUG):
print prefix + 'was called'
#Set plot style
if(DEBUG):
print prefix + "Getting histogram: %s" % ("hoMuonAnalyzer/efficiency/GenAndL1MuonPt" + str(pt) + "_Efficiency")
l1Muon = fileHandler.getHistogram("hoMuonAnalyzer/efficiency/GenAndL1MuonPt" + str(pt) + "_Efficiency")
l1MuonAndHo = fileHandler.getHistogram("hoMuonAnalyzer/efficiency/L1MuonHoRecoPt" + str(pt) + "_Efficiency")
if(DEBUG):
print prefix + "Getting histogram: %s" % ("hoMuonAnalyzer/efficiency/GenAndL1MuonAndHoAboveThrPt" + str(pt) + "_Efficiency")
l1MuonAndHoAboveThr = fileHandler.getHistogram("hoMuonAnalyzer/efficiency/GenAndL1MuonAndHoAboveThrPt" + str(pt) + "_Efficiency")
canv = TCanvas("efficiencyCanvas" + str(pt),'efficiencyCanvas' + str(pt),1200,1200)
l1Muon.SetMarkerStyle(markerpairs[pt/5 -1][0])
l1MuonAndHo.SetMarkerStyle(21)
l1MuonAndHoAboveThr.SetMarkerStyle(markerpairs[pt/5 -1][1])
l1Muon.SetMarkerColor(colorRwthDarkBlue)
l1MuonAndHo.SetMarkerColor(ROOT.kBlue)
l1MuonAndHoAboveThr.SetMarkerColor(colorRwthMagenta)
l1Muon.SetLineColor(colorRwthDarkBlue)
l1MuonAndHo.SetLineColor(ROOT.kBlue)
l1MuonAndHoAboveThr.SetLineColor(colorRwthMagenta)
upperPad = TPad("upperPad", "upperPad", .005, .25, .995, .995);
lowerPad = TPad("lowerPad", "lowerPad", .005, .005, .995, .25);
upperPad.SetBottomMargin(0)
lowerPad.SetTopMargin(0)
upperPad.Draw()
lowerPad.Draw()
upperPad.cd()
l1Muon.Draw()
# l1MuonAndHo.Draw('same')
l1MuonAndHoAboveThr.Draw('same')
canv.Update()
l1Muon.GetPaintedGraph().GetYaxis().SetTitleFont(62)
l1Muon.GetPaintedGraph().GetYaxis().SetLabelFont(62)
l1Muon.GetPaintedGraph().GetXaxis().SetRangeUser(0,50)
#.GetPaintedGraph()
l1Muon.SetTitle("Efficiency, p_{T} = " + str(pt) + " GeV;p_{T};Eff.")
canv.Update()
line = TLine(pt,0,pt,1)
line.SetLineColor(ROOT.kRed)
line.SetLineWidth(2)
line.Draw()
legend = TLegend(0.5,0.1,0.9,0.35)
legend.AddEntry(l1Muon,'L1 Efficiency','ep')
legend.AddEntry(l1MuonAndHoAboveThr,'L1 + HO hits > 0.2 GeV','ep')
legend.AddEntry(line,'Trg. threshold','e')
legend.Draw()
integralL1 = 0
integralL1AndHo = 0
for i in range(0,pt+1):
integralL1 += l1Muon.GetPassedHistogram().GetBinContent(pt+1)
integralL1AndHo += l1MuonAndHoAboveThr.GetPassedHistogram().GetBinContent(pt+1)
paveText = TPaveText(0.5,0.35,0.9,0.4,'NDC')
if(not integralL1 == 0):
paveText.AddText('%s: %.2f%% #pm %.2f%%' % ('Reduction below threshold',100 - integralL1AndHo/integralL1*100,calcSigma(integralL1AndHo, integralL1)*100))
paveText.SetBorderSize(1)
paveText.Draw()
label = drawLabelCmsPrivateSimulation()
##### Try creating residuals
lowerPad.cd()
l1MuonGraph = l1Muon.GetPaintedGraph()
l1MuonAndHoAboveThrGraph = l1MuonAndHoAboveThr.GetPaintedGraph()
newGraph = TGraph()
x1 = Double(0)
y1 = Double(0)
x2 = Double(0)
y2 = Double(0)
for i in range(0,50):
l1MuonGraph.GetPoint(i,x1,y1)
l1MuonAndHoAboveThrGraph.GetPoint(i,x2,y2)
newGraph.SetPoint(i,x1,(y1-y2)*100)
newGraph.SetMarkerStyle(20)
newGraph.GetYaxis().SetTitle("%")
newGraph.Draw("a,p")
newGraph.GetXaxis().SetLimits(0,50)
line2 = TLine(0,0,50,0)
line2.SetLineColor(ROOT.kRed)
line2.SetLineWidth(2)
line2.Draw()
##### Finally save the stuff
#.........这里部分代码省略.........
示例12: draw_canvas_with_pull
# 需要导入模块: from ROOT import TPad [as 别名]
# 或者: from ROOT.TPad import cd [as 别名]
def draw_canvas_with_pull(mplot, mplot_pull, in_directory, in_file_name, in_model_name="", logy=0): # mplot + pull
mplot.GetXaxis().SetTitleOffset(1.1)
mplot.GetYaxis().SetTitleOffset(1.3)
mplot.GetXaxis().SetTitleSize(0.05)
mplot.GetYaxis().SetTitleSize(0.05)
mplot.GetXaxis().SetLabelSize(0.045)
mplot.GetYaxis().SetLabelSize(0.045)
mplot_pull.GetXaxis().SetLabelSize(0.15)
mplot_pull.GetYaxis().SetLabelSize(0.15)
mplot_pull.GetYaxis().SetTitleSize(0.15)
mplot_pull.GetYaxis().SetNdivisions(205)
cMassFit = TCanvas("cMassFit", "cMassFit", 600, 600)
pad1 = TPad("pad1", "pad1", 0.0, 0.0, 0.99, 0.24)
pad2 = TPad("pad2", "pad2", 0.0, 0.24, 0.99, 1.0)
pad1.Draw()
pad2.Draw()
pad2.cd()
mplot.Draw()
banner = banner4Plot(1)
banner.Draw()
pad1.cd()
mplot_pull.Draw()
## create the directory where store the plots
Directory = TString(in_directory)
if not Directory.EndsWith("/"):
Directory = Directory.Append("/")
if not os.path.isdir(Directory.Data()):
os.system("mkdir -p " + Directory.Data())
rlt_file = TString()
rlt_file.Form("%s_%s" % (Directory, in_file_name))
if rlt_file.EndsWith(".root"):
TString(in_model_name).ReplaceAll(".root", "")
rlt_file.ReplaceAll(".root", "_" + in_model_name + "_with_pull.png")
else:
TString(in_model_name).ReplaceAll(".root", "")
rlt_file.ReplaceAll(".root", "")
rlt_file = rlt_file.Append("_" + in_model_name + "_with_pull.png")
cMassFit.SaveAs(rlt_file.Data())
rlt_file.ReplaceAll(".png", ".pdf")
cMassFit.SaveAs(rlt_file.Data())
rlt_file.ReplaceAll(".pdf", ".root")
cMassFit.SaveAs(rlt_file.Data())
string_file_name = TString(in_file_name)
if string_file_name.EndsWith(".root"):
string_file_name.ReplaceAll(".root", "_" + in_model_name)
else:
string_file_name.ReplaceAll(".root", "")
string_file_name.Append("_" + in_model_name)
if logy:
pad2.SetLogy()
pad2.Update()
cMassFit.Update()
rlt_file.ReplaceAll(".root", "_log.root")
cMassFit.SaveAs(rlt_file.Data())
rlt_file.ReplaceAll(".root", ".pdf")
cMassFit.SaveAs(rlt_file.Data())
rlt_file.ReplaceAll(".pdf", ".png")
cMassFit.SaveAs(rlt_file.Data())
draw_canvas(mplot, in_directory, string_file_name.Data(), 0, logy)
示例13: plot_nice1D
# 需要导入模块: from ROOT import TPad [as 别名]
# 或者: from ROOT.TPad import cd [as 别名]
def plot_nice1D(channel, var, bin, low, high, ylabel, xlabel, save, setLog = False, finalcuts = False):
result = true
# Choose 1, ratio or pull
drawPull = False
drawRatio = True
#folder = 'Trig_Sys'
folder = 'JEC_CR1'
#folder = 'Preliminary'
#folder = 'Lepton_CR'
#folder = 'ModelIndep'
#folder = 'SusyHiggs'
#folder = 'Sys'
#No Tau
List = [ 'DiPhotonJets','DiphotonBox_Pt_25to250','DiphotonBox_Pt_250toInf','WtoLNuMu','WtoLNuTau','WGamma','ZGToLLG','ZGamma_Inclusive','efake_dd','qcd_dd','GJets_HT_40To100','GJets_HT_100To200','GJets_HT_200To400','GJets_HT_400','SinglePhotonParked','DM','MChi_70']
SF_photon = "( (0.99 * 0.97 * (Pho_Pt>40 && Pho_Pt<50)) + (0.99 * 1.01 * (Pho_Pt>=50) ) )"
cut_GGFTrig = " && (hltmatched==1)"
stack = THStack('a', 'a')
added = TH1D('a', 'a',bin,low,high)
added.Sumw2()
added_mconly = TH1D('added_mconly', 'added_mconly',bin,low,high)
added_mconly.Sumw2()
added_nogjets = TH1D('added_nogets', 'added_nogjets',bin,low,high)
added_nogjets.Sumw2()
justGJets = TH1D('justGJets', 'justGJets',bin,low,high)
justGJets.Sumw2()
Variables = {}
efficiency ={}
totalbkg = 0
diphoton = 0.
gamma_jet = 0.
print ' '
print var
for Type in List:
pu_weight = "MyWeightData_new"
#pu_weight = "MyWeightData_new_sys"
#What i used for the pre-approval
trig_met = "((0.5*0.977*(1+TMath::Erf( (MET - 28.23) / (25.0*sqrt(2))))) * (MET>40.) )"
trig_phoid = "((0.5*0.892*(1+TMath::Erf( (Pho_Pt + 36.8) / (43.8*sqrt(2))))) * (Pho_Pt >30.) )"
#Shift up, met
#trig_met = "((0.5*0.98*(1+TMath::Erf( (MET - 28.33) / (25.3*sqrt(2))))) * (MET>40.) )"
#trig_phoid = "((0.5*0.892*(1+TMath::Erf( (Pho_Pt + 36.8) / (43.8*sqrt(2))))) * (Pho_Pt >30.) )"
#Shift down, met
#trig_met = "((0.5*0.98*(1+TMath::Erf( (MET - 28.33) / (25.3*sqrt(2))))) * (MET>40.) )"
#trig_phoid = "((0.5*0.892*(1+TMath::Erf( (Pho_Pt + 36.8) / (43.8*sqrt(2))))) * (Pho_Pt >30.) )"
#trig_phoid = "((0.5*0.89*(1+TMath::Erf( (Pho_Pt - 19.44) / (7.15*sqrt(2))))) * (Pho_Pt >30.) )"
#trig_met = "((0.5*0.977*(1+TMath::Erf( (MET - 28.23) / (25.0*sqrt(2))))) * (MET>40.) )"
#trig_phoid = "((0.5*0.892*(1+TMath::Erf( (Pho_Pt + 36.8) / (43.8*sqrt(2))))) * (Pho_Pt >30.) )"
#trig_met = "((0.5*0.986*(1+TMath::Erf( (MET - 28.0) / (26.0*sqrt(2))))) * (MET>40.) )"
puweight = "(1.0)"
#dphi_weight = "(0.380604 - 0.162698*TMath::Abs(dphi_pho_met) + 1.36338*pow(TMath::Abs(dphi_pho_met),2) - 0.446155*pow(TMath::Abs(dphi_pho_met),3)- 0.183011*pow(TMath::Abs(dphi_pho_met),4) + 0.103991*pow(TMath::Abs(dphi_pho_met),5) -0.0126396*pow(TMath::Abs(dphi_pho_met),6))"
if (Type.startswith('GJets')):
other_weight = "(1.7 * (n_jets_mva_loose == 0) + 1.1 * (n_jets_mva_loose > 0))"
dphi_weight = "(0.378403 - 0.159585*TMath::Abs(dphi_pho_met) + 1.35184*pow(TMath::Abs(dphi_pho_met),2) - 0.423989*pow(TMath::Abs(dphi_pho_met),3)- 0.19808*pow(TMath::Abs(dphi_pho_met),4) + 0.108294*pow(TMath::Abs(dphi_pho_met),5) - 0.0130729*pow(TMath::Abs(dphi_pho_met),6))"
else:
other_weight = "(1.0)"
dphi_weight = "(1.0)"
#PRELIMINARY
cut_standard ="(Pho_Pt > 45 && Pho_R9>0.9 &&TMath::Abs(Pho_Eta)<1.442 && sigmaIEtaIEta > 0.001 && sqrt(sigmaIPhiIPhi) > 0.001 && Pho_R9<1.0 && seedCrystalEnergy/(e1x3+e1x5-seedCrystalEnergy) < 0.9 && MET>40. && loose_mu_10==0 && foundvetoEl_10==0 )"
#LEPTON_CR
#cut_standard= "(Pho_Pt > 45 && Pho_R9>0.9 &&TMath::Abs(Pho_Eta)<1.442 && sigmaIEtaIEta > 0.001 && sqrt(sigmaIPhiIPhi) > 0.001 && seedCrystalEnergy/(e1x3+e1x5-seedCrystalEnergy) < 0.9 && Pho_R9<1.0 && MET>40. && (loose_mu_10==1 || foundvetoEl_10 == 1) )"
#MODELINDEP
#cut_standard ="(Pho_Pt > 45 && Pho_R9>0.9 &&TMath::Abs(Pho_Eta)<1.442 && sigmaIEtaIEta > 0.001 && sqrt(sigmaIPhiIPhi) > 0.001 && Pho_R9<1.0 && seedCrystalEnergy/(e1x3+e1x5-seedCrystalEnergy) < 0.9 && MET>140. && loose_mu_10==0 && foundvetoEl_10==0 && n_jets_mva_loose < 2 && (TMath::Abs(dphi_jet_pho) <2.5 || dphi_jet_pho == -99) )"
#.........这里部分代码省略.........
示例14: Plot
# 需要导入模块: from ROOT import TPad [as 别名]
# 或者: from ROOT.TPad import cd [as 别名]
#.........这里部分代码省略.........
int(self.PLOT_HEIGHT))
SetOwnership(self._canvas, False)
# Create the main plot and draw it
self._plot = TPad(
name + '_plot',
name,
0.0,
(self.PLOT_RATIO_FRACTION
if ratio
else 0.0),
1.0,
1.0
)
SetOwnership(self._plot, False)
self._plot.SetMargin(*(self.PLOT_MARGINS_WITH_RATIO
if ratio
else self.PLOT_MARGINS))
self._plot.Draw()
# HACK: Draw the plot title.
# https://root.cern.ch/phpBB3/viewtopic.php?t=18282. Wonderful.
self._draw_title()
# Store ranges
self._x_range = x_range
if y_max is not None:
self._set_maximum_value(y_max)
# Store log scale
self._y_log_scale = y_log_scale
# Switch back to the context of the canvas
self._canvas.cd()
# Create a ratio plot and draw it if requested
if ratio:
self._ratio_plot = TPad(
name + '_ratio',
name,
0.0,
0.0,
1.0,
self.PLOT_RATIO_FRACTION
)
SetOwnership(self._ratio_plot, False)
self._ratio_plot.SetMargin(*self.PLOT_RATIO_MARGINS)
self._ratio_plot.SetGridy(True)
self._ratio_plot.Draw()
else:
self._ratio_plot = None
# Track whether or not we've already drawn to the main pad
self._drawn = False
# Track whether or not we've already drawn to the ratio pad
self._ratio_drawn = False
# Track that object which sets up the axes in the main plot
self._axes_object = None
# Create a structure to track any histograms we generate internally
# which need to be added to any legends created
self._legend_extras = []
# Create lists of the cloned drawables, just to be certain
示例15: array
# 需要导入模块: from ROOT import TPad [as 别名]
# 或者: from ROOT.TPad import cd [as 别名]
for i in temp_another_dict:
list1.append(float(temp_another_dict[i][0]))
list2.append(float(temp_another_dict[i][1]))
x = array("d",list1)
y = array("d",list2)
corr = correlation(x,y)
c = TCanvas('canvas','can1',600,600)
c.Draw()
c.cd()
tp1 = TPad('MYDATA','MYDATA',0.0,0.0,1,1)
tp1.SetGrid()
tp1.Draw()
tp1.cd()
maximum = 1
bins =500
bin_to_value = (bins/2)/maximum
gr_2 = TH1F('h1','myhist',bins, -maximum, maximum)
for i in range(len(p_corr_list)):
gr_2.Fill(p_corr_list[i],1.0/trials)
gr_2.Draw()
fitsignal = TF1("FSignal","gaus", -maximum, maximum) # this gaussian can then be integrated to get the two tailed p-values. Input these values into correlation_gaussian.np code to integrate.
gr_2.Fit(fitsignal,'R')
norm_gaus = fitsignal.Integral(-1,1)
if corr < 0:
integrals = 2*fitsignal.Integral(-1,corr)/norm_gaus