You are here: Home log ROOT

ROOT

a data analysis framework using C++ syntax http://root.cern.ch/

1   2010-5-25 python plugin

Install both the libroot-python and libroot-python-dev (key) package. And add a symbolic link of libPyROOT.so in /usr/lib/pymodules/python2.6/. otherwise this error:

xxx@banyan:~$ python
Python 2.6.4 (r264:75706, Dec  7 2009, 18:43:55)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from ROOT import TLorentzVector
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/pymodules/python2.6/ROOT.py", line 88, in <module>
    import libPyROOT as _root
ImportError: No module named libPyROOT
>>>

add symbolic link:

xxx@banyan:~$ cd /usr/lib/pymodules/python2.6/
xxx@banyan:/usr/lib/pymodules/python2.6$ sudo ln -s /usr/lib/root/libPyROOT.so ./

1.1   2010-5-25 batch mode

use gROOT.SetBatch():

from ROOT import TFormula, TF1, TGraph, gROOT
gROOT.SetBatch(True)  #to avoid interative mode (drawing canvas and etc.)

1.2   2010-5-25 ROOT python-plugin is very strict about numpy data type

If numpy.float32 is used below in place of numpy.float, the model fitting will produce a sensible slope but a far-off intercept. No idea of why.:

from ROOT import TFormula, TF1, TGraph, gROOT
gROOT.SetBatch(True)    #to avoid interative mode (drawing canvas and etc.)
import numpy
lm = TF1('lm', 'pol1', 1, 5 )
#ROOT is very dtype-sensitive. numpy.float32 won't work.
gr = TGraph(len(x_ls), numpy.array(x_ls, dtype=numpy.float), numpy.array(y_ls, dtype=numpy.float))
gr.Fit(lm, "+rob=%s"%fractionUsed)
fit = gr.GetFunction('lm')
fit_y_ls = []
for x in x_ls:
        fit_y_ls.append(fit.Eval(x))

1.3   2010-5-25 specify model in fitting

[0]+[1]*x is essentially same as pol1 but option rob (robust fitting, like least trimmed square) in Fit() only works with pol1.

Comments (0)