ATLAS Offline Software
Functions | Variables
python.HLT.Jet.JetPresel Namespace Reference

Functions

def getPreselRecoDict (reco, roiftf=False)
 
def extractPreselection (fullChainDict)
 
def caloPreselJetHypoToolFromDict (flags, mainChainDict)
 
def roiPreselJetHypoToolFromDict (flags, mainChainDict)
 
def _preselJetHypoToolFromDict (flags, mainChainDict, doTaggingSel=False)
 

Variables

 log
 

Function Documentation

◆ _preselJetHypoToolFromDict()

def python.HLT.Jet.JetPresel._preselJetHypoToolFromDict (   flags,
  mainChainDict,
  doTaggingSel = False 
)
private

Definition at line 63 of file JetPresel.py.

63 def _preselJetHypoToolFromDict(flags, mainChainDict, doTaggingSel=False):
64 
65  preselChainDict = dict(mainChainDict)
66  preselChainDict['chainParts']=[]
67  trkpresel = extractPreselection(mainChainDict)
68 
69  # Get from the last chainPart in order to avoid to specify preselection for every leg
70  #TODO: add protection for cases where the preselection is not specified in the last chainPart
71  presel_matched = re.match(r'presel(?P<cut>\d?\d?(Z[\d\D]+)?[jacf](HT)?[\d\D]+)', trkpresel)
72  assert presel_matched is not None, "Impossible to match preselection pattern for self.trkpresel=\'{0}\'.".format(trkpresel)
73  presel_cut_str = presel_matched.groupdict()['cut'] #This is the cut string you want to parse. For example 'presel2j50XXj40'
74 
75  usingDIPZ = bool(re.match(r'.*Z', presel_cut_str)) # Need to determine if there's DIPZ leg anywhere to enforce central jets across all calopresel legs
76  if usingDIPZ:
77  findSel = re.finditer(r'(?P<nJet>\d?[jacf])(?P<ptcut>\d+)', presel_cut_str)
78  findAllJets=[]
79  findAllPts=[]
80  for match in findSel:
81  nJ = match.group("nJet")
82  findAllJets.append('1'+nJ if len(nJ)==1 else nJ)
83  findAllPts.append(int(match.group("ptcut")))
84  nAllJets = sum(int(i[:-1]) for i in findAllJets)
85  nCentralJets = sum(int(i[:-1]) if 'c' in i else 0 for i in findAllJets)
86  ptCut = min(int(i) for i in findAllPts)
87  assert nAllJets == nCentralJets, "Your preselection has a DIPZ part but not only central jets were required. This isn't currently supported. Please investigate."
88 
89  preselCommonJetParts = dict(JetChainParts_Default)
90 
91  for ip,p in enumerate(presel_cut_str.split('XX')):
92  hascalSel= bool(re.match(r'.*emf\w?\d+', p))
93  # This appears to be very much a hack... we should just have separate
94  # functions for with/without bjet or tau selections. -- Chris Pollard
95  if not doTaggingSel: # Removing b-jet and tau parts if b-jet presel is not requested
96  p = re.sub(r'(b|bg|bgtwo|gntau|uht1tau)\d\d', '', p)
97 
98  hasBjetSel = bool(re.match(r'.*(b|bg|bgtwo)\d\d', p))
99  hasTauSel = bool(re.match(r'.*(gntau|uht1tau)\d\d', p))
100  hasDIPZsel = bool(re.match(r'.*Z', p))
101 
102  if hasDIPZsel and not doTaggingSel: continue # Skipping calopresel step when DIPZ is run
103  if usingDIPZ and not hasDIPZsel and not hasBjetSel and doTaggingSel: continue # Skipping roiftf step only when running the calo selection leg (and if in the DIPZ scenario)
104 
105  assert not ( (hasBjetSel or hasDIPZsel) and not doTaggingSel), "Your jet preselection has a b-jet or DIPZ part but a calo-only preselection was requested instead. This should not be possible. Please investigate."
106 
107  bmatches = r'(?P<btagger>(b|bg|bgtwo))(?P<bwp>\d\d)' if hasBjetSel else ""
108  taumatches = r'(?P<tauid>(gntau|uht1tau))(?P<tauwp>\d\d)' if hasTauSel else ""
109 
110  pattern_to_test = r'(?P<mult>\d?\d?)(?P<region>[jacf])' # jet multiplicity and region
111  pattern_to_test += r'(?P<scenario>(HT)?)(?P<cut>\d+)' # scenario string # could be made more general
112  pattern_to_test += bmatches
113  pattern_to_test += taumatches
114  pattern_to_test += r'emf(?P<emfc>\d+)' if hascalSel else ''
115  if hasDIPZsel: pattern_to_test = r'(?P<scenario>Z)(?P<dipzwp>\d+)?(?P<prefilt>(MAXMULT\d+[jacf]?)?)'
116  matched = re.match(pattern_to_test, p)
117  assert matched is not None, "Impossible to extract preselection cut for \'{0}\' substring. Please investigate.".format(p)
118  cut_dict = matched.groupdict()
119  if hasDIPZsel: cut_dict['region'] = 'c'
120  if hasDIPZsel: cut_dict['cut'] = ptCut
121 
122 
123  # any missing keys k below need to have cut_dict[k] set to "".
124  testkeys = \
125  [ "mult" , "emfc" , "cut" , "cut_add" , "prefilt"
126  , "bwp" , "btagger" , "dipzwp"
127  , "tauwp"
128  ]
129 
130 
131  for k in testkeys:
132  cut_dict.setdefault(k, "")
133 
134  mult = cut_dict['mult']
135  region = cut_dict['region']
136  scenario = cut_dict['scenario']
137  cut = cut_dict['cut']
138  dipzwp = cut_dict['dipzwp']
139  emfc = cut_dict['emfc']
140  prefilters = []
141 
142  if mult=='': mult='1'
143  etarange = etaRangeAbbrev[region]
144  if scenario == "HT":
145  hyposcenario=f'HT{cut}XX{etarange}'
146  threshold='0'
147  chainPartName=f'j0_{hyposcenario}'
148  elif scenario == "Z":
149  hyposcenario=f'Z{dipzwp}XX{nCentralJets}c{cut}'
150  prefilt = cut_dict['prefilt']
151  if prefilt != '': prefilters.append(prefilt)
152  threshold='0'
153  chainPartName=f'j0_{hyposcenario}'
154  else:
155  hyposcenario='simple'
156  threshold=cut
157  chainPartName=f'{mult}j{cut}_{etarange}'
158 
159  if hasBjetSel:
160  btagger = cut_dict['btagger']
161  bwp = cut_dict['bwp']
162 
163  if btagger == 'bg':
164  btagger = 'gnone'
165  elif btagger =='bgtwo':
166  btagger = 'bgntwo'
167  elif btagger == 'b':
168  btagger = 'bdips'
169 
170 
171  tmpChainDict = dict(preselCommonJetParts)
172 
173  if hasTauSel:
174  tauid = cut_dict["tauid"]
175  tauwp = cut_dict["tauwp"]
176 
177  tmpChainDict[tauid] = tauwp+tauid
178 
179  tmpChainDict.update(
180  {'L1threshold': 'FSNOSEED',
181  'chainPartName': chainPartName,
182  'multiplicity': mult,
183  'threshold': threshold,
184  'etaRange':etarange,
185  'jvt':'',
186  'clrsel': emfc,
187  'bsel': f'{bwp}{btagger}' if hasBjetSel else "",
188  'chainPartIndex': ip,
189  'hypoScenario': hyposcenario,
190  'prefilters': prefilters,
191  }
192  )
193 
194  preselChainDict['chainParts'] += [tmpChainDict]
195 
196 
197  # We need to pad by the legs not in the preselection expression
198  # otherwise the ComboHypo does not find the corresponding
199  # legs in the DecisionObject and kills the event
200  jetlegs = sum([p['signature'] in ["Jet","Bjet"] for p in mainChainDict['chainParts']])
201  padding = jetlegs-len(preselChainDict['chainParts'])
202  if padding>0:
203  preselChainDict['chainParts'][-1]['chainPartName']+='_SHARED'
204  preselChainDict['chainParts'][-1]['tboundary']='SHARED'
205  dummyLegPart = dict(preselCommonJetParts)
206  dummyLegPart.update(
207  {'L1threshold': 'FSNOSEED',
208  'chainPartName': 'j0_SHARED',
209  'multiplicity': '1',
210  'threshold': '0',
211  'jvt':'',
212  'tboundary': 'SHARED',
213  }
214  )
215  preselChainDict['chainParts'] += [dict(dummyLegPart) for i in range(padding)]
216  # Last one is not permitted to be shared as there is nothing following
217  preselChainDict['chainParts'][-1]['chainPartName']='j0'
218  preselChainDict['chainParts'][-1]['tboundary']=''
219 
220  # Update certain keys to be consistent with the main dict
221  # Also set the chainPart indices correctly from the main dict
222  # These should be index-parallel now, as we only receive jet chainParts
223  for porig,ppresel in zip(mainChainDict['chainParts'],preselChainDict['chainParts']):
224  for key in ['chainPartIndex','signature']:
225  ppresel[key] = porig[key]
226 
227  assert(len(preselChainDict['chainParts'])==len(mainChainDict['chainParts']))
228  try:
229  return trigJetHypoToolFromDict(flags, preselChainDict)
230  except NoHypoToolCreated as nohypo:
231  raise nohypo # We only generate the hypo tool for the first jet leg
232  except Exception as e:
233  log.error("Failure with preselection for chain %s",mainChainDict['chainName'])
234  raise e

