Exemplo n.º 1
0
def main():
    acc = acc_from_dir("./input/das_lhevpt_v3")
    outputrootfile = uproot.recreate(f'2017_gen_v_pt_stat1_qcd_sf.root')
    plot_lhe_v_pt(acc,
                  tag='wjet_dilep',
                  regex='W.*',
                  pttype='dilepton',
                  outputrootfile=outputrootfile)
    plot_lhe_v_pt(acc,
                  tag='dy_dilep',
                  regex='.*DY.*',
                  pttype='dilepton',
                  outputrootfile=outputrootfile)

    outputrootfile = uproot.recreate(f'2017_gen_v_pt_lhe_qcd_sf.root')
    plot_lhe_v_pt(acc,
                  tag='wjet_nano',
                  regex='W.*',
                  pttype='nano',
                  outputrootfile=outputrootfile)
    plot_lhe_v_pt(acc,
                  tag='dy_nano',
                  regex='.*DY.*',
                  pttype='nano',
                  outputrootfile=outputrootfile)
def main(args):

    files = [
        ifile for ifile in glob('{}/*.root'.format(args.input))
        if valid_background(ifile)
    ]
    backgrounds = pandas.DataFrame()
    for ifile in files:
        open_file = uproot.open(ifile)
        tree_name = parse_tree_name(open_file.keys())
        events = open_file[tree_name].arrays(['*'],
                                             outputtype=pandas.DataFrame)
        signal_events = events[(events['is_signal'] > 0)
                               & (events['contamination'] > 0)]
        backgrounds = pandas.concat([backgrounds, signal_events], sort=False)

    shift_up = backgrounds.copy(deep=True)
    shift_dn = backgrounds.copy(deep=True)

    shift_up['evtwt'] *= 0.1
    shift_dn['evtwt'] *= -0.1

    open_file = uproot.open('{}/embed.root'.format(args.input))
    tree_name = parse_tree_name(open_file.keys())
    oldtree = open_file[tree_name].arrays(['*'])
    treedict = {ikey: oldtree[ikey].dtype for ikey in oldtree.keys()}

    events = pandas.DataFrame(oldtree)
    signal_events = events[(events['is_signal'] > 0)]

    shift_up = pandas.concat([shift_up, signal_events], sort=False)
    shift_dn = pandas.concat([shift_dn, signal_events], sort=False)

    call('mkdir -p {}/../SYST_embed_contam_up'.format(args.input), shell=True)
    call('mkdir -p {}/../SYST_embed_contam_down'.format(args.input),
         shell=True)

    output_name_up = 'embed_up.root' if '/hdfs' in args.input else '{}/../SYST_embed_contam_up/embed.root'.format(
        args.input)
    output_name_dn = 'embed_down.root' if '/hdfs' in args.input else '{}/../SYST_embed_contam_down/embed.root'.format(
        args.input)
    with uproot.recreate(output_name_up) as f:
        f[tree_name] = uproot.newtree(treedict)
        f[tree_name].extend(shift_up.to_dict('list'))

    with uproot.recreate(output_name_dn) as f:
        f[tree_name] = uproot.newtree(treedict)
        f[tree_name].extend(shift_dn.to_dict('list'))

    if '/hdfs' in args.input:
        call(
            'mv -v embed_up.root {}/../SYST_embed_contam_up/embed.root'.format(
                args.input),
            shell=True)
        call('mv -v embed_down.root {}/../SYST_embed_contam_down/embed.root'.
             format(args.input),
             shell=True)
Exemplo n.º 3
0
def main(progname, name):
    df = np.transpose(np.loadtxt("results_%s/B0toDDbarK_pi-_LHCb.txt" %
                                 (name)))
    df_conj = np.transpose(
        np.loadtxt("results_%s/B0toDDbarK_pi-_conj_LHCb.txt" % (name)))
    df_all = np.transpose(
        np.loadtxt("results_%s/B0toDDbarK_pi-_all_LHCb.txt" % (name)))
    file = uproot.recreate("results_%s/Event.root" % (name))
    file_conj = uproot.recreate("results_%s/Event_conj.root" % (name))
    file_all = uproot.recreate("results_%s/Event_all.root" % (name))
    convert(file, df)
    convert(file_conj, df_conj)
    convert(file_all, df_all)
