ATLAS Offline Software
TrigBjetBtagHypoTool.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
3 import re
4 from TrigBjetHypo.TrigBjetMonitoringConfig import TrigBjetBtagHypoToolMonitoring
5 from AthenaConfiguration.ComponentFactory import CompFactory
6 
7 from AthenaCommon.Logging import logging
8 log = logging.getLogger('TrigBjetBtagHypoTool')
9 
10 
11 
12 # DL1r (Place Holder while we wait for WPs to be defined)
13 # Values taken from https://twiki.cern.ch/twiki/bin/view/AtlasProtected/BTaggingBenchmarksRelease21#DL1rnn_tagger
14 bTaggingWP = \
15  { "dl1d40" : 6.957
16  , "dl1d45" : 6.344
17  , "dl1d50" : 5.730
18  , "dl1d55" : 5.121
19  , "dl1d60" : 4.512
20  , "dl1d65" : 3.882
21  , "dl1d70" : 3.251
22  , "dl1d72" : 2.964
23  , "dl1d75" : 2.489
24  , "dl1d77" : 2.157
25  , "dl1d80" : 1.626
26  , "dl1d82" : 1.254
27  , "dl1d85" : 0.634
28  , "dl1d90" : -0.465
29  , "dl1d95" : -1.616
30 
31  , "gn140": 7.370
32  , "gn145": 6.748
33  , "gn150": 6.094
34  , "gn155": 5.425
35  , "gn160": 4.757
36  , "gn165": 4.095
37  , "gn170": 3.423
38  , "gn172": 3.141
39  , "gn175": 2.703
40  , "gn177": 2.392
41  , "gn180": 1.884
42  , "gn182": 1.510
43  , "gn185": 0.881
44  , "gn190": -0.351
45  , "gn195": -1.794
46 
47  , "gn240": 7.718
48  , "gn245": 7.017
49  , "gn250": 6.241
50  , "gn255": 5.440
51  , "gn260": 4.640
52  , "gn265": 3.889
53  , "gn270": 3.163
54  , "gn272": 2.863
55  , "gn275": 2.412
56  , "gn277": 2.087
57  , "gn280": 1.5866
58  , "gn282": 1.186
59  , "gn285": 0.5355
60  , "gn290": -0.741
61  , "gn295": -2.242
62 
63 
64 
65  , "offperf" : -999
66  }
67 
68 bbTaggingWP = \
69  { "gn182bb96": -1.201
70  , "gn177bb96": -1.201
71  , "gn175bb90": -0.590
72  }
73 
74 
75 
76 def TrigBjetBtagHypoToolFromDict( flags, chainDict ):
77 
78  chainPart = chainDict['chainParts'][0]
79  conf_dict = { 'threshold' : chainPart['threshold'],
80  'multiplicity' : '1' if len(chainPart['multiplicity']) == 0 else chainPart['multiplicity'],
81  'bTag' : chainPart['bTag'][1:],
82  'bConfig' : 'EF' if len(chainPart['bConfig']) == 0 else chainPart['bConfig'][0],
83  'minEta' : chainPart['etaRange'].split('eta')[0],
84  'maxEta' : chainPart['etaRange'].split('eta')[1]}
85  name = chainDict['chainName']
86  # TODO the chain dict can be probably passed over down the line here
87 
88  MonTool = None
89  nolegname = re.sub("(^leg.*?_)", "", name)
90  if 'bJetMon:online' in chainDict['monGroups']:
91  MonTool = TrigBjetBtagHypoToolMonitoring(flags, f'TrigBjetOnlineMonitoring/{nolegname}')
92  tool = getBjetBtagHypoConfiguration( name,conf_dict, MonTool )
93 
94  return tool
95 
96 
97 
98 
99 def decodeThreshold( threshold_btag ):
100  """ decodes the b-tagging thresholds """
101 
102  log.debug("decoded b-jet threshold: b%s", threshold_btag)
103 
104  tagger = "offperf" if threshold_btag == "offperf" else re.findall("(.*)[0-9]{2}",threshold_btag)[0]
105 
106  allowedTaggers = ["offperf", "dl1d", "gn182bb", "gn177bb", "gn175bb", "gn1","gn2"]
107  if tagger not in allowedTaggers:
108  log.debug("tagger = %s not amidst allowed taggers ",threshold_btag)
109  raise RuntimeError("Can't recognize tagger during TrigBjetHypoTool configuration. Tagger = "+threshold_btag)
110 
111  btagger = "GN120220813" # default tagger for boffperf chain monitoring
112  bbtagger = "dl1dbb20230314"
113 
114  bbcut = bbTaggingWP.get(threshold_btag)
115 
116  # remove the bb part to get the b-only cut
117  threshold_btag = threshold_btag.split("bb", maxsplit=1)[0]
118 
119  # for chains wanting to use DL1d
120  if "dl1d" in threshold_btag:
121  btagger = "DL1d20211216"
122 
123  # for chains wanting to use GN1
124  if "gn1" in threshold_btag:
125  btagger = "GN120220813"
126 
127  if "gn2" in threshold_btag:
128  btagger = "GN220240122"
129  bcut = bTaggingWP[threshold_btag]
130 
131  return [btagger, bcut] , [bbtagger, bbcut]
132 
133 
134 
135 def getBjetBtagHypoConfiguration( name,conf_dict, MonTool ):
136 
137  tool = CompFactory.TrigBjetBtagHypoTool( name )
138  if MonTool is not None:
139  tool.MonTool = MonTool
140 
141  [btagger, bcut] , [bbtagger, bbcut] = decodeThreshold( conf_dict['bTag'] )
142  tool.monitoredFloats = {f'{btagger}_p{x}':f'btag_p{x}' for x in 'cub'}
143 
144  if conf_dict['bTag'] == "offperf":
145  # we shoudln't be worried about rates blowing up due to bad
146  # b-tagging in the boffperf chains
147  tool.vetoBadBeamspot = False
148  return tool
149 
150  btagTool = CompFactory.BJetThreeValueCheck(
151  f'{name}_btag',
152  b=f'{btagger}_pb',
153  c=f'{btagger}_pc',
154  u=f'{btagger}_pu',
155  cFraction=0.018,
156  threshold=bcut)
157  if MonTool is not None:
158  btagTool.MonTool = MonTool
159  tool.checks.append(btagTool)
160 
161  if bbcut is not None:
162  bbTool = CompFactory.BJetTwoValueCheck(
163  f'{name}_bbtag',
164  numerator=f'{bbtagger}_pb',
165  denominator=f'{bbtagger}_pbb',
166  threshold=bbcut)
167  if MonTool is not None:
168  bbTool.MonTool = MonTool
169  tool.checks.append(bbTool)
170  tool.monitoredFloats.update({
171  f'{bbtagger}_p{x}':f'bbtag_p{x}' for x in ['b','bb']})
172 
173  return tool
TrigBjetBtagHypoTool.TrigBjetBtagHypoToolFromDict
def TrigBjetBtagHypoToolFromDict(flags, chainDict)
Definition: TrigBjetBtagHypoTool.py:76
TrigBjetMonitoringConfig.TrigBjetBtagHypoToolMonitoring
def TrigBjetBtagHypoToolMonitoring(flags, histPath)
Definition: TrigBjetMonitoringConfig.py:4
TrigBjetBtagHypoTool.decodeThreshold
def decodeThreshold(threshold_btag)
Definition: TrigBjetBtagHypoTool.py:99
TrigBjetBtagHypoTool.getBjetBtagHypoConfiguration
def getBjetBtagHypoConfiguration(name, conf_dict, MonTool)
Definition: TrigBjetBtagHypoTool.py:135
Trk::split
@ split
Definition: LayerMaterialProperties.h:38