-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsimple_example.py
94 lines (73 loc) · 2.65 KB
/
simple_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from dask.distributed import Client
from lpc_dask import HTCondorCluster
import socket
import time
extra = ['--worker-port 10002:10100']
hostname = socket.gethostname()
cluster = HTCondorCluster(scheduler_options = {'host': f'{hostname}:10000'},
cores=1,
memory="4GB",
disk="2GB",
python='python',
nanny=False,
extra=extra
)
cluster.scale(jobs=10)
client = Client(cluster)
from coffea import hist, processor, nanoevents
# register our candidate behaviors
from coffea.nanoevents.methods import candidate
class MyProcessor(processor.ProcessorABC):
def __init__(self):
self._accumulator = processor.dict_accumulator({
"sumw": processor.defaultdict_accumulator(float),
"mass": hist.Hist(
"Events",
hist.Cat("dataset", "Dataset"),
hist.Bin("mass", "$m_{\mu\mu}$ [GeV]", 60, 60, 120),
),
})
@property
def accumulator(self):
return self._accumulator
def process(self, events):
output = self.accumulator.identity()
dataset = events.metadata['dataset']
muons = events.Muon
cut = (muons.counts == 2) & (muons.charge.sum() == 0)
# add first and second muon in every event together
dimuon = muons[cut][:, 0] + muons[cut][:, 1]
output["sumw"][dataset] += len(events)
output["mass"].fill(
dataset=dataset,
mass=dimuon.mass,
)
return output
def postprocess(self, accumulator):
return accumulator
fileset = {
'DoubleMuon': [
'root://eospublic.cern.ch//eos/root-eos/cms_opendata_2012_nanoaod/Run2012B_DoubleMuParked.root',
'root://eospublic.cern.ch//eos/root-eos/cms_opendata_2012_nanoaod/Run2012C_DoubleMuParked.root',
],
'ZZ to 4mu': [
'root://eospublic.cern.ch//eos/root-eos/cms_opendata_2012_nanoaod/ZZTo4mu.root'
]
}
exe_args = {
'client': client,
'savemetrics': True,
'schema': processor.NanoEvents,
'align_clusters': True
}
while len(client.ncores()) < 4:
print('Waiting for more cores to spin up, currently there are {0} available...'.format(len(client.ncores())))
print('Dask client info ->', client)
time.sleep(10)
proc = MyProcessor()
hists = processor.run_uproot_job(fileset,
treename="Events",
processor_instance=proc,
executor=processor.dask_executor,
executor_args=exe_args)
print(hists)