Exemplo n.º 4
0
def main():
    inpath = sys.argv[1]

    acc = dir_archive(inpath, serialized=True, compression=0, memsize=1e3)

    acc.load('sumw')
    acc.load('sumw2')

    # Create the output ROOT file to save the
    # PDF uncertainties as a function of v-pt
    outputrootpath = './output/theory_variations/rootfiles'
    if not os.path.exists(outputrootpath):
        os.makedirs(outputrootpath)

    outputrootfile_z_over_w = uproot.recreate(
        pjoin(outputrootpath, 'zoverw_pdf_unc.root'))
    outputrootfile_g_over_z = uproot.recreate(
        pjoin(outputrootpath, 'goverz_pdf_unc.root'))

    w_nom, w_unc, vpt_edges, vpt_centers = get_pdf_uncertainty(
        acc, regex='WNJetsToLNu.*', tag='wjet')
    dy_nom, dy_unc, vpt_edges, vpt_centers = get_pdf_uncertainty(
        acc, regex='DYNJetsToLL.*', tag='dy')
    gjets_nom, gjets_unc, vpt_edges, vpt_centers = get_pdf_uncertainty(
        acc, regex='G1Jet.*', tag='gjets')

    data_for_ratio = {
        'z_over_w': {
            'noms': (dy_nom, w_nom),
            'uncs': (dy_unc, w_unc),
            'rootfile': outputrootfile_z_over_w
        },
        'g_over_z': {
            'noms': (gjets_nom, dy_nom),
            'uncs': (gjets_unc, dy_unc),
            'rootfile': outputrootfile_g_over_z
        },
    }

    for tag, entry in data_for_ratio.items():
        noms = entry['noms']
        uncs = entry['uncs']
        plot_ratio(noms=noms,
                   uncs=uncs,
                   tag=tag,
                   vpt_edges=vpt_edges,
                   vpt_centers=vpt_centers,
                   outputrootfile=entry['rootfile'])
Exemplo n.º 5
0
def test_structured_array(tmp_path):
    newfile = os.path.join(tmp_path, "newfile.root")

    with uproot.recreate(newfile, compression=None) as fout:
        fout["tree"] = np.array(
            [(1, 1.1), (2, 2.2), (3, 3.3)], [("x", np.int32), ("y", np.float64)]
        )
        fout["tree"].extend(
            np.array(
                [(4, 4.4), (5, 5.5), (6, 6.6)], [("x", np.int32), ("y", np.float64)]
            )
        )

    f1 = ROOT.TFile(newfile)
    t1 = f1.Get("tree")

    assert t1.GetBranch("x").GetName() == "x"
    assert t1.GetBranch("y").GetName() == "y"
    assert [np.asarray(x.x).tolist() for x in t1] == [1, 2, 3, 4, 5, 6]
    assert [np.asarray(x.y).tolist() for x in t1] == [1.1, 2.2, 3.3, 4.4, 5.5, 6.6]

    with uproot.open(newfile) as fin:
        assert fin["tree/x"].name == "x"
        assert fin["tree/y"].name == "y"
        assert fin["tree/x"].typename == "int32_t"
        assert fin["tree/y"].typename == "double"
        assert fin["tree/x"].array().tolist() == [1, 2, 3, 4, 5, 6]
        assert fin["tree/y"].array().tolist() == [1.1, 2.2, 3.3, 4.4, 5.5, 6.6]

    f1.Close()
Exemplo n.º 6
0
def save_data(folder, data):
    from os.path import join
    with uproot.recreate(join(folder, 'data.root')) as f:
        f['data'] = uproot.newtree(
            {key: val.dtype
             for key, val in data.items()})
        f['data'].extend(data)
Exemplo n.º 7
0
def test_recreate(tmp_path):
    filename = os.path.join(tmp_path, "whatever.root")

    with uproot.recreate(filename) as f1:
        f1["hey"] = "you"
        f1["subdir/there"] = "you guys"

    with uproot.open(filename) as f2:
        assert f2["hey"] == "you"
        assert f2["subdir/there"] == "you guys"
        assert list(f2.file.streamers) == ["TObjString"]

    f3 = ROOT.TFile(filename, "update")
    assert [x.GetName() for x in f3.GetStreamerInfoList()] == ["TObjString"]
    assert f3.Get("hey") == "you"
    assert f3.Get("subdir/there") == "you guys"
    f3.cd("subdir")
    x = ROOT.TObjString("wowie")
    x.Write()
    f3.Close()

    with uproot.open(filename) as f4:
        assert f4["hey"] == "you"
        assert f4["subdir/there"] == "you guys"
        assert f4["subdir/wowie"] == "wowie"
        assert list(f4.file.streamers) == ["TObjString"]
Exemplo n.º 8
0
def test_compressed_tprofile(tmp_path):
    filename = join(str(tmp_path), "example.root")
    testfile = join(str(tmp_path), "test.root")

    f = ROOT.TFile.Open(testfile, "RECREATE")
    h = ROOT.TProfile("hvar", "title", 5, 1, 10)
    h.Sumw2()
    h.Fill(1.0, 3)
    h.Fill(2.0, 4)
    h.Write()
    f.Close()

    t = uproot.open(testfile)
    hist = t["hvar"]
    with uproot.recreate(filename, compression=uproot.LZMA(5)) as f:
        f["test"] = hist

    f = ROOT.TFile.Open(filename)
    h = f.Get("test")
    sums = [0.0, 25.0, 0.0, 0.0, 0.0, 0.0, 0.0]
    bincontents = [3.5, 0.0, 0.0, 0.0, 0.0]
    assert list(h.GetSumw2()) == sums
    assert h.GetMean() == 1.5
    assert h.GetRMS() == 0.5
    count = 0
    for x in range(1, 6):
        assert h.GetBinContent(x) == bincontents[count]
        count += 1
