ATLAS Offline Software
Loading...
Searching...
No Matches
TruthDerivationToolsConfig.py
Go to the documentation of this file.
1# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2
3#==============================================================================
4# Provides configs for the tools used for building the common truth collections
5# Note that taus are handled separately (see MCTruthCommon.py)
6# Note also that navigation info is dropped here and added separately
7# Two kinds of config are defined here - for general config of the tools
8# and for specific configurations, which implement the former.
9#==============================================================================
10
11from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
12from AthenaConfiguration.ComponentFactory import CompFactory
13
14
15#==============================================================================
16# TruthCollectionMaker instances
17#==============================================================================
18
19def TruthCollectionMakerCfg(flags, name, **kwargs):
20 """Configure the TruthCollectionMaker tool"""
21 acc = ComponentAccumulator()
22 acc.addPublicTool(CompFactory.DerivationFramework.TruthCollectionMaker(name = name,**kwargs),
23 primary = True)
24 return acc
25
26
28 """Muon truth collection maker"""
29 return TruthCollectionMakerCfg(flags,
30 name = "DFCommonTruthMuonTool",
31 OutputCollectionName = "TruthMuons",
32 KeepNavigationInfo = False,
33 ParticleSelectionString = "(abs(TruthParticles.pdgId) == 13) && TruthParticles.isGenStable")
34
35
36def DFCommonTruthCharmToolCfg(flags, name):
37 """Charm truth collection maker"""
38 return TruthCollectionMakerCfg(
39 flags,
40 name = name,
41 OutputCollectionName = "TruthCharm",
42 KeepNavigationInfo = False,
43 ParticleSelectionString = "(abs(TruthParticles.pdgId) == 4)",
44 Do_Compress = True)
45
46
47def DFCommonTruthElectronToolCfg(flags):
48 """Electron truth collection maker"""
49 return TruthCollectionMakerCfg(flags,
50 name = "DFCommonTruthElectronTool",
51 OutputCollectionName = "TruthElectrons",
52 KeepNavigationInfo = False,
53 ParticleSelectionString = "(abs(TruthParticles.pdgId) == 11) && TruthParticles.isGenStable")
54
55
56def DFCommonTruthPhotonToolCfg(flags):
57 """Photon truth collection maker (Currently unused?)"""
58 return TruthCollectionMakerCfg(flags,
59 name = "DFCommonTruthPhotonTool",
60 OutputCollectionName = "TruthPhotons",
61 KeepNavigationInfo = False,
62 ParticleSelectionString = "(abs(TruthParticles.pdgId) == 22) && TruthParticles.isGenStable")
63
64
65# this tool is needed for making TruthPhotons from sim samples, where extra cuts are needed. Origin 42 (pi0) and 23 (light meson) cut way down uninteresting photons
66def DFCommonTruthPhotonToolSimCfg(flags):
67 """Tool for making TruthPhotons from sim samples"""
68 return TruthCollectionMakerCfg(flags,
69 name = "DFCommonTruthPhotonToolSim",
70 OutputCollectionName = "TruthPhotons",
71 KeepNavigationInfo = False,
72 ParticleSelectionString = "(abs(TruthParticles.pdgId) == 22) && TruthParticles.isGenStable && ((TruthParticles.classifierParticleOrigin != 42 && TruthParticles.classifierParticleOrigin !=23) || (TruthParticles.pt > 20.0*GeV))")
73
74
75def DFCommonTruthNeutrinoToolCfg(flags):
76 """Neutrino truth collection maker"""
77 neutrinoexpression = "(TruthParticles.isNeutrino && TruthParticles.isGenStable)"
78 return TruthCollectionMakerCfg(flags,
79 name = "DFCommonTruthNeutrinoTool",
80 OutputCollectionName = "TruthNeutrinos",
81 KeepNavigationInfo = False,
82 ParticleSelectionString = neutrinoexpression)
83
84
85def DFCommonTruthBottomToolCfg(flags):
86 """B-quark truth collection maker"""
87 return TruthCollectionMakerCfg(flags,
88 name = "DFCommonTruthBottomTool",
89 OutputCollectionName = "TruthBottom",
90 KeepNavigationInfo = False,
91 ParticleSelectionString = "(abs(TruthParticles.pdgId) == 5)",
92 Do_Compress = True)
93
94
95def DFCommonTruthTopToolCfg(flags):
96 """Top-quark truth collection maker"""
97 return TruthCollectionMakerCfg(flags,
98 name = "DFCommonTruthTopTool",
99 OutputCollectionName = "TruthTop",
100 KeepNavigationInfo = False,
101 ParticleSelectionString = "(abs(TruthParticles.pdgId) == 6)",
102 Do_Compress = True)
103
104
105def DFCommonTruthBosonToolCfg(flags):
106 """Gauge bosons and Higgs truth collection maker"""
107 return TruthCollectionMakerCfg(flags,
108 name = "DFCommonTruthBosonTool",
109 OutputCollectionName = "TruthBoson",
110 KeepNavigationInfo = False,
111 ParticleSelectionString = "(abs(TruthParticles.pdgId) == 23 || abs(TruthParticles.pdgId) == 24 || abs(TruthParticles.pdgId) == 25)",
112 Do_Compress = True,
113 Do_Sherpa = True)
114
115
116def DFCommonTruthBSMToolCfg(flags):
117 """BSM particles truth collection maker"""
118 return TruthCollectionMakerCfg(flags,
119 name = "DFCommonTruthBSMTool",
120 OutputCollectionName = "TruthBSM",
121 KeepNavigationInfo = False,
122 ParticleSelectionString = "(TruthParticles.isBSM)",
123 Do_Compress = True)
124
125
126def DFCommonTruthForwardProtonToolCfg(flags):
127 """Forward proton truth collection maker"""
128 beam_energy = flags.Beam.Energy
129 return TruthCollectionMakerCfg(flags,
130 name = "DFCommonTruthForwardProtonTool",
131 OutputCollectionName = "TruthForwardProtons",
132 KeepNavigationInfo = False,
133 ParticleSelectionString = "(TruthParticles.isStable) && (abs(TruthParticles.pdgId)==2212) && (TruthParticles.e>0.8*"+str(beam_energy)+")", # TODO Check whether isGenStable was intended here.
134 Do_Compress = True)
135
136#==============================================================================
137# Decoration tools
138#==============================================================================
139
140def TruthD2DecoratorCfg(flags, name, **kwargs):
141 """Configure the truth D2 decorator tool"""
142 acc = ComponentAccumulator()
143 TruthD2Decorator = CompFactory.DerivationFramework.TruthD2Decorator
144 acc.addPublicTool(TruthD2Decorator(name, **kwargs), primary = True)
145 return acc
146
147
148def TruthClassificationDecoratorCfg(flags, name, **kwargs):
149 """Configure the TruthClassificationDecorator tool"""
150 acc = ComponentAccumulator()
151 from MCTruthClassifier.MCTruthClassifierConfig import DFCommonMCTruthClassifierCfg
152 kwargs.setdefault("MCTruthClassifier", acc.addPublicTool(acc.popToolsAndMerge(DFCommonMCTruthClassifierCfg(flags))))
153 TruthClassificationDecorator = CompFactory.DerivationFramework.TruthClassificationDecorator
154 acc.setPrivateTools(TruthClassificationDecorator(name = name, **kwargs))
155 return acc
156
157
158def MuonTruthClassifierFallbackCfg(flags, name, **kwargs):
159 """Config the MuonTruthClassifierFallback tool"""
160 acc = ComponentAccumulator()
161
162 if "MCTruthClassifierTool" not in kwargs:
163 from MCTruthClassifier.MCTruthClassifierConfig import (
164 MCTruthClassifierCfg)
165 kwargs.setdefault("MCTruthClassifierTool", acc.popToolsAndMerge(
166 MCTruthClassifierCfg(flags, name = "MuonTruthClassifierFallbackMCTruthClassifier")))
167
168 MuonTruthClassifierFallback = CompFactory.DerivationFramework.MuonTruthClassifierFallback
169 acc.addPublicTool(MuonTruthClassifierFallback(name = name, **kwargs),
170 primary = True)
171 return acc
172
173
174def TruthDressingToolCfg(flags, name, **kwargs):
175 """Configure the TruthDressingTool"""
176 acc = ComponentAccumulator()
177 TruthDressingTool = CompFactory.DerivationFramework.TruthDressingTool
178 acc.addPublicTool(TruthDressingTool( name = name, **kwargs),
179 primary = True)
180 return acc
181
182
183def TruthIsolationToolCfg(flags, name, **kwargs):
184 """Configure the truth isolation tool"""
185 acc = ComponentAccumulator()
186 TruthIsolationTool = CompFactory.DerivationFramework.TruthIsolationTool
187 acc.addPublicTool(TruthIsolationTool(name = name, **kwargs),
188 primary = True)
189 return acc
190
191
192def MuonTruthIsolationDecorAlgCfg(flags, name, **kwargs):
193 """Configure the MuonTruthIsolationTool"""
194 acc = ComponentAccumulator()
195 acc.addEventAlgo(CompFactory.DerivationFramework.MuonTruthIsolationDecorAlg(name = name, **kwargs),
196 primary = True)
197 return acc
198
199
200def TruthQGDecorationToolCfg(flags, name, **kwargs):
201 """Configure the quark/gluon decoration tool"""
202 acc = ComponentAccumulator()
203 TruthQGDecorationTool = CompFactory.DerivationFramework.TruthQGDecorationTool
204 acc.addPublicTool(TruthQGDecorationTool(name = name, **kwargs),
205 primary = True)
206 return acc
207
208
209def TruthNavigationDecoratorCfg(flags, name, **kwargs):
210 """Congigure the truth navigation decorator tool"""
211 acc = ComponentAccumulator()
212 kwargs.setdefault("InputCollections", [])
213 kwargs.setdefault("parentDecorKeys", [ key + ".parentLinks" for key in kwargs["InputCollections"] ])
214 kwargs.setdefault("childDecorKeys", [ key + ".childLinks" for key in kwargs["InputCollections"] ])
215 TruthNavigationDecorator = CompFactory.DerivationFramework.TruthNavigationDecorator
216 acc.addPublicTool(TruthNavigationDecorator(name = name, **kwargs),
217 primary = True)
218 return acc
219
220
221def TruthDecayCollectionMakerCfg(flags, name, **kwargs):
222 """Configure the truth decay collection maker"""
223 acc = ComponentAccumulator()
224 TruthDecayCollectionMaker = CompFactory.DerivationFramework.TruthDecayCollectionMaker
225 acc.addPublicTool(TruthDecayCollectionMaker(name = name, **kwargs),
226 primary = True)
227 return acc
228
229
230def TruthBornLeptonCollectionMakerCfg(flags, name, **kwargs):
231 """Configure the truth Born lepton collection tool"""
232 acc = ComponentAccumulator()
233 TruthBornLeptonCollectionMaker = CompFactory.DerivationFramework.TruthBornLeptonCollectionMaker
234 acc.addPublicTool(TruthBornLeptonCollectionMaker(name = name, **kwargs),
235 primary = True)
236 return acc
237
238
239def HardScatterCollectionMakerCfg(flags, name, **kwargs):
240 """Add a mini-collection for the hard scatter and N subsequent generations"""
241 acc = ComponentAccumulator()
242 return acc
243
244
245#add the 'decoration' tool to dress the main truth collection with the classification
246def DFCommonTruthClassificationToolCfg(flags):
247 """dress the main truth collection with the classification"""
248 return TruthClassificationDecoratorCfg(flags,
249 name = "DFCommonTruthClassificationTool",
250 ParticlesKey = "TruthParticles")
251
252
253# Hadron origin decoration tools
254def HadronOriginClassifierCfg(flags, name, **kwargs):
255 """get the hadron origin classification"""
256 acc = ComponentAccumulator()
257 HadronOriginClassifier = CompFactory.DerivationFramework.HadronOriginClassifier
258 kwargs.setdefault("DSID", flags.Input.MCChannelNumber)
259 acc.addPublicTool(HadronOriginClassifier(name = name, **kwargs),
260 primary = True)
261 return acc
262
263
264def HadronOriginDecoratorCfg(flags, name, **kwargs):
265 """decorate with the hadron origin classification"""
266 acc = ComponentAccumulator()
267 if not hasattr(kwargs, "ToolName"):
268 kwargs.setdefault("ToolName", acc.getPrimaryAndMerge(HadronOriginClassifierCfg(flags,
269 name="DFCommonHadronOriginClassifier")))
270 acc.addPublicTool(CompFactory.DerivationFramework.HadronOriginDecorator
271 (name = name, **kwargs),
272 primary = True)
273 return acc
274
275
276#add the 'decoration' tools for dressing and isolation
277def DFCommonTruthElectronDressingToolCfg(flags, decorationName = "dressedPhoton"):
278 """Configure the electron truth dressing tool"""
279 return TruthDressingToolCfg(flags,
280 name = "DFCommonTruthElectronDressingTool",
281 dressParticlesKey = "TruthElectrons",
282 usePhotonsFromHadrons = False,
283 dressingConeSize = 0.1,
284 particleIDsToDress = [11],
285 decorationName = decorationName+"_e")
286
287
288def DFCommonTruthMuonDressingToolCfg(flags, decorationName = "dressedPhoton"):
289 """Configure the muon truth dressing tool"""
290 return TruthDressingToolCfg(flags,
291 name = "DFCommonTruthMuonDressingTool",
292 dressParticlesKey = "TruthMuons",
293 usePhotonsFromHadrons = False,
294 dressingConeSize = 0.1,
295 particleIDsToDress = [13],
296 decorationName = decorationName+"_mu")
297
298
299def DFCommonTruthTauDressingToolCfg(flags):
300 """Configure the tau truth dressing tool"""
301 return TruthDressingToolCfg(flags,
302 name = "DFCommonTruthTauDressingTool",
303 dressParticlesKey = "TruthTaus",
304 usePhotonsFromHadrons = False,
305 dressingConeSize = 0.2, # Tau special
306 particleIDsToDress = [15],
307 decoratePhotons = False)
308
309
310def DFCommonTruthElectronIsolationTool1Cfg(flags):
311 """Configure the electron isolation tool, cone=0.2"""
312 return TruthIsolationToolCfg(flags,
313 name = "DFCommonTruthElectronIsolationTool1",
314 isoParticlesKey = "TruthElectrons",
315 allParticlesKey = "TruthParticles",
316 particleIDsToCalculate = [11],
317 IsolationConeSizes = [0.2],
318 IsolationVarNamePrefix = 'etcone',
319 ChargedParticlesOnly = False)
320
321
322def DFCommonTruthElectronIsolationTool2Cfg(flags):
323 """Configure the electron isolation tool, cone=0.3"""
324 return TruthIsolationToolCfg(flags,
325 name = "DFCommonTruthElectronIsolationTool2",
326 isoParticlesKey = "TruthElectrons",
327 allParticlesKey = "TruthParticles",
328 particleIDsToCalculate = [11],
329 IsolationConeSizes = [0.3],
330 IsolationVarNamePrefix = 'ptcone',
331 ChargedParticlesOnly = True)
332
333
334def DFCommonTruthMuonIsolationTool1Cfg(flags):
335 """Configure the muon isolation tool, cone=0.2"""
336 return TruthIsolationToolCfg(flags,
337 name = "DFCommonTruthMuonIsolationTool1",
338 isoParticlesKey = "TruthMuons",
339 allParticlesKey = "TruthParticles",
340 particleIDsToCalculate = [13],
341 IsolationConeSizes = [0.2],
342 IsolationVarNamePrefix = 'etcone',
343 ChargedParticlesOnly = False)
344
345
346def DFCommonTruthMuonIsolationTool2Cfg(flags):
347 """Configure the muon isolation tool, cone=0.3"""
348 return TruthIsolationToolCfg(flags,
349 name = "DFCommonTruthMuonIsolationTool2",
350 isoParticlesKey = "TruthMuons",
351 allParticlesKey = "TruthParticles",
352 particleIDsToCalculate = [13],
353 IsolationConeSizes = [0.3],
354 IsolationVarNamePrefix = 'ptcone',
355 ChargedParticlesOnly = True)
356
357
358def DFCommonTruthPhotonIsolationTool1Cfg(flags):
359 """Configure the photon isolation tool, etcone"""
360 return TruthIsolationToolCfg(flags,
361 name = "DFCommonTruthPhotonIsolationTool1",
362 isoParticlesKey = "TruthPhotons",
363 allParticlesKey = "TruthParticles",
364 particleIDsToCalculate = [22],
365 IsolationConeSizes = [0.2],
366 IsolationVarNamePrefix = 'etcone',
367 ChargedParticlesOnly = False)
368
369
370def DFCommonTruthPhotonIsolationTool2Cfg(flags):
371 """Configure the photon isolation tool, ptcone"""
372 return TruthIsolationToolCfg(flags,
373 name = "DFCommonTruthPhotonIsolationTool2",
374 isoParticlesKey = "TruthPhotons",
375 allParticlesKey = "TruthParticles",
376 particleIDsToCalculate = [22],
377 IsolationConeSizes = [0.2],
378 IsolationVarNamePrefix = 'ptcone',
379 ChargedParticlesOnly = True)
380
381
382def DFCommonTruthPhotonIsolationTool3Cfg(flags):
383 """Configure the photon isolation tool, etcone=0.4"""
384 return TruthIsolationToolCfg(flags,
385 name = "DFCommonTruthPhotonIsolationTool3",
386 isoParticlesKey = "TruthPhotons",
387 allParticlesKey = "TruthParticles",
388 particleIDsToCalculate = [22],
389 IsolationConeSizes = [0.4],
390 IsolationVarNamePrefix = 'etcone',
391 ChargedParticlesOnly = False)
392
393
394# Quark/gluon decoration for jets
395def DFCommonTruthDressedWZQGLabelToolCfg(flags):
396 """Configure the QG decoration tool for AntiKt4TruthDressedWZJets"""
397 return TruthQGDecorationToolCfg(flags,
398 name = "DFCommonTruthDressedWZQGLabelTool",
399 JetCollection = "AntiKt4TruthDressedWZJets")
400
401#==============================================================================
402# Truth thinning
403#==============================================================================
404
405# Menu truth thinning: removes truth particles on the basis of a menu of
406# options (rather than a string)
407def MenuTruthThinningCfg(flags, name, **kwargs):
408 """Configure the menu truth thinning tool"""
409 acc = ComponentAccumulator()
410 MenuTruthThinning = CompFactory.DerivationFramework.MenuTruthThinning
411 acc.addPublicTool(MenuTruthThinning(name, **kwargs),
412 primary = True)
413 return acc
414
415#==============================================================================
416# Other tools
417#==============================================================================
418# Truth links on some objects point to the main truth particle container.
419# This re-points the links from the old container to the new container
420def TruthLinkRepointToolCfg(flags, name, **kwargs):
421 """Configure the truth link repointing tool"""
422 acc = ComponentAccumulator()
423 TruthLinkRepointTool = CompFactory.DerivationFramework.TruthLinkRepointTool
424 acc.addPublicTool(TruthLinkRepointTool(name, **kwargs),
425 primary = True)
426 return acc
427
428
429# Makes a small collection of 'primary' vertices, one per event
430# A bit like a collection of 'reconstructable' vertices
431def TruthPVCollectionMakerCfg(flags, name, **kwargs):
432 """Configure the truth PV collection maker tool"""
433 acc = ComponentAccumulator()
434 TruthPVCollectionMaker = CompFactory.DerivationFramework.TruthPVCollectionMaker
435 acc.addPublicTool(TruthPVCollectionMaker(name, **kwargs),
436 primary = True)
437 return acc
438
439
440# Tool for thinning TruthParticles
441def GenericTruthThinningCfg(flags, name, **kwargs):
442 """Configure the GenericTruthThinning tool"""
443 acc = ComponentAccumulator()
444 GenericTruthThinning = CompFactory.DerivationFramework.GenericTruthThinning
445 acc.addPublicTool(GenericTruthThinning(name, **kwargs),
446 primary = True)
447 return acc