Exemple #1
0
#-----------------------------------------------------------------------
# imports
#-----------------------------------------------------------------------

import hep.table
from   hep.test import compare

#-----------------------------------------------------------------------
# test
#-----------------------------------------------------------------------

schema = hep.table.Schema()
table = hep.table.create("index1.table", schema)
for i in range(10):
    table.append()
del table

table = hep.table.open("index1.table")
index_expr = table.compile("_index")

for i in range(9, -1, -1):
    row = table[i]
    compare(row["_index"], i)
    compare(index_expr.evaluate(row), i)
    
for row in table.select("_index % 3 == 1"):
    compare(row["_index"] % 3, 1)
Exemple #2
0
import hep.table
import hep.table.parse
from   math import sqrt

table = hep.table.open("tracks.table")

momentum = hep.expr.parse(
    "sqrt(momentum_x**2 + momentum_y**2 + momentum_z**2)")
momentum = table.compile(momentum)
print momentum

for track in table:
    energy = track["energy"]
    mass = sqrt(energy ** 2 - momentum ** 2)

    print "energy=%8.6f  momentum=%8.6f  mass=%8.6f" \
          % (energy, momentum(track), mass)