ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Reconstruction
RecoAlgs
IsolationAlgs
python
DerivationTrackIsoConfig.py
Go to the documentation of this file.
1
# Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
2
3
""" Instantiate more custom track isolation in derivation
4
"""
5
6
from
AthenaCommon.Logging
import
logging
7
from
AthenaConfiguration.ComponentAccumulator
import
ComponentAccumulator
8
from
AthenaConfiguration.ComponentFactory
import
CompFactory
9
10
def
DerivationTrackIsoCfg
(flags,**jwarg):
11
12
mlog = logging.getLogger(
'DerivationTrackIsoConfig'
)
13
mlog.info(
'Starting track isolation for derivation'
)
14
15
acc = ComponentAccumulator()
16
17
from
xAODPrimitives.xAODIso
import
xAODIso
as
isoPar
18
# dR in decreasing order
19
ptcone_list = [ [ isoPar.ptcone40, isoPar.ptcone30, isoPar.ptcone20 ] ]
20
trkcor_list = [ [ isoPar.coreTrackPtr ] ]
21
22
if
'object_types'
not
in
jwarg:
23
object_types = (
"Electrons"
,
"Photons"
,
"Muons"
)
24
else
:
25
object_types = jwarg[
'object_types'
]
26
27
if
'WP'
not
in
jwarg:
28
WP =
'Nonprompt_All_MaxWeight'
29
else
:
30
WP = jwarg[
'WP'
]
31
# TrackIsolationTool need a specific track-vertex association tool
32
# if WP is not Nonprompt_All_MaxWeight
33
from
TrackVertexAssociationTool.TrackVertexAssociationToolConfig
import
isoTTVAToolCfg
34
ttvaCA = acc.popToolsAndMerge(
35
isoTTVAToolCfg(flags, WorkingPoint = WP))
36
37
postfix =
''
38
if
'postfix'
in
jwarg:
39
postfix = jwarg[
'postfix'
]
40
41
if
'ptCuts'
not
in
jwarg:
42
ptCuts = (500, 1000)
43
else
:
44
ptCuts = jwarg[
'ptCuts'
]
45
46
do_egamma = any(x
in
object_types
for
x
in
(
"Electrons"
,
"Photons"
))
47
48
mlog.info(
'will isolate objects '
+
" "
.join(object_types)+
' with TTVA WP = '
+WP)
49
50
for
track_pt
in
ptCuts:
51
for
loose_cone
in
(
True
,
False
):
52
if
loose_cone
and
not
do_egamma:
53
# Loose cone isolation variables only for electrons and photons
54
continue
55
56
cone_str =
"LooseCone"
if
loose_cone
else
""
57
58
# The custom variable suffix
59
name = f
"{WP}TTVA{cone_str}_pt{track_pt}"
60
61
# Build up extra IsolationBuilder kwargs
62
kwargs = {}
63
if
"Electrons"
in
object_types:
64
kwargs[
"ElIsoTypes"
] = ptcone_list
65
kwargs[
"ElCorTypes"
] = trkcor_list
66
kwargs[
"ElCorTypesExtra"
] = [[]]
67
kwargs[
"CustomConfigurationNameEl"
] = name
68
if
"Electrons"
in
object_types
and
"LRT"
in
postfix:
69
kwargs[
"ElectronCollectionContainerName"
] =
"LRTElectrons"
70
if
"Photons"
in
object_types:
71
kwargs[
"PhIsoTypes"
] = ptcone_list
72
kwargs[
"PhCorTypes"
] = trkcor_list
73
kwargs[
"PhCorTypesExtra"
] = [[]]
74
kwargs[
"CustomConfigurationNamePh"
] = name
75
if
"Muons"
in
object_types
and
not
loose_cone:
76
kwargs[
"MuIsoTypes"
] = ptcone_list
77
kwargs[
"MuCorTypes"
] = trkcor_list
78
kwargs[
"MuCorTypesExtra"
] = [[]]
79
kwargs[
"CustomConfigurationNameMu"
] = name
80
if
"Muons"
in
object_types
and
not
loose_cone
and
"LRT"
in
postfix:
81
kwargs[
"MuonCollectionContainerName"
] =
"MuonsLRT"
82
83
84
toolkwargs = {}
85
# the TTVA tool is not the default choice
86
if
'WP'
in
jwarg:
87
toolkwargs[
'TTVATool'
] = ttvaCA
88
# and a track selection tool
89
90
from
InDetTrackSelectionTool.InDetTrackSelectionToolConfig
import
(
91
isoTrackSelectionToolCfg )
92
toolkwargs[
'TrackSelectionTool'
] = acc.popToolsAndMerge(
93
isoTrackSelectionToolCfg(flags, minPt = track_pt))
94
95
if
loose_cone:
96
toolkwargs[
'CoreTrackEtaRange'
] = 0.01
97
98
from
IsolationAlgs.IsoToolsConfig
import
TrackIsolationToolCfg
99
kwargs[
'TrackIsolationTool'
] = acc.popToolsAndMerge(
100
TrackIsolationToolCfg(flags,**toolkwargs))
101
102
# The algorithm
103
kwargs[
'name'
] = f
"IsolationBuilder{WP}{cone_str}{track_pt}{postfix}"
104
acc.addEventAlgo(CompFactory.IsolationBuilder(**kwargs))
105
106
return
acc
107
108
def
iso_vars
(WP = "Nonprompt_All_MaxWeight"):
109
# Get the list of isolation variables calculated by these functions
110
iso_vars = []
111
for
track_pt
in
500, 1000:
112
for
cone_str
in
""
,
"LooseCone"
:
113
name = f
"{WP}TTVA{cone_str}_pt{track_pt}"
114
iso_vars += [
"ptconeCorrBitset_"
+name,
115
"ptconecoreTrackPtrCorrection_"
+name ]
116
for
cone_size
in
20, 30, 40:
117
for
var_str
in
""
,
"var"
:
118
iso_vars.append(f
"pt{var_str}cone{cone_size}_{name}"
)
119
return
iso_vars
120
121
if
__name__ ==
"__main__"
:
122
from
AthenaConfiguration.AllConfigFlags
import
initConfigFlags
123
from
AthenaConfiguration.ComponentAccumulator
import
printProperties
124
from
AthenaConfiguration.TestDefaults
import
defaultTestFiles
125
from
AthenaConfiguration.MainServicesConfig
import
MainServicesCfg
126
flags = initConfigFlags()
127
flags.Input.Files = defaultTestFiles.RDO_RUN2
128
flags.Output.doWriteESD =
True
# To test the ESD parts
129
flags.Output.doWriteAOD =
True
# To test the AOD parts
130
flags.lock()
131
132
mlog = logging.getLogger(
"derivationTrackIsolationConfigTest"
)
133
mlog.info(
"Configuring derivation track isolation: "
)
134
135
acc = MainServicesCfg(flags)
136
acc.merge(
DerivationTrackIsoCfg
(flags))
137
# print config of some of the algs :
138
for
par
in
(
'500'
,
'1000'
,
'LooseCone1000'
):
139
print
(
'------ Config for '
,par,
' ----------'
)
140
name =
"IsolationBuilderNonprompt_All_MaxWeight"
+par
141
printProperties(mlog,
142
acc.getEventAlgo(name),
143
nestLevel=1,
144
printDefaults=
True
)
print
void print(char *figname, TCanvas *c1)
Definition
TRTCalib_StrawStatusPlots.cxx:26
DerivationTrackIsoConfig.DerivationTrackIsoCfg
DerivationTrackIsoCfg(flags, **jwarg)
Definition
DerivationTrackIsoConfig.py:10
DerivationTrackIsoConfig.iso_vars
iso_vars(WP="Nonprompt_All_MaxWeight")
Definition
DerivationTrackIsoConfig.py:108
Generated on
for ATLAS Offline Software by
1.17.0