do anyone experience of MakeClass in pyROOT? I have and everything work fine until you generate your own class
from ROOT import *
tf = TFile("/home/kusanagi/Data/RootData/040720_004Stripped/Log/040720_004Stripped.Log.Event.root")
tr = tf.Get(“Log”)
lg = LogProva()
Traceback (most recent call last):
File “”, line 1, in ?
SystemError: NULL result without error in PyObject_Call
i have found a workaround using
gROOT.ProcessLine(‘aa = LogProva()’)
and it work but then if i do
aa.Show() <----- Doesn’t work because i can’t find aa
It’s a Bug?
Another likely work-around is to compile the result of MakeClass:
first, which release of ROOT are you using and on which platform are you running?
Second, can you put the .root file in a public area, such that I may repeat what you
tried to do?
Testing HEAD CVS: using simple classes, LoadMacro() without ‘+’ is sufficient to
make the class available. Also, MakeClass() is a C++ necessity. There’s no reason
to use it with python.
With HEAD CVS (doesn’t work fully in the 4.01/02 because of a caching pb), I do
tfile = TFile( tfilename % num )
tfile.cd( 'CBNT' )
fchain = gDirectory.Get( 't3333' )
entries = fchain.GetEntriesFast()
for jentry in xrange( entries ):
# get the next tree in the chain
ientry = fchain.LoadTree(jentry)
if ientry < 0:
# verify file/tree/chain integrity
nb = fchain.GetEntry( jentry )
if nb <= 0 or not hasattr( fchain, 'eg_nc' ):
# histogram main vertex
VertZ.Fill( fchain.ZV )
##### reconstruction section #####
# get number of electron candidates
nc = int(fchain.eg_nc)
eReco = 
for k in range( nc ):
# check e-ID flag, 0:e, >=1:jet
if fchain.eg_IsEM[k] != 0:
# load properties into an electron candidate data object
ecan = PhysicsObject()
ecan.match = fchain.eg_trkmatch_X[k]
ecan.PtInvV = fchain.eg_trkpTV_X[k]
ecan.Et = fchain.eg_et[k]
ecan.eta = fchain.eg_eta[k]
ecan.phi = fchain.eg_phi[k]
# etc ...
That is, you need the LoadTree() and the GetEntry() to cycle through the chain,
but other than that, you can access your data directly, without needing to map the
branch addresses (arrays will also be range checked).
For older releases, you can still use the tree directly (as above), but you’ll need to
access the data with GetLeaf() and GetValue(). For example:
ecan.match = fchain.GetLeaf( 'eg_trkmatch_X' ).GetValue( k )
But send me the details, and I’ll try to trace down any MakeClass() pbs?
sorry for the late replay… well yes it works the way you shown, but in case you would fix also the “MakeClass” problem i don’t think you really need my root file (but i attach here anyway); BTW my root version is 4.01/03.
040720_004Stripped.Log.Event.root (7.75 KB)
thanks for the file. With the new implementation of “from ROOT import *”, this:
>>> gROOT.ProcessLine('aa = LogProva()')
now works. Also, I haven’t found out yet why the macro that comes from MakeClass()
isn’t properly loaded, but I have a workaround. (G__CallFunc fails, but TClass::New()
works, and the generated class has a default ctor, so that works in the end.)