2009年7月2日木曜日

How to use pyROOT 基礎編

・pyROOT の使い方

グラフツールの ROOT を python で import できるようにしたのが pyROOT

いよいよ ROOT でグラフを描きたくなったので、練習練習

必要なもの
・python
・pyROOT

今回はすでに設定されている PC で使い方を練習するので、
設定方法は他のところで調べて下さい
http://root.cern.ch/root/HowtoPyROOT.html
あたりで
もしかしたら後で書くかも
マニュアルはこちら
http://wlav.web.cern.ch/wlav/pyroot/


#/bin/usr/env python

import sys, math
import ROOT

if __name__=='__main__':

graph = ROOT.TGraph()

# set line width
graph.SetLineWidth(2)

# set line color
# 1: black (default)
# 2: red
# 3: green
# 4: blue
# 5: yellow
# 6: magenda
# 7: cyan
# 8: yellowgreen
# 9: purple
# 10: white
graph.SetLineColor(4)

# set line style
# 1: line (default)
# 2: dashed line
# 3: dot line
# 4: dot-dashed line
graph.SetLineStyle(1)

# set title
graph.SetTitle("Graph Test 1")


# set data point
for x in range(10) :
np = graph.GetN()
graph.SetPoint(np, x, x**2)

# open canvas
cv = ROOT.TCanvas("cv", "Graph Test", 800, 800)

pad = cv.cd()

# set grid
pad.SetGridx(1)
pad.SetGridy(1)

# set axises
axisX = graph.GetXaxis()
axisX.SetTitle("x")

axisY = graph.GetYaxis()
axisY.SetTitle("x**2")

# plot
graph.Draw("APC")


# plot line
line = ROOT.TLine(0, 40, 10, 40)
line.SetLineWidth(4)
line.SetLineColor(2)
line.SetLineStyle(2)
line.Draw("SAME")

# export
cv.Print("graphtest1.png")


0 件のコメント:

コメントを投稿