8 bit unsigned integer

Hi,

I am having problem handling 8 bit unsigned integers read from a TTree.
The tree has one of the the leafs declared as type “b” - “ipart/b”. mytree.Show() shows data in this leaf while trying to do print of values in each event fails. Trying to convert these with int() raises a type error. This is the code snippet I use to read in the tree entries:
mytree = mcfile.Get(treename)
mytree.Show(5)
for event in mytree:
print event.ipart

Thanks,
Vyacheslav

Hi,

how do you convert (the actual code, please), and what is the error?

Cheers, Axel.

Hi,

This is the code:

import sys, os
from ROOT import TFile

def process_file(filname):
    mcfile = TFile(filname)
    mytree = mcfile.Get('h9001')
    mytree.Print()
    for event in mytree:
        print event.ipart
        if type(event.ipart).__name__=='str':
            int(event.ipart)

if __name__=='__main__':
    process_file('test.root')

print does not show anything and the error when I try to convert to an integer is

I have also attached a root file I am analyzing
test.root (17.7 KB)

Hi,

the leaf proclaims to be an UChar_t, and char’s are turned into python strings. To convert into a python integer, use ord() instead of int().

HTH,
Wim