本文整理汇总了Python中rootpy.plotting.Graph类的典型用法代码示例。如果您正苦于以下问题:Python Graph类的具体用法?Python Graph怎么用?Python Graph使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Graph类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: luminosity_vs_time
def luminosity_vs_time(timing_list, luminosity_list, style, run_name):
'''
:param timing_list: Python list containing the timing data
:param luminosity_list: Python list containing the luminosity data
:param style: ROOT style in string, such as 'ATLAS'
:return:
'''
# Set ROOT graph style
set_style(str(style))
# create graph
graph = Graph(len(timing_list))
for i, (xx, yy) in enumerate(zip(timing_list, luminosity_list)):
graph.SetPoint(i, xx, yy)
# set visual attributes
graph.markercolor = 'blue'
graph.xaxis.SetTitle("Time")
graph.yaxis.SetTitle("Luminosity")
graph.xaxis.SetRangeUser(min(timing_list), max(timing_list))
graph.yaxis.SetRangeUser(min(luminosity_list), max(luminosity_list))
# plot with ROOT
canvas = Canvas()
graph.Draw("AP")
label = ROOT.TText(0.8, 0.9, str(run_name))
label.SetTextFont(43)
label.SetTextSize(25)
label.SetNDC()
label.Draw()
canvas.Modified()
canvas.Update()
wait(True)
示例2: plot_raw_detector_vs_detector
def plot_raw_detector_vs_detector(detector_one_data, detector_two_data, style, name):
# Set ROOT graph style
set_style(str(style))
detector_one_list = []
detector_two_list = []
for block in range(len(detector_one_data)):
for bcid in range(len(detector_one_data[block])):
detector_one_list.append(detector_one_data[block][bcid])
detector_two_list.append(detector_two_data[block][bcid])
# create graph
graph = Graph(len(detector_one_list))
for i, (xx, yy) in enumerate(zip(detector_one_list, detector_two_list)):
graph.SetPoint(i, float(xx), float(yy))
# set visual attributes
graph.markercolor = 'blue'
graph.xaxis.SetTitle("BCM V [Raw Rate]")
graph.yaxis.SetTitle("LUCID BI [Raw Rate]")
graph.xaxis.SetRangeUser(0, 1)
graph.yaxis.SetRangeUser(0, 1)
# plot with ROOT
canvas = Canvas()
graph.Draw("AP")
label = ROOT.TText(0.6, 0.9, str(name))
label.SetTextFont(43)
label.SetTextSize(25)
label.SetNDC()
label.Draw()
canvas.Modified()
canvas.Update()
wait(True)
示例3: plot_percent_luminosity_ratio
def plot_percent_luminosity_ratio(detector_one_data, detector_two_data, style, run_name):
'''
:param detector_one_data: Data from one detector type, such as ATLAS' LUCID, in a list of lists, every entry is one
luminsoity block, with the luminosity block being a list of BCID data, assumed to be same
length as detector_two_data
:param detector_two_data: Data from another detector type, such as ATLAS' LUCID, in a list of lists, every entry is
one luminosity block, with the luminosity block being a list of BCID data, assumed to be same
length as detector_one_data
:param style: The ROOT style for the graph, generally 'ATLAS'
:return: ROOT plots of the ratio of luminosities over the luminosity, as percetnage difference from first data point
'''
# Set ROOT graph style
set_style(str(style))
print("Number of Luminosity Blocks included: " + str(len(detector_one_data)))
# Get ratio of the detectors
luminosity_ratio = []
lumi_blocks = []
for block in range(len(detector_one_data)):
for bcid in range(len(detector_one_data[block])):
detector_one_point = detector_one_data[block][bcid]
detector_two_point = detector_two_data[block][bcid]
# Check if the blocks are zero
if detector_one_point != 0.0 and detector_two_point != 0.0:
ratio = -math.log(1 - detector_one_point) / -math.log(1 - detector_two_point)
luminosity_ratio.append(ratio)
lumi_blocks.append(block)
# Get percentage difference based off the first block and BCID
first_point = luminosity_ratio[0]
for index in range(len(luminosity_ratio)):
luminosity_ratio[index] = (luminosity_ratio[index] / first_point) - 1
# create graph
graph = Graph(len(lumi_blocks), title=run_name)
for i, (xx, yy) in enumerate(zip(lumi_blocks, luminosity_ratio)):
graph.SetPoint(i, float(xx), float(yy))
# set visual attributes
graph.markercolor = 'blue'
graph.xaxis.SetTitle("Luminosity Block")
graph.yaxis.SetTitle("Luminosity [Percent Ratio]")
graph.xaxis.SetRangeUser(min(lumi_blocks), max(lumi_blocks))
graph.yaxis.SetRangeUser(min(luminosity_ratio), max(luminosity_ratio))
# plot with ROOT
canvas = Canvas()
graph.Draw("AP")
label = ROOT.TText(0.8, 0.9, str(run_name))
label.SetTextFont(43)
label.SetTextSize(25)
label.SetNDC()
label.Draw()
canvas.Modified()
canvas.Update()
wait(True)
示例4: rejection
def rejection(eff):
htot = asrootpy(eff.GetTotalHistogram()).Clone()
hpass = asrootpy(eff.GetPassedHistogram())
if hpass.Integral !=0:
rej = htot/hpass
else:
rej = htot
rej = Graph(rej)
name = '_'.join(eff.name.split('_')[1:])
rej.name = 'rej_{0}'.format(name)
rej.title = eff.title
return rej
示例5: draw_curve_8
def draw_curve_8(_func, name, title, ylow, yhigh, num_errs=1):
""" Draw 8TeV trigger efficiency curves """
graphs = []
for (trigger, color) in triggers:
tool = ROOT.TrigTauEfficiency()
tool.loadInputFile(os.path.join(base, 'triggerSF_{0}.root'.format(trigger)))
func = getattr(tool, _func)
eff = np.array(map(lambda x: func(x, eta, 0, period, prong, wpflag, eveto), pt))
errs_low = []
errs_high = []
for ierr in xrange(num_errs):
eff_low = np.array(map(lambda x: func(x, eta, -1, period, prong, wpflag, eveto), pt))
eff_high = np.array(map(lambda x: func(x, eta, 1, period, prong, wpflag, eveto), pt))
errs_low.append(eff_low)
errs_high.append(eff_high)
# quadrature sum of error
eff_low = np.sqrt(np.sum([np.power(err, 2) for err in errs_low], axis=0))
eff_high = np.sqrt(np.sum([np.power(err, 2) for err in errs_high], axis=0))
graph = Graph(len(pt), name=trigger)
for i, (p, e, e_low, e_high) in enumerate(zip(pt, eff, eff_low, eff_high)):
graph.SetPoint(i, p / 1000, e)
graph.SetPointError(i, 0.4, 0.4, e_low, e_high)
graph.linecolor = color
graph.linewidth = 2
graph.fillstyle = '/'
graph.fillcolor = color
graphs.append(graph)
c = Canvas()
leg = Legend(len(graphs),
pad=c, topmargin=0.6, leftmargin=0.3,
textsize=25, margin=0.2)
for i, g in enumerate(graphs):
if i == 0:
g.Draw('3AL')
g.xaxis.title = '#font[52]{p}_{T} [GeV]'
g.xaxis.SetLimits(20, 100)
g.yaxis.SetLimits(ylow, yhigh)
g.yaxis.SetRangeUser(ylow, yhigh)
g.yaxis.title = title
else:
g.Draw('3L SAME')
leg.AddEntry(g, g.name, 'L')
leg.Draw()
lines = []
for thresh in (25, 35):
line = Line(thresh, ylow, thresh, yhigh)
line.linestyle = 'dashed'
line.linewidth = 2
line.Draw()
lines.append(line)
c.SaveAs('trigger_{0}.png'.format(name))
c.SaveAs('trigger_{0}.eps'.format(name))
示例6: test_init_from_file_1d
def test_init_from_file_1d():
with tempfile.NamedTemporaryFile() as f:
for i in xrange(100):
f.write('{0:.3f},{1:.3f}\n'.format(
random(), random()))
f.flush()
g = Graph.from_file(f.name, sep=',')
assert_equal(len(g), 100)
示例7: draw_curve_7
def draw_curve_7(_func, name, title, ylow, yhigh):
""" Draw 7TeV trigger efficiency curves """
graphs = []
for (trigger, color) in triggers:
tool = ROOT.TauTriggerCorrections(os.path.join(base, 'triggerSF_%s.root' % trigger))
func = getattr(tool, _func)
eff = map(lambda x: func(x, 0), pt)
eff_low = map(lambda x: func(x, -1), pt)
eff_high = map(lambda x: func(x, 1), pt)
graph = Graph(len(pt), name=trigger)
for i, (p, e, e_low, e_high) in enumerate(zip(pt, eff, eff_low, eff_high)):
graph.SetPoint(i, p / 1000, e)
graph.SetPointError(i, 0.4, 0.4, e - e_low, e_high - e)
graph.linecolor = color
graph.linewidth = 2
graph.fillstyle = '/'
graph.fillcolor = color
graphs.append(graph)
c = Canvas()
leg = Legend(len(graphs),
pad=c, topmargin=0.4, leftmargin=0.3, textsize=25, margin=0.2)
for i, g in enumerate(graphs):
if i == 0:
g.Draw('3AC')
g.xaxis.title = '#font[52]{p}_{T} [GeV]'
g.xaxis.SetLimits(20, 100)
g.yaxis.SetLimits(ylow, yhigh)
g.yaxis.SetRangeUser(ylow, yhigh)
g.yaxis.title = title
else:
g.Draw('3C SAME')
leg.AddEntry(g, g.name, 'L')
leg.Draw()
lines = []
for thresh in (25, 35):
line = Line(thresh, ylow, thresh, yhigh)
line.linestyle = 'dashed'
line.linewidth = 2
line.Draw()
lines.append(line)
c.SaveAs('trigger_{0}.png'.format(name))
c.SaveAs('trigger_{0}.eps'.format(name))
示例8: get_ratios
def get_ratios(results_7TeV, results_8TeV):
ratios = {}
for key in results_7TeV.keys():
ratio = None
if 'Graph' in str(type(results_7TeV[key])):
ratio = Graph.divide(results_7TeV[key], results_8TeV[key], False)
else:
ratio = results_7TeV[key].Clone( 'ratio_' + key )
ratio.Divide(results_8TeV[key])
ratios[key] = ratio
return ratios
示例9: test_xerr
def test_xerr():
g = Graph(10)
list(g.xerr())
g = Graph(10, type='errors')
list(g.xerr())
g = Graph(10, type='asymm')
list(g.xerr())
示例10: luminosity_block_log_time
def luminosity_block_log_time(luminosity_list, style):
'''
:param timing_list: Python list containing the timing data
:param luminosity_list: Python list containing the luminosity data
:param style: ROOT style in string, such as 'ATLAS'
:return: Graph of the luminosity over a single block
'''
# Set ROOT graph style
set_style(str(style))
luminosity_ratio = []
for bcid in range(len(luminosity_list)):
detector_one_point = luminosity_list[bcid]
# Check if the blocks are zero
if detector_one_point != 0.0:
ratio = -math.log(1 - detector_one_point)
luminosity_ratio.append(ratio)
# create graph
graph = Graph(len(luminosity_ratio))
for i, (xx, yy) in enumerate(zip(range(len(luminosity_ratio)), luminosity_ratio)):
graph.SetPoint(i, xx, yy)
# set visual attributes
graph.markercolor = 'blue'
graph.xaxis.SetTitle("Time")
graph.yaxis.SetTitle("-Ln(1 - Rate) [Single Detector]")
graph.xaxis.SetRangeUser(0, 3564)
graph.yaxis.SetRangeUser(min(luminosity_ratio), max(luminosity_ratio))
# plot with ROOT
canvas = Canvas()
graph.Draw("AP")
wait(True)
示例11: plot_all_luminosity_block_ratio
#.........这里部分代码省略.........
print("Detector 2 Point: " + str(detector_two_point))
detector_one_avg += detector_one_point
one_count += 1
detector_two_avg += detector_two_point
two_count += 1
else:
#print(" RUN: " + str(run) + " END")
#print(all_detector_one_data.get(run)[block][bcid])
# Checking if the status is stable
if 1 > all_detector_one_data.get(run)[block][bcid] > 0.0 and 1 > all_detector_two_data.get(run)[block][bcid] > 0.0\
and status_data.get(run)[block][bcid] > 0.0:
#print("Value of Block, BCID: " + str(block) + " " + str(bcid) + " " + str(all_detector_one_data.get(run)[block][bcid]))
detector_one_point = -math.log(1 - all_detector_one_data.get(run)[block][bcid])
detector_two_point = -math.log(1 - all_detector_two_data.get(run)[block][bcid])
detector_one_avg += detector_one_point
one_count += 1
detector_two_avg += detector_two_point
two_count += 1
if one_count != 0:
detector_one_avg = detector_one_avg / one_count
detector_two_avg = detector_two_avg / two_count
if run == "286282":
print("One Average: " + str(detector_one_avg))
temp_detector_one.get(run)[block_count - 1].append(detector_one_avg)
temp_detector_two.get(run)[block_count - 1].append(detector_two_avg)
# Remove the last luminosity block from each run, the one that generally spikes
temp_detector_one[run] = temp_detector_one[run][:-10]
temp_detector_two[run] = temp_detector_two[run][:-10]
# Reassign temp to the original lists
all_detector_one_data = temp_detector_one
all_detector_two_data = temp_detector_two
# Get ratio of the detectors
luminosity_ratio = []
lumi_blocks = []
block_count1 = 0
for run in sorted(all_detector_one_data.keys()):
for block in range(len(all_detector_one_data.get(run))):
block_count1 += 1
for bcid in range(len(all_detector_one_data.get(run)[block])):
detector_one_point = all_detector_one_data.get(run)[block][bcid]
detector_two_point = all_detector_two_data.get(run)[block][bcid]
# Check if the blocks are zero
if detector_one_point != 0.0 or detector_two_point != 0.0:
ratio = detector_one_point / detector_two_point
luminosity_ratio.append(ratio)
lumi_blocks.append(block_count1)
else:
print("Run", str(run), " Block:", str(block), "One:", str(detector_one_point),
"Two:", str(detector_two_point))
print("Length lumi_blocks: " + str(len(lumi_blocks)))
print("length lumi_ratio: " + str((len(luminosity_ratio))))
# Get percentage difference based off the first block and BCID
first_point = detector_one_calibration / detector_two_calibration
for index in range(len(luminosity_ratio)):
luminosity_ratio[index] = 100 * ((luminosity_ratio[index] / first_point) - 1)
# create graph
graph = Graph(len(lumi_blocks))
for i, (xx, yy) in enumerate(zip(lumi_blocks, luminosity_ratio)):
#print (xx, yy)
graph.SetPoint(i, float(xx), float(yy))
# set visual attributes
graph.markercolor = 'blue'
graph.xaxis.SetTitle("Luminosity Block")
graph.yaxis.SetTitle("Luminosity [Average Percent Ratio]")
graph.xaxis.SetRangeUser(min(lumi_blocks), max(lumi_blocks))
#graph.yaxis.SetRangeUser(min(luminosity_ratio), max(luminosity_ratio))
graph.yaxis.SetRangeUser(-5, 5)
# plot with ROOT
canvas = Canvas()
graph.Draw("AP")
# Draw lines for different runs
run_length = 0
for run in sorted(all_detector_one_data.keys()):
#print("Length of Run " + str(run) + ": " + str(len(all_detector_one_data.get(run))))
run_length += len(all_detector_one_data.get(run))
line = ROOT.TLine(run_length, -5, #min(luminosity_ratio),
run_length, 5,) # max(luminosity_ratio))
line.Draw()
line_label = ROOT.TText(run_length - 30, 5 -1.5, str(run)) #max(luminosity_ratio) - 1.5, str(run))
line_label.SetTextAngle(90)
line_label.SetTextSize(18)
line_label.SetTextFont(43)
line_label.Draw()
label = ROOT.TText(0.7, 0.8, str(name))
label.SetTextFont(43)
label.SetTextSize(25)
label.SetNDC()
label.Draw()
canvas.Modified()
canvas.Update()
wait(True)
示例12: zip
# remove the errorbars
tmphandles = []
tmplabels = []
for a,b in zip(handles,labels):
if type(a)==Line2D:
continue
tmphandles.append(a[0])
tmplabels.append(b)
# use them in the legend
axes.legend(tmphandles, tmplabels, loc='best',numpoints=1)
if 'Data' in hists:
# print list(stack.sum.y())
# ratioplot = Graph.divide( Graph(hists['Data']), stack.sum )
ratioplot = Graph()
ratioplot.Divide( hists['Data'], stack.sum , 'pois' )
ratioplot.color = "black"
if hists["Data"].Integral():
tmpyerror,tmpyerror2 = zip(*list(ratioplot.yerr()) )
tmpx = list(ratioplot.x())
tmpy = list(ratioplot.y())
tmpxy = zip(tmpx,tmpy,tmpyerror)
# print tmpxy
tmpxy = [tmp for tmp in tmpxy if tmp[1]!=0 ]
# print tmpxy
tmpx,tmpy,tmpyerror = zip(*tmpxy)
# print tmpyerror
axes_ratio.errorbar(tmpx, tmpy,
# list(ratioplot.y()),
示例13: set_style
import matplotlib.pyplot as plt
from matplotlib.ticker import AutoMinorLocator, MultipleLocator
# set the random seed
ROOT.gRandom.SetSeed(42)
np.random.seed(42)
# points
x = np.sort(np.random.random(10)) * 3500
y = np.random.random(10)
# set style for ROOT
set_style('ATLAS')
# create graph
graph = Graph(x.shape[0])
for i, (xx, yy) in enumerate(zip(x, y)):
graph.SetPoint(i, xx, yy)
# set visual attributes
graph.linecolor = 'blue'
graph.markercolor = 'blue'
graph.xaxis.SetTitle("E_{T} [GeV]")
graph.yaxis.SetTitle("d#sigma_{jet}/dE_{T,jet} [fb/GeV]")
graph.xaxis.SetRangeUser(0, 3500)
graph.yaxis.SetRangeUser(0, 1)
# plot with ROOT
canvas = Canvas()
graph.Draw("APL")
示例14: plot_multiple_all_luminosity_block_ratio
#.........这里部分代码省略.........
all_detector_one_data = temp_detector_one
all_detector_two_data = temp_detector_two
all_detector_three_data = temp_detector_three
# Get ratio of the detectors 1 and 2
luminosity_ratio = []
lumi_blocks = []
block_count1 = 0
for run in sorted(all_detector_one_data.keys()):
for block in range(len(all_detector_one_data.get(run))):
block_count1 += 1
for bcid in range(len(all_detector_one_data.get(run)[block])):
detector_one_point = all_detector_one_data.get(run)[block][bcid]
detector_two_point = all_detector_two_data.get(run)[block][bcid]
# Check if the blocks are zero
if detector_one_point != 0.0 and detector_two_point != 0.0:
ratio = detector_one_point / detector_two_point
luminosity_ratio.append(ratio)
lumi_blocks.append(block_count1)
# Get ratio of the detectors 1 and 3
luminosity_ratio_1 = []
lumi_blocks_1 = []
block_count2 = 0
for run in sorted(all_detector_one_data.keys()):
for block in range(len(all_detector_one_data.get(run))):
block_count2 += 1
for bcid in range(len(all_detector_one_data.get(run)[block])):
detector_one_point = all_detector_one_data.get(run)[block][bcid]
detector_three_point = all_detector_three_data.get(run)[block][bcid]
# Check if the blocks are zero
if detector_one_point != 0.0 and detector_three_point != 0.0:
ratio = detector_one_point / detector_three_point
luminosity_ratio_1.append(ratio)
lumi_blocks_1.append(block_count2)
# Get percentage difference based off the first block and BCID
first_point = luminosity_ratio[0]
first_point_1 = luminosity_ratio_1[0]
for index in range(len(luminosity_ratio)):
luminosity_ratio[index] = 100 * ((luminosity_ratio[index] / first_point) - 1)
for index in range(len(luminosity_ratio_1)):
luminosity_ratio_1[index] = 100 * ((luminosity_ratio_1[index] / first_point_1) - 1)
# create graph
graph = Graph(len(lumi_blocks))
for i, (xx, yy) in enumerate(zip(lumi_blocks, luminosity_ratio)):
graph.SetPoint(i, float(xx), float(yy))
# set visual attributes
graph.markercolor = 'blue'
graph.xaxis.SetTitle("Luminosity Block")
graph.yaxis.SetTitle("Luminosity [Average Percent Ratio]")
graph.xaxis.SetRangeUser(min(lumi_blocks), max(lumi_blocks))
graph.yaxis.SetRangeUser(min(luminosity_ratio), max(luminosity_ratio))
# plot with ROOT
canvas = Canvas()
graph.Draw("AP")
canvas.Update()
# add points from detectors 1 and 3
# create graph
graph1 = Graph(len(lumi_blocks_1))
for i, (xx, yy) in enumerate(zip(lumi_blocks_1, luminosity_ratio_1)):
graph1.SetPoint(i, float(xx), float(yy))
# set visual attributes
graph1.linecolor = 'white' # Hides the lines at this time
graph1.markercolor = 'red'
# graph1.xaxis.SetRangeUser(min(lumi_blocks_1), max(lumi_blocks_1))
# graph1.yaxis.SetRangeUser(min(luminosity_ratio_1), max(luminosity_ratio_1))
graph1.Draw("P")
canvas.Update()
# Draw lines for different runs
run_length = 0
for run in sorted(all_detector_one_data.keys()):
run_length += len(all_detector_one_data.get(run))
line = ROOT.TLine(run_length, min(luminosity_ratio),
run_length, max(luminosity_ratio))
line.Draw()
line_label = ROOT.TText(run_length - 30, max(luminosity_ratio) - 1.5, str(run))
line_label.SetTextAngle(90)
line_label.SetTextSize(18)
line_label.SetTextFont(43)
line_label.Draw()
label = ROOT.TText(0.7, 0.8, str(name))
label.SetTextFont(43)
label.SetTextSize(25)
label.SetNDC()
label.Draw()
canvas.Modified()
canvas.Update()
wait(True)
示例15: test_divide
def test_divide():
Graph.divide(Graph(Hist(10, 0, 1).FillRandom('gaus')),
Hist(10, 0, 1).FillRandom('gaus'), 'pois')