Skip to content

Commit

Permalink
Update tests accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
oshadura committed Feb 13, 2024
1 parent 382dbb0 commit 4e7609e
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 39 deletions.
38 changes: 0 additions & 38 deletions tests/test_adl1.py

This file was deleted.

3 changes: 2 additions & 1 deletion tests/test_dimuon.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from coffea.nanoevents import NanoEventsFactory, BaseSchema

from dask.distributed import Client
import pytest

fileset = {
'DoubleMuon': [
Expand Down Expand Up @@ -61,7 +62,7 @@ def process(self, events):
def postprocess(self, accumulator):
pass

@pytest.mark.coffeav0
@pytest.mark.v0
def test_processor_dimu_mass():
client = Client()
iterative_run = processor.Runner(executor = processor.dask_executor,
Expand Down
76 changes: 76 additions & 0 deletions tests/test_doublemuon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import hist
import dask
import awkward as ak
import hist.dask as hda
import dask_awkward as dak

from coffea import processor
from coffea.nanoevents.methods import candidate
from coffea.nanoevents import NanoEventsFactory, BaseSchema

from distributed import Client

import pytest

client = Client()


class MyProcessor(processor.ProcessorABC):
def __init__(self):
pass

def process(self, events):
dataset = events.metadata['dataset']
muons = ak.zip(
{
"pt": events.Muon_pt,
"eta": events.Muon_eta,
"phi": events.Muon_phi,
"mass": events.Muon_mass,
"charge": events.Muon_charge,
},
with_name="PtEtaPhiMCandidate",
behavior=candidate.behavior,
)

h_mass = (
hda.Hist.new
.StrCat(["opposite", "same"], name="sign")
.Log(1000, 0.2, 200., name="mass", label="$m_{\mu\mu}$ [GeV]")
.Int64()
)

cut = (ak.num(muons) == 2) & (ak.sum(muons.charge, axis=1) == 0)
# add first and second muon in every event together
dimuon = muons[cut][:, 0] + muons[cut][:, 1]
h_mass.fill(sign="opposite", mass=dimuon.mass)

cut = (ak.num(muons) == 2) & (ak.sum(muons.charge, axis=1) != 0)
dimuon = muons[cut][:, 0] + muons[cut][:, 1]
h_mass.fill(sign="same", mass=dimuon.mass)

return {
dataset: {
"entries": ak.num(events, axis=0),
"mass": h_mass,
}
}

def postprocess(self, accumulator):
pass

filename = "root://eospublic.cern.ch//eos/root-eos/cms_opendata_2012_nanoaod/Run2012B_DoubleMuParked.root"

events = NanoEventsFactory.from_root(
{filename: "Events"},
metadata={"dataset": "DoubleMuon"},
schemaclass=BaseSchema,
).events()


@pytest.mark.calver
def test_adl1():
p = MyProcessor()
out = p.process(events)
(computed,) = dask.compute(out)
print(computed)

0 comments on commit 4e7609e

Please sign in to comment.