Python and PyROOT

[ Home ] [ Back ]

Contents

Keywords:

Introduction

Scriptini utili per analisi dati

Set up the environment

./configure linux --enable-python
setenv ROOTSYS /opt/root
setenv PYTHONPATH $ROOTSYS/bin

Plot y-data vs. x-data

from ROOT import TGraph

plot = TGraph("filename","%lg %lg")
# plot = TGraph("filename","%lg ; %lg")     # csv values

plot.Draw("ALP")

Histogram of a simple column of data

3.14159
2.71828
1.61803
...
...
#!/usr/bin/env python

from ROOT import TH1F

file = open("data.dat","r")
histo = TH1F("histo","histo",100,-5,5)

for line in file:
   xval = float(line.split("\n")[0])
   histo.Fill(xval)

histo.SetTitle("Title")
histo.GetXaxis().SetTitle("x-axis")
histo.GetYaxis().SetTitle("y-axis")
histo.Draw("options")

file.close()
raw_input()

Histogram of a csv file

3.14159 ; ...
2.71828 ; ...
1.61803 ; ...
...     ; ...
...     ; ...



Last update: