-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
78 additions
and
39 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |