3 from AthenaCommon.Logging
import logging
4 log = logging.getLogger(__name__)
8 from .JetRecoCommon
import getJetCalibDefaultString, jetChainParts, etaRangeAbbrev, jetRecoDictToString
9 from ..Menu.SignatureDicts
import JetChainParts_Default
10 from TriggerMenuMT.HLT.Config.ControlFlow.HLTCFTools
import NoHypoToolCreated
13 from TrigHLTJetHypo.TrigJetHypoToolConfig
import trigJetHypoToolFromDict
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...
30 if preselRecoDict['recoAlg']=='a10': #Setting LC calibrations for large-R jets
31 preselRecoDict['clusterCalib']='lcw'
33 preselRecoDict.update({
34 'jetCalib':
getJetCalibDefaultString(preselRecoDict[
'recoAlg'],preselRecoDict[
'constitType'],preselRecoDict[
'clusterCalib'])
35 if preselRecoDict[
'recoAlg']==
'a4' else 'nojcalib'
39 if roiftf: preselRecoDict[
'trkopt'] =
'roiftf'
49 return jparts[-1][
'trkpresel']
65 preselChainDict = dict(mainChainDict)
66 preselChainDict[
'chainParts']=[]
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']
75 usingDIPZ =
bool(re.match(
r'.*Z', presel_cut_str))
77 findSel = re.finditer(
r'(?P<nJet>\d?[jacf])(?P<ptcut>\d+)', presel_cut_str)
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."
89 preselCommonJetParts = dict(JetChainParts_Default)
91 for ip,p
in enumerate(presel_cut_str.split(
'XX')):
92 hascalSel=
bool(re.match(
r'.*emf\w?\d+', p))
96 p = re.sub(
r'(b|bg|bgtwo|gntau|uht1tau)\d\d',
'', p)
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))
102 if hasDIPZsel
and not doTaggingSel:
continue
103 if usingDIPZ
and not hasDIPZsel
and not hasBjetSel
and doTaggingSel:
continue
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."
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 ""
110 pattern_to_test =
r'(?P<mult>\d?\d?)(?P<region>[jacf])'
111 pattern_to_test +=
r'(?P<scenario>(HT)?)(?P<cut>\d+)'
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
125 [
"mult" ,
"emfc" ,
"cut" ,
"cut_add" ,
"prefilt"
126 ,
"bwp" ,
"btagger" ,
"dipzwp"
132 cut_dict.setdefault(k,
"")
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']
142 if mult==
'': mult=
'1'
143 etarange = etaRangeAbbrev[region]
145 hyposcenario=f
'HT{cut}XX{etarange}'
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)
153 chainPartName=f
'j0_{hyposcenario}'
155 hyposcenario=
'simple'
157 chainPartName=f
'{mult}j{cut}_{etarange}'
160 btagger = cut_dict[
'btagger']
161 bwp = cut_dict[
'bwp']
165 elif btagger ==
'bgtwo':
171 tmpChainDict = dict(preselCommonJetParts)
174 tauid = cut_dict[
"tauid"]
175 tauwp = cut_dict[
"tauwp"]
177 tmpChainDict[tauid] = tauwp+tauid
180 {
'L1threshold':
'FSNOSEED',
181 'chainPartName': chainPartName,
182 'multiplicity': mult,
183 'threshold': threshold,
187 'bsel': f
'{bwp}{btagger}' if hasBjetSel
else "",
188 'chainPartIndex': ip,
189 'hypoScenario': hyposcenario,
190 'prefilters': prefilters,
194 preselChainDict[
'chainParts'] += [tmpChainDict]
200 jetlegs =
sum([p[
'signature']
in [
"Jet",
"Bjet"]
for p
in mainChainDict[
'chainParts']])
201 padding = jetlegs-len(preselChainDict[
'chainParts'])
203 preselChainDict[
'chainParts'][-1][
'chainPartName']+=
'_SHARED'
204 preselChainDict[
'chainParts'][-1][
'tboundary']=
'SHARED'
205 dummyLegPart = dict(preselCommonJetParts)
207 {
'L1threshold':
'FSNOSEED',
208 'chainPartName':
'j0_SHARED',
212 'tboundary':
'SHARED',
215 preselChainDict[
'chainParts'] += [dict(dummyLegPart)
for i
in range(padding)]
217 preselChainDict[
'chainParts'][-1][
'chainPartName']=
'j0'
218 preselChainDict[
'chainParts'][-1][
'tboundary']=
''
223 for porig,ppresel
in zip(mainChainDict[
'chainParts'],preselChainDict[
'chainParts']):
224 for key
in [
'chainPartIndex',
'signature']:
225 ppresel[key] = porig[key]
227 assert(len(preselChainDict[
'chainParts'])==len(mainChainDict[
'chainParts']))
230 except NoHypoToolCreated
as nohypo:
232 except Exception
as e:
233 log.error(
"Failure with preselection for chain %s",mainChainDict[
'chainName'])