ATLAS Offline Software
Loading...
Searching...
No Matches
MCTruthCommonConfig.py
Go to the documentation of this file.
1# Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
2
3# MCTruthCommonConfig
4# Contains the configuration for the common truth containers/decorations used in analysis DAODs
5# including PHYS(LITE)
6
7from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
8from AthenaConfiguration.ComponentFactory import CompFactory
9from DerivationFrameworkMCTruth.TruthDerivationToolsConfig import TruthDecayCollectionMakerCfg
10
11def TruthMetaDataWriterCfg(flags, name):
12 acc = ComponentAccumulator()
13 acc.flagPerfmonDomain('Truth')
14 theTruthMetaDataWriter = CompFactory.DerivationFramework.TruthMetaDataWriter(name)
15 acc.addPublicTool(theTruthMetaDataWriter)
16 CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
17 acc.addEventAlgo(CommonAugmentation(f"{name}Kernel", AugmentationTools = [theTruthMetaDataWriter]))
18 return acc
19
21 """Conversion of HepMC to xAOD truth"""
22 acc = ComponentAccumulator()
23 acc.flagPerfmonDomain('Truth')
24 # Only run for MC input
25 if flags.Input.isMC is False and flags.Overlay.DataOverlay is False:
26 raise RuntimeError("Common MC truth building requested for non-MC input")
27
28 # Local steering flag to identify EVNT input
29 # Commented because the block it is needed for isn't working (TruthMetaData)
30 isEVNT = False
31
32 # Ensure EventInfoCnvAlg is scheduled
33 if "EventInfo#McEventInfo" in flags.Input.TypedCollections and "xAOD::EventInfo#EventInfo" not in flags.Input.TypedCollections:
34 from xAODEventInfoCnv.xAODEventInfoCnvConfig import EventInfoCnvAlgCfg
35 acc.merge(EventInfoCnvAlgCfg(flags, inputKey="McEventInfo", outputKey="Input_EventInfo", disableBeamSpot=True))
36
37 from xAODEventInfoCnv.xAODEventInfoCnvConfig import EventInfoUpdateFromContextAlgCfg
38 acc.merge(EventInfoUpdateFromContextAlgCfg(flags, disableBeamSpot=True))
39
40 # Build truth collection if input is HepMC. Must be scheduled first to allow slimming.
41 # Input file is event generator output (EVNT)
42 from xAODTruthCnv.xAODTruthCnvConfig import GEN_EVNT2xAODCfg
43 if "McEventCollection#GEN_EVENT" in flags.Input.TypedCollections:
44 acc.merge(GEN_EVNT2xAODCfg(flags,name="GEN_EVNT2xAOD",AODContainerName="GEN_EVENT"))
45 isEVNT = True
46 # Input file is simulation output (HITS)
47 elif "McEventCollection#TruthEvent" in flags.Input.TypedCollections:
48 acc.merge(GEN_EVNT2xAODCfg(flags,name="GEN_EVNT2xAOD",AODContainerName="TruthEvent"))
49 # This is not really EVNT, but we do need to treat it like EVNT for Metadata
50 isEVNT = True
51 # Input file already has xAOD truth. Don't do anything.
52 elif "xAOD::TruthEventContainer#TruthEvents" in flags.Input.TypedCollections:
53 pass
54 else:
55 raise RuntimeError("No recognised HepMC truth information found in the input")
56
57 # If it isn't available, make a truth meta data object (will hold MC Event Weights)
58 if "TruthMetaDataContainer#TruthMetaData" not in flags.Input.TypedCollections and not isEVNT:
59 # If we are going to be making the truth collection (isEVNT) then this will be made elsewhere
60 acc.merge(TruthMetaDataWriterCfg(flags, name = 'DFCommonTruthMetaDataWriter'))
61
62 return acc
63
64
65# Helper for adding truth jet collections via new jet config
66def AddTruthJetsCfg(flags):
67
68 acc = ComponentAccumulator()
69 acc.flagPerfmonDomain('Truth')
70 from JetRecConfig.StandardSmallRJets import AntiKt4Truth,AntiKt4TruthWZ,AntiKt4TruthDressedWZ,AntiKtVRTruthCharged
71 from JetRecConfig.StandardLargeRJets import AntiKt10TruthSoftDrop
72 from JetRecConfig.JetRecConfig import JetRecCfg
73
74 inputCollections = set(flags.Input.Collections)
75 jetList = [AntiKt4Truth,AntiKt4TruthWZ,AntiKt4TruthDressedWZ,AntiKtVRTruthCharged,
76 AntiKt10TruthSoftDrop]
77
78 for jd in jetList:
79 # Encode the expected name to match the bytes in inputCollections.
80 expectedName = jd.fullname().encode("utf-8")
81 if expectedName in inputCollections:
82 continue
83 acc.merge(JetRecCfg(flags, jd))
84 return acc
85
86# Helper for scheduling the truth MET collection
87def AddTruthMETCfg(flags):
88
89 acc = ComponentAccumulator()
90 acc.flagPerfmonDomain('Truth')
91 # Only do this if the truth MET is not present
92 # This should handle EVNT correctly without an explicit check
93 if ( "MissingETContainer#MET_Truth") not in flags.Input.TypedCollections:
94 from METReconstruction.METTruth_Cfg import METTruth_Cfg
95 acc.merge(METTruth_Cfg(flags))
96
97 return acc
98
99
101
102 acc = ComponentAccumulator()
103 acc.flagPerfmonDomain('Truth')
104 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig import DFCommonTruthClassificationToolCfg
105 acc.addEventAlgo(CompFactory.DerivationFramework.CommonAugmentation(name ="MCTruthClassificationKernel",
106 AugmentationTools = [ acc.addPublicTool(acc.popToolsAndMerge(DFCommonTruthClassificationToolCfg(flags))) ]))
107
108 return acc
109
110
111def PreJetMCTruthAugmentationsCfg(flags, **kwargs):
112
114 acc.flagPerfmonDomain('Truth')
115 augmentationToolsList = []
116
117 # These augmentations do *not* require truth jets at all
118 # If requested, add a decoration to photons that were used in the dressing
119
120 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig import ( DFCommonTruthElectronDressingToolCfg,
121 DFCommonTruthMuonDressingToolCfg, DFCommonTruthMuonToolCfg, DFCommonTruthElectronToolCfg,
122 DFCommonTruthPhotonToolSimCfg, DFCommonTruthNeutrinoToolCfg, DFCommonTruthBottomToolCfg, DFCommonTruthTopToolCfg,
123 DFCommonTruthBosonToolCfg, DFCommonTruthBSMToolCfg, DFCommonTruthForwardProtonToolCfg, DFCommonTruthElectronIsolationTool1Cfg,
124 DFCommonTruthElectronIsolationTool2Cfg, DFCommonTruthMuonIsolationTool1Cfg, DFCommonTruthMuonIsolationTool2Cfg,
125 DFCommonTruthPhotonIsolationTool1Cfg, DFCommonTruthPhotonIsolationTool2Cfg, DFCommonTruthPhotonIsolationTool3Cfg )
126
127 # schedule the special truth building tools and add them to a common augmentation; note taus are handled separately below
128 for item in [ DFCommonTruthMuonToolCfg, DFCommonTruthElectronToolCfg,
129 DFCommonTruthPhotonToolSimCfg, DFCommonTruthNeutrinoToolCfg, DFCommonTruthBottomToolCfg, DFCommonTruthTopToolCfg,
130 DFCommonTruthBosonToolCfg, DFCommonTruthBSMToolCfg, DFCommonTruthElectronIsolationTool1Cfg,
131 DFCommonTruthElectronIsolationTool2Cfg, DFCommonTruthMuonIsolationTool1Cfg, DFCommonTruthMuonIsolationTool2Cfg,
132 DFCommonTruthPhotonIsolationTool1Cfg, DFCommonTruthPhotonIsolationTool2Cfg, DFCommonTruthPhotonIsolationTool3Cfg]:
133 augmentationToolsList.append(acc.getPrimaryAndMerge(item(flags)))
134 augmentationToolsList.append(acc.getPrimaryAndMerge(DFCommonTruthForwardProtonToolCfg(flags)))
135
136 if 'decorationDressing' in kwargs:
137 augmentationToolsList.append(acc.getPrimaryAndMerge(DFCommonTruthElectronDressingToolCfg(flags, decorationName = kwargs['decorationDressing'])))
138 augmentationToolsList.append(acc.getPrimaryAndMerge(DFCommonTruthMuonDressingToolCfg(flags, decorationName = kwargs['decorationDressing'])))
139
140 for i, tool in enumerate(augmentationToolsList):
141 acc.addEventAlgo(CompFactory.DerivationFramework.CommonAugmentation(name ="MCTruthCommonPreJetKernelNo{num}".format(num = i+1), AugmentationTools = [tool]))
142
143 return(acc)
144
145
147
148 acc = ComponentAccumulator()
149 acc.flagPerfmonDomain('Truth')
150 # Tau collections are built separately
151 # truth tau matching needs truth jets, truth electrons and truth muons
152 from DerivationFrameworkTau.TauTruthCommonConfig import TauTruthToolsCfg
153 acc.merge(TauTruthToolsCfg(flags))
154 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig import DFCommonTruthTauDressingToolCfg
155 augmentationToolsList = [ acc.getPrimaryAndMerge(DFCommonTruthTauDressingToolCfg(flags)) ]
156
157 #Save the post-shower HT and MET filter values that will make combining filtered samples easier (adds to the EventInfo)
158 from DerivationFrameworkMCTruth.GenFilterToolConfig import GenFilterToolCfg
159 # schedule the special truth building tools and add them to a common augmentation; note taus are handled separately below
160 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig import DFCommonTruthDressedWZQGLabelToolCfg
161 augmentationToolsList += [ acc.addPublicTool(acc.popToolsAndMerge(GenFilterToolCfg(flags))),
162 acc.getPrimaryAndMerge(DFCommonTruthDressedWZQGLabelToolCfg(flags))]
163
164 # SUSY signal decorations
165 from DerivationFrameworkSUSY.DecorateSUSYProcessConfig import IsSUSYSignalRun3
166 if IsSUSYSignalRun3(flags):
167 from DerivationFrameworkSUSY.DecorateSUSYProcessConfig import SUSYSignalTaggerCfg
168 augmentationToolsList += [ acc.getPrimaryAndMerge(SUSYSignalTaggerCfg(flags, 'MCTruthCommon')) ]
169
170 CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
171 for i, tool in enumerate(augmentationToolsList):
172 acc.addEventAlgo(CommonAugmentation(name = "MCTruthCommonPostJetKernelNo{num}".format(num = i+1),
173 AugmentationTools = [tool]))
174
175 # add SoW of individual SUSY final states, relies on augmentation from DecorateSUSYProcess()
176 if IsSUSYSignalRun3(flags):
177 from DerivationFrameworkSUSY.SUSYWeightMetadataConfig import AddSUSYWeightsCfg
178 acc.merge(AddSUSYWeightsCfg(flags))
179
180 return(acc)
181
182# Standard truth content (truth collections, truth jets and MET, navigation)
184 decorationDressing='dressedPhoton',
185 includeTausInDressingPhotonRemoval=False,
186 navInputCollections = ["TruthElectrons", "TruthMuons", "TruthPhotons", "TruthTaus", "TruthNeutrinos", "TruthBSM", "TruthBottom", "TruthTop", "TruthBoson"],
187 prefix=''):
188
189 acc = ComponentAccumulator()
190 acc.flagPerfmonDomain('Truth')
191 # Schedule HepMC->xAOD truth conversion
192 acc.merge(HepMCtoXAODTruthCfg(flags))
193
194 # Local flag
195 isEVNT = False
196 if "McEventCollection#GEN_EVENT" in flags.Input.TypedCollections: isEVNT = True
197 # Tools that must come before jets
198 acc.merge(PreJetMCTruthAugmentationsCfg(flags,decorationDressing = decorationDressing))
199 # Jets and MET
200 acc.merge(AddTruthJetsCfg(flags))
201 acc.merge(AddTruthMETCfg(flags))
202 # Tools that must come after jets
203 acc.merge(PostJetMCTruthAugmentationsCfg(flags))
204 # Should photons that are dressed onto taus also be removed from truth jets?
205 if includeTausInDressingPhotonRemoval:
206 acc.getPublicTool("DFCommonTruthTauDressingTool").decorationName=decorationDressing+"_tau"
207
208 # Add back the navigation contect for the collections we want
209 acc.merge(AddTruthCollectionNavigationDecorationsCfg(flags, navInputCollections, prefix=prefix))
210 # Some more additions for standard TRUTH3
211 acc.merge(AddBosonsAndDownstreamParticlesCfg(flags))
212 if isEVNT: acc.merge(AddLargeRJetD2Cfg(flags))
213 # Special collection for BSM particles
214 acc.merge(AddBSMAndDownstreamParticlesCfg(flags))
215 # Special collection for Born leptons
216 acc.merge(AddBornLeptonCollectionCfg(flags))
217 # Energy density for isolation corrections
218 if isEVNT: acc.merge(AddTruthEnergyDensityCfg(flags))
219
220 return acc
221
223 generations=1,
224 parents=[6],
225 prefix='TopQuark',
226 collection_prefix=None,
227 rejectHadronChildren=False):
228 """Configure tools for adding immediate parents and descendants"""
229 acc = ComponentAccumulator()
230 acc.flagPerfmonDomain('Truth')
231 collection_name=collection_prefix+'WithDecay' if collection_prefix is not None else 'Truth'+prefix+'WithDecay'
232 # Set up a tool to keep the W/Z/H bosons and all downstream particles
233 collection_maker = acc.getPrimaryAndMerge(TruthDecayCollectionMakerCfg(flags,
234 name ='DFCommon'+prefix+'AndDecaysTool',
235 NewParticleKey = collection_name+'Particles',
236 NewVertexKey = collection_name+'Vertices',
237 PDGIDsToKeep = parents,
238 Generations = generations,
239 RejectHadronChildren = rejectHadronChildren))
240 CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
241 kernel_name = 'MCTruthCommon'+prefix+'AndDecaysKernel'
242 acc.addEventAlgo(CommonAugmentation(kernel_name, AugmentationTools = [collection_maker] ))
243 return acc
244
245# Next two don't seem to be used for anything...
246
261
262# Add W/Z/H bosons and their downstream particles (notice "boson" here does not include photons and gluons)
264 generations=1,
265 rejectHadronChildren=False):
266 """Add bosons and downstream particles (not photons/gluons)"""
268 generations = generations,
269 parents = [23,24,25],
270 prefix = 'Bosons',
271 rejectHadronChildren = rejectHadronChildren)
272
273# Add top quark and their downstream particles
275 generations=1,
276 rejectHadronChildren=False):
277 """Add top quarks and downstream particles"""
279 generations=generations,
280 parents=[6],
281 prefix='TopQuark',
282 rejectHadronChildren=rejectHadronChildren)
283
285 generations=-1,
286 rejectHadronChildren=False):
287 """Add tau and downstream particles"""
289 generations=generations,
290 parents=[15],
291 prefix='Taus',
292 rejectHadronChildren=rejectHadronChildren)
293
294# Following commented methods don't seem to be used for anything...
295
296#def addBottomQuarkAndDownstreamParticles(kernel=None, generations=1, rejectHadronChildren=False):
297# return addParentAndDownstreamParticles(kernel=kernel,
298# generations=generations,
299# parents=[5],
300# prefix='BottomQuark',
301# rejectHadronChildren=rejectHadronChildren)
302#
303#
304
311
312# Add b/c-hadrons and their downstream particles (immediate and further decay products) in a special collection
314 """Add b/c-hadrons and their downstream particles"""
315 kwargs.setdefault("addB",True)
316 kwargs.setdefault("addC",True)
317 kwargs.setdefault("generations",-1)
318 kwargs.setdefault("prefix",'')
320 # Set up a tool to keep b- and c-quarks and all downstream particles
321 collection_name = kwargs['prefix']+"TruthHFWithDecay"
322 DFCommonHFAndDecaysTool = acc.getPrimaryAndMerge(TruthDecayCollectionMakerCfg(
323 flags,
324 name=kwargs['prefix']+"DFCommonHFAndDecaysTool",
325 NewParticleKey = collection_name+'Particles',
326 NewVertexKey = collection_name+'Vertices',
327 KeepBHadrons=kwargs['addB'],
328 KeepCHadrons=kwargs['addC'],
329 Generations=kwargs['generations']))
330 acc.addEventAlgo(CompFactory.DerivationFramework.CommonAugmentation(
331 kwargs['prefix']+"MCTruthCommonHFAndDecaysKernel",
332 AugmentationTools = [DFCommonHFAndDecaysTool] ))
333 return acc
334
335
336# Truth collections with navigation decorations in DAOD_PHYS
337PhysTruthNavigationCollections = ["TruthElectrons",
338 "TruthMuons",
339 "TruthPhotons",
340 "TruthTaus",
341 "TruthNeutrinos",
342 "TruthBSM",
343 "TruthBottom",
344 "TruthTop",
345 "TruthBoson",
346 "TruthCharm",
347 "TruthHFWithDecayParticles"]
348
349# Expects xAOD truth: on EVNT input, schedule HepMCtoXAODTruthCfg before it
351 """Truth augmentations of DAOD_PHYS that need only the truth record"""
352 acc = ComponentAccumulator()
353 acc.flagPerfmonDomain('Truth')
355 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig import DFCommonTruthCharmToolCfg
356 PhysCommonTruthCharmTool = acc.getPrimaryAndMerge(DFCommonTruthCharmToolCfg(
357 flags,
358 name = "PhysCommonTruthCharmTool"))
359 CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
360 acc.addEventAlgo(CommonAugmentation("PhysCommonTruthCharmKernel",AugmentationTools=[PhysCommonTruthCharmTool]))
361 acc.merge(AddHFAndDownstreamParticlesCfg(flags))
362 acc.merge(AddStandardTruthContentsCfg(flags, navInputCollections = PhysTruthNavigationCollections))
363 acc.merge(AddPVCollectionCfg(flags))
364 return acc
365
367 """Truth content that DAOD_PHYS adds to AddPhysTruthContentsCfg: HF classification,
368 Higgs truth categories, tau decay collections"""
369 acc = ComponentAccumulator()
370 acc.flagPerfmonDomain('Truth')
371 from DerivationFrameworkMCTruth.HFClassificationCommonConfig import HFClassificationCommonCfg
372 acc.merge(HFClassificationCommonCfg(flags))
373 from DerivationFrameworkHiggs.TruthCategoriesConfig import TruthCategoriesDecoratorCfg
374 acc.merge(TruthCategoriesDecoratorCfg(flags))
375 acc.merge(AddTauAndDownstreamParticlesCfg(flags))
376 return acc
377
379 """Truth content of DAOD_PHYS for the truth derivations (TRUTH1, TRUTH3)"""
380 acc = ComponentAccumulator()
381 acc.flagPerfmonDomain('Truth')
382 # The HepMC->xAOD conversion must run before the truth augmentations
383 # (merged again in AddStandardTruthContentsCfg, it is scheduled once)
384 acc.merge(HepMCtoXAODTruthCfg(flags))
385 acc.merge(AddPhysTruthContentsCfg(flags))
386 acc.merge(AddPhysTruthExtrasCfg(flags))
387 return acc
388
389# Add a one-vertex-per event "primary vertex" container
391 """Add a one-vertex-per event "primary vertex" container"""
392 acc = ComponentAccumulator()
393 acc.flagPerfmonDomain('Truth')
394 # Set up a tool to keep the primary vertices
395 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig import TruthPVCollectionMakerCfg
396 DFCommonTruthPVCollTool = acc.getPrimaryAndMerge(TruthPVCollectionMakerCfg(
397 flags,
398 name="DFCommonTruthPVCollTool",
399 NewCollectionName="TruthPrimaryVertices"))
400 acc.addEventAlgo(CompFactory.DerivationFramework.CommonAugmentation(
401 "MCTruthCommonTruthPVCollKernel",
402 AugmentationTools = [DFCommonTruthPVCollTool] ))
403 return acc
404
405
406# Add navigation decorations on the truth collections
407def AddTruthCollectionNavigationDecorationsCfg(flags, TruthCollections=[], prefix=''):
408 """Tool to add navigation decorations on the truth collections"""
409 acc = ComponentAccumulator()
410 acc.flagPerfmonDomain('Truth')
411 if len(TruthCollections) > 0:
412 # Set up a tool to add the navigation decorations
413 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig import TruthNavigationDecoratorCfg
414 DFCommonTruthNavigationDecorator = acc.getPrimaryAndMerge(TruthNavigationDecoratorCfg(flags,
415 name = prefix+'DFCommonTruthNavigationDecorator',
416 InputCollections = TruthCollections))
417 CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
418 acc.addEventAlgo(CommonAugmentation(prefix+"MCTruthNavigationDecoratorKernel",
419 AugmentationTools = [DFCommonTruthNavigationDecorator] ))
420 return acc
421
422# Add BSM particles and their downstream particles (immediate and further decay products) in a special collection
423def AddBSMAndDownstreamParticlesCfg(flags, generations=-1):
424 """Add BSM particles and their downstream particles in a special collection"""
425 acc = ComponentAccumulator()
426 acc.flagPerfmonDomain('Truth')
427 # Set up a tool to keep the taus and all downstream particles
428 collection_name = "TruthBSMWithDecay"
429 DFCommonBSMAndDecaysTool = acc.getPrimaryAndMerge(TruthDecayCollectionMakerCfg(flags,
430 name = "DFCommonBSMAndDecaysTool",
431 NewParticleKey = collection_name+'Particles',
432 NewVertexKey = collection_name+'Vertices',
433 KeepBSM = True,
434 Generations = generations))
435 CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
436 acc.addEventAlgo(CommonAugmentation(name = "MCTruthCommonBSMAndDecaysKernel",
437 AugmentationTools = [DFCommonBSMAndDecaysTool] ))
438 return acc
439
440# Add a mini-collection for the born leptons
441def AddBornLeptonCollectionCfg(flags):
442 """Add born leptons as a mini collection"""
443 acc = ComponentAccumulator()
444 acc.flagPerfmonDomain('Truth')
445 # Set up a tool to keep the taus and all downstream particles
446 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig import TruthBornLeptonCollectionMakerCfg
447 DFCommonBornLeptonCollTool = acc.getPrimaryAndMerge(TruthBornLeptonCollectionMakerCfg(flags,
448 name = "DFCommonBornLeptonCollTool",
449 NewCollectionName ="BornLeptons"))
450 CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
451 acc.addEventAlgo(CommonAugmentation("MCTruthCommonBornLeptonsKernel", AugmentationTools = [DFCommonBornLeptonCollTool] ))
452 return acc
453
454def AddLargeRJetD2Cfg(flags):
455 """Add large-R jet D2 variable"""
456 #Extra classifier for D2 variable
457 acc = ComponentAccumulator()
458 acc.flagPerfmonDomain('Truth')
459 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig import TruthD2DecoratorCfg
460 theTruthD2Decorator = acc.getPrimaryAndMerge(TruthD2DecoratorCfg(flags,
461 name = "TruthD2Decorator",
462 JetContainerKey = "AntiKt10TruthSoftDropBeta100Zcut10Jets",
463 DecorationName = "D2"))
464 TruthD2DecoratorKernel = CompFactory.DerivationFramework.CommonAugmentation
465 acc.addEventAlgo(TruthD2DecoratorKernel("TRUTHD2Kernel", AugmentationTools = [theTruthD2Decorator] ))
466 return acc
467
468
469def DFCommonTruthEDDecoratorCfg(flags, name="DFCommonTruthEDDecorator", **kwargs):
470 """Truth energy density decorator"""
471 acc = ComponentAccumulator()
472 acc.flagPerfmonDomain('Truth')
473 kwargs.setdefault("EventInfoName", "EventInfo")
474 kwargs.setdefault("EventShapeKeys", ["TruthIsoCentralEventShape","TruthIsoForwardEventShape"])
475 suffix = kwargs.pop("DecorationSuffix", "_rho")
476 kwargs.setdefault("EnergyDensityDecorKeys", [ x + suffix for x in kwargs["EventShapeKeys"] ])
477 acc.setPrivateTools(CompFactory.DerivationFramework.TruthEDDecorator(name, **kwargs))
478 return acc
479
480
481# Truth energy density tools
482def DFCommonTruthCentralEDAlgCfg(flags):
483 """ """
484 acc = ComponentAccumulator()
485 acc.flagPerfmonDomain('Truth')
486 from EventShapeTools.EventDensityConfig import configEventDensityTool
487 from JetRecConfig.StandardJetConstits import stdConstitDic as cst
488 DFCommonTruthCentralEDTool = configEventDensityTool("DFCommonTruthCentralEDTool",
489 cst.Truth,
490 0.5,
491 AbsRapidityMax = 1.5,
492 OutputContainer = "TruthIsoCentralEventShape",
493 )
494 acc.addEventAlgo(CompFactory.EventDensityAthAlg("DFCommonTruthCentralEDAlg",
495 EventDensityTool = DFCommonTruthCentralEDTool ))
496 return acc
497
498
499def DFCommonTruthForwardEDAlgCfg(flags):
500 """ """
501 acc = ComponentAccumulator()
502 acc.flagPerfmonDomain('Truth')
503 from EventShapeTools.EventDensityConfig import configEventDensityTool
504 from JetRecConfig.StandardJetConstits import stdConstitDic as cst
505 DFCommonTruthForwardEDTool = configEventDensityTool("DFCommonTruthForwardEDTool",
506 cst.Truth,
507 0.5,
508 AbsRapidityMin = 1.5,
509 AbsRapidityMax = 3.0,
510 OutputContainer = "TruthIsoForwardEventShape",
511 )
512 acc.addEventAlgo(CompFactory.EventDensityAthAlg("DFCommonTruthForwardEDAlg",
513 EventDensityTool = DFCommonTruthForwardEDTool ))
514 return acc
515
516
517def AddTruthEnergyDensityCfg(flags):
518 """Truth energy density tools"""
519 acc = ComponentAccumulator()
520 acc.flagPerfmonDomain('Truth')
521 # Algorithms for the energy density - needed only if e/gamma hasn't set things up already
522 acc.merge(DFCommonTruthCentralEDAlgCfg(flags))
523 acc.merge(DFCommonTruthForwardEDAlgCfg(flags))
524
525 DFCommonTruthEDKernel = CompFactory.DerivationFramework.CommonAugmentation("DFCommonTruthEDKernel",
526 AugmentationTools =
527 [acc.addPublicTool(acc.popToolsAndMerge(DFCommonTruthEDDecoratorCfg(flags)))] )
528 acc.addEventAlgo(DFCommonTruthEDKernel)
529 return acc
530
531
532# Sets up modifiers to move pointers to old truth collections to new mini truth collections
533def AddMiniTruthCollectionLinksCfg(flags, **kwargs):
534 """Tool to move pointers to new mini truth collections"""
535 acc = ComponentAccumulator()
536 acc.flagPerfmonDomain('Truth')
537 kwargs.setdefault("doElectrons",True)
538 kwargs.setdefault("doPhotons",True)
539 kwargs.setdefault("doMuons",True)
540 aug_tools = []
541 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig import TruthLinkRepointToolCfg
542 if kwargs['doElectrons']:
543 electron_relink = acc.getPrimaryAndMerge(TruthLinkRepointToolCfg(
544 flags,
545 name="ElMiniCollectionTruthLinkTool",
546 RecoCollection="Electrons",
547 TargetCollections=["TruthMuons","TruthPhotons","TruthElectrons"]))
548 aug_tools += [ electron_relink ]
549 if kwargs['doPhotons']:
550 photon_relink = acc.getPrimaryAndMerge(TruthLinkRepointToolCfg(
551 flags,
552 name="PhMiniCollectionTruthLinkTool",
553 RecoCollection="Photons",
554 TargetCollections=["TruthMuons","TruthPhotons","TruthElectrons"]))
555 aug_tools += [ photon_relink ]
556 if kwargs['doMuons']:
557 muon_relink = acc.getPrimaryAndMerge(TruthLinkRepointToolCfg(
558 flags,
559 name="MuMiniCollectionTruthLinkTool",
560 RecoCollection="Muons",
561 TargetCollections=["TruthMuons","TruthPhotons","TruthElectrons"]))
562 aug_tools += [ muon_relink ]
563 for i, tool in enumerate(aug_tools):
564 acc.addEventAlgo(CompFactory.DerivationFramework.CommonAugmentation(
565 "MiniCollectionTruthLinkKernelNo{num}".format(num=i+1),
566 AugmentationTools = [tool] ))
567 return acc
568
569
570def addTruth3ContentToSlimmerTool(slimmer, reduced=False):
571 slimmer.ExtraVariables += [
572 f"AntiKt4TruthDressedWZJets.GhostCHadronsFinalCount.GhostBHadronsFinalCount.pt.eta.phi.m.numConstit.HadronConeExclTruthLabelID.HadronConeExclExtendedTruthLabelID.{'HadronConeExclTruthLabelPdgId.HadronGhostTruthLabelID.HadronGhostExtendedTruthLabelID.' if not reduced else ''}PartonTruthLabelID.TrueFlavor",
573 "AntiKt10TruthSoftDropBeta100Zcut10Jets.pt.eta.phi.m.Tau1_wta.Tau2_wta.Tau3_wta.D2.numConstit",
574 "TruthEvents.Q.XF1.XF2.PDGID1.PDGID2.PDFID1.PDFID2.X1.X2.crossSection",
575 "MET_Truth.mpx.mpy.sumet.name.source",
576 "TruthElectrons.prodVtxLink.decayVtxLink.parentLinks.childLinks.m.px.py.pz.e.pdgId.ptcone30.etcone20.classifierParticleOrigin.Classification.status.classifierParticleType.classifierParticleOutCome.polarizationPhi.polarizationTheta.e_dressed.pt_dressed.eta_dressed.phi_dressed.nPhotons_dressed.uid",
577 "TruthMuons.m.px.py.pz.e.pdgId.status.classifierParticleOrigin.classifierParticleType.classifierParticleOutCome.Classification.e_dressed.pt_dressed.eta_dressed.phi_dressed.nPhotons_dressed.ptcone30.etcone20.decayVtxLink.prodVtxLink.parentLinks.childLinks.polarizationPhi.polarizationTheta.uid",
578 "TruthPhotons.m.px.py.pz.e.pdgId.status.classifierParticleOrigin.classifierParticleType.classifierParticleOutCome.Classification.ptcone20.etcone20.etcone40.prodVtxLink.decayVtxLink.parentLinks.childLinks.polarizationPhi.polarizationTheta.uid",
579 "TruthTaus.prodVtxLink.decayVtxLink.parentLinks.childLinks.m.px.py.pz.e.pdgId.classifierParticleOrigin.Classification.pt_vis.eta_vis.phi_vis.m_vis.status.classifierParticleType.classifierParticleOutCome.originalTruthParticle.polarizationPhi.polarizationTheta.pt_vis_dressed.eta_vis_dressed.phi_vis_dressed.m_vis_dressed.nPhotons_dressed.numCharged.numChargedPion.numNeutral.numNeutralPion.IsHadronicTau.pt_invis.eta_invis.phi_invis.m_invis.pt_vis_neutral.eta_vis_neutral.phi_vis_neutral.m_vis_neutral.DecayModeVector.decay_vertex_x.decay_vertex_y.decay_vertex_z.prod_vertex_x.prod_vertex_y.prod_vertex_z.uid",
580 "TruthNeutrinos.m.px.py.pz.e.pdgId.status.classifierParticleOrigin.classifierParticleType.classifierParticleOutCome.Classification.prodVtxLink.decayVtxLink.parentLinks.childLinks.polarizationPhi.polarizationTheta.uid",
581 "TruthBSM.childLinks.Classification.classifierParticleOrigin.classifierParticleOutCome.classifierParticleType.decayVtxLink.e.m.parentLinks.pdgId.polarizationPhi.polarizationTheta.prodVtxLink.px.py.pz.status.uid",
582 "TruthBottom.m.px.py.pz.e.pdgId.status.classifierParticleOrigin.classifierParticleType.classifierParticleOutCome.Classification.prodVtxLink.decayVtxLink.parentLinks.childLinks.polarizationPhi.polarizationTheta.uid",
583 "TruthTop.m.px.py.pz.e.pdgId.status.prodVtxLink.decayVtxLink.parentLinks.childLinks.classifierParticleOrigin.classifierParticleType.classifierParticleOutCome.Classification.polarizationPhi.polarizationTheta.uid",
584 "TruthBoson.m.px.py.pz.e.pdgId.status.classifierParticleOrigin.classifierParticleType.classifierParticleOutCome.Classification.prodVtxLink.decayVtxLink.parentLinks.childLinks.polarizationPhi.polarizationTheta.uid",
585 "TruthForwardProtons.m.px.py.pz.e.pdgId.status.classifierParticleOrigin.classifierParticleType.classifierParticleOutCome.Classification.prodVtxLink.decayVtxLink.polarizationPhi.polarizationTheta.uid",
586 "BornLeptons.prodVtxLink.decayVtxLink.m.px.py.pz.e.pdgId.classifierParticleOrigin.Classification.status.classifierParticleType.classifierParticleOutCome.polarizationPhi.polarizationTheta.uid",
587 "TruthBosonsWithDecayParticles.m.px.py.pz.e.pdgId.status.classifierParticleOrigin.classifierParticleType.classifierParticleOutCome.Classification.id.x.y.z.t.prodVtxLink.decayVtxLink.incomingParticleLinks.outgoingParticleLinks.uid",
588 "TruthBosonsWithDecayVertices.id.x.y.z.t.prodVtxLink.decayVtxLink.incomingParticleLinks.outgoingParticleLinks.uid.status",
589 "TruthBSMWithDecayParticles.Classification.classifierParticleOrigin.classifierParticleOutCome.classifierParticleType.decayVtxLink.e.m.pdgId.prodVtxLink.px.py.pz.status.uid",
590 "TruthBSMWithDecayVertices.id.incomingParticleLinks.outgoingParticleLinks.t.x.y.z.uid"
591 ]
592
593
594# Truth slimming of DAOD_PHYS that needs only the truth record
595def addPhysTruthContentToSlimmerTool(slimmer):
596 addTruth3ContentToSlimmerTool(slimmer)
597 slimmer.AllVariables += ['TruthLHEParticles']
598 slimmer.ExtraVariables += [
599 "AntiKt4TruthDressedWZJets.IsoFixedCone5Pt.HFHadronOriginID",
600 # Truth large-R jets: PHYS gets these from the smart slimming of the reco UFO large-R jets
601 # (AntiKt10UFOCSSKSoftDropBeta100Zcut10JetsCPContent.py), which TRUTH3 does not have
602 "AntiKt10TruthSoftDropBeta100Zcut10Jets.pt.eta.phi.m.Parent.numConstit.D2.Tau1_wta.Tau2_wta.Tau3_wta.Qw.GhostCHadronsFinalCount.GhostBHadronsFinalCount",
603 "AntiKt10TruthJets.pt.eta.phi.m.numConstit.Split12.Split23.GhostCHadronsFinalCount.GhostBHadronsFinalCount",
604 "TruthPrimaryVertices.t.x.y.z",
605 "TruthHFWithDecayParticles.prodVtxLink.prodVtxLink.prodVtxLink.decayVtxLink.decayVtxLink.decayVtxLink.parentLinks.childLinks.m.px.py.pz.e.pdgId.Classification.uid.classifierParticleOrigin.classifierParticleType.classifierParticleOutCome.status",
606 "TruthHFWithDecayVertices.incomingParticleLinks.outgoingParticleLinks.uid.status.x.y.z.t",
607 "TruthCharm.prodVtxLink.prodVtxLink.prodVtxLink.decayVtxLink.decayVtxLink.decayVtxLink.parentLinks.childLinks.m.px.py.pz.e.pdgId.Classification.uid.classifierParticleOrigin.classifierParticleType.classifierParticleOutCome.status.polarizationPhi.polarizationTheta",
608 "TruthTausWithDecayParticles.prodVtxLink.prodVtxLink.prodVtxLink.decayVtxLink.decayVtxLink.decayVtxLink.m.px.py.pz.e.pdgId.Classification.uid.classifierParticleOrigin.classifierParticleType.classifierParticleOutCome.status",
609 "TruthTausWithDecayVertices.incomingParticleLinks.outgoingParticleLinks.uid.status.x.y.z.t"
610 ]
STL class.
TruthClassificationAugmentationsCfg(flags, **kwargs)
AddBSMAndDownstreamParticlesCfg(flags, generations=-1)
AddBosonsAndDownstreamParticlesCfg(flags, generations=1, rejectHadronChildren=False)
Add taus and their downstream particles (immediate and further decay products) in a special collectio...
AddHFAndDownstreamParticlesCfg(flags, **kwargs)
Add electrons, photons, and their downstream particles in a special collection def addEgammaAndDownst...
PostJetMCTruthAugmentationsCfg(flags, **kwargs)
AddTruthCollectionNavigationDecorationsCfg(flags, TruthCollections=[], prefix='')
PreJetMCTruthAugmentationsCfg(flags, **kwargs)
AddTauAndDownstreamParticlesCfg(flags, generations=-1, rejectHadronChildren=False)
AddParentAndDownstreamParticlesCfg(flags, generations=1, parents=[6], prefix='TopQuark', collection_prefix=None, rejectHadronChildren=False)
AddStandardTruthContentsCfg(flags, decorationDressing='dressedPhoton', includeTausInDressingPhotonRemoval=False, navInputCollections=["TruthElectrons", "TruthMuons", "TruthPhotons", "TruthTaus", "TruthNeutrinos", "TruthBSM", "TruthBottom", "TruthTop", "TruthBoson"], prefix='')
AddTopQuarkAndDownstreamParticlesCfg(flags, generations=1, rejectHadronChildren=False)