Skip to content

Instantly share code, notes, and snippets.

@alexander-held
Last active April 10, 2023 14:03
Show Gist options
  • Save alexander-held/1c91a599096465528fc5d7cee71b0174 to your computer and use it in GitHub Desktop.
Save alexander-held/1c91a599096465528fc5d7cee71b0174 to your computer and use it in GitHub Desktop.
debugging coffea 2023 with simplified AGC setup
import warnings
warnings.filterwarnings("error")
import os
import urllib.request
from coffea import processor
from coffea.nanoevents import NanoAODSchema, NanoEventsFactory
import dask_awkward as dak
import hist.dask
class TtbarAnalysis(processor.ProcessorABC):
def process(self, events):
histogram = hist.dask.Hist.new.Reg(25, 50, 550, name="observable", label="observable [GeV]").Double()
trijet = dak.combinations(events.Jet, 3, fields=["j1", "j2", "j3"]) # trijet candidates
trijet["p4"] = trijet.j1 + trijet.j2 + trijet.j3 # calculate four-momentum of tri-jet system
observable = dak.sum(trijet.p4.mass, axis=-1)
histogram.fill(observable=observable)
return histogram
def postprocess(self, accumulator):
return accumulator
if __name__ == "__main__":
NanoAODSchema.warn_missing_crossrefs = False # silences warnings about branches we will not use here
ttbar_file = "https://github.com/scikit-hep/scikit-hep-testdata/raw/main/src/skhep_testdata/data/nanoAOD_2015_CMS_Open_Data_ttbar.root"
events = NanoEventsFactory.from_root(ttbar_file, schemaclass=NanoAODSchema, treepath="Events", permit_dask=True).events()
output = TtbarAnalysis().process(events)
print(output.dask)
print(dak.necessary_columns(output))
print(output.compute())
breakpoint()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment