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/

  1. #/bin/usr/env python  
  2.   
  3. import sys, math  
  4. import ROOT  
  5.   
  6. if __name__=='__main__':  
  7.   
  8.     graph = ROOT.TGraph()  
  9.   
  10.     # set line width  
  11.     graph.SetLineWidth(2)  
  12.   
  13.     # set line color  
  14.     # 1: black  (default)  
  15.     # 2: red  
  16.     # 3: green  
  17.     # 4: blue  
  18.     # 5: yellow  
  19.     # 6: magenda  
  20.     # 7: cyan  
  21.     # 8: yellowgreen  
  22.     # 9: purple  
  23.     # 10: white  
  24.     graph.SetLineColor(4)  
  25.   
  26.     # set line style  
  27.     # 1: line  (default)  
  28.     # 2: dashed line  
  29.     # 3: dot line  
  30.     # 4: dot-dashed line  
  31.     graph.SetLineStyle(1)  
  32.   
  33.     # set title  
  34.     graph.SetTitle("Graph Test 1")  
  35.   
  36.   
  37.     # set data point  
  38.     for x in range(10) :  
  39.         np = graph.GetN()  
  40.         graph.SetPoint(np, x, x**2)  
  41.   
  42.     # open canvas  
  43.     cv = ROOT.TCanvas("cv""Graph Test"800800)  
  44.   
  45.     pad = cv.cd()  
  46.   
  47.     # set grid  
  48.     pad.SetGridx(1)  
  49.     pad.SetGridy(1)  
  50.   
  51.     # set axises  
  52.     axisX = graph.GetXaxis()  
  53.     axisX.SetTitle("x")  
  54.   
  55.     axisY = graph.GetYaxis()  
  56.     axisY.SetTitle("x**2")  
  57.   
  58.     # plot  
  59.     graph.Draw("APC")  
  60.   
  61.   
  62.     # plot line  
  63.     line = ROOT.TLine(0401040)  
  64.     line.SetLineWidth(4)  
  65.     line.SetLineColor(2)  
  66.     line.SetLineStyle(2)  
  67.     line.Draw("SAME")  
  68.   
  69.     # export  
  70.     cv.Print("graphtest1.png")  


0 件のコメント:

コメントを投稿