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