7 from AthenaConfiguration.ComponentAccumulator
import ComponentAccumulator
8 from AthenaConfiguration.ComponentFactory
import CompFactory
9 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import TruthDecayCollectionMakerCfg
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"""
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:
65 from JetRecConfig.StandardSmallRJets
import AntiKt4Truth,AntiKt4TruthWZ,AntiKt4TruthDressedWZ,AntiKtVRTruthCharged
66 from JetRecConfig.StandardLargeRJets
import AntiKt10TruthTrimmed,AntiKt10TruthSoftDrop
67 from JetRecConfig.JetRecConfig
import JetRecCfg
68 from JetRecConfig.JetConfigFlags
import jetInternalFlags
70 jetInternalFlags.isRecoJob =
True
72 jetList = [AntiKt4Truth,AntiKt4TruthWZ,AntiKt4TruthDressedWZ,AntiKtVRTruthCharged,
73 AntiKt10TruthTrimmed,AntiKt10TruthSoftDrop]
87 if (
"MissingETContainer#MET_Truth")
not in flags.Input.TypedCollections:
88 from METReconstruction.METTruth_Cfg
import METTruth_Cfg
97 augmentationToolsList = []
102 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import ( DFCommonTruthElectronDressingToolCfg,
103 DFCommonTruthMuonDressingToolCfg, DFCommonTruthClassificationToolCfg, DFCommonTruthMuonToolCfg, DFCommonTruthElectronToolCfg,
104 DFCommonTruthPhotonToolSimCfg, DFCommonTruthNeutrinoToolCfg, DFCommonTruthBottomToolCfg, DFCommonTruthTopToolCfg,
105 DFCommonTruthBosonToolCfg, DFCommonTruthBSMToolCfg, DFCommonTruthForwardProtonToolCfg, DFCommonTruthElectronIsolationTool1Cfg,
106 DFCommonTruthElectronIsolationTool2Cfg, DFCommonTruthMuonIsolationTool1Cfg, DFCommonTruthMuonIsolationTool2Cfg,
107 DFCommonTruthPhotonIsolationTool1Cfg, DFCommonTruthPhotonIsolationTool2Cfg, DFCommonTruthPhotonIsolationTool3Cfg )
110 for item
in [ DFCommonTruthClassificationToolCfg, DFCommonTruthMuonToolCfg, DFCommonTruthElectronToolCfg,
111 DFCommonTruthPhotonToolSimCfg, DFCommonTruthNeutrinoToolCfg, DFCommonTruthBottomToolCfg, DFCommonTruthTopToolCfg,
112 DFCommonTruthBosonToolCfg, DFCommonTruthBSMToolCfg, DFCommonTruthElectronIsolationTool1Cfg,
113 DFCommonTruthElectronIsolationTool2Cfg, DFCommonTruthMuonIsolationTool1Cfg, DFCommonTruthMuonIsolationTool2Cfg,
114 DFCommonTruthPhotonIsolationTool1Cfg, DFCommonTruthPhotonIsolationTool2Cfg, DFCommonTruthPhotonIsolationTool3Cfg]:
115 augmentationToolsList.append(acc.getPrimaryAndMerge(
item(flags)))
118 if 'decorationDressing' in kwargs:
122 for i, tool
in enumerate(augmentationToolsList):
123 acc.addEventAlgo(CompFactory.DerivationFramework.CommonAugmentation(name =
"MCTruthCommonPreJetKernelNo{num}".
format(num = i+1), AugmentationTools = [tool]))
134 from DerivationFrameworkTau.TauTruthCommonConfig
import TauTruthToolsCfg
136 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import DFCommonTruthTauDressingToolCfg
140 from DerivationFrameworkMCTruth.GenFilterToolConfig
import GenFilterToolCfg
142 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import DFCommonTruthDressedWZQGLabelToolCfg
143 augmentationToolsList += [ acc.getPrimaryAndMerge(
GenFilterToolCfg(flags)) ,
147 from DerivationFrameworkSUSY.DecorateSUSYProcessConfig
import IsSUSYSignalRun3
149 from DerivationFrameworkSUSY.DecorateSUSYProcessConfig
import SUSYSignalTaggerCfg
150 augmentationToolsList += [ acc.getPrimaryAndMerge(
SUSYSignalTaggerCfg(flags,
'MCTruthCommon')) ]
152 CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
153 for i, tool
in enumerate(augmentationToolsList):
154 acc.addEventAlgo(CommonAugmentation(name =
"MCTruthCommonPostJetKernelNo{num}".
format(num = i+1),
155 AugmentationTools = [tool]))
159 from DerivationFrameworkSUSY.SUSYWeightMetadataConfig
import AddSUSYWeightsCfg
166 decorationDressing='dressedPhoton',
167 includeTausInDressingPhotonRemoval=False,
177 if "McEventCollection#GEN_EVENT" in flags.Input.TypedCollections: isEVNT =
True
181 if includeTausInDressingPhotonRemoval:
182 acc.getPublicTool(
"DFCommonTruthTauDressingTool").decorationName=decorationDressing
189 acc.merge(
AddTruthCollectionNavigationDecorationsCfg(flags, [
"TruthElectrons",
"TruthMuons",
"TruthPhotons",
"TruthTaus",
"TruthNeutrinos",
"TruthBSM",
"TruthBottom",
"TruthTop",
"TruthBoson"], prefix=prefix))
208 collection_prefix=None,
209 rejectHadronChildren=False):
210 """Configure tools for adding immediate parents and descendants"""
212 collection_name=collection_prefix+
'WithDecay' if collection_prefix
is not None else 'Truth'+prefix+
'WithDecay'
215 name =
'DFCommon'+prefix+
'AndDecaysTool',
216 NewCollectionName = collection_name,
217 PDGIDsToKeep = parents,
218 Generations = generations,
219 RejectHadronChildren = rejectHadronChildren))
220 CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
221 kernel_name =
'MCTruthCommon'+prefix+
'AndDecaysKernel'
222 acc.addEventAlgo(CommonAugmentation(kernel_name, AugmentationTools = [collection_maker] ))
245 rejectHadronChildren=False):
246 """Add bosons and downstream particles (not photons/gluons)"""
248 generations = generations,
249 parents = [23,24,25],
251 rejectHadronChildren = rejectHadronChildren)
256 rejectHadronChildren=False):
257 """Add top quarks and downstream particles"""
259 generations=generations,
262 rejectHadronChildren=rejectHadronChildren)
266 rejectHadronChildren=False):
267 """Add tau and downstream particles"""
269 generations=generations,
272 rejectHadronChildren=rejectHadronChildren)
294 """Add b/c-hadrons and their downstream particles"""
295 kwargs.setdefault(
"addB",
True)
296 kwargs.setdefault(
"addC",
True)
297 kwargs.setdefault(
"generations",-1)
298 kwargs.setdefault(
"prefix",
'')
301 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import TruthDecayCollectionMakerCfg
304 name=kwargs[
'prefix']+
"DFCommonHFAndDecaysTool",
305 NewCollectionName=kwargs[
'prefix']+
"TruthHFWithDecay",
306 KeepBHadrons=kwargs[
'addB'],
307 KeepCHadrons=kwargs[
'addC'],
308 Generations=kwargs[
'generations']))
309 acc.addEventAlgo(CompFactory.DerivationFramework.CommonAugmentation(
310 kwargs[
'prefix']+
"MCTruthCommonHFAndDecaysKernel",
311 AugmentationTools = [DFCommonHFAndDecaysTool] ))
317 """Add a one-vertex-per event "primary vertex" container"""
320 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import TruthPVCollectionMakerCfg
323 name=
"DFCommonTruthPVCollTool",
324 NewCollectionName=
"TruthPrimaryVertices"))
325 acc.addEventAlgo(CompFactory.DerivationFramework.CommonAugmentation(
326 "MCTruthCommonTruthPVCollKernel",
327 AugmentationTools = [DFCommonTruthPVCollTool] ))
332 """Add a mini-collection for the hard scatter and N subsequent generations"""
339 """Tool to add navigation decorations on the truth collections"""
341 if len(TruthCollections)==0:
return
343 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import TruthNavigationDecoratorCfg
345 name = prefix+
'DFCommonTruthNavigationDecorator',
346 InputCollections = TruthCollections))
347 CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
348 acc.addEventAlgo(CommonAugmentation(prefix+
"MCTruthNavigationDecoratorKernel",
349 AugmentationTools = [DFCommonTruthNavigationDecorator] ))
354 """Add BSM particles and their downstream particles in a special collection"""
359 name =
"DFCommonBSMAndDecaysTool",
360 NewCollectionName =
"TruthBSMWithDecay",
362 Generations = generations))
363 CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
364 acc.addEventAlgo(CommonAugmentation(name =
"MCTruthCommonBSMAndDecaysKernel",
365 AugmentationTools = [DFCommonBSMAndDecaysTool] ))
370 """Add born leptons as a mini collection"""
373 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import TruthBornLeptonCollectionMakerCfg
375 name =
"DFCommonBornLeptonCollTool",
376 NewCollectionName =
"BornLeptons"))
377 CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
378 acc.addEventAlgo(CommonAugmentation(
"MCTruthCommonBornLeptonsKernel", AugmentationTools = [DFCommonBornLeptonCollTool] ))
382 """Add large-R jet D2 variable"""
385 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import TruthD2DecoratorCfg
387 name =
"TruthD2Decorator",
388 JetContainerKey =
"AntiKt10TruthSoftDropBeta100Zcut10Jets",
389 DecorationName =
"D2"))
390 TruthD2DecoratorKernel = CompFactory.DerivationFramework.CommonAugmentation
391 acc.addEventAlgo(TruthD2DecoratorKernel(
"TRUTHD2Kernel", AugmentationTools = [theTruthD2Decorator] ))
396 """Truth energy density tools"""
398 from EventShapeTools.EventDensityConfig
import configEventDensityTool
399 from JetRecConfig.StandardJetConstits
import stdConstitDic
as cst
400 EventDensityAthAlg = CompFactory.EventDensityAthAlg
405 AbsRapidityMax = 1.5,
406 OutputContainer =
"TruthIsoCentralEventShape",
408 acc.addPublicTool(DFCommonTruthCentralEDTool)
409 acc.addEventAlgo(
EventDensityAthAlg(
"DFCommonTruthCentralEDAlg", EventDensityTool = DFCommonTruthCentralEDTool ))
413 AbsRapidityMin = 1.5,
414 AbsRapidityMax = 3.0,
415 OutputContainer =
"TruthIsoForwardEventShape",
417 acc.addPublicTool(DFCommonTruthForwardEDTool)
418 acc.addEventAlgo(
EventDensityAthAlg(
"DFCommonTruthForwardEDAlg", EventDensityTool = DFCommonTruthForwardEDTool ))
421 DFCommonTruthEDDecorator = CompFactory.DerivationFramework.TruthEDDecorator(
"DFCommonTruthEDDecorator",
422 EventInfoName=
"EventInfo",
423 EnergyDensityKeys=[
"TruthIsoCentralEventShape",
"TruthIsoForwardEventShape"],
424 DecorationSuffix=
"_rho"
426 acc.addPublicTool(DFCommonTruthEDDecorator)
428 DFCommonTruthEDKernel = CompFactory.DerivationFramework.CommonAugmentation
429 acc.addEventAlgo(DFCommonTruthEDKernel(
"DFCommonTruthEDKernel", AugmentationTools = [DFCommonTruthEDDecorator] ))
435 """Tool to move pointers to new mini truth collections"""
437 kwargs.setdefault(
"doElectrons",
True)
438 kwargs.setdefault(
"doPhotons",
True)
439 kwargs.setdefault(
"doMuons",
True)
441 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import TruthLinkRepointToolCfg
442 if kwargs[
'doElectrons']:
445 name=
"ElMiniCollectionTruthLinkTool",
446 RecoCollection=
"Electrons",
447 TargetCollections=[
"TruthMuons",
"TruthPhotons",
"TruthElectrons"]))
448 aug_tools += [ electron_relink ]
449 if kwargs[
'doPhotons']:
452 name=
"PhMiniCollectionTruthLinkTool",
453 RecoCollection=
"Photons",
454 TargetCollections=[
"TruthMuons",
"TruthPhotons",
"TruthElectrons"]))
455 aug_tools += [ photon_relink ]
456 if kwargs[
'doMuons']:
459 name=
"MuMiniCollectionTruthLinkTool",
460 RecoCollection=
"Muons",
461 TargetCollections=[
"TruthMuons",
"TruthPhotons",
"TruthElectrons"]))
462 aug_tools += [ muon_relink ]
463 for i, tool
in enumerate(aug_tools):
464 acc.addEventAlgo(CompFactory.DerivationFramework.CommonAugmentation(
465 "MiniCollectionTruthLinkKernelNo{num}".
format(num=i+1),
466 AugmentationTools = [tool] ))
470 slimmer.AllVariables += [
481 "TruthForwardProtons",
483 "TruthBosonsWithDecayParticles",
484 "TruthBosonsWithDecayVertices",
485 "TruthBSMWithDecayParticles",
486 "TruthBSMWithDecayVertices",
487 "HardScatterParticles",
488 "HardScatterVertices",
490 slimmer.ExtraVariables += [
491 "AntiKt4TruthDressedWZJets.GhostCHadronsFinalCount.GhostBHadronsFinalCount.pt.HadronConeExclTruthLabelID.ConeTruthLabelID.PartonTruthLabelID.TrueFlavor",
492 "AntiKt10TruthSoftDropBeta100Zcut10Jets.pt.Tau1_wta.Tau2_wta.Tau3_wta.D2",
493 "TruthEvents.Q.XF1.XF2.PDGID1.PDGID2.PDFID1.PDFID2.X1.X2.crossSection"]