Exemplo n.º 9
0
def writexml(spec, specdir, data_rootdir, resultprefix):
    global _ROOT_DATA_FILE

    shutil.copyfile(
        pkg_resources.resource_filename(__name__,
                                        'schemas/HistFactorySchema.dtd'),
        os.path.join(os.path.dirname(specdir), 'HistFactorySchema.dtd'),
    )
    combination = ET.Element("Combination",
                             OutputFilePrefix=os.path.join(
                                 '.', specdir, resultprefix))

    with uproot.recreate(os.path.join(data_rootdir,
                                      'data.root')) as _ROOT_DATA_FILE:
        for channelspec in spec['channels']:
            channelfilename = os.path.join(
                specdir, '{0:s}_{1:s}.xml'.format(resultprefix,
                                                  channelspec['name']))
            with open(channelfilename, 'w') as channelfile:
                channel = build_channel(channelspec, spec.get('data'))
                indent(channel)
                channelfile.write(
                    "<!DOCTYPE Channel SYSTEM '../HistFactorySchema.dtd'>\n\n")
                channelfile.write(
                    ET.tostring(channel, encoding='utf-8').decode('utf-8'))

            inp = ET.Element("Input")
            inp.text = channelfilename
            combination.append(inp)

    for measurement in spec['measurements']:
        combination.append(build_measurement(measurement))
    indent(combination)
    return "<!DOCTYPE Combination  SYSTEM 'HistFactorySchema.dtd'>\n\n".encode(
        "utf-8") + ET.tostring(combination, encoding='utf-8')
Exemplo n.º 10
0
def test_TProfile(tmp_path):
    original = os.path.join(tmp_path, "original.root")
    newfile = os.path.join(tmp_path, "newfile.root")

    f1 = ROOT.TFile(original, "recreate")
    h1 = ROOT.TProfile("h1", "title", 2, -3.14, 2.71)
    h1.Fill(-4, 10)
    h1.Fill(-3.1, 10)
    h1.Fill(-3.1, 20)
    h1.Fill(2.7, 20)
    h1.Fill(3, 20)
    h1.Write()
    f1.Close()

    with uproot.open(original) as fin:
        h2 = fin["h1"]

        with uproot.recreate(newfile) as fout:
            fout["out"] = h2

    f3 = ROOT.TFile(newfile)
    h3 = f3.Get("out")
    assert h3.GetEntries() == 5
    assert h3.GetSumOfWeights() == 35
    assert h3.GetBinLowEdge(1) == pytest.approx(-3.14)
    assert h3.GetBinWidth(1) == pytest.approx((2.71 - -3.14) / 2)
    assert h3.GetBinContent(0) == pytest.approx(10)
    assert h3.GetBinContent(1) == pytest.approx(15)
    assert h3.GetBinContent(2) == pytest.approx(20)
    assert h3.GetBinContent(3) == pytest.approx(20)
    assert h3.GetBinError(0) == pytest.approx(0)
    assert h3.GetBinError(1) == pytest.approx(np.sqrt(12.5))
    assert h3.GetBinError(2) == pytest.approx(0)
    assert h3.GetBinError(3) == pytest.approx(0)
    f3.Close()
Exemplo n.º 11
0
def test_fromroot_TH3(tmp_path):
    original = os.path.join(tmp_path, "original.root")
    newfile = os.path.join(tmp_path, "newfile.root")

    f1 = ROOT.TFile(original, "recreate")
    h1 = ROOT.TH3D(
        "h1", "title", 2, 3.0, 5.0, 3, 10, 13, 4, 100, 104
    )  # centers: 3.5 4.5; 10.5 11.5 12.5; 100.5, 101.5, 102.5, 103.5
    h1.Sumw2()
    h1.Fill(3.5, 10.5, 100.5)
    h1.Fill(3.5, 10.5, 100.5)
    h1.Fill(3.5, 11.5, 102.5)
    h1.Fill(3.5, 12.5, 101.5)
    h1.Write()
    f1.Close()

    with uproot.open(original) as fin:
        h2 = fin["h1"]

        with uproot.recreate(newfile) as fout:
            fout["out"] = h2
            fout["there"] = h2.to_numpy()

    with uproot.open(newfile) as finagin:
        assert np.array_equal(
            finagin["out"].member("fSumw2"), finagin["there"].member("fSumw2")
        )
        assert {
            k: v for k, v in finagin["out"].all_members.items() if k.startswith("fTs")
        } == {
            k: v for k, v in finagin["there"].all_members.items() if k.startswith("fTs")
        }

    f1.Close()
