ATLAS Offline Software
Loading...
Searching...
No Matches
TrackCaloClusterConfig.py
Go to the documentation of this file.
1# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2from AthenaCommon import Logging
3from AthenaConfiguration.ComponentFactory import CompFactory
4from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
5ufolog = Logging.logging.getLogger('TCCorUFO')
6
7#from AthenaConfiguration import UnifyProperties
8
9
10
11def _unifyPV0onlyTrkClustAssoc( vxContName1, vxContName2):
12 if vxContName2 == vxContName1 : return vxContName1
13 if "" in [vxContName1, vxContName2] : return vxContName1 or vxContName2
14 raise Exception(" Error : incompatible VertexContainerName of 2 instance of TrackParticleClusterAssociationAlg : '{}' and '{}'".format(vxContName1, vxContName2))
15
16
17# we make sure a unique TrackParticleAssociationAlg is well behaved when configured for both TCC and UFOInfo
18# in the same job. The function below will be used in the de-duplication and implies all tracks (not only PV0)
19# have associated clusters only if TCC is scheduled.
20# !! Doesn't seem to work yet ??!!
21#UnifyProperties.setUnificationFunction( "TrackParticleClusterAssociationAlg.VertexContainerName", _unifyPV0onlyTrkClustAssoc)
22
23
24
25
26
27
28
29def getDecorationKeyFunc(trackParticleName, assocPostfix):
30 """Simple helper returning a function to build decoration keys """
31 return lambda d : trackParticleName+'.'+d+assocPostfix
32
33def setupTrackCaloAssoc(flags, caloClusterName="CaloCalTopoClusters",detectorEtaName="default",trackParticleName="InDetTrackParticles", assocPostfix = "TCC", onlyPV0Tracks=False):
34 """ Schedule a TrackParticleClusterAssociationAlg in the top sequence, taking as input clusters and tracks defined
35 by the keys caloClusterName and trackParticleName.
36
37 onlyPV0Tracks : calculate associated clusters only for PV0 tracks. Avoids unnecessary calculation (used in the UFO case).
38 (IMPORTANT CaloExtensionBuilderAlg does extrapolate all tracks : if too much time consuming, it needs a new option to mask non-PV0 tracks)
39 """
40
41
42
43 components = ComponentAccumulator()
44
45 from TrackToCalo.CaloExtensionBuilderAlgCfg import CaloExtensionBuilderAlgCfg
46 caloExtAlg =CaloExtensionBuilderAlgCfg( flags )
47 caloExtAlg.TrkPartContainerName = trackParticleName
48
49 components.merge(caloExtAlg) #since its a stack of algorithms
50
51 from TrackVertexAssociationTool.TrackVertexAssociationToolConfig import TTVAToolCfg
52 TrackVertexAssoTool = components.popToolsAndMerge(
53 TTVAToolCfg(flags, "tvaTool", WorkingPoint="Nonprompt_All_MaxWeight"))
54
55 trackParticleClusterAssociation = CompFactory.TrackParticleClusterAssociationAlg(
56 "TrackParticleClusterAssociationAlg"+assocPostfix,
57 #ParticleCaloClusterAssociationTool = particleCaloClusterAssociation,
58 TrackParticleContainerName = trackParticleName,
59 PtCut = 400.,
60 CaloExtensionName = (caloExtAlg.getEventAlgos()[0]).ParticleCache, # ParticleCache is a defunct attribute
61 CaloClusterLocation = caloClusterName,
62 DetectorEtaName = detectorEtaName if detectorEtaName.lower() != "default" else ("DetectorEta" if "Origin" in caloClusterName else ""),
63 TrackVertexAssoTool=TrackVertexAssoTool, # will associate trks from PV0 only
64 VertexContainerName = "PrimaryVertices" if onlyPV0Tracks else "",
65 #VertexContainerName = "PrimaryVertices" if onlyPV0Tracks else "TTVA_AMVFVertices",
66 AssociatedClusterDecorKey = "AssoClusters"+assocPostfix,
67 UseCovariance = flags.UFO.UseCov,
68 DeltaR = flags.UFO.dR,
69# OutputLevel=2
70 )
71
72
73 components.addEventAlgo( trackParticleClusterAssociation )
74 return components
75
76
77
78def runTCCReconstruction(flags, caloClusterName="CaloCalTopoClusters", detectorEtaName = "default", trackParticleName="InDetTrackParticles",
79 assocPostfix="TCC", doCombined=False, doCharged=False, doNeutral=True, outputTCCName="TrackCaloClusters"):
80 """
81 Create a TrackCaloCluster collection from clusters and tracks (caloClusterName and trackParticleName).
82 Depending on options, the collection contains combined, neutral and/or charged TCC.
83 This functions schedules 2 TCC specific algs :
84 * a TrackCaloClusterInfoAlg to build the TrackCaloClusterInfo object
85 * a TrackCaloClusterAlg to build the TCC
86 """
87
88 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
89
90 decorKey = getDecorationKeyFunc(trackParticleName,assocPostfix)
91
92 components = ComponentAccumulator()
93
94 components.merge(
95 setupTrackCaloAssoc(flags, caloClusterName, detectorEtaName, trackParticleName, assocPostfix, onlyPV0Tracks=False)
96 )
97
98
100 tccInfoAlg = CompFactory.TrackCaloClusterInfoAlg(
101 "TCCInfoAlg",
102 TCCInfoName = "TCCInfo",
103 InputTracks = trackParticleName,
104 InputClusters = caloClusterName,
105 VertexContainer = "PrimaryVertices",
106 AssoClustersDecor = decorKey("AssoClusters"),
107 )
108
109 components.addEventAlgo( tccInfoAlg)
110
111
114 tccTools = []
115
116 from TrackVertexAssociationTool.TrackVertexAssociationToolConfig import TTVAToolCfg
117 commonArgs=dict(
118 TrackVertexAssoTool = components.popToolsAndMerge(
119 TTVAToolCfg(flags,"tvaTool",WorkingPoint="Nonprompt_All_MaxWeight")),
120 AssoClustersDecor=decorKey("AssoClusters"),
121 )
122
123 if doCombined:
124 tccCombined = CompFactory.TCCCombinedTool("TCCcombined", **commonArgs)
125 tccTools.append(tccCombined)
126 if doCharged:
127 tccCharged = CompFactory.TCCChargedTool("TCCCharged", **commonArgs )
128 tccTools.append(tccCharged)
129 if doNeutral:
130 tccNeutral = CompFactory.TCCNeutralTool("TCCNeutral", **commonArgs )
131 tccTools.append(tccNeutral)
132
133 tccAlg = CompFactory.TrackCaloClusterAlg(name = "TrackCaloClusterAlg",
134 OutputTCCName = outputTCCName,
135 TCCInfo = "TCCInfo",
136 TCCTools = tccTools,
137 )
138
139 components.addEventAlgo(tccAlg)
140
141 return components
142
143
144def runUFOReconstruction(flags, constits, caloClusterName="CaloCalTopoClusters", detectorEtaName = "default", assocPostfix="UFO", inputFEcontainerkey=""):
145
146 """Create a UFO collection from PFlow and tracks (PFO retrieved from PFOPrefix and tracks directly from trackParticleName).
147 This functions schedules 2 UFO specific algs :
148 * a TrackCaloClusterInfoUFOAlg to build the TrackCaloClusterInfo object
149 * a TrackCaloClusterAlg to build the UFO
150 """
151 from JetRecConfig.JetDefinition import JetDefinition
152 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
153 components=ComponentAccumulator()
154
155 if isinstance(constits, JetDefinition):
156 jdef = constits
157 constits = jdef.inputdef
158 trackParticleName = jdef._contextDic['Tracks'] # defaults to "InDetTrackParticles"
159 else:
160 trackParticleName = "InDetTrackParticles"
161
162 pfoVariant= constits.label.split("PFlow")[-1] # We expect label to be EMPFlowXYZ or LCPFlowXYZ -> extrat XYZ
163
164 decorKey = getDecorationKeyFunc(trackParticleName,assocPostfix)
165
166
167
168 components.merge(
169 setupTrackCaloAssoc(flags, caloClusterName, detectorEtaName, trackParticleName, assocPostfix, onlyPV0Tracks=False) #onlyPV0Tracks True was original option
170 )
171
172
173 from TrackVertexAssociationTool.TrackVertexAssociationToolConfig import TTVAToolCfg
174 commonArgs=dict(
175 TrackVertexAssoTool = components.popToolsAndMerge(
176 TTVAToolCfg(flags,"tvaTool",WorkingPoint="Nonprompt_All_MaxWeight")),
177 AssoClustersDecor=decorKey("AssoClusters"),
178 )
179
180
181 inputFEcontainerkey = inputFEcontainerkey or constits.containername
182
183
184 UFOInfoAlg = CompFactory.TrackCaloClusterInfoUFOAlg(f"UFOInfoAlg{pfoVariant}",
185 TCCInfoName = pfoVariant+"UFOInfo",
186 InputTracks = trackParticleName,
187 InputClusters = caloClusterName,
188 VertexContainer = "PrimaryVertices",
189 InputPFO=inputFEcontainerkey,
190 OriginPFO='originalObjectLink',
191 ClusterECut = 0.,
192 **commonArgs
193 )
194
195
196 components.addEventAlgo( UFOInfoAlg)
197
198 tccUFO = CompFactory.UFOTool(f"UFOtool{pfoVariant}",
199 ClusterECut = UFOInfoAlg.ClusterECut,
200 InputPFO=inputFEcontainerkey,
201 OriginPFO='originalObjectLink',
202 **commonArgs
203 )
204
205 UFOAlg = CompFactory.TrackCaloClusterAlg(name = f"TrackCaloClusterAlgUFO{pfoVariant}",
206 OutputTCCName = f"UFO{pfoVariant}",
207 TCCInfo = UFOInfoAlg.TCCInfoName ,
208 TCCTools = [tccUFO,],
209 )
210
211
212
213 components.addEventAlgo( UFOAlg)
214 return components
runUFOReconstruction(flags, constits, caloClusterName="CaloCalTopoClusters", detectorEtaName="default", assocPostfix="UFO", inputFEcontainerkey="")
setupTrackCaloAssoc(flags, caloClusterName="CaloCalTopoClusters", detectorEtaName="default", trackParticleName="InDetTrackParticles", assocPostfix="TCC", onlyPV0Tracks=False)
runTCCReconstruction(flags, caloClusterName="CaloCalTopoClusters", detectorEtaName="default", trackParticleName="InDetTrackParticles", assocPostfix="TCC", doCombined=False, doCharged=False, doNeutral=True, outputTCCName="TrackCaloClusters")
getDecorationKeyFunc(trackParticleName, assocPostfix)
_unifyPV0onlyTrkClustAssoc(vxContName1, vxContName2)