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:
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=
"EventInfo", disableBeamSpot=
True))
38 from xAODTruthCnv.xAODTruthCnvConfig
import GEN_EVNT2xAODCfg
39 if "McEventCollection#GEN_EVENT" in flags.Input.TypedCollections:
40 acc.merge(GEN_EVNT2xAODCfg(flags,name=
"GEN_EVNT2xAOD",AODContainerName=
"GEN_EVENT"))
43 elif "McEventCollection#TruthEvent" in flags.Input.TypedCollections:
44 acc.merge(GEN_EVNT2xAODCfg(flags,name=
"GEN_EVNT2xAOD",AODContainerName=
"TruthEvent"))
48 elif "xAOD::TruthEventContainer#TruthEvents" in flags.Input.TypedCollections:
51 raise RuntimeError(
"No recognised HepMC truth information found in the input")
54 if "TruthMetaDataContainer#TruthMetaData" not in flags.Input.TypedCollections
and not isEVNT:
64 acc = ComponentAccumulator()
66 from JetRecConfig.StandardSmallRJets
import AntiKt4Truth,AntiKt4TruthWZ,AntiKt4TruthDressedWZ,AntiKtVRTruthCharged
67 from JetRecConfig.StandardLargeRJets
import AntiKt10TruthSoftDrop
68 from JetRecConfig.JetRecConfig
import JetRecCfg
70 inputCollections =
set(flags.Input.Collections)
71 jetList = [AntiKt4Truth,AntiKt4TruthWZ,AntiKt4TruthDressedWZ,AntiKtVRTruthCharged,
72 AntiKt10TruthSoftDrop]
76 expectedName = jd.fullname().encode(
"utf-8")
77 if expectedName
in inputCollections:
79 acc.merge(JetRecCfg(flags, jd))
111 augmentationToolsList = []
116 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import ( DFCommonTruthElectronDressingToolCfg,
117 DFCommonTruthMuonDressingToolCfg, DFCommonTruthMuonToolCfg, DFCommonTruthElectronToolCfg,
118 DFCommonTruthPhotonToolSimCfg, DFCommonTruthNeutrinoToolCfg, DFCommonTruthBottomToolCfg, DFCommonTruthTopToolCfg,
119 DFCommonTruthBosonToolCfg, DFCommonTruthBSMToolCfg, DFCommonTruthForwardProtonToolCfg, DFCommonTruthElectronIsolationTool1Cfg,
120 DFCommonTruthElectronIsolationTool2Cfg, DFCommonTruthMuonIsolationTool1Cfg, DFCommonTruthMuonIsolationTool2Cfg,
121 DFCommonTruthPhotonIsolationTool1Cfg, DFCommonTruthPhotonIsolationTool2Cfg, DFCommonTruthPhotonIsolationTool3Cfg )
124 for item
in [ DFCommonTruthMuonToolCfg, DFCommonTruthElectronToolCfg,
125 DFCommonTruthPhotonToolSimCfg, DFCommonTruthNeutrinoToolCfg, DFCommonTruthBottomToolCfg, DFCommonTruthTopToolCfg,
126 DFCommonTruthBosonToolCfg, DFCommonTruthBSMToolCfg, DFCommonTruthElectronIsolationTool1Cfg,
127 DFCommonTruthElectronIsolationTool2Cfg, DFCommonTruthMuonIsolationTool1Cfg, DFCommonTruthMuonIsolationTool2Cfg,
128 DFCommonTruthPhotonIsolationTool1Cfg, DFCommonTruthPhotonIsolationTool2Cfg, DFCommonTruthPhotonIsolationTool3Cfg]:
129 augmentationToolsList.append(acc.getPrimaryAndMerge(item(flags)))
130 augmentationToolsList.append(acc.getPrimaryAndMerge(DFCommonTruthForwardProtonToolCfg(flags)))
132 if 'decorationDressing' in kwargs:
133 augmentationToolsList.append(acc.getPrimaryAndMerge(DFCommonTruthElectronDressingToolCfg(flags, decorationName = kwargs[
'decorationDressing'])))
134 augmentationToolsList.append(acc.getPrimaryAndMerge(DFCommonTruthMuonDressingToolCfg(flags, decorationName = kwargs[
'decorationDressing'])))
136 for i, tool
in enumerate(augmentationToolsList):
137 acc.addEventAlgo(CompFactory.DerivationFramework.CommonAugmentation(name =
"MCTruthCommonPreJetKernelNo{num}".format(num = i+1), AugmentationTools = [tool]))
144 acc = ComponentAccumulator()
148 from DerivationFrameworkTau.TauTruthCommonConfig
import TauTruthToolsCfg
149 acc.merge(TauTruthToolsCfg(flags))
150 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import DFCommonTruthTauDressingToolCfg
151 augmentationToolsList = [ acc.getPrimaryAndMerge(DFCommonTruthTauDressingToolCfg(flags)) ]
154 from DerivationFrameworkMCTruth.GenFilterToolConfig
import GenFilterToolCfg
156 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import DFCommonTruthDressedWZQGLabelToolCfg
157 augmentationToolsList += [ acc.addPublicTool(acc.popToolsAndMerge(GenFilterToolCfg(flags))),
158 acc.getPrimaryAndMerge(DFCommonTruthDressedWZQGLabelToolCfg(flags))]
161 from DerivationFrameworkSUSY.DecorateSUSYProcessConfig
import IsSUSYSignalRun3
162 if IsSUSYSignalRun3(flags):
163 from DerivationFrameworkSUSY.DecorateSUSYProcessConfig
import SUSYSignalTaggerCfg
164 augmentationToolsList += [ acc.getPrimaryAndMerge(SUSYSignalTaggerCfg(flags,
'MCTruthCommon')) ]
166 CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
167 for i, tool
in enumerate(augmentationToolsList):
168 acc.addEventAlgo(CommonAugmentation(name =
"MCTruthCommonPostJetKernelNo{num}".format(num = i+1),
169 AugmentationTools = [tool]))
172 if IsSUSYSignalRun3(flags):
173 from DerivationFrameworkSUSY.SUSYWeightMetadataConfig
import AddSUSYWeightsCfg
174 acc.merge(AddSUSYWeightsCfg(flags))
180 decorationDressing='dressedPhoton',
181 includeTausInDressingPhotonRemoval=False,
182 navInputCollections = ["TruthElectrons", "TruthMuons", "TruthPhotons", "TruthTaus", "TruthNeutrinos", "TruthBSM", "TruthBottom", "TruthTop", "TruthBoson"],
185 acc = ComponentAccumulator()
192 if "McEventCollection#GEN_EVENT" in flags.Input.TypedCollections: isEVNT =
True
201 if includeTausInDressingPhotonRemoval:
202 acc.getPublicTool(
"DFCommonTruthTauDressingTool").decorationName=decorationDressing+
"_tau"
222 collection_prefix=None,
223 rejectHadronChildren=False):
224 """Configure tools for adding immediate parents and descendants"""
225 acc = ComponentAccumulator()
226 collection_name=collection_prefix+
'WithDecay' if collection_prefix
is not None else 'Truth'+prefix+
'WithDecay'
228 collection_maker = acc.getPrimaryAndMerge(TruthDecayCollectionMakerCfg(flags,
229 name =
'DFCommon'+prefix+
'AndDecaysTool',
230 NewParticleKey = collection_name+
'Particles',
231 NewVertexKey = collection_name+
'Vertices',
232 PDGIDsToKeep = parents,
233 Generations = generations,
234 RejectHadronChildren = rejectHadronChildren))
235 CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
236 kernel_name =
'MCTruthCommon'+prefix+
'AndDecaysKernel'
237 acc.addEventAlgo(CommonAugmentation(kernel_name, AugmentationTools = [collection_maker] ))
309 """Add b/c-hadrons and their downstream particles"""
310 kwargs.setdefault(
"addB",
True)
311 kwargs.setdefault(
"addC",
True)
312 kwargs.setdefault(
"generations",-1)
313 kwargs.setdefault(
"prefix",
'')
316 collection_name = kwargs[
'prefix']+
"TruthHFWithDecay"
317 DFCommonHFAndDecaysTool = acc.getPrimaryAndMerge(TruthDecayCollectionMakerCfg(
319 name=kwargs[
'prefix']+
"DFCommonHFAndDecaysTool",
320 NewParticleKey = collection_name+
'Particles',
321 NewVertexKey = collection_name+
'Vertices',
322 KeepBHadrons=kwargs[
'addB'],
323 KeepCHadrons=kwargs[
'addC'],
324 Generations=kwargs[
'generations']))
325 acc.addEventAlgo(CompFactory.DerivationFramework.CommonAugmentation(
326 kwargs[
'prefix']+
"MCTruthCommonHFAndDecaysKernel",
327 AugmentationTools = [DFCommonHFAndDecaysTool] ))
348def AddTruthCollectionNavigationDecorationsCfg(flags, TruthCollections=[], prefix=''):
349 """Tool to add navigation decorations on the truth collections"""
350 acc = ComponentAccumulator()
351 if len(TruthCollections) > 0:
352 # Set up a tool to add the navigation decorations
353 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig import TruthNavigationDecoratorCfg
354 DFCommonTruthNavigationDecorator = acc.getPrimaryAndMerge(TruthNavigationDecoratorCfg(flags,
355 name = prefix+'DFCommonTruthNavigationDecorator',
356 InputCollections = TruthCollections))
357 CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
358 acc.addEventAlgo(CommonAugmentation(prefix+"MCTruthNavigationDecoratorKernel",
359 AugmentationTools = [DFCommonTruthNavigationDecorator] ))
362# Add BSM particles and their downstream particles (immediate and further decay products) in a special collection
363def AddBSMAndDownstreamParticlesCfg(flags, generations=-1):
364 """Add BSM particles and their downstream particles in a special collection"""
365 acc = ComponentAccumulator()
366 # Set up a tool to keep the taus and all downstream particles
367 collection_name = "TruthBSMWithDecay"
368 DFCommonBSMAndDecaysTool = acc.getPrimaryAndMerge(TruthDecayCollectionMakerCfg(flags,
369 name = "DFCommonBSMAndDecaysTool",
370 NewParticleKey = collection_name+'Particles',
371 NewVertexKey = collection_name+'Vertices',
373 Generations = generations))
374 CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
375 acc.addEventAlgo(CommonAugmentation(name = "MCTruthCommonBSMAndDecaysKernel",
376 AugmentationTools = [DFCommonBSMAndDecaysTool] ))
379# Add a mini-collection for the born leptons
380def AddBornLeptonCollectionCfg(flags):
381 """Add born leptons as a mini collection"""
382 acc = ComponentAccumulator()
383 # Set up a tool to keep the taus and all downstream particles
384 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig import TruthBornLeptonCollectionMakerCfg
385 DFCommonBornLeptonCollTool = acc.getPrimaryAndMerge(TruthBornLeptonCollectionMakerCfg(flags,
386 name = "DFCommonBornLeptonCollTool",
387 NewCollectionName ="BornLeptons"))
388 CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
389 acc.addEventAlgo(CommonAugmentation("MCTruthCommonBornLeptonsKernel", AugmentationTools = [DFCommonBornLeptonCollTool] ))
392def AddLargeRJetD2Cfg(flags):
393 """Add large-R jet D2 variable"""
394 #Extra classifier for D2 variable
395 acc = ComponentAccumulator()
396 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig import TruthD2DecoratorCfg
397 theTruthD2Decorator = acc.getPrimaryAndMerge(TruthD2DecoratorCfg(flags,
398 name = "TruthD2Decorator",
399 JetContainerKey = "AntiKt10TruthSoftDropBeta100Zcut10Jets",
400 DecorationName = "D2"))
401 TruthD2DecoratorKernel = CompFactory.DerivationFramework.CommonAugmentation
402 acc.addEventAlgo(TruthD2DecoratorKernel("TRUTHD2Kernel", AugmentationTools = [theTruthD2Decorator] ))
418def DFCommonTruthCentralEDAlgCfg(flags):
420 acc = ComponentAccumulator()
421 from EventShapeTools.EventDensityConfig import configEventDensityTool
422 from JetRecConfig.StandardJetConstits import stdConstitDic as cst
423 DFCommonTruthCentralEDTool = configEventDensityTool("DFCommonTruthCentralEDTool",
426 AbsRapidityMax = 1.5,
427 OutputContainer = "TruthIsoCentralEventShape",
429 acc.addEventAlgo(CompFactory.EventDensityAthAlg("DFCommonTruthCentralEDAlg",
430 EventDensityTool = DFCommonTruthCentralEDTool ))
434def DFCommonTruthForwardEDAlgCfg(flags):
436 acc = ComponentAccumulator()
437 from EventShapeTools.EventDensityConfig import configEventDensityTool
438 from JetRecConfig.StandardJetConstits import stdConstitDic as cst
439 DFCommonTruthForwardEDTool = configEventDensityTool("DFCommonTruthForwardEDTool",
442 AbsRapidityMin = 1.5,
443 AbsRapidityMax = 3.0,
444 OutputContainer = "TruthIsoForwardEventShape",
446 acc.addEventAlgo(CompFactory.EventDensityAthAlg("DFCommonTruthForwardEDAlg",
447 EventDensityTool = DFCommonTruthForwardEDTool ))
451def AddTruthEnergyDensityCfg(flags):
452 """Truth energy density tools"""
453 acc = ComponentAccumulator()
454 # Algorithms for the energy density - needed only if e/gamma hasn't set things up already
455 acc.merge(DFCommonTruthCentralEDAlgCfg(flags))
456 acc.merge(DFCommonTruthForwardEDAlgCfg(flags))
458 DFCommonTruthEDKernel = CompFactory.DerivationFramework.CommonAugmentation("DFCommonTruthEDKernel",
460 [acc.addPublicTool(acc.popToolsAndMerge(DFCommonTruthEDDecoratorCfg(flags)))] )
461 acc.addEventAlgo(DFCommonTruthEDKernel)
465# Sets up modifiers to move pointers to old truth collections to new mini truth collections
466def AddMiniTruthCollectionLinksCfg(flags, **kwargs):
467 """Tool to move pointers to new mini truth collections"""
468 acc = ComponentAccumulator()
469 kwargs.setdefault("doElectrons",True)
470 kwargs.setdefault("doPhotons",True)
471 kwargs.setdefault("doMuons",True)
473 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig import TruthLinkRepointToolCfg
474 if kwargs['doElectrons']:
475 electron_relink = acc.getPrimaryAndMerge(TruthLinkRepointToolCfg(
477 name="ElMiniCollectionTruthLinkTool",
478 RecoCollection="Electrons",
479 TargetCollections=["TruthMuons","TruthPhotons","TruthElectrons"]))
480 aug_tools += [ electron_relink ]
481 if kwargs['doPhotons']:
482 photon_relink = acc.getPrimaryAndMerge(TruthLinkRepointToolCfg(
484 name="PhMiniCollectionTruthLinkTool",
485 RecoCollection="Photons",
486 TargetCollections=["TruthMuons","TruthPhotons","TruthElectrons"]))
487 aug_tools += [ photon_relink ]
488 if kwargs['doMuons']:
489 muon_relink = acc.getPrimaryAndMerge(TruthLinkRepointToolCfg(
491 name="MuMiniCollectionTruthLinkTool",
492 RecoCollection="Muons",
493 TargetCollections=["TruthMuons","TruthPhotons","TruthElectrons"]))
494 aug_tools += [ muon_relink ]
495 for i, tool in enumerate(aug_tools):
496 acc.addEventAlgo(CompFactory.DerivationFramework.CommonAugmentation(
497 "MiniCollectionTruthLinkKernelNo{num}".format(num=i+1),
498 AugmentationTools = [tool] ))
502def addTruth3ContentToSlimmerTool(slimmer):
503 slimmer.ExtraVariables += [
504 "AntiKt4TruthDressedWZJets.GhostCHadronsFinalCount.GhostBHadronsFinalCount.pt.HadronConeExclTruthLabelID.PartonTruthLabelID.TrueFlavor",
505 "AntiKt10TruthSoftDropBeta100Zcut10Jets.pt.Tau1_wta.Tau2_wta.Tau3_wta.D2",
506 "TruthEvents.Q.XF1.XF2.PDGID1.PDGID2.PDFID1.PDFID2.X1.X2.crossSection",
507 "MET_Truth.mpx.mpy.sumet.name.source",
508 "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",
509 "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",
510 "TruthPhotons.m.px.py.pz.e.pdgId.barcode.status.classifierParticleOrigin.classifierParticleType.classifierParticleOutCome.Classification.ptcone20.etcone20.etcone40.prodVtxLink.decayVtxLink.parentLinks.childLinks.polarizationPhi.polarizationTheta.uid",
511 "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",
512 "TruthNeutrinos.m.px.py.pz.e.pdgId.barcode.status.classifierParticleOrigin.classifierParticleType.classifierParticleOutCome.Classification.prodVtxLink.decayVtxLink.parentLinks.childLinks.polarizationPhi.polarizationTheta.uid",
513 "TruthBSM.barcode.childLinks.Classification.classifierParticleOrigin.classifierParticleOutCome.classifierParticleType.decayVtxLink.e.m.parentLinks.pdgId.polarizationPhi.polarizationTheta.prodVtxLink.px.py.pz.status",
514 "TruthBottom.m.px.py.pz.e.pdgId.barcode.status.classifierParticleOrigin.classifierParticleType.classifierParticleOutCome.Classification.prodVtxLink.decayVtxLink.parentLinks.childLinks.polarizationPhi.polarizationTheta.uid",
515 "TruthTop.m.px.py.pz.e.pdgId.barcode.status.prodVtxLink.decayVtxLink.parentLinks.childLinks.classifierParticleOrigin.classifierParticleType.classifierParticleOutCome.Classification.polarizationPhi.polarizationTheta.uid",
516 "TruthBoson.m.px.py.pz.e.pdgId.barcode.status.classifierParticleOrigin.classifierParticleType.classifierParticleOutCome.Classification.prodVtxLink.decayVtxLink.parentLinks.childLinks.polarizationPhi.polarizationTheta.uid",
517 "TruthForwardProtons.m.px.py.pz.e.pdgId.barcode.status.classifierParticleOrigin.classifierParticleType.classifierParticleOutCome.Classification.prodVtxLink.decayVtxLink.polarizationPhi.polarizationTheta.uid",
518 "BornLeptons.prodVtxLink.decayVtxLink.m.px.py.pz.e.pdgId.classifierParticleOrigin.Classification.barcode.status.classifierParticleType.classifierParticleOutCome.polarizationPhi.polarizationTheta.uid",
519 "TruthBosonsWithDecayParticles.m.px.py.pz.e.pdgId.barcode.status.classifierParticleOrigin.classifierParticleType.classifierParticleOutCome.Classification.barcode.id.x.y.z.t.prodVtxLink.decayVtxLink.incomingParticleLinks.outgoingParticleLinks.uid",
520 "TruthBosonsWithDecayVertices.barcode.id.x.y.z.t.prodVtxLink.decayVtxLink.incomingParticleLinks.outgoingParticleLinks.uid.status",
521 "TruthBSMWithDecayParticles.barcode.Classification.classifierParticleOrigin.classifierParticleOutCome.classifierParticleType.decayVtxLink.e.m.pdgId.prodVtxLink.px.py.pz.status",
522 "TruthBSMWithDecayVertices.barcode.id.incomingParticleLinks.outgoingParticleLinks.t.x.y.z"
AddStandardTruthContentsCfg(flags, decorationDressing='dressedPhoton', includeTausInDressingPhotonRemoval=False, navInputCollections=["TruthElectrons", "TruthMuons", "TruthPhotons", "TruthTaus", "TruthNeutrinos", "TruthBSM", "TruthBottom", "TruthTop", "TruthBoson"], prefix='')