Exemplo n.º 12
0
def test_awkward_record_dict_1(tmp_path):
    newfile = os.path.join(tmp_path, "newfile.root")

    with uproot.recreate(newfile, compression=None) as fout:
        b1 = np.array([1, 2, 3], np.int32)
        b2 = {
            "x": np.array([1.1, 2.2, 3.3]),
            "y": np.array([4, 5, 6], np.int64)
        }
        fout.mktree("tree", {
            "b1": b1.dtype,
            "b2": {
                "x": b2["x"].dtype,
                "y": b2["y"].dtype
            }
        })
        fout["tree"].extend({"b1": b1, "b2": b2})

    with uproot.open(newfile) as fin:
        assert fin["tree/b1"].typename == "int32_t"
        assert fin["tree/b2_x"].typename == "double"
        assert fin["tree/b2_y"].typename == "int64_t"
        assert fin["tree/b1"].array().tolist() == [1, 2, 3]
        assert fin["tree/b2_x"].array().tolist() == [1.1, 2.2, 3.3]
        assert fin["tree/b2_y"].array().tolist() == [4, 5, 6]
Exemplo n.º 13
0
def tmp_root_datafiles(tmp_path_factory):
    """Generate 3 test root file to read in"""
    data_prefix = 'test_data'
    tmpdir = tmp_path_factory.mktemp('data')
    a_n = 0
    for i in [1, 2, 3]:
        datapath = tmpdir / f'{data_prefix}{i}.root'
        with uproot.recreate(datapath) as test_file:
            test_file['tree1'] = {
                'testvar1': np.arange(1000 * i),
                'testvar2': np.arange(1000 * i) * 1.1 * i,
                'testvar3': np.arange(1000 * i) * i,
                'weight_mc': np.append(np.ones(990 * i), -1 * np.ones(10 * i)),
                'mcChannelNumber': np.full(1000 * i, i),
                'eventNumber':
                np.arange(1000 * a_n,
                          1000 * (a_n := a_n + i)),  # a_{n+1}=a_n+n+1, a_0=0
                'weight_pileup': np.ones(1000 * i)
            }
            test_file['tree2'] = {
                'testvar4': np.arange(1500 * i) * -1,
                'eventNumber': np.arange(1500 * i)
            }
            test_file['sumWeights'] = {
                'totalEventsWeighted': np.array([980 * i]),
                'dsid': [i]
            }
    yield str(tmpdir / f'{data_prefix}*.root')
Exemplo n.º 14
0
def test_awkward_jagged_data_3(tmp_path):
    newfile = os.path.join(tmp_path, "newfile.root")

    with uproot.recreate(newfile, compression=None) as fout:
        big = awkward.Array(
            [[0.0, 1.1, 2.2], [], [3.3, 4.4], [5.5], [6.6, 7.7, 8.8, 9.9]] *
            300)
        fout["tree"] = {"big": big}
        # more than 1000 entries, a special number for fNevBufSize and fEntryOffsetLen

    with uproot.open(newfile) as fin:
        assert fin["tree/nbig"].member("fLeaves")[0].member("fMaximum") == 4
        assert fin["tree/big"].member("fEntryOffsetLen") == 4 * 1500
        assert fin["tree/nbig"].array().tolist() == [3, 0, 2, 1, 4] * 300
        assert (fin["tree/big"].array().tolist() == [
            [0.0, 1.1, 2.2],
            [],
            [3.3, 4.4],
            [5.5],
            [6.6, 7.7, 8.8, 9.9],
        ] * 300)

    f1 = ROOT.TFile(newfile)
    t1 = f1.Get("tree")
    assert [x.nbig for x in t1] == [3, 0, 2, 1, 4] * 300
    assert [list(x.big) for x in t1] == [
        [0.0, 1.1, 2.2],
        [],
        [3.3, 4.4],
        [5.5],
        [6.6, 7.7, 8.8, 9.9],
    ] * 300
    f1.Close()
