ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
JetTagging
FlavorTagDiscriminants
python
FlavorTagDLNNConfig.py
Go to the documentation of this file.
1
# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2
3
from
AthenaConfiguration.ComponentAccumulator
import
ComponentAccumulator
4
from
AthenaConfiguration.ComponentFactory
import
CompFactory
5
6
from
FlavorTagInference.FlavorTagNNConfig
import
getStaticTrackVars
7
8
def
DL2ToolCfg
(flags, NNFile, **options):
9
acc = ComponentAccumulator()
10
11
# default is "STANDARD" in case of a setup of the standard b-taggers. "NEGATIVE_IP_ONLY" [and "FLIP_SIGN"] if want to set up the flip taggers
12
# naming convention, see here: https://gitlab.cern.ch/atlas/athena/-/blob/master/PhysicsAnalysis/JetTagging/FlavorTagDiscriminants/Root/FlipTagEnums.cxx
13
14
# this map lets us change the names of EDM inputs with respect to
15
# the values we store in the saved NN
16
remap = {}
17
# This is a hack to accomodate the older b-tagging training with
18
# old names for variables. We should be able to remove it when we
19
# move over to the 2020 / 2021 retraining.
20
if
'201903'
in
NNFile
and
'dl1'
in
NNFile:
21
for
aggragate
in
[
'minimum'
,
'maximum'
,
'average'
]:
22
remap[f
'{aggragate}TrackRelativeEta'
] = (
23
f
'JetFitterSecondaryVertex_{aggragate}AllJetTrackRelativeEta'
)
24
25
# Similar hack for 21.9-based upgrade training
26
if
'20221008'
in
NNFile
and
'dips'
in
NNFile:
27
for
aggragate
in
[
'InnermostPixelLayer'
,
'NextToInnermostPixelLayer'
,
28
'InnermostPixelLayerShared'
,
29
'InnermostPixelLayerSplit'
]:
30
remap[f
'numberOf{aggragate}Hits'
] = (
31
f
'numberOf{aggragate}Hits21p9'
)
32
33
mkey =
'variableRemapping'
34
options[mkey] = remap | options.get(mkey,{})
35
36
dl2 = CompFactory.FlavorTagDiscriminants.DL2Tool(
37
name=
'decorator'
,
38
nnFile=NNFile,
39
**options)
40
41
acc.setPrivateTools(dl2)
42
43
return
acc
44
45
def
getUndeclaredBtagVars
(BTaggingCollection):
46
#
47
# In the case of b-tagging we should really declare these
48
# variables using WriteDecorHandle, but this is very much a work
49
# in progress.
50
#
51
# We should revisit this once in a while, last time this was
52
# checked was:
53
#
54
# - 20210602
55
#
56
undeclared_btag = [
57
'JetFitter_N2Tpair'
,
58
'JetFitter_energyFraction'
,
59
'JetFitter_mass'
,
60
'JetFitter_nSingleTracks'
,
61
'JetFitter_nTracksAtVtx'
,
62
'JetFitter_nVTX'
,
63
'JetFitter_significance3d'
,
64
'SV1_L3d'
,
65
'SV1_Lxy'
,
66
'SV1_N2Tpair'
,
67
'SV1_NGTinSvx'
,
68
'SV1_deltaR'
,
69
'SV1_efracsvx'
,
70
'SV1_masssvx'
,
71
'SV1_significance3d'
,
72
'BTagTrackToJetAssociator'
,
73
]
74
return
[f
'{BTaggingCollection}.{x}'
for
x
in
undeclared_btag]
75
76
def
FlavorTagDLNNCfg
(
77
flags,
78
BTaggingCollection,
79
TrackCollection,
80
NNFile,
81
JetCollection=None,
82
FlipConfig="STANDARD",
83
variableRemapping={},
84
):
85
86
alg = CompFactory.FlavorTagInference.BTagDecoratorAlg
87
88
acc = ComponentAccumulator()
89
90
NNFile_extension = NNFile.split(
"."
)[-1]
91
nn_opts = dict(
92
NNFile=NNFile,
93
flipTagConfig=FlipConfig,
94
variableRemapping=variableRemapping)
95
if
NNFile_extension ==
"json"
:
96
nn_name = NNFile.replace(
"/"
,
"_"
).
replace
(
"_network.json"
,
""
)
97
decorator = acc.popToolsAndMerge(
DL2ToolCfg
(flags, **nn_opts))
98
else
:
99
raise
ValueError(
"FlavorTagDLNNCfg: Wrong NNFile extension. Please check the NNFile argument"
)
100
101
name =
'_'
.join([
'FtagNN'
, nn_name.lower(), BTaggingCollection])
102
103
# Ensure different names for standard and flip taggers
104
if
FlipConfig !=
"STANDARD"
:
105
name = name + FlipConfig
106
107
veto_list =
getUndeclaredBtagVars
(BTaggingCollection)
108
veto_list += getStaticTrackVars(TrackCollection)
109
110
decorAlg = alg(
111
name=name,
112
container=BTaggingCollection,
113
constituentContainer=TrackCollection,
114
decorator=decorator,
115
undeclaredReadDecorKeys=veto_list,
116
)
117
118
# -- create the association algorithm
119
acc.addEventAlgo(decorAlg)
120
121
return
acc
122
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition
hcg.cxx:312
python.FlavorTagDLNNConfig.getUndeclaredBtagVars
getUndeclaredBtagVars(BTaggingCollection)
Definition
FlavorTagDLNNConfig.py:45
python.FlavorTagDLNNConfig.FlavorTagDLNNCfg
FlavorTagDLNNCfg(flags, BTaggingCollection, TrackCollection, NNFile, JetCollection=None, FlipConfig="STANDARD", variableRemapping={})
Definition
FlavorTagDLNNConfig.py:84
python.FlavorTagDLNNConfig.DL2ToolCfg
DL2ToolCfg(flags, NNFile, **options)
Definition
FlavorTagDLNNConfig.py:8
Generated on
for ATLAS Offline Software by
1.17.0