CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
dataLoader.py
Go to the documentation of this file.
1 import itertools
2 import ROOT
3 ROOT.gSystem.Load('libCondFormatsBTagObjects')
4 
5 
7  def __init__(self, csv_data, measurement_type):
8  self.meas_type = measurement_type
9 
10  # list of entries
11  ens = []
12  for l in csv_data:
13  if not l.strip():
14  continue # skip empty lines
15  try:
16  e = ROOT.BTagEntry(l)
17  if e.params.measurementType == measurement_type:
18  ens.append(e)
19  except TypeError:
20  raise RuntimeError("Error: can not interpret line: " + l)
21  self.entries = ens
22 
23  self.ETA_MIN = -2.4
24  self.ETA_MAX = 2.4
25  self.PT_MIN = min(e.params.ptMin for e in ens)
26  self.PT_MAX = max(e.params.ptMax for e in ens)
27  self.DISCR_MIN = min(e.params.discrMin for e in ens)
28  self.DISCR_MAX = max(e.params.discrMax for e in ens)
29 
30  # sets of fixed data
31  self.ops = set(e.params.operatingPoint for e in ens)
32  self.flavs = set(e.params.jetFlavor for e in ens)
33  self.syss = set(e.params.sysType for e in ens)
34  self.etas = set((e.params.etaMin, e.params.etaMax) for e in ens)
35  self.pts = set((e.params.ptMin, e.params.ptMax) for e in ens)
36  self.discrs = set((e.params.discrMin, e.params.discrMax) for e in ens)
37 
38  # test points for variable data (using bound +- epsilon)
39  eps = 1e-4
40  eta_test_points = list(itertools.ifilter(
41  lambda x: self.ETA_MIN < x < self.ETA_MAX,
42  itertools.chain(
43  (a + eps for a, _ in self.etas),
44  (a - eps for a, _ in self.etas),
45  (b + eps for _, b in self.etas),
46  (b - eps for _, b in self.etas),
47  (self.ETA_MIN + eps, self.ETA_MAX - eps),
48  )
49  ))
50  abseta_test_points = list(itertools.ifilter(
51  lambda x: 0. < x < self.ETA_MAX,
52  itertools.chain(
53  (a + eps for a, _ in self.etas),
54  (a - eps for a, _ in self.etas),
55  (b + eps for _, b in self.etas),
56  (b - eps for _, b in self.etas),
57  (eps, self.ETA_MAX - eps),
58  )
59  ))
60  pt_test_points = list(itertools.ifilter(
61  lambda x: self.PT_MIN < x < self.PT_MAX,
62  itertools.chain(
63  (a + eps for a, _ in self.pts),
64  (a - eps for a, _ in self.pts),
65  (b + eps for _, b in self.pts),
66  (b - eps for _, b in self.pts),
67  (self.PT_MIN + eps, self.PT_MAX - eps),
68  )
69  ))
70  discr_test_points = list(itertools.ifilter(
71  lambda x: self.DISCR_MIN < x < self.DISCR_MAX,
72  itertools.chain(
73  (a + eps for a, _ in self.discrs),
74  (a - eps for a, _ in self.discrs),
75  (b + eps for _, b in self.discrs),
76  (b - eps for _, b in self.discrs),
77  (self.DISCR_MIN + eps, self.DISCR_MAX - eps),
78  )
79  ))
80  # use sets
81  self.eta_test_points = set(round(f, 5) for f in eta_test_points)
82  self.abseta_test_points = set(round(f, 5) for f in abseta_test_points)
83  self.pt_test_points = set(round(f, 5) for f in pt_test_points)
84  self.discr_test_points = set(round(f, 5) for f in discr_test_points)
85 
86  def print_data(self):
87  print "\nFound operating points (need at least 0, 1, 2):"
88  print self.ops
89 
90  print "\nFound jet flavors (need 0, 1, 2):"
91  print self.flavs
92 
93  print "\nFound sys types (need at least 'central', 'up', 'down'; " \
94  "also 'up_SYS'/'down_SYS' compatibility is checked):"
95  print self.syss
96 
97  print "\nFound eta ranges: (need everything covered from %g or 0. " \
98  "up to %g):" % (self.ETA_MIN, self.ETA_MAX)
99  print self.etas
100 
101  print "\nFound pt ranges: (need everything covered from %g " \
102  "to %g):" % (self.PT_MIN, self.PT_MAX)
103  print self.pts
104 
105  print "\nFound discr ranges: (only needed for operatingPoint==3, " \
106  "covered from %g to %g):" % (self.DISCR_MIN, self.DISCR_MAX)
107  print self.discrs
108 
109  print "\nTest points for eta (bounds +- epsilon):"
110  print self.eta_test_points
111 
112  print "\nTest points for pt (bounds +- epsilon):"
113  print self.pt_test_points
114 
115  print "\nTest points for discr (bounds +- epsilon):"
116  print self.discr_test_points
117  print ""
118 
119 
120 def get_data_csv(csv_data):
121  # grab measurement types
122  meas_types = set(
123  l.split(',')[1].strip()
124  for l in csv_data
125  if len(l.split()) == 11
126  )
127  return list(DataLoader(csv_data, mt) for mt in meas_types)
128 
129 
130 def get_data(filename):
131  with open(filename) as f:
132  csv_data = f.readlines()
133  if not (csv_data and "OperatingPoint" in csv_data[0]):
134  print "Data file does not contain typical header: %s. Exit" % filename
135  return False
136  csv_data.pop(0) # remove header
137  return get_data_csv(csv_data)
def get_data_csv
Definition: dataLoader.py:120
T min(T a, T b)
Definition: MathUtil.h:58
list object
Definition: dbtoconf.py:77
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