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