Example #1
0
def io_test2_write(fname, nevts=1000, sz=1000, dtype='i'):
    """testing writing 1000 evts with arrays of (variable length) 1000- ints
    """
    f = ROOT.TFile.Open(fname, 'RECREATE')
    t = ROOT.TTree('t', 't')

    nevts = nevts
    imax = sz

    n = carray('i', [0])
    data = carray(dtype, imax * [0])
    t.Branch('sz', n, 'sz/I')
    t.Branch('data', data, 'data[sz]/%s' % _py_dtype_to_root[dtype])

    from random import randint

    fill = t.Fill
    for i in range(nevts):
        jmax = randint(1, sz)
        n[0] = jmax
        for j in range(jmax):
            data[j] = randint(0, sz)
        fill()

    f.Write()
    f.Close()
    return
Example #2
0
 def passes(self, event):
     for el in event.electrons:
         tracketa = el.trackParticle().eta()
         pt = el.caloCluster().e() / cosh(tracketa)
         if pt <= 15 * GeV:
             continue
         if not ((abs(tracketa) < 1.37) or (1.52 < abs(tracketa) < 2.47)):
             continue
         if el.author() not in (1, 3):
             continue
         if not abs(el.charge()) == 1:
             continue
         if el.passSelection(self.el_sel) != 1:
             continue
         from array import array as carray
         mask = carray('I', [ROOT.xAOD.EgammaParameters.BADCLUSELECTRON])
         if not el.isGoodOQ(mask[0]):
             continue
         return False
     return True
Example #3
0
 def passes(self, event):
     for el in event.electrons:
         tracketa = el.trackParticle().eta()
         pt = el.caloCluster().e() / cosh(tracketa)
         if pt <= 15 * GeV:
             continue
         if not ((abs(tracketa) < 1.37) or (1.52 < abs(tracketa) < 2.47)):
             continue
         if el.author() not in (1, 3):
             continue
         if not abs(el.charge()) == 1:
             continue
         if el.passSelection(self.el_sel) != 1:
             continue
         from array import array as carray
         mask = carray('I', [ROOT.xAOD.EgammaParameters.BADCLUSELECTRON])
         if not el.isGoodOQ(mask[0]):
             continue
         return False
     return True
Example #4
0
    def passes(self, event):
        # set the event weights
        if self.datatype == datasets.MC:
            truth_event = event.TruthEvent[0]
            self.tree.mc_weight = event.EventInfo.mcEventWeight()
            val_i = ROOT.Long(0)
            if truth_event.pdfInfoParameter(val_i, truth_event.PDFID1):
                self.tree.mcevent_pdf_id1_0 = val_i
            if truth_event.pdfInfoParameter(val_i, truth_event.PDFID2):
                self.tree.mcevent_pdf_id2_0 = val_i
            val_f = carray('f', [0.])
            if truth_event.pdfInfoParameter(val_f, truth_event.X1):
                self.tree.mcevent_pdf_x1_0 = val_f[0]
            if truth_event.pdfInfoParameter(val_f, truth_event.X2):
                self.tree.mcevent_pdf_x2_0 = val_f[0] 
            if truth_event.pdfInfoParameter(val_f, truth_event.scalePDF):
                self.tree.mcevent_pdf_scale_0 = val_f[0]

        elif self.datatype == datasets.EMBED:
            self.tree.mc_weight = event.EventInfo.mcEventWeight()
        return True
Example #5
0
def io_test1_write(fname, nevts=1000, sz=1000, dtype='i'):
    """testing writing 1000 evts with arrays of 1000- integers
    """
    f = ROOT.TFile.Open(fname, 'RECREATE')
    t = ROOT.TTree('t', 't')

    nevts = nevts
    imax = sz
    data = carray(dtype, imax * [0])
    #t.Branch( 'mynum', n, 'mynum/I' )
    t.Branch('i', data, 'data[%d]/%s' % (imax, _py_dtype_to_root[dtype]))

    from random import randint

    fill = t.Fill
    for i in range(nevts):
        for j in range(sz):
            data[j] = randint(0, sz)
        fill()

    f.Write()
    f.Close()
    return
Example #6
0
# Copyright ©2017 The go-hep Authors.  All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

from array import array as carray
import ROOT