◆ caloPreselJetHypoToolFromDict()

def python.HLT.Jet.JetPresel.caloPreselJetHypoToolFromDict (   flags,
  mainChainDict 
)

Definition at line 55 of file JetPresel.py.

55 def caloPreselJetHypoToolFromDict(flags, mainChainDict):
56  return _preselJetHypoToolFromDict(flags, mainChainDict)
57 
58 

◆ extractPreselection()

def python.HLT.Jet.JetPresel.extractPreselection (   fullChainDict)

Definition at line 47 of file JetPresel.py.

47 def extractPreselection(fullChainDict):
48  jparts = jetChainParts(fullChainDict['chainParts'])
49  return jparts[-1]['trkpresel']
50 
51 # Calo jet preselection hypo tool generator
52 # Translate the preselection expression in the main jet chainDict into a temporary chainDict
53 # that is only seen by the standard hypo tool generator, and used to return a configured
54 # hypo tool for the preselection step

◆ getPreselRecoDict()

def python.HLT.Jet.JetPresel.getPreselRecoDict (   reco,
  roiftf = False 
)

Definition at line 17 of file JetPresel.py.

17 def getPreselRecoDict(reco,roiftf=False):
18 
19  # Define a fixed preselection dictionary for prototyping -- we may expand the options
20  preselRecoDict = {
21  'recoAlg':reco,
22  'constitType':'tc',
23  'clusterCalib':'em',
24  'constitMod':'',
25  'trkopt':'notrk',
26  'ionopt':'noion',
27  }
28  ''' #Here you can set custom calibrations for large-R preselections. If you set to LCW you'll get an issue though, as the trigger expects the *same* topocluster collection to be used in the preselection and in the PFlow stage with tracking. Therefore this would need to be adapted, but it might not be so easy...
29 
30  if preselRecoDict['recoAlg']=='a10': #Setting LC calibrations for large-R jets
31  preselRecoDict['clusterCalib']='lcw'
32  '''
33  preselRecoDict.update({
34  'jetCalib':getJetCalibDefaultString(preselRecoDict['recoAlg'],preselRecoDict['constitType'],preselRecoDict['clusterCalib'])
35  if preselRecoDict['recoAlg']=='a4' else 'nojcalib'
36  }) #Adding default calibration for corresponding chain
37 
38  # Overwriting tracking option to roiftf tracking
39  if roiftf: preselRecoDict['trkopt'] = 'roiftf'
40 
41  preselRecoDict['jetDefStr'] = jetRecoDictToString(preselRecoDict)
42 
43  return preselRecoDict
44 
45 # Find the preselection definition in the chainParts
46 # Simply taken from the last chainPart

