Esempio n. 1
0
def rootpy(tree):

    return np.unique(tree_to_ndarray(tree, branches=["a_x"]))
Esempio n. 2
0

# define the model
class Event(TreeModel):

    x = FloatCol()
    y = FloatCol()
    z = FloatCol()
    i = IntCol()

tree = Tree("test", model=Event)

# fill the tree
for i in xrange(100000):
    tree.x = gauss(.5, 1.)
    tree.y = gauss(.3, 2.)
    tree.z = gauss(13., 42.)
    tree.i = i
    tree.fill()
tree.write()

# convert tree into a numpy record array
from rootpy.root2array import tree_to_recarray, tree_to_ndarray
array = tree_to_recarray(tree)
print array
print array.x
print array.i
print tree_to_ndarray(tree)

f.close()
Esempio n. 3
0
                 'include_weight=True)')

    print "time without profiler overhead:"
    t1 = time.time()
    arr2 = tree_to_recarray(tree, branches=branches,
                            include_weight=True)
    t2 = time.time()
    print "%f seconds" % (t2 - t1)

    print '=' * 40
    print "Comparison of output:"

    print
    print "Python result:"
    print arr1
    print arr1['a_x']
    print arr1['weight']

    print
    print "C result:"
    print arr2
    print arr2['a_x']
    print arr2['weight']

    arr3 = tree_to_ndarray(tree, branches=branches,
                           include_weight=True)

    print
    print "C result as ndarray:"
    print arr3
Esempio n. 4
0
    print "Using compiled C extension..."
    cProfile.run('arr2 = tree_to_recarray(tree, branches=branches,'
                 'include_weight=True)')

    print "time without profiler overhead:"
    t1 = time.time()
    arr2 = tree_to_recarray(tree, branches=branches, include_weight=True)
    t2 = time.time()
    print "%f seconds" % (t2 - t1)

    print '=' * 40
    print "Comparison of output:"

    print
    print "Python result:"
    print arr1
    print arr1['a_x']
    print arr1['weight']

    print
    print "C result:"
    print arr2
    print arr2['a_x']
    print arr2['weight']

    arr3 = tree_to_ndarray(tree, branches=branches, include_weight=True)

    print
    print "C result as ndarray:"
    print arr3