def test_lazy_colon(): uproot4.lazy(skhep_testdata.data_path("uproot-issue63.root") + ":WtLoop_nominal") uproot4.lazy( [ skhep_testdata.data_path("uproot-issue63.root") + ":WtLoop_nominal", skhep_testdata.data_path("uproot-issue63.root") + ":WtLoop_Fake_nominal", ] )
def test_awkward_pluralization(): awkward1 = pytest.importorskip("awkward1") files = ( skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root").replace( "6.20.04", "*" ) + ":sample/i4" ) assert awkward1.to_list(uproot4.lazy(files)[:5, "i4"]) == [-15, -14, -13, -12, -11]
def test_dask(): awkward1 = pytest.importorskip("awkward1") dask_array = pytest.importorskip("dask.array") files = ( skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root").replace( "6.20.04", "*" ) + ":sample" ) array1 = uproot4.lazy(files, "i4", library="da") array2 = uproot4.lazy(files, "i4", library="da") array3 = uproot4.lazy(files, "i8", library="da") assert array1.name == array2.name assert array1.name != array3.name assert array1[0].compute() == -15 assert array2[0].compute() == -15 assert array3[0].compute() == -15
def test_daskframe(): awkward1 = pytest.importorskip("awkward1") dask_frame = pytest.importorskip("dask.dataframe") files = ( skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root").replace( "6.20.04", "*" ) + ":sample" ) array1 = uproot4.lazy(files, library="dd") repr(array1)
def load_data(self, path, label, topo=None): if len(self.datasets) == 2: raise ValueError('Cannot compare more than 2 datasets') print("Loading:") print(path) tree_data = uproot4.lazy(path, executor=self.executor, blocking=False, cache=self.cache) # check if topo given, careful with zero! if topo is not None: tree_data = tree_data[tree_data['Topo'] == topo] self.datasets[label] = tree_data
def test_awkward(): awkward1 = pytest.importorskip("awkward1") files = ( skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root").replace( "6.20.04", "*" ) + ":sample" ) cache = {} array = uproot4.lazy(files, array_cache=cache) assert len(cache) == 0 assert awkward1.to_list(array[:5, "i4"]) == [-15, -14, -13, -12, -11] assert len(cache) == 1 assert awkward1.to_list(array[:5, "ai4"]) == [ [-14, -13, -12], [-13, -12, -11], [-12, -11, -10], [-11, -10, -9], [-10, -9, -8], ] assert len(cache) == 2 assert awkward1.to_list(array[:5, "Ai4"]) == [ [], [-15], [-15, -13], [-15, -13, -11], [-15, -13, -11, -9], ] assert len(cache) == 3 assert awkward1.to_list(array[:5, "str"]) == [ "hey-0", "hey-1", "hey-2", "hey-3", "hey-4", ] assert len(cache) == 4
import matplotlib.pyplot as plt import mplhep as hep plt.style.use(hep.style.ROOT) base = '/Users/chrispap/QCD/' datasets = { base + 'Autumn18.QCD_HT500to700_TuneCP5_13TeV-madgraphMLM-pythia8_RA2AnalysisTree.root': 'TreeMaker2/PreSelection', base + 'Autumn18.QCD_HT700to1000_TuneCP5_13TeV-madgraphMLM-pythia8_RA2AnalysisTree.root': 'TreeMaker2/PreSelection', base + 'Autumn18.QCD_HT1000to1500_TuneCP5_13TeV-madgraphMLM-pythia8_RA2AnalysisTree.root': 'TreeMaker2/PreSelection', base + 'Autumn18.QCD_HT1500to2000_TuneCP5_13TeV-madgraphMLM-pythia8_RA2AnalysisTree.root': 'TreeMaker2/PreSelection', base + 'Autumn18.QCD_HT2000toInf_TuneCP5_13TeV-madgraphMLM-pythia8_RA2AnalysisTree.root': 'TreeMaker2/PreSelection', } events = uproot.lazy(datasets) ht = events['HT'] CrossSection = events['CrossSection'] CrossSection = CrossSection[ht > 1200] ht = ht[ht > 1200] integrated_Luminosity = 137.19*1000 # fb^{-1} to pb^{-1} Nevents = 100000 Weight = integrated_Luminosity*CrossSection/Nevents # Plot results fig = plt.figure(figsize=(8,8)) ax = plt.gca() ax.hist(ht, bins=100, weights=Weight, histtype='step')
def test_lazy_called_on_nonexistent_file(): filename = "nonexistent_file.root" with pytest.raises(FileNotFoundError) as excinfo: uproot4.lazy(filename) assert filename in str(excinfo.value)
def test_lazy(): with pytest.raises(ValueError): uproot4.lazy(skhep_testdata.data_path("uproot-issue63.root")) with pytest.raises(ValueError): uproot4.lazy( {skhep_testdata.data_path("uproot-issue63.root"): "blah"}, allow_missing=True, ) uproot4.lazy({skhep_testdata.data_path("uproot-issue63.root"): "WtLoop_nominal"}) uproot4.lazy( { skhep_testdata.data_path("uproot-issue63.root"): "WtLoop_nominal", skhep_testdata.data_path("uproot-issue63.root"): "WtLoop_Fake_nominal", } ) uproot4.lazy([{skhep_testdata.data_path("uproot-issue63.root"): "WtLoop_nominal"}]) uproot4.lazy( {skhep_testdata.data_path("uproot-issue63.root") + "*": "WtLoop_nominal"} ) uproot4.lazy( [{skhep_testdata.data_path("uproot-issue63.root") + "*": "WtLoop_nominal"}] )