f = ROOT.TFile.Open("gauss-h1.root","RECREATE")
histos = []
for t in [
        (ROOT.TH1D, "h1d", (10,-4,4)),
        (ROOT.TH1F, "h1f", (10,-4,4)),
        (ROOT.TH1F, "h1d-var", (10, carray("d", [
            -4.0, -3.2, -2.4, -1.6, -0.8,  0,
            +0.8, +1.6, +2.4, +3.2, +4.0
        ]))),
        (ROOT.TH1F, "h1f-var", (10, carray("f", [
            -4.0, -3.2, -2.4, -1.6, -0.8,  0,
            +0.8, +1.6, +2.4, +3.2, +4.0
        ])))
        ]:
    cls, name, args = t
    if len(args) == 3:
        h = cls(name, name, args[0], args[1], args[2])
    elif len(args) == 2:
        h = cls(name, name, args[0], args[1])
    else:
        raise ValueError("invalid number of arguments %d" % len(args))
    h.StatOverflows(True)
    h.Sumw2()
    with open("gauss-1d-data.dat") as ff:
Example #7
0
# Copyright ©2017 The go-hep Authors.  All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

from array import array as carray
import ROOT

f = ROOT.TFile.Open("gauss-h2.root", "RECREATE")
for t in [(ROOT.TH2F, "h2f", (3, 0, 3, 3, 0, 3)),
          (ROOT.TH2D, "h2d", (3, 0, 3, 3, 0, 3)),
          (ROOT.TH2F, "h2f-var", ((3, carray("f", [0.0, 1.5, 2.0, 3.0])),
                                  (3, carray("f", [0.0, 1.5, 2.0, 3.0])))),
          (ROOT.TH2D, "h2d-var", ((3, carray("d", [0.0, 1.5, 2.0, 3.0])),
                                  (3, carray("d", [0.0, 1.5, 2.0, 3.0]))))]:
    cls, name, args = t
    if len(args) == 6:
        h = cls(name, name, args[0], args[1], args[2], args[3], args[4],
                args[5])
    elif len(args) == 2:
        h = cls(name, name, args[0][0], args[0][1], args[1][0], args[1][1])
    else:
        raise ValueError("invalid number of arguments %d" % len(args))
    h.StatOverflows(True)
    h.Sumw2()
    with open("gauss-2d-data.dat") as ff:
        for l in ff.readlines():
            x, y, w = l.split()
            h.Fill(float(x), float(y), float(w))
            pass
        pass
    h.Fill(+5, +5, 101)  # NE