Exemplo n.º 15
0
def test_awkward_jagged_data_1(tmp_path):
    newfile = os.path.join(tmp_path, "newfile.root")

    with uproot.recreate(newfile, compression=None) as fout:
        b1 = np.array([1, 2, 3, 4, 5], np.int64)
        b2 = awkward.Array([[0.0, 1.1, 2.2], [], [3.3, 4.4], [5.5],
                            [6.6, 7.7, 8.8, 9.9]])
        fout.mktree("tree", {"b1": b1.dtype, "b2": b2.type})
        fout["tree"].extend({"b1": b1, "b2": b2})

    with uproot.open(newfile) as fin:
        assert fin["tree/nb2"].member("fLeaves")[0].member("fMaximum") == 4
        assert fin["tree/b2"].member("fEntryOffsetLen") == 4 * 5
        assert fin["tree/b1"].array().tolist() == [1, 2, 3, 4, 5]
        assert fin["tree/nb2"].array().tolist() == [3, 0, 2, 1, 4]
        assert fin["tree/b2"].array().tolist() == [
            [0.0, 1.1, 2.2],
            [],
            [3.3, 4.4],
            [5.5],
            [6.6, 7.7, 8.8, 9.9],
        ]

    f1 = ROOT.TFile(newfile)
    t1 = f1.Get("tree")
    assert [x.b1 for x in t1] == [1, 2, 3, 4, 5]
    assert [x.nb2 for x in t1] == [3, 0, 2, 1, 4]
    assert [list(x.b2) for x in t1] == [
        [0.0, 1.1, 2.2],
        [],
        [3.3, 4.4],
        [5.5],
        [6.6, 7.7, 8.8, 9.9],
    ]
    f1.Close()
Exemplo n.º 16
0
def Export2TTree(sOutputName, fits):
    with uproot.recreate(sOutputName) as f:
        f["Recon"] = uproot.newtree({
            "X":
            uproot.newbranch(float, title="X"),
            "Y":
            uproot.newbranch(float, title="Y"),
            "Z":
            uproot.newbranch(float, title="Z"),
            "T":
            uproot.newbranch(float, title="T"),
            "Theta":
            uproot.newbranch(float, title="Theta"),
            "Phi":
            uproot.newbranch(float, title="Phi"),
            "MCID":
            uproot.newbranch(int, title="MCID")
        })
        f["Recon"].extend({
            "X": fits[:, 0],
            "Y": fits[:, 1],
            "Z": fits[:, 2],
            "T": fits[:, 3],
            "Theta": fits[:, 4],
            "Phi": fits[:, 5],
            "MCID": fits[:, 6]
        })
Exemplo n.º 17
0
def test_pandas(tmp_path):
    pandas = pytest.importorskip("pandas")

    newfile = os.path.join(tmp_path, "newfile.root")

    df1 = pandas.DataFrame({"x": [1, 2, 3], "y": [1.1, 2.2, 3.3]})
    df2 = pandas.DataFrame({"x": [4, 5, 6], "y": [4.4, 5.5, 6.6]})

    with uproot.recreate(newfile, compression=None) as fout:
        fout["tree"] = df1
        fout["tree"].extend(df2)

    f1 = ROOT.TFile(newfile)
    t1 = f1.Get("tree")

    assert t1.GetBranch("index").GetName() == "index"
    assert t1.GetBranch("x").GetName() == "x"
    assert t1.GetBranch("y").GetName() == "y"
    assert [np.asarray(x.x).tolist() for x in t1] == [1, 2, 3, 4, 5, 6]
    assert [np.asarray(x.y).tolist() for x in t1] == [1.1, 2.2, 3.3, 4.4, 5.5, 6.6]

    with uproot.open(newfile) as fin:
        assert fin["tree/index"].name == "index"
        assert fin["tree/x"].name == "x"
        assert fin["tree/y"].name == "y"
        assert fin["tree/index"].typename.startswith("int")
        assert fin["tree/x"].typename.startswith("int")
        assert fin["tree/y"].typename == "double"
        assert fin["tree/x"].array().tolist() == [1, 2, 3, 4, 5, 6]
        assert fin["tree/y"].array().tolist() == [1.1, 2.2, 3.3, 4.4, 5.5, 6.6]

    f1.Close()
Exemplo n.º 18
0
def main():
    inpath = sys.argv[1]
    #acc = acc_from_dir("./input/2019-10-07_das_lhevpt_dressed_v1")
    
    acc = dir_archive(
                      inpath,
                      serialized=True,
                      compression=0,
                      memsize=1e3
                      )
    acc.load('sumw')
    acc.load('sumw2')


    outputrootfile = uproot.recreate(f'2017_gen_v_pt_qcd_sf.root')
    sf_1d(acc, tag='wjet', regex='W.*',outputrootfile=outputrootfile)
    sf_1d(acc, tag='dy', regex='.*DY.*',outputrootfile=outputrootfile)
    # # outputrootfile = uproot.recreate(f'test.root')
    sf_2d(acc, tag='wjet', regex='W.*',pt_type='dress',outputrootfile=outputrootfile)
    sf_2d(acc, tag='dy', regex='.*DY.*',pt_type='dress',outputrootfile=outputrootfile)

    sf_1d(acc, tag='gjets', regex='G\d?Jet.*',outputrootfile=outputrootfile)
    # outputrootfile = uproot.recreate('test.root')

    sf_2d(acc, tag='gjets',regex='G\d?Jet.*',pt_type='stat1',outputrootfile=outputrootfile)
