forked from jpata/hepaccelerate-cms
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcounts.py
34 lines (26 loc) · 931 Bytes
/
counts.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
import os, glob
import argparse
import json
import numpy as np
import uproot
def count_weighted(filenames):
sumw = 0
for fi in filenames:
print(fi)
ff = uproot.open(fi)
#bl = ff.get("nanoAOD/Runs")
bl = ff.get("Runs")
sumw += bl.array("genEventSumw").sum()
return sumw
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='get weights (counted) for config file')
parser.add_argument('--filelist', action='store', help='List of files to load', type=str, default=None, required=False)
parser.add_argument('filenames', nargs=argparse.REMAINDER)
args = parser.parse_args()
filenames = None
if not args.filelist is None:
filenames = [l.strip() for l in open(args.filelist).readlines()]
else:
filenames = args.filenames
genWeight = count_weighted(filenames)
print("Number of events (weighted)", genWeight)