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]))
20 """Conversion of HepMC to xAOD truth"""
21 acc = ComponentAccumulator()
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")
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))
36 from xAODEventInfoCnv.xAODEventInfoCnvConfig
import EventInfoUpdateFromContextAlgCfg
37 acc.merge(EventInfoUpdateFromContextAlgCfg(flags, disableBeamSpot=
True))
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"))
46 elif "McEventCollection#TruthEvent" in flags.Input.TypedCollections:
47 acc.merge(GEN_EVNT2xAODCfg(flags,name=
"GEN_EVNT2xAOD",AODContainerName=
"TruthEvent"))
51 elif "xAOD::TruthEventContainer#TruthEvents" in flags.Input.TypedCollections:
54 raise RuntimeError(
"No recognised HepMC truth information found in the input")
57 if "TruthMetaDataContainer#TruthMetaData" not in flags.Input.TypedCollections
and not isEVNT:
67 acc = ComponentAccumulator()
69 from JetRecConfig.StandardSmallRJets
import AntiKt4Truth,AntiKt4TruthWZ,AntiKt4TruthDressedWZ,AntiKtVRTruthCharged
70 from JetRecConfig.StandardLargeRJets
import AntiKt10TruthSoftDrop
71 from JetRecConfig.JetRecConfig
import JetRecCfg
73 inputCollections =
set(flags.Input.Collections)
74 jetList = [AntiKt4Truth,AntiKt4TruthWZ,AntiKt4TruthDressedWZ,AntiKtVRTruthCharged,
75 AntiKt10TruthSoftDrop]
79 expectedName = jd.fullname().encode(
"utf-8")
80 if expectedName
in inputCollections:
82 acc.merge(JetRecCfg(flags, jd))
114 augmentationToolsList = []
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 )
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)))
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'])))
139 for i, tool
in enumerate(augmentationToolsList):
140 acc.addEventAlgo(CompFactory.DerivationFramework.CommonAugmentation(name =
"MCTruthCommonPreJetKernelNo{num}".format(num = i+1), AugmentationTools = [tool]))
147 acc = ComponentAccumulator()
151 from DerivationFrameworkTau.TauTruthCommonConfig
import TauTruthToolsCfg
152 acc.merge(TauTruthToolsCfg(flags))
153 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import DFCommonTruthTauDressingToolCfg
154 augmentationToolsList = [ acc.getPrimaryAndMerge(DFCommonTruthTauDressingToolCfg(flags)) ]
157 from DerivationFrameworkMCTruth.GenFilterToolConfig
import GenFilterToolCfg
159 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import DFCommonTruthDressedWZQGLabelToolCfg
160 augmentationToolsList += [ acc.addPublicTool(acc.popToolsAndMerge(GenFilterToolCfg(flags))),
161 acc.getPrimaryAndMerge(DFCommonTruthDressedWZQGLabelToolCfg(flags))]
164 from DerivationFrameworkSUSY.DecorateSUSYProcessConfig
import IsSUSYSignalRun3
165 if IsSUSYSignalRun3(flags):
166 from DerivationFrameworkSUSY.DecorateSUSYProcessConfig
import SUSYSignalTaggerCfg
167 augmentationToolsList += [ acc.getPrimaryAndMerge(SUSYSignalTaggerCfg(flags,
'MCTruthCommon')) ]
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]))
175 if IsSUSYSignalRun3(flags):
176 from DerivationFrameworkSUSY.SUSYWeightMetadataConfig
import AddSUSYWeightsCfg
177 acc.merge(AddSUSYWeightsCfg(flags))
183 decorationDressing='dressedPhoton',
184 includeTausInDressingPhotonRemoval=False,
185 navInputCollections = ["TruthElectrons", "TruthMuons", "TruthPhotons", "TruthTaus", "TruthNeutrinos", "TruthBSM", "TruthBottom", "TruthTop", "TruthBoson"],
188 acc = ComponentAccumulator()
195 if "McEventCollection#GEN_EVENT" in flags.Input.TypedCollections: isEVNT =
True
204 if includeTausInDressingPhotonRemoval:
205 acc.getPublicTool(
"DFCommonTruthTauDressingTool").decorationName=decorationDressing+
"_tau"
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'
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] ))
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",
'')
319 collection_name = kwargs[
'prefix']+
"TruthHFWithDecay"
320 DFCommonHFAndDecaysTool = acc.getPrimaryAndMerge(TruthDecayCollectionMakerCfg(
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] ))
351def AddTruthCollectionNavigationDecorationsCfg(flags, TruthCollections=[], prefix=''):
352 """Tool to add navigation decorations on the truth collections"""
353 acc = ComponentAccumulator()
354 if len(TruthCollections) > 0:
355 # Set up a tool to add the navigation decorations
356 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig import TruthNavigationDecoratorCfg
357 DFCommonTruthNavigationDecorator = acc.getPrimaryAndMerge(TruthNavigationDecoratorCfg(flags,
358 name = prefix+'DFCommonTruthNavigationDecorator',
359 InputCollections = TruthCollections))
360 CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
361 acc.addEventAlgo(CommonAugmentation(prefix+"MCTruthNavigationDecoratorKernel",
362 AugmentationTools = [DFCommonTruthNavigationDecorator] ))
365# Add BSM particles and their downstream particles (immediate and further decay products) in a special collection
366def AddBSMAndDownstreamParticlesCfg(flags, generations=-1):
367 """Add BSM particles and their downstream particles in a special collection"""
368 acc = ComponentAccumulator()
369 # Set up a tool to keep the taus and all downstream particles
370 collection_name = "TruthBSMWithDecay"
371 DFCommonBSMAndDecaysTool = acc.getPrimaryAndMerge(TruthDecayCollectionMakerCfg(flags,
372 name = "DFCommonBSMAndDecaysTool",
373 NewParticleKey = collection_name+'Particles',
374 NewVertexKey = collection_name+'Vertices',
376 Generations = generations))
377 CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
378 acc.addEventAlgo(CommonAugmentation(name = "MCTruthCommonBSMAndDecaysKernel",
379 AugmentationTools = [DFCommonBSMAndDecaysTool] ))
382# Add a mini-collection for the born leptons
383def AddBornLeptonCollectionCfg(flags):
384 """Add born leptons as a mini collection"""
385 acc = ComponentAccumulator()
386 # Set up a tool to keep the taus and all downstream particles
387 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig import TruthBornLeptonCollectionMakerCfg
388 DFCommonBornLeptonCollTool = acc.getPrimaryAndMerge(TruthBornLeptonCollectionMakerCfg(flags,
389 name = "DFCommonBornLeptonCollTool",
390 NewCollectionName ="BornLeptons"))
391 CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
392 acc.addEventAlgo(CommonAugmentation("MCTruthCommonBornLeptonsKernel", AugmentationTools = [DFCommonBornLeptonCollTool] ))
395def AddLargeRJetD2Cfg(flags):
396 """Add large-R jet D2 variable"""
397 #Extra classifier for D2 variable
398 acc = ComponentAccumulator()
399 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig import TruthD2DecoratorCfg
400 theTruthD2Decorator = acc.getPrimaryAndMerge(TruthD2DecoratorCfg(flags,
401 name = "TruthD2Decorator",
402 JetContainerKey = "AntiKt10TruthSoftDropBeta100Zcut10Jets",
403 DecorationName = "D2"))
404 TruthD2DecoratorKernel = CompFactory.DerivationFramework.CommonAugmentation
405 acc.addEventAlgo(TruthD2DecoratorKernel("TRUTHD2Kernel", AugmentationTools = [theTruthD2Decorator] ))
421def DFCommonTruthCentralEDAlgCfg(flags):
423 acc = ComponentAccumulator()
424 from EventShapeTools.EventDensityConfig import configEventDensityTool
425 from JetRecConfig.StandardJetConstits import stdConstitDic as cst
426 DFCommonTruthCentralEDTool = configEventDensityTool("DFCommonTruthCentralEDTool",
429 AbsRapidityMax = 1.5,
430 OutputContainer = "TruthIsoCentralEventShape",
432 acc.addEventAlgo(CompFactory.EventDensityAthAlg("DFCommonTruthCentralEDAlg",
433 EventDensityTool = DFCommonTruthCentralEDTool ))
437def DFCommonTruthForwardEDAlgCfg(flags):
439 acc = ComponentAccumulator()
440 from EventShapeTools.EventDensityConfig import configEventDensityTool
441 from JetRecConfig.StandardJetConstits import stdConstitDic as cst
442 DFCommonTruthForwardEDTool = configEventDensityTool("DFCommonTruthForwardEDTool",
445 AbsRapidityMin = 1.5,
446 AbsRapidityMax = 3.0,
447 OutputContainer = "TruthIsoForwardEventShape",
449 acc.addEventAlgo(CompFactory.EventDensityAthAlg("DFCommonTruthForwardEDAlg",
450 EventDensityTool = DFCommonTruthForwardEDTool ))
454def AddTruthEnergyDensityCfg(flags):
455 """Truth energy density tools"""
456 acc = ComponentAccumulator()
457 # Algorithms for the energy density - needed only if e/gamma hasn't set things up already
458 acc.merge(DFCommonTruthCentralEDAlgCfg(flags))
459 acc.merge(DFCommonTruthForwardEDAlgCfg(flags))
461 DFCommonTruthEDKernel = CompFactory.DerivationFramework.CommonAugmentation("DFCommonTruthEDKernel",
463 [acc.addPublicTool(acc.popToolsAndMerge(DFCommonTruthEDDecoratorCfg(flags)))] )
464 acc.addEventAlgo(DFCommonTruthEDKernel)
468# Sets up modifiers to move pointers to old truth collections to new mini truth collections
469def AddMiniTruthCollectionLinksCfg(flags, **kwargs):
470 """Tool to move pointers to new mini truth collections"""
471 acc = ComponentAccumulator()
472 kwargs.setdefault("doElectrons",True)
473 kwargs.setdefault("doPhotons",True)
474 kwargs.setdefault("doMuons",True)
476 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig import TruthLinkRepointToolCfg
477 if kwargs['doElectrons']:
478 electron_relink = acc.getPrimaryAndMerge(TruthLinkRepointToolCfg(
480 name="ElMiniCollectionTruthLinkTool",
481 RecoCollection="Electrons",
482 TargetCollections=["TruthMuons","TruthPhotons","TruthElectrons"]))
483 aug_tools += [ electron_relink ]
484 if kwargs['doPhotons']:
485 photon_relink = acc.getPrimaryAndMerge(TruthLinkRepointToolCfg(
487 name="PhMiniCollectionTruthLinkTool",
488 RecoCollection="Photons",
489 TargetCollections=["TruthMuons","TruthPhotons","TruthElectrons"]))
490 aug_tools += [ photon_relink ]
491 if kwargs['doMuons']:
492 muon_relink = acc.getPrimaryAndMerge(TruthLinkRepointToolCfg(
494 name="MuMiniCollectionTruthLinkTool",
495 RecoCollection="Muons",
496 TargetCollections=["TruthMuons","TruthPhotons","TruthElectrons"]))
497 aug_tools += [ muon_relink ]
498 for i, tool in enumerate(aug_tools):
499 acc.addEventAlgo(CompFactory.DerivationFramework.CommonAugmentation(
500 "MiniCollectionTruthLinkKernelNo{num}".format(num=i+1),
501 AugmentationTools = [tool] ))
505def addTruth3ContentToSlimmerTool(slimmer):
506 slimmer.ExtraVariables += [
507 "AntiKt4TruthDressedWZJets.GhostCHadronsFinalCount.GhostBHadronsFinalCount.pt.HadronConeExclTruthLabelID.PartonTruthLabelID.TrueFlavor",
508 "AntiKt10TruthSoftDropBeta100Zcut10Jets.pt.Tau1_wta.Tau2_wta.Tau3_wta.D2",
509 "TruthEvents.Q.XF1.XF2.PDGID1.PDGID2.PDFID1.PDFID2.X1.X2.crossSection",
510 "MET_Truth.mpx.mpy.sumet.name.source",
511 "TruthElectrons.prodVtxLink.decayVtxLink.parentLinks.childLinks.m.px.py.pz.e.pdgId.ptcone30.etcone20.classifierParticleOrigin.Classification.barcode.status.classifierParticleType.classifierParticleOutCome.polarizationPhi.polarizationTheta.e_dressed.pt_dressed.eta_dressed.phi_dressed.nPhotons_dressed.uid",
512 "TruthMuons.m.px.py.pz.e.pdgId.barcode.status.classifierParticleOrigin.classifierParticleType.classifierParticleOutCome.Classification.e_dressed.pt_dressed.eta_dressed.phi_dressed.nPhotons_dressed.ptcone30.etcone20.decayVtxLink.prodVtxLink.parentLinks.childLinks.polarizationPhi.polarizationTheta.uid",
513 "TruthPhotons.m.px.py.pz.e.pdgId.barcode.status.classifierParticleOrigin.classifierParticleType.classifierParticleOutCome.Classification.ptcone20.etcone20.etcone40.prodVtxLink.decayVtxLink.parentLinks.childLinks.polarizationPhi.polarizationTheta.uid",
514 "TruthTaus.prodVtxLink.decayVtxLink.parentLinks.childLinks.m.px.py.pz.e.pdgId.classifierParticleOrigin.Classification.pt_vis.eta_vis.phi_vis.m_vis.barcode.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",
515 "TruthNeutrinos.m.px.py.pz.e.pdgId.barcode.status.classifierParticleOrigin.classifierParticleType.classifierParticleOutCome.Classification.prodVtxLink.decayVtxLink.parentLinks.childLinks.polarizationPhi.polarizationTheta.uid",
516 "TruthBSM.barcode.childLinks.Classification.classifierParticleOrigin.classifierParticleOutCome.classifierParticleType.decayVtxLink.e.m.parentLinks.pdgId.polarizationPhi.polarizationTheta.prodVtxLink.px.py.pz.status",
517 "TruthBottom.m.px.py.pz.e.pdgId.barcode.status.classifierParticleOrigin.classifierParticleType.classifierParticleOutCome.Classification.prodVtxLink.decayVtxLink.parentLinks.childLinks.polarizationPhi.polarizationTheta.uid",
518 "TruthTop.m.px.py.pz.e.pdgId.barcode.status.prodVtxLink.decayVtxLink.parentLinks.childLinks.classifierParticleOrigin.classifierParticleType.classifierParticleOutCome.Classification.polarizationPhi.polarizationTheta.uid",
519 "TruthBoson.m.px.py.pz.e.pdgId.barcode.status.classifierParticleOrigin.classifierParticleType.classifierParticleOutCome.Classification.prodVtxLink.decayVtxLink.parentLinks.childLinks.polarizationPhi.polarizationTheta.uid",
520 "TruthForwardProtons.m.px.py.pz.e.pdgId.barcode.status.classifierParticleOrigin.classifierParticleType.classifierParticleOutCome.Classification.prodVtxLink.decayVtxLink.polarizationPhi.polarizationTheta.uid",
521 "BornLeptons.prodVtxLink.decayVtxLink.m.px.py.pz.e.pdgId.classifierParticleOrigin.Classification.barcode.status.classifierParticleType.classifierParticleOutCome.polarizationPhi.polarizationTheta.uid",
522 "TruthBosonsWithDecayParticles.m.px.py.pz.e.pdgId.barcode.status.classifierParticleOrigin.classifierParticleType.classifierParticleOutCome.Classification.barcode.id.x.y.z.t.prodVtxLink.decayVtxLink.incomingParticleLinks.outgoingParticleLinks.uid",
523 "TruthBosonsWithDecayVertices.barcode.id.x.y.z.t.prodVtxLink.decayVtxLink.incomingParticleLinks.outgoingParticleLinks.uid.status",
524 "TruthBSMWithDecayParticles.barcode.Classification.classifierParticleOrigin.classifierParticleOutCome.classifierParticleType.decayVtxLink.e.m.pdgId.prodVtxLink.px.py.pz.status.uid",
525 "TruthBSMWithDecayVertices.barcode.id.incomingParticleLinks.outgoingParticleLinks.t.x.y.z.uid"
AddStandardTruthContentsCfg(flags, decorationDressing='dressedPhoton', includeTausInDressingPhotonRemoval=False, navInputCollections=["TruthElectrons", "TruthMuons", "TruthPhotons", "TruthTaus", "TruthNeutrinos", "TruthBSM", "TruthBottom", "TruthTop", "TruthBoson"], prefix='')