◆ roiPreselJetHypoToolFromDict()

def python.HLT.Jet.JetPresel.roiPreselJetHypoToolFromDict (   flags,
  mainChainDict 
)

Definition at line 59 of file JetPresel.py.

59 def roiPreselJetHypoToolFromDict(flags, mainChainDict):
60  return _preselJetHypoToolFromDict(flags, mainChainDict,doTaggingSel=True)
61 
62 

Variable Documentation

◆ log

python.HLT.Jet.JetPresel.log

Definition at line 4 of file JetPresel.py.

vtune_athena.format
format
Definition: vtune_athena.py:14
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
python.HLT.Jet.JetPresel.getPreselRecoDict
def getPreselRecoDict(reco, roiftf=False)
Definition: JetPresel.py:17
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
python.HLT.Jet.JetRecoCommon.getJetCalibDefaultString
def getJetCalibDefaultString(recoAlg, constitType, trkopt)
Definition: JetRecoCommon.py:264
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:194
python.HLT.Jet.JetRecoCommon.jetRecoDictToString
def jetRecoDictToString(jetRecoDict)
— General reco dict handling —
Definition: JetRecoCommon.py:45
python.HLT.Jet.JetPresel._preselJetHypoToolFromDict
def _preselJetHypoToolFromDict(flags, mainChainDict, doTaggingSel=False)
Definition: JetPresel.py:63
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
python.HLT.Jet.JetPresel.roiPreselJetHypoToolFromDict
def roiPreselJetHypoToolFromDict(flags, mainChainDict)
Definition: JetPresel.py:59
python.HLT.Jet.JetRecoCommon.jetChainParts
def jetChainParts(chainParts)
— Extracting jet chain parts —
Definition: JetRecoCommon.py:34
python.TrigJetHypoToolConfig.trigJetHypoToolFromDict
def trigJetHypoToolFromDict(flags, chain_dict)
Definition: TrigJetHypoToolConfig.py:20
python.HLT.Jet.JetPresel.caloPreselJetHypoToolFromDict
def caloPreselJetHypoToolFromDict(flags, mainChainDict)
Definition: JetPresel.py:55
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60
python.HLT.Jet.JetPresel.extractPreselection
def extractPreselection(fullChainDict)
Definition: JetPresel.py:47