Exemplo n.º 19
0
def test_histogram_interface(tmp_path):
    newfile = os.path.join(tmp_path, "newfile.root")

    with uproot.open(skhep_testdata.data_path("uproot-hepdata-example.root")) as fin:
        h1d, h2d = fin["hpx"], fin["hpxpy"]
        (h1d_entries_1, h1d_xedges_1) = h1d.to_numpy()
        (h2d_entries_1, h2d_xedges_1, h2d_yedges_1) = h2d.to_numpy(dd=False)
        (h2d_dd_entries_1, (h2d_dd_xedges_1, h2d_dd_yedges_1)) = h2d.to_numpy(dd=True)

        with uproot.recreate(newfile) as fout:
            fout["h1d"] = h1d.to_numpy()
            fout["h2d"] = h2d.to_numpy(dd=False)
            fout["h2d_dd"] = h2d.to_numpy(dd=True)
            (h1d_entries_2, h1d_xedges_2) = fout["h1d"].to_numpy()
            (h2d_entries_2, h2d_xedges_2, h2d_yedges_2) = fout["h2d"].to_numpy(dd=False)
            (h2d_dd_entries_2, (h2d_dd_xedges_2, h2d_dd_yedges_2)) = fout[
                "h2d_dd"
            ].to_numpy(dd=True)

    with uproot.open(newfile) as finagin:
        assert np.array_equal(h1d_entries_1, h1d_entries_2)
        assert np.array_equal(h1d_xedges_1, h1d_xedges_2)

        assert np.array_equal(h2d_entries_1, h2d_entries_2)
        assert np.array_equal(h2d_xedges_1, h2d_xedges_2)
        assert np.array_equal(h2d_yedges_1, h2d_yedges_2)

        assert np.array_equal(h2d_dd_entries_1, h2d_dd_entries_2)
        assert np.array_equal(h2d_dd_xedges_1, h2d_dd_xedges_2)
        assert np.array_equal(h2d_dd_yedges_1, h2d_dd_yedges_2)
Exemplo n.º 20
0
def test_bulk_copy(tmp_path):
    source_filename = os.path.join(tmp_path, "source.root")
    dest_filename = os.path.join(tmp_path, "dest.root")

    f_histogram = ROOT.TFile(source_filename, "recreate")
    f_histogram.mkdir("subdir")
    f_histogram.cd("subdir")
    x = ROOT.TH1F("hist", "title", 100, -5, 5)
    x.Write()
    f_histogram.Close()

    with uproot.open(source_filename) as source:
        with uproot.recreate(dest_filename) as dest:
            dest.copy_from(source, "subdir/hist")

    with uproot.open(dest_filename) as dest:
        assert dest.keys() == ["subdir;1", "subdir/hist;1"]
        hist = dest["subdir/hist"]
        assert hist.name == "hist"
        assert hist.title == "title"
        assert hist.axis().low == -5

    f2 = ROOT.TFile(dest_filename, "update")
    h2 = f2.Get("subdir/hist")
    assert h2.GetName() == "hist"
    assert h2.GetTitle() == "title"
    assert h2.GetNbinsX() == 100

    y = ROOT.TObjString("hello")
    y.Write()
    f2.Close()

    assert set(uproot.open(dest_filename).keys()) == set(
        ["subdir;1", "subdir/hist;1", "hello;1"])
Exemplo n.º 21
0
def test_2dim_interface_2(tmp_path):
    newfile = os.path.join(tmp_path, "newfile.root")

    with uproot.recreate(newfile, compression=None) as fout:
        fout["tree"] = {"branch": [[1.1, 2.2, 3.3], [4.4, 5.5, 6.6]]}
        fout["tree"].extend(
            {"branch": [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]}
        )
        with pytest.raises(ValueError):
            fout["tree"].extend({"branch": [7.7, 8.8, 9.9]})
        with pytest.raises(ValueError):
            fout["tree"].extend({"branch": [[7.7], [8.8], [9.9]]})

    f1 = ROOT.TFile(newfile)
    t1 = f1.Get("tree")

    assert [np.asarray(x.branch).tolist() for x in t1] == [
        [1.1, 2.2, 3.3],
        [4.4, 5.5, 6.6],
        [1.0, 2.0, 3.0],
        [4.0, 5.0, 6.0],
        [7.0, 8.0, 9.0],
    ]

    with uproot.open(newfile) as fin:
        assert fin["tree/branch"].array().tolist() == [
            [1.1, 2.2, 3.3],
            [4.4, 5.5, 6.6],
            [1.0, 2.0, 3.0],
            [4.0, 5.0, 6.0],
            [7.0, 8.0, 9.0],
        ]

    f1.Close()
