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