ATLAS Offline Software
MenuUtils.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
2 
3 __all__ = ['log', 'idgen', 'binstr', 'get_smk_psk_Name']
4 
5 from AthenaCommon.Logging import logging
6 log = logging.getLogger(__name__)
7 
8 
9 # unique id generator
10 class idgen(object):
11  from collections import defaultdict
12  a = defaultdict(int)
13  def get(self, kind):
14  self.a[kind] += 1
15  return str(self.a[kind])
16  def reset(self, kind=None):
17  if kind:
18  self.a[kind] = 0
19  else:
20  for kind in self.a:
21  self.a[kind] = 0
22 
23 idgen = idgen()
24 
25 
26 # turns an integer into a binary representation string of given width ( for the reverse just use int('10011',2) )
27 def binstr(value, width):
28  return ''.join([str( value >> i & 1 ) for i in range( width-1, -1, -1 ) ])
29 
30 def get_smk_psk_Name(menuName):
31  import re
32  smk_psk_Name = {}
33  if "mc_prescale" in menuName:
34  form = "(.*)_(.*)_mc_prescale"
35  m = re.match(form, menuName)
36  (smkName, pskName) = m.groups()
37  pskName = pskName+"_mc"
38  elif "prescale" in menuName:
39  #eg lumi1e31_simpleL1Calib_no_prescale
40  form = "(.*)_(.*)_prescale"
41  m = re.match(form,menuName)
42  (smkName, pskName) = m.groups()
43  else:
44  #eg lumi1e31 ps set name can be "default"
45  smkName = menuName
46  pskName = "default"
47  smk_psk_Name["smkName"] = str(smkName)
48  smk_psk_Name["pskName"] = str(smkName+"_"+pskName+"_prescale")
49 
50  return smk_psk_Name
51 
52 def getJetWeights(triggerPythonConfig, use_fj=False):
53  jw = []
54  jthr, fjthr = [], []
55  def thr2weights(thrs, factor=1.25):
56  n = len(thrs)
57  # need to skip any turned-off thresholds
58  use = []
59  for i in range(n):
60  if thrs[i]<1023:
61  use.append(1)
62  else:
63  use.append(0)
64  # allow for thresholds being out of order
65  index = order(thrs)
66  # compute weights
67  sum = 0
68  weights = [0]*n
69  for j in range(n):
70  w = 0
71  if use[index[j]]>0:
72  jnext = j + 1
73  while (jnext < n and use[index[jnext]]==0):
74  jnext = jnext + 1
75  if (jnext < n):
76  w = int( (thrs[index[j]]+thrs[index[jnext]]+1)/2.0) - sum
77  else:
78  w = int(thrs[index[j]]*factor - sum)
79  weights[index[j]]=w
80  sum += w
81  return weights
82 #
83  def order(thrs):
84  n = len(thrs)
85  thr1 = list(thrs)
86  thr2 = sorted(thrs)
87  index = []
88  for i in range(n):
89  val = thr2[i]
90  pos = thr1.index(val)
91  index.append(pos)
92  if (thr1.count(val)>1):
93  thr1[pos] = -thr1[pos]
94  return index
95 #
96  l1_thrs = triggerPythonConfig.Lvl1Thresholds()
97  jet_thresholds = l1_thrs.allThresholdsOf('JET')
98  fjet_thresholds = l1_thrs.allThresholdsOf('JF')
99  log.debug('N jet thresholds: %d (8 expected)', len(jet_thresholds))
100  log.debug('N fjet thresholds: %d (4 expected)', len(fjet_thresholds))
101  jthr = [1023]*8
102  fjthr = [1023]*4
103  jet_names, fjet_names = ['---']*8, ['---']*4
104  for j in jet_thresholds:
105  log.debug('jet threshold %s: %d', j.name, j.thresholdInGeV())
106  # jthr.append(j.thresholdInGeV())
107  jthr[j.mapping] = j.thresholdInGeV()
108  jet_names[j.mapping] = j.name
109  for j in fjet_thresholds:
110  tvalues = j.thresholdValues
111  priority = 0
112  threshold_value = 0
113  for tv in tvalues:
114  if tv.priority > priority:
115  threshold_value = tv.value
116  log.debug('fjet threshold %s: %d', j.name, threshold_value)
117  fjthr.append(threshold_value)
118  fjthr[j.mapping] = threshold_value
119  fjet_names[j.mapping] = j.name
120  #
121  s = ''
122  for j in jet_names:
123  s += '%s ' % j
124  log.debug('Jet thresholds: %s', s)
125  s = ''
126  for j in fjet_names:
127  s += '%s ' % j
128  log.debug('Fjet thresholds: %s', s)
129  if len(jthr) <= 8:
130  w = thr2weights(jthr)
131  jw = w
132  else:
133  jw = [0]*8
134  w = [0]*4
135  if use_fj:
136  if len(fjthr) <= 4:
137  w = thr2weights(fjthr)
138  jw.extend(w)
139  return jw
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
python.L1.Base.MenuUtils.idgen
Definition: MenuUtils.py:10
python.L1.Base.MenuUtils.idgen.a
a
Definition: MenuUtils.py:12
python.L1.Base.MenuUtils.get_smk_psk_Name
def get_smk_psk_Name(menuName)
Definition: MenuUtils.py:30
mc.order
order
Configure Herwig7.
Definition: mc.Herwig7_Dijet.py:12
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
python.L1.Base.MenuUtils.idgen.reset
def reset(self, kind=None)
Definition: MenuUtils.py:16
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
python.L1.Base.MenuUtils.getJetWeights
def getJetWeights(triggerPythonConfig, use_fj=False)
Definition: MenuUtils.py:52
python.L1.Base.MenuUtils.binstr
def binstr(value, width)
Definition: MenuUtils.py:27
pickleTool.object
object
Definition: pickleTool.py:30
str
Definition: BTagTrackIpAccessor.cxx:11
python.L1.Base.MenuUtils.idgen.get
def get(self, kind)
Definition: MenuUtils.py:13