3 from __future__
import print_function
4 from __future__
import absolute_import
8 from .
import dataLoader
9 from .
import checkBTagCalibrationConsistency
as checker
14 flav_b_data = [e
for e
in loaded_data.entries
if e.params.jetFlavor == 0]
15 flav_b_data = sorted(flav_b_data, key=
lambda e: e.params.operatingPoint)
16 flav_b_data = sorted(flav_b_data, key=
lambda e: e.params.measurementType)
17 flav_b_data = sorted(flav_b_data, key=
lambda e: e.params.etaMin)
18 flav_b_data = sorted(flav_b_data, key=
lambda e: e.params.ptMin)
19 flav_b_data = sorted(flav_b_data, key=
lambda e: e.params.discrMin)
20 sys_groups = itertools.groupby(
22 key=
lambda e:
'%d, %s, %.02f, %.02f, %.02f' % (
23 e.params.operatingPoint,
24 e.params.measurementType,
31 def gen_entry_dict(groups):
34 entries_by_sys = dict((e.params.sysType, e)
for e
in grp)
35 assert len(grp) == len(entries_by_sys)
37 sys_dicts = gen_entry_dict(sys_groups)
39 def gen_flavb_csv_line(dicts):
41 central = d.pop(
'central')
42 central.params.jetFlavor = 1
43 yield central.makeCSVLine()
44 for e
in six.itervalues(d):
45 e.params.jetFlavor = 1
46 e.formula =
'2*(%s)-(%s)' % (e.formula, central.formula)
48 csv_lines = gen_flavb_csv_line(sys_dicts)
50 return list(l
for l
in csv_lines)
55 print(
'Need input/output filenames as first/second arguments. Exit.')
57 if os.path.exists(sys.argv[2]):
58 print(
'Output file exists. Exit.')
61 print(
'\nChecking input file consistency...')
63 checks = checker.run_check_data(loaders,
True,
True,
False)
67 print(
'FLAV_C already present in input file for %s. Exit.' % typ)
69 if not any(0
in data.flavs
for data
in loaders):
70 print(
'FLAV_B not found in input file. Exit.')
74 print(
'\nGenerating new csv content...')
75 new_csv_data =
list(itertools.chain.from_iterable(
81 with open(sys.argv[1])
as f:
82 old_csv_data = f.readlines()
84 with open(sys.argv[2],
'w')
as f:
85 f.writelines(old_csv_data)
87 f.writelines(new_csv_data)
92 if __name__ ==
'__main__':