Exemplo n.º 22
0
def test_100_branches(tmp_path):
    newfile = os.path.join(tmp_path, "newfile.root")

    with uproot.recreate(newfile, compression=None) as fout:
        tree = fout.mktree(
            "t1",
            {"branch" + str(i): np.float64
             for i in range(100)},
            "title",
        )

    f2 = ROOT.TFile(newfile)
    t2 = f2.Get("t1")

    assert t2.GetName() == "t1"
    assert t2.GetTitle() == "title"

    for branchname in ["branch" + str(i) for i in range(100)]:
        assert t2.GetBranch(branchname).GetName() == branchname
        assert t2.GetBranch(branchname).GetTitle() == branchname + "/D"

        assert t2.GetBranch(branchname).GetLeaf(
            branchname).GetName() == branchname
        assert t2.GetBranch(branchname).GetLeaf(
            branchname).GetTitle() == branchname

        assert t2.GetLeaf(branchname).GetName() == branchname
        assert t2.GetLeaf(branchname).GetTitle() == branchname

    f2.Close()
Exemplo n.º 23
0
def test_all_TH1(tmp_path, cls):
    original = os.path.join(tmp_path, "original.root")
    newfile = os.path.join(tmp_path, "newfile.root")

    f1 = ROOT.TFile(original, "recreate")
    h1 = cls("h1", "title", 2, -3.14, 2.71)
    h1.Fill(-4)
    h1.Fill(-3.1)
    h1.Fill(-3.1)
    h1.Fill(2.7, 5)
    h1.Fill(3, 4)
    h1.Write()
    f1.Close()

    with uproot.open(original) as fin:
        h2 = fin["h1"]

        with uproot.recreate(newfile) as fout:
            fout["out"] = h2

    f3 = ROOT.TFile(newfile)
    h3 = f3.Get("out")
    assert h3.GetEntries() == 5
    assert h3.GetSumOfWeights() == 7
    assert h3.GetBinLowEdge(1) == pytest.approx(-3.14)
    assert h3.GetBinWidth(1) == pytest.approx((2.71 - -3.14) / 2)
    assert h3.GetBinContent(0) == pytest.approx(1)
    assert h3.GetBinContent(1) == pytest.approx(2)
    assert h3.GetBinContent(2) == pytest.approx(5)
    assert h3.GetBinContent(3) == pytest.approx(4)
    assert h3.GetBinError(0) == pytest.approx(1)
    assert h3.GetBinError(1) == pytest.approx(1.4142135623730951)
    assert h3.GetBinError(2) == pytest.approx(5)
    assert h3.GetBinError(3) == pytest.approx(4)
    f3.Close()
Exemplo n.º 24
0
def test_basic(tmp_path):
    # original = os.path.join(tmp_path, "original.root")
    newfile = os.path.join(tmp_path, "newfile.root")

    # f1 = ROOT.TFile(original, "recreate")
    # f1.SetCompressionLevel(0)
    # t1 = ROOT.TTree("t1", "title")
    # d1 = array.array("d", [0.0])
    # t1.Branch("branch1", d1, "branch1/D")

    # t1.Write()
    # f1.Close()

    # with uproot.open(original) as fin:
    #     fin["t1"]

    with uproot.recreate(newfile, compression=None) as fout:
        tree = fout.mktree("t1", {"branch1": np.float64}, "title")

    f2 = ROOT.TFile(newfile)
    t2 = f2.Get("t1")

    assert t2.GetName() == "t1"
    assert t2.GetTitle() == "title"

    assert t2.GetBranch("branch1").GetName() == "branch1"
    assert t2.GetBranch("branch1").GetTitle() == "branch1/D"

    assert t2.GetBranch("branch1").GetLeaf("branch1").GetName() == "branch1"
    assert t2.GetBranch("branch1").GetLeaf("branch1").GetTitle() == "branch1"

    assert t2.GetLeaf("branch1").GetName() == "branch1"
    assert t2.GetLeaf("branch1").GetTitle() == "branch1"

    f2.Close()
Exemplo n.º 25
0
def test_new_name(tmp_path):
    newfile = os.path.join(tmp_path, "newfile.root")

    with uproot.open(
            skhep_testdata.data_path("uproot-histograms.root")) as fin:
        one = fin["one"]

        with uproot.recreate(newfile) as fout:
            fout["whatever"] = one

    f1 = ROOT.TFile(newfile)
    h1 = f1.Get("whatever")
    assert h1.GetBinContent(0) == 0
    assert h1.GetBinContent(1) == 68
    assert h1.GetBinContent(2) == 285
    assert h1.GetBinContent(3) == 755
    assert h1.GetBinContent(4) == 1580
    assert h1.GetBinContent(5) == 2296
    assert h1.GetBinContent(6) == 2286
    assert h1.GetBinContent(7) == 1570
    assert h1.GetBinContent(8) == 795
    assert h1.GetBinContent(9) == 289
    assert h1.GetBinContent(10) == 76
    assert h1.GetBinContent(11) == 0
    f1.Close()