Example #8
0
def main():
    fname = "test-small.root"

    compress = True
    netopt = 0
    splitlevel = 32
    bufsiz = 32000

    f = ROOT.TFile.Open(fname, "recreate", "small event file", compress,
                        netopt)
    if not f:
        raise SystemError()

    t = ROOT.TTree("tree", "my tree title", splitlevel)

    i32 = carray("i", [0])
    i64 = carray("l", [0])
    u32 = carray("I", [0])
    u64 = carray("L", [0])
    f32 = carray("f", [0.])
    f64 = carray("d", [0.])
    s06 = carray("b", [0] * 7)

    arr_i32 = carray("i", [0] * ARRAYSZ)
    arr_i64 = carray("l", [0] * ARRAYSZ)
    arr_u32 = carray("I", [0] * ARRAYSZ)
    arr_u64 = carray("L", [0] * ARRAYSZ)
    arr_f32 = carray("f", [0] * ARRAYSZ)
    arr_f64 = carray("d", [0] * ARRAYSZ)

    n = carray("i", [0])
    sli_i32 = carray("i", [0] * ARRAYSZ)
    sli_i64 = carray("l", [0] * ARRAYSZ)
    sli_u32 = carray("I", [0] * ARRAYSZ)
    sli_u64 = carray("L", [0] * ARRAYSZ)
    sli_f32 = carray("f", [0] * ARRAYSZ)
    sli_f64 = carray("d", [0] * ARRAYSZ)

    t.Branch("Int32", i32, "Int32/I")
    t.Branch("Int64", i64, "Int64/L")
    t.Branch("UInt32", u32, "UInt32/i")
    t.Branch("UInt64", u64, "UInt64/l")
    t.Branch("Float32", f32, "Float32/F")
    t.Branch("Float64", f64, "Float64/D")
    t.Branch("Str", s06, "Str/C")

    t.Branch("ArrayInt32", arr_i32, "ArrayInt32[10]/I")
    t.Branch("ArrayInt64", arr_i64, "ArrayInt64[10]/L")
    t.Branch("ArrayUInt32", arr_u32, "ArrayInt32[10]/i")
    t.Branch("ArrayUInt64", arr_u64, "ArrayInt64[10]/l")
    t.Branch("ArrayFloat32", arr_f32, "ArrayFloat32[10]/F")
    t.Branch("ArrayFloat64", arr_f64, "ArrayFloat64[10]/D")

    t.Branch("N", n, "N/I")
    t.Branch("SliceInt32", sli_i32, "SliceInt32[N]/I")
    t.Branch("SliceInt64", sli_i64, "SliceInt64[N]/L")
    t.Branch("SliceUInt32", sli_u32, "SliceInt32[N]/i")
    t.Branch("SliceUInt64", sli_u64, "SliceInt64[N]/l")
    t.Branch("SliceFloat32", sli_f32, "SliceFloat32[N]/F")
    t.Branch("SliceFloat64", sli_f64, "SliceFloat64[N]/D")

    for i in range(EVTMAX):
        #print ">>>",i
        i32[0] = i
        i64[0] = i
        u32[0] = i
        u64[0] = i

        f32[0] = i
        f64[0] = i
        for ii, vv in enumerate(bytes("evt-%03d" % i, "ascii")):
            s06[ii] = vv
            pass

        for jj in range(ARRAYSZ):
            arr_i32[jj] = i
            arr_i64[jj] = i
            arr_u32[jj] = i
            arr_u64[jj] = i
            arr_f32[jj] = i
            arr_f64[jj] = i

        n[0] = i % 10
        for jj in range(ARRAYSZ):
            sli_i32[jj] = i
            sli_i64[jj] = i
            sli_u32[jj] = i
            sli_u64[jj] = i
            sli_f32[jj] = i
            sli_f64[jj] = i

        t.Fill()
        pass

    f.Write()
    f.Close()
def main():
    fname = "test-small.root"

    compress = True
    netopt = 0
    splitlevel = 32
    bufsiz = 32000

    f = ROOT.TFile.Open(fname, "recreate", "small event file", compress,
                        netopt)
    if not f:
        raise SystemError()

    t = ROOT.TTree("tree", "my tree title", splitlevel)

    i32 = carray("i", [0])
    i64 = carray("l", [0])
    u32 = carray("I", [0])
    u64 = carray("L", [0])
    f32 = carray("f", [0.])
    f64 = carray("d", [0.])

    arr_i32 = carray("i", [0] * ARRAYSZ)
    arr_i64 = carray("l", [0] * ARRAYSZ)
    arr_u32 = carray("I", [0] * ARRAYSZ)
    arr_u64 = carray("L", [0] * ARRAYSZ)
    arr_f32 = carray("f", [0] * ARRAYSZ)
    arr_f64 = carray("d", [0] * ARRAYSZ)

    t.Branch("Int32", i32, "Int32/I")
    t.Branch("Int64", i64, "Int64/L")
    t.Branch("UInt32", u32, "UInt32/i")
    t.Branch("UInt64", u64, "UInt64/l")
    t.Branch("Float32", f32, "Float32/F")
    t.Branch("Float64", f64, "Float64/D")

    t.Branch("ArrayInt32", arr_i32, "Int32[10]/I")
    t.Branch("ArrayInt64", arr_i64, "Int64[10]/L")
    t.Branch("ArrayUInt32", arr_u32, "Int32[10]/i")
    t.Branch("ArrayUInt64", arr_u64, "Int64[10]/l")
    t.Branch("ArrayFloat32", arr_f32, "Float32[10]/F")
    t.Branch("ArrayFloat64", arr_f64, "Float64[10]/D")

    for i in xrange(EVTMAX):
        #print ">>>",i
        i32[0] = i
        i64[0] = i
        u32[0] = i
        u64[0] = i

        f32[0] = i
        f64[0] = i

        for jj in range(ARRAYSZ):
            arr_i32[jj] = i
            arr_i64[jj] = i
            arr_u32[jj] = i
            arr_u64[jj] = i
            arr_f32[jj] = i
            arr_f64[jj] = i
        t.Fill()
        pass

    f.Write()
    f.Close()