3 from __future__
import print_function
4 from __future__
import absolute_import
8 from .
import dataLoader
9 from .
import checkBTagCalibrationConsistency
as checker
13 flav_b_data = [e
for e
in loaded_data.entries
if e.params.jetFlavor == 0]
14 flav_b_data = sorted(flav_b_data, key=
lambda e: e.params.operatingPoint)
15 flav_b_data = sorted(flav_b_data, key=
lambda e: e.params.measurementType)
16 flav_b_data = sorted(flav_b_data, key=
lambda e: e.params.etaMin)
17 flav_b_data = sorted(flav_b_data, key=
lambda e: e.params.ptMin)
18 flav_b_data = sorted(flav_b_data, key=
lambda e: e.params.discrMin)
19 sys_groups = itertools.groupby(
21 key=
lambda e:
'%d, %s, %.02f, %.02f, %.02f' % (
22 e.params.operatingPoint,
23 e.params.measurementType,
30 def gen_entry_dict(groups):
33 entries_by_sys = dict((e.params.sysType, e)
for e
in grp)
34 assert len(grp) == len(entries_by_sys)
36 sys_dicts = gen_entry_dict(sys_groups)
38 def gen_flavb_csv_line(dicts):
40 central = d.pop(
'central')
41 central.params.jetFlavor = 1
42 yield central.makeCSVLine()
44 e.params.jetFlavor = 1
45 e.formula =
'2*(%s)-(%s)' % (e.formula, central.formula)
47 csv_lines = gen_flavb_csv_line(sys_dicts)
49 return list(l
for l
in csv_lines)
54 print(
'Need input/output filenames as first/second arguments. Exit.')
56 if os.path.exists(sys.argv[2]):
57 print(
'Output file exists. Exit.')
60 print(
'\nChecking input file consistency...')
62 checks = checker.run_check_data(loaders,
True,
True,
False)
66 print(
'FLAV_C already present in input file for %s. Exit.' % typ)
68 if not any(0
in data.flavs
for data
in loaders):
69 print(
'FLAV_B not found in input file. Exit.')
73 print(
'\nGenerating new csv content...')
74 new_csv_data = list(itertools.chain.from_iterable(
80 with open(sys.argv[1])
as f:
81 old_csv_data = f.readlines()
83 with open(sys.argv[2],
'w')
as f:
84 f.writelines(old_csv_data)
86 f.writelines(new_csv_data)
91 if __name__ ==
'__main__':