Exemplo n.º 26
0
def test_rename(tmp_path):
    newfile = os.path.join(tmp_path, "newfiley_file.root")

    with uproot.recreate(newfile, compression=None) as fout:
        tree = fout.mktree(
            "treey_tree",
            {"branchy_branch": np.float64},
            "titley_title",
        )

    f2 = ROOT.TFile(newfile)
    t2 = f2.Get("treey_tree")

    assert t2.GetName() == "treey_tree"
    assert t2.GetTitle() == "titley_title"

    assert t2.GetBranch("branchy_branch").GetName() == "branchy_branch"
    assert t2.GetBranch("branchy_branch").GetTitle() == "branchy_branch/D"

    assert (t2.GetBranch("branchy_branch").GetLeaf("branchy_branch").GetName()
            == "branchy_branch")
    assert (t2.GetBranch("branchy_branch").GetLeaf(
        "branchy_branch").GetTitle() == "branchy_branch")

    assert t2.GetLeaf("branchy_branch").GetName() == "branchy_branch"
    assert t2.GetLeaf("branchy_branch").GetTitle() == "branchy_branch"

    f2.Close()
Exemplo n.º 27
0
def test_th3(tmp_path):
    filename = join(str(tmp_path), "example.root")
    testfile = join(str(tmp_path), "test.root")

    f = ROOT.TFile.Open(testfile, "RECREATE")
    h = ROOT.TH3F("hvar", "title", 5, 1, 10, 6, 1, 20, 7, 1, 30)
    h.Sumw2()
    h.Fill(1.0, 5.0, 8.0, 3)
    h.Fill(2.0, 10.0, 9.0, 4)
    h.Write()
    f.Close()

    t = uproot.open(testfile)
    hist = t["hvar"]
    with uproot.recreate(filename, compression=None) as f:
        f["test"] = hist

    f = ROOT.TFile.Open(filename)
    h = f.Get("test")
    sums = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0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, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
    assert h.GetNbinsX() == 5
    assert h.GetNbinsY() == 6
    assert h.GetNbinsZ() == 7
    assert list(h.GetSumw2()) == sums
    assert h.GetMean() == 1.5714285714285714
    assert h.GetRMS() == 0.4948716593053938
    count = 0
    for x in range(1, 6):
        for y in range(1, 7):
            for z in range(1, 8):
                assert h.GetBinContent(x, y, z) == bincontents[count]
                count += 1
Exemplo n.º 28
0
 def postprocess(self, accumulator):
     f = recreate(self.outfile)
     for h, hist in accumulator.items():
         f[h] = export1d(hist)
         print(f'wrote {h} to {self.outfile}')
     f.close()
     return accumulator
Exemplo n.º 29
0
def test_compressed_tprofile3d(tmp_path):
    filename = join(str(tmp_path), "example.root")
    testfile = join(str(tmp_path), "test.root")

    f = ROOT.TFile.Open(testfile, "RECREATE")
    h = ROOT.TProfile3D("hvar", "title", 5, 1, 10, 6, 1, 20, 8, 2, 8)
    h.Sumw2()
    h.Fill(1.0, 5.0, 3, 6)
    h.Fill(2.0, 10.0, 4, 7)
    h.Write()
    f.Close()

    t = uproot.open(testfile)
    hist = t["hvar"]
    with uproot.recreate(filename, compression=uproot.LZMA(6)) as f:
        f["test"] = h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ent(x, y, z) == bincontents[count]
                count += 1
    assert list(h.GetSumw2()) == sums
    assert h.GetMean() == 1.5
    assert h.GetRMS() == 0.5
    assert h.GetNbinsX() == 5
    assert h.GetNbinsY() == 6
    assert h.GetNbinsZ() == 8
Exemplo n.º 30
0
def test_multicompression_5(tmp_path):
    newfile = os.path.join(tmp_path, "newfile.root")

    branch1 = np.arange(100)
    branch2 = 1.1 * np.arange(100)

    with uproot.recreate(newfile, compression=uproot.ZLIB(5)) as fout:
        fout.compression = None
        fout.mktree("tree", {"branch1": branch1.dtype, "branch2": branch2.dtype})
        fout["tree"].extend({"branch1": branch1, "branch2": branch2})

    with uproot.open(newfile) as fin:
        assert fin["tree/branch1"].array(library="np").tolist() == branch1.tolist()
        assert fin["tree/branch2"].array(library="np").tolist() == branch2.tolist()
        assert fin["tree/branch1"].compression is None
        assert fin["tree/branch2"].compression is None
        assert fin["tree/branch1"].compressed_bytes == 874
        assert fin["tree/branch2"].compressed_bytes == 874
        assert fin["tree/branch1"].uncompressed_bytes == 874
        assert fin["tree/branch2"].uncompressed_bytes == 874

    f3 = ROOT.TFile(newfile)
    t3 = f3.Get("tree")
    assert [x.branch1 for x in t3] == branch1.tolist()
    assert [x.branch2 for x in t3] == branch2.tolist()
    f3.Close()