CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
generateFlavCfromFlavB.py
Go to the documentation of this file.
1 import os
2 import sys
3 import itertools
4 import dataLoader
5 import checkBTagCalibrationConsistency as checker
6 
7 
8 def generate_flav_c(loaded_data):
9  flav_b_data = filter(
10  lambda e: e.params.jetFlavor == 0,
11  loaded_data.entries
12  )
13  flav_b_data = sorted(flav_b_data, key=lambda e: e.params.operatingPoint)
14  flav_b_data = sorted(flav_b_data, key=lambda e: e.params.measurementType)
15  flav_b_data = sorted(flav_b_data, key=lambda e: e.params.etaMin)
16  flav_b_data = sorted(flav_b_data, key=lambda e: e.params.ptMin)
17  flav_b_data = sorted(flav_b_data, key=lambda e: e.params.discrMin)
18  sys_groups = itertools.groupby(flav_b_data,
19  key=lambda e: e.params.operatingPoint)
20 
21  def gen_entry_dict(groups):
22  for _, grp in groups:
23  grp = list(grp)
24  entries_by_sys = dict((e.params.sysType, e) for e in grp)
25  assert len(grp) == len(entries_by_sys) # every sysType is unique
26  yield entries_by_sys
27  sys_dicts = gen_entry_dict(sys_groups)
28 
29  def gen_flavb_csv_line(dicts):
30  for d in dicts:
31  central = d.pop('central')
32  central.params.jetFlavor = 1
33  yield central.makeCSVLine()
34  for e in d.itervalues():
35  e.params.jetFlavor = 1
36  e.formula = '2*(%s)-(%s)' % (e.formula, central.formula)
37  yield e.makeCSVLine()
38  csv_lines = gen_flavb_csv_line(sys_dicts)
39 
40  return list(l for l in csv_lines)
41 
42 
43 def main():
44  if len(sys.argv) < 3:
45  print 'Need input/output filenames as first/second arguments. Exit.'
46  exit(-1)
47  if os.path.exists(sys.argv[2]):
48  print 'Output file exists. Exit.'
49  exit(-1)
50 
51  print '\nChecking input file consistency...'
52  loaders = dataLoader.get_data(sys.argv[1])
53  checks = checker.run_check_data(loaders, True, True, False)
54  for res, data in itertools.izip(checks, loaders):
55  typ = data.meas_type
56  if not res:
57  print 'Checks on input file failed for %s. Exit.' % typ
58  exit(-1)
59  if not 0 in data.flavs:
60  print 'FLAV_B not found in input file for %s. Exit.' % typ
61  exit(-1)
62  if 1 in data.flavs:
63  print 'FLAV_C already present in input file for %s. Exit.' % typ
64  exit(-1)
65 
66  print '\nGenerating new csv content...'
67  new_csv_data = list(itertools.chain.from_iterable(
68  l
69  for d in loaders
70  for l in generate_flav_c(d)
71  ))
72 
73  with open(sys.argv[1]) as f:
74  old_csv_data = f.readlines()
75 
76  with open(sys.argv[2], 'w') as f:
77  f.writelines(old_csv_data)
78  f.write('\n')
79  f.writelines(new_csv_data)
80 
81  print 'Done.'
82 
83 
84 if __name__ == '__main__':
85  main()
Definition: main.py:1
def get_data
Definition: dataLoader.py:130
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run