ATLAS Offline Software
scenario_simple.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2 
3 from TrigHLTJetHypo.RepeatedConditionParams import RepeatedConditionParams
4 from TrigHLTJetHypo.HelperConfigToolParams import HelperConfigToolParams
5 from TrigHLTJetHypo.ConditionDefaults import defaults
6 from TrigHLTJetHypo.make_treevec import make_treevec
7 
8 
9 # make a list of all possible cut items for the simple scenario
10 all_elemental_keys = ('etaRange', 'jvt', 'smc',
11  'threshold', 'momCuts', 'bsel', 'tausel',
12  'clrsel','pileuprm', 'timing', 'timeSig')
13 
14 # Extract moment cuts
15 def _cuts_from_momCuts(momCuts):
16  separator = 'XX'
17  args = momCuts.split(separator)
18  if len(args) > 1:
19  return args
20  return ''
21 
23 
24  # determine which cut variable are present in this chain part,
25  # and find their chain part values
26  elemental_keys = [k for k in all_elemental_keys if k in cp]
27  cp_elemental_args = {k : cp[k] for k in elemental_keys if cp[k]}
28 
29  # remove place holders
30  todelete = []
31  for k, v in cp_elemental_args.items():
32  if v == 'nosmc': todelete.append(k)
33 
34  for k in todelete: del cp_elemental_args[k]
35 
36  # decode the chain part cut values to find the numerical cut values
37 
38  condargs = list()
39 
40  for k, v in cp_elemental_args.items():
41  if k == 'threshold':
42  key = 'pt'
43  vals = defaults(key, lo=v)
44  condargs.append((key, vals))
45 
46  if k == 'etaRange':
47  key='eta'
48  lo, hi = v.split(key)
49  vals = defaults(key, lo=lo, hi=hi)
50  condargs.append((key, vals))
51 
52  if k == 'smc':
53  key = 'smc'
54  lo, hi = v.split(key)
55  vals = defaults(key, lo=lo, hi=hi)
56  condargs.append((key, vals))
57 
58  if k == 'jvt':
59  key = 'jvt'
60  values = v.split(key)
61  assert values[1] == '','jvt condition takes only one argument, two were given' # protection when an upper (not supported) cut is requested
62  lo = values[0]
63  vals = defaults(key, lo=lo)
64  condargs.append((key, vals))
65 
66  if k == 'timing':
67  key = 'timing'
68  values = v.split(key)
69  lo = values[0]
70  vals = defaults(key, lo=lo)
71  condargs.append((key, vals))
72 
73  if k == 'timeSig':
74  key = 'timeSig'
75  values = v.split(key)
76  lo = values[0]
77  vals = defaults(key, lo=lo)
78  condargs.append((key, vals))
79 
80  if k =='clrsel':
81  key = 'clrsel'
82  values = v.split(key)
83  lo = values[0]
84  vals = defaults(key, lo=lo)
85  condargs.append((key, vals))
86  if k == 'bsel':
87  if 'bgnone' in v:
88  key = 'bgnone'
89  values = v.split(key)
90  assert values[1] == '', 'bgn1 condition takes only one argument, two were given'
91 
92  gn1_WPs = {
93  '': float('-inf'),
94  "95": -2.0886,
95  "90": -0.7981,
96  "85": 0.4462,
97  "82": 1.0965,
98  "80": 1.4991,
99  "77": 2.0717,
100  "75": 2.4110,
101  "60": 4.5465,
102  }
103 
104  assert (values[0] in gn1_WPs.keys()),f"The efficiency of the specified GN1 cut \'{v}\' can not be found in the WP dictionary. Please add or remove the WP from the GN1 WP dictionary."
105 
106  lo = gn1_WPs[values[0]]
107 
108  vals = {
109  'min': str(lo),
110  'max': '',
111  'cfrac': '0.018',
112  'namePb': 'fastGN120230331_pb',
113  'namePc': 'fastGN120230331_pc',
114  'namePu': 'fastGN120230331_pu',
115  'nameValid': 'TracksForMinimalJetTag_isValid'
116  }
117 
118  condargs.append((k, vals))
119  # GN2x has to go before GN2 in order to avoid ` elif 'bgntwo' in v:` l149 to pass 'bgntwox'
120  elif 'bgntwox' in v:
121  key = 'bgntwox'
122  values = v.split(key)
123  assert values[1] == '','bgntwox condition takes only one argument, two were given'
124 
125  #This dictionary maps the bdips efficiency into the WP cut to be applied to the DIPS output
126  gn2x_WPs = {
127  '': float('-inf'),
128  '60': 3.1077,
129  '70': 2.2998,
130  '80': 1.2486,
131  '90': -0.4298,
132  }
133 
134  assert (values[0] in gn2x_WPs.keys()),f"The efficiency of the specified gn2x cut \'{v}\' can not be found in the WP dictionary. Please add or remove the WP from the dips WP dictionary."
135 
136  lo = gn2x_WPs[values[0]]
137  vals = {
138  'min': str(lo),
139  'max': '',
140  'cfrac': '0.25',
141  'namePb': 'GN2Xv01_phbb',
142  'namePc': 'GN2Xv01_ptop',
143  'namePu': 'GN2Xv01_pqcd',
144  'nameValid': 'TracksForMinimalJetTag_isValid'
145  }
146  condargs.append((k, vals))
147 
148  elif 'bgntwo' in v:
149  key = 'bgntwo'
150  values = v.split(key)
151  assert values[1] == '', 'bgn2 condition takes only one argument, two were given'
152 
153  gn2_WPs = {
154  '': float('-inf'),
155  "95": -2.432,
156  "90": -1.351,
157  "85": -0.150,
158  "82": 0.5105,
159  "80": 0.931,
160  "77": 1.471,
161  "75": 1.832,
162  "60": 4.054,
163  }
164 
165  assert (values[0] in gn2_WPs.keys()),f"The efficiency of the specified GN2 cut \'{v}\' can not be found in the WP dictionary. Please add or remove the WP from the GN2 WP dictionary."
166 
167  lo = gn2_WPs[values[0]]
168 
169  vals = {
170  'min': str(lo),
171  'max': '',
172  'cfrac': '0.018',
173  'namePb': 'fastGN220240122_pb',
174  'namePc': 'fastGN220240122_pc',
175  'namePu': 'fastGN220240122_pu',
176  'nameValid': 'TracksForMinimalJetTag_isValid'
177  }
178 
179  condargs.append((k, vals))
180  elif 'bdips' in v:
181  key = 'bdips'
182  values = v.split(key)
183  assert values[1] == '','bdips condition takes only one argument, two were given' # protection when an upper (not supported) cut is requested
184 
185  #This dictionary maps the bdips efficiency into the WP cut to be applied to the DIPS output
186  dips_WPs = {
187  '': float('-inf'),
188  '95': -1.6495,
189  '90': -0.8703,
190  '85': -0.0295,
191  '82': 0.4560,
192  '80': 0.7470,
193  '77': 1.1540,
194  '75': 1.4086,
195  '60': 3.0447,
196  }
197 
198  assert (values[0] in dips_WPs.keys()),f"The efficiency of the specified dips cut \'{v}\' can not be found in the WP dictionary. Please add or remove the WP from the dips WP dictionary."
199 
200  lo = dips_WPs[values[0]]
201  vals = {
202  'min': str(lo),
203  'max': '',
204  'cfrac': '0.018',
205  'namePb': 'fastDips_pb',
206  'namePc': 'fastDips_pc',
207  'namePu': 'fastDips_pu',
208  'nameValid': 'TracksForMinimalJetTag_isValid'
209  }
210  condargs.append((k, vals))
211 
212  else:
213  raise ValueError(f'btagger {v.split("b")[1]} not supportted')
214 
215  if k == "tausel":
216  key = 'gntau'
217  values = v.split(key)
218  assert values[1] == '' , 'gntau condition takes only one argument, two were given' # protection when an upper (not supported) cut is requested
219 
220  gntau_WPs = \
221  { '': float('-inf')
222  , '90': -0.846
223  , '85': 0.048
224  , '80': 0.693
225  , '75': 1.229
226  }
227 
228  assert (values[0] in gntau_WPs.keys()),f"The efficiency of the specified gntau cut \'{v}\' can not be found in the WP dictionary. Please add or remove the WP from the gntau WP dictionary."
229 
230  lo = gntau_WPs[values[0]]
231  vals = {
232  'min': str(lo),
233  'max': '',
234  'namePtau': 'fastGNTau20240216_ptau',
235  'namePu': 'fastGNTau20240216_pu',
236  'nameValid': 'TracksForMinimalJetTag_isValid'
237  }
238  condargs.append((k, vals))
239 
240 
241  if k == 'momCuts':
242  from TrigHLTJetHypo.FastReductionAlgToolFactory import jetMoments
243  if 'XX' in v: # several moment cuts are requested
244 
245  # loop over requested moment strings
246  for cutstr in _cuts_from_momCuts(v):
247  for moment in jetMoments: # loop over possible jet moments
248  if moment in cutstr:
249  key='mom{}'.format(moment)
250  lo, hi = cutstr.split(key)
251  vals = defaults(k, lo=lo, hi=hi)
252  vals["moment"] = jetMoments[moment]
253  condargs.append((key, vals))
254  else: # a single moment cut is requested
255  for moment in jetMoments: # loop over possible jet moments
256  if moment in v:
257  key='mom{}'.format(moment)
258  lo, hi = v.split(key)
259  vals = defaults(k, lo=lo, hi=hi)
260  vals["moment"] = jetMoments[moment]
261  condargs.append((key, vals))
262  if k =='pileuprm':
263  key = 'pileuprm'
264  values = v.split(key)
265  if "n" in values[0]:
266  lo=values[0].replace("n","-",1)
267  if "n" in values[1]:
268  hi=values[1].replace("n","-",1)
269  vals = defaults(key, lo=lo, hi=hi)
270  condargs.append((key, vals))
271  return condargs
272 
273 
274 def scenario_simple(chain_parts):
275  """build two lists of RepeatedConditionConfig objects
276  one list contains the Conditions to be used by FastReducer,
277  and the other Contains the conditions used to filter the Condition.
278  Each list has one entry per chain part"""
279 
280  assert chain_parts, 'routing error, module %s: no chain parts' % __name__
281 
282  repcondargs = []
283  filterparams = []
284  filterparam_inds = []
285 
286  ncp = 0
287 
288  # keep track of identical cond_args, which are given the same
289  # clique number.
290  # the C++ code will use the clique number for optimisation of
291  # the calculation of the combinations
292  #
293  # current implementation: condition filter not included.
294  clique_list = []
295  for cp in chain_parts:
296  ncp += 1
297 
298  # get the Condition parameters (cut values) for the
299  # elemental Conditions
300 
301  condargs = get_condition_args_from_chainpart(cp)
302 
303  multiplicity = int(cp['multiplicity'])
304  chainPartInd = cp['chainPartIndex']
305 
306  # no condition filtering
307  filterparam_inds.append(-1) # no Condition filter
308 
309  clique = None
310  try:
311  clique = clique_list.index(condargs)
312  except ValueError:
313  # seen for the first time
314  clique_list.append(condargs)
315  clique = len(clique_list)-1
316 
317  repcondargs.append(RepeatedConditionParams(tree_id = ncp,
318  tree_pid=0,
319  clique=clique,
320  chainPartInd=chainPartInd,
321  multiplicity=multiplicity,
322  condargs=condargs))
323 
324 
325  # treevec[i] gives the tree_id of the parent of the
326  # node with tree_id = i
327  treevec = make_treevec(repcondargs)
328  assert treevec == [0 for i in range(len(chain_parts) + 1)]
329 
330  assert len(repcondargs) == len(filterparam_inds)
331  helper_params = HelperConfigToolParams(treevec=treevec,
332  repcondargs=repcondargs,
333  filterparams=filterparams,
334  filterparam_inds=filterparam_inds)
335 
336  return [helper_params] # a list is one entry per FastReduction tree
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
vtune_athena.format
format
Definition: vtune_athena.py:14
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
python.scenario_simple.get_condition_args_from_chainpart
def get_condition_args_from_chainpart(cp)
Definition: scenario_simple.py:22
Base_Fragment.defaults
dictionary defaults
This includes now the top quark, the leptons and the bosons.
Definition: GeneratorFilters/share/common/Base_Fragment.py:79
python.make_treevec.make_treevec
def make_treevec(repcondargs)
Definition: make_treevec.py:3
str
Definition: BTagTrackIpAccessor.cxx:11
python.scenario_simple.scenario_simple
def scenario_simple(chain_parts)
Definition: scenario_simple.py:274
readCCLHist.float
float
Definition: readCCLHist.py:83
python.scenario_simple._cuts_from_momCuts
def _cuts_from_momCuts(momCuts)
Definition: scenario_simple.py:15