Hi all,
I’m trying to use Jupyter Notebook with python3 (Python3.4) and ROOT in Linux environment. Firstly, I compile the last release from ROOT (ROOT 6.06/00) with my python3 version, before that I check that the directories contain Python.h and libpython.3.4.so files:
./configure --enable-python --with-python-incdir=/usr/include/python3.4/ --with-python-libdir=/usr/lib/python3.4/ and
make
When I executed my codes written with python 2.6 and ROOT 5.27/06b everything worked. Now, when the codes are executed with python3.4 and ROOT6.06/00 fail, giving us an error message. But, changing the ROOT version doesn’t fix the problems. Here there is a brief summary of error:
My code reads a tree from a rootfile (written in ROOT 5.27/06b). It fails (in Python3.4) reading the tree branch information after the statement SetBranchAddress, so I can 't charge my variable associated.
[code]
import ROOT
from ROOT import gROOT , TCanvas, TH1F
import numpy as n
import array
class Analyzer(object):
""“
Analyzer
”""
def init(self):
’’‘
Analyzer Constructor. Only read the tree from the root file.
’’’
# Get tree from mytree.root file
#self.file = ROOT.gROOT.GetListOfFiles().FindObject(“mytree.root”)
#if not self.file or not file.IsOpen():
self.file = ROOT.TFile(“mytree.root”, “read”)
self.tree = self.file.Get(“muons”)
#Call Init function to initialize the tree and set branches
self.init()
def init(self):
'''
Function to declare the variables for each branch and the histograms for all
and selected muons
'''
....
# Define and init the variables for each branch as ROOT vectors
self.Muon_pt = ROOT.std.vector('float')()
self.process()
#####################################################################
### PROCESS ###
#####################################################################
def process(self):
'''
Initialization of the reading process. This function reads the NTuples.root,
select the good muons and fill the histograms.
'''
self.tree.SetBranchAddress("Muon_pt", self.Muon_pt)
...
#Loop over events
#--------------------------------------------------------------------
# Get the number of entries(events) of the TTree (file.root)
numEntries= self.tree.GetEntries()
# For each event or entry,the following loop populates the tree branches, creates every muon and add it to all_muons list
for event in range(0, self.Muon_pt.size()):
# Address the data of each physical variable registed in this event or entry number to its branch associated listed above.
self.tree.GetEntry(event)
print (event)
print (self.tree.Scan("Muon_pt")) # This line works fine
print (self.Muon_pt.size()) ## this line give us number with at least 10 digits and that has non sense. The size should be, more or less, 3 or 4.
print (self.Muon_pt[0]) ## this line breaks the running
....
[/code]
The last line give us the next error:
IndexError: index out of range
Later, we run the same code compiling ROOT version 5.34 with python3 and the error is:
self.tree.SetBranchAddress("Muon_pt", self.Muon_pt)
TypeError: none of the 3 overloaded methods succeeded. Full details:
Int_t TTree::SetBranchAddress(const char* bname, void** add,
TBranch** ptr = 0) =>
could not convert argument 1 (must be bytes, not str)
Int_t TTree::SetBranchAddress(const char* bname, void* add, TClass*
realClass, EDataType datatype, Bool_t isptr) =>
takes at least 5 arguments (2 given)
Int_t TTree::SetBranchAddress(const char* bname, void* add, TBranch**
ptr, TClass* realClass, EDataType datatype, Bool_t isptr) =>
takes at least 6 arguments (2 given)
To end, I probe other ROOT versions with the Python3.4 including 5.29, 5.27/06b/a, 5.28.00b, 5.30, but they didn’t compile because bin/rmkdepend: Command not found.
Please help!
Thanks and cheers!