diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkMCTruth/python/MCTruthCommon.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkMCTruth/python/MCTruthCommon.py index 6b2790589620051a4daccc0c42f3a906a796eb96..b120796b22269b6da7f4cb750aa75d895f93d763 100644 --- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkMCTruth/python/MCTruthCommon.py +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkMCTruth/python/MCTruthCommon.py @@ -293,11 +293,17 @@ def schedulePostJetMCTruthAugmentations(kernel=None, decorationDressing=None): if IsSUSYSignal(): from DerivationFrameworkSUSY.DecorateSUSYProcess import DecorateSUSYProcess augmentationToolsList += DecorateSUSYProcess('MCTruthCommon') + from DerivationFrameworkCore.DerivationFrameworkCoreConf import DerivationFramework__CommonAugmentation kernel += CfgMgr.DerivationFramework__CommonAugmentation("MCTruthCommonPostJetKernel", AugmentationTools = augmentationToolsList ) + # add SoW of individual SUSY final states, relies on augmentation from DecorateSUSYProcess() + if IsSUSYSignal(): + from DerivationFrameworkSUSY.SUSYWeightMetadata import addSUSYWeights + addSUSYWeights(kernel) + # This adds the entirety of TRUTH3 def addStandardTruthContents(kernel=None, decorationDressing='dressedPhoton', diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkPhys/share/PHYS.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkPhys/share/PHYS.py index f81b9d36d90651436519df4e54d2d6ed530c3a17..972575733b07335a334a03e36c064ff0ce50426b 100644 --- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkPhys/share/PHYS.py +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkPhys/share/PHYS.py @@ -66,10 +66,6 @@ if (DerivationFrameworkIsMonteCarlo): addPVCollection(SeqPHYS) # Set appropriate truth jet collection for tau truth matching ToolSvc.DFCommonTauTruthMatchingTool.TruthJetContainerName = "AntiKt4TruthDressedWZJets" - # SUSY signal - from DerivationFrameworkSUSY.DecorateSUSYProcess import IsSUSYSignal - if IsSUSYSignal(): - from DerivationFrameworkSUSY import SUSYWeightMetadata # Add sumOfWeights metadata for LHE3 multiweights ======= #from DerivationFrameworkCore.LHE3WeightMetadata import * diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkPhys/share/PHYS2.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkPhys/share/PHYS2.py index 4a7a7c73ebdf97b3bfdf3fd7f80fc73f75db5ef2..ca304e4abd614d20e2d9b6aa8053a79611e97301 100644 --- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkPhys/share/PHYS2.py +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkPhys/share/PHYS2.py @@ -73,10 +73,6 @@ if (DerivationFrameworkIsMonteCarlo): addPVCollection(SeqPHYS2) # Set appropriate truth jet collection for tau truth matching ToolSvc.DFCommonTauTruthMatchingTool.TruthJetContainerName = "AntiKt4TruthDressedWZJets" - # SUSY signal - from DerivationFrameworkSUSY.DecorateSUSYProcess import IsSUSYSignal - if IsSUSYSignal(): - from DerivationFrameworkSUSY.SUSYWeightMetadata import * # Add sumOfWeights metadata for LHE3 multiweights ======= from DerivationFrameworkCore.LHE3WeightMetadata import * diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkPhys/share/PHYSLITE.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkPhys/share/PHYSLITE.py index f0a3390bd1cc1ed17420a0e529aafcc3dda53e56..1ca9b696259a0644cd7b2e5807e97f5292620f56 100644 --- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkPhys/share/PHYSLITE.py +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkPhys/share/PHYSLITE.py @@ -54,9 +54,6 @@ if DerivationFrameworkIsMonteCarlo: ToolSvc.DFCommonTauTruthMatchingTool.TruthJetContainerName = "AntiKt4TruthDressedWZJets" # Add sumOfWeights metadata for LHE3 multiweights ======= from DerivationFrameworkCore.LHE3WeightMetadata import * - from DerivationFrameworkSUSY.DecorateSUSYProcess import IsSUSYSignal - if IsSUSYSignal(): - from DerivationFrameworkSUSY.SUSYWeightMetadata import * #============================================================================== # HEAVY FLAVOR DECORATION diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkSUSY/CMakeLists.txt b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkSUSY/CMakeLists.txt index 8f920cef442d9a9acc1dbd6a3c614016df107637..91d85c845b6c28dabd97ad0c35cc3a89ca96a965 100644 --- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkSUSY/CMakeLists.txt +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkSUSY/CMakeLists.txt @@ -11,7 +11,7 @@ atlas_add_component( DerivationFrameworkSUSY src/*.cxx src/components/*.cxx INCLUDE_DIRS ${CLHEP_INCLUDE_DIRS} DEFINITIONS ${CLHEP_DEFINITIONS} - LINK_LIBRARIES ${CLHEP_LIBRARIES} AthenaBaseComps AthenaKernel DerivationFrameworkInterfaces ExpressionEvaluationLib GaudiKernel MCTruthClassifierLib RecoToolInterfaces xAODAssociations xAODEventInfo xAODJet xAODTracking xAODTruth ) + LINK_LIBRARIES ${CLHEP_LIBRARIES} AthenaBaseComps AthenaKernel DerivationFrameworkInterfaces ExpressionEvaluationLib GaudiKernel MCTruthClassifierLib RecoToolInterfaces xAODAssociations xAODEventInfo xAODJet xAODTracking xAODTruth ReweightUtilsLib) # Install files from the package: atlas_install_python_modules( python/*.py POST_BUILD_CMD ${ATLAS_FLAKE8} ) diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkSUSY/DerivationFrameworkSUSY/SUSYIDWeight.h b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkSUSY/DerivationFrameworkSUSY/SUSYIDWeight.h new file mode 100644 index 0000000000000000000000000000000000000000..d57d4d77d13e937cc69849a83af1dda91ee5877e --- /dev/null +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkSUSY/DerivationFrameworkSUSY/SUSYIDWeight.h @@ -0,0 +1,58 @@ +///////////////////////// -*- C++ -*- ///////////////////////////// + +/* + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +*/ + +// SUSYIDWeight.h +// Header file for class SUSYIDWeight +// Author: M.Tripiana <tripiana@cern.ch> +// based on the McEventWeight class by O.Arnaez +/////////////////////////////////////////////////////////////////// +#ifndef DerivationFramework_SUSY_ID_WEIGHT_H +#define DerivationFramework_SUSY_ID_WEIGHT_H 1 + +// STL includes +#include <string> +#include <vector> + +// FrameWork includes +#include "ReweightUtils/WeightToolBase.h" + +//namespace DerivationFramework { + + class SUSYIDWeight : public WeightToolBase + { + /// Create a proper constructor for Athena + ASG_TOOL_CLASS2( SUSYIDWeight, IWeightTool, IObservableTool ) + + /////////////////////////////////////////////////////////////////// + // Public methods: + /////////////////////////////////////////////////////////////////// + public: + + /// The default constructor with the instance name of the tool class + SUSYIDWeight( const std::string& name ); + + /// Destructor: + virtual ~SUSYIDWeight(){}; + + /// returns: the value that was calculated from the xAOD::IParticle (composite built event object for instance) + virtual double evaluate( const xAOD::IParticle* part ) const override; + + /// returns: the value that was calculated from the usual Athena storegate + virtual double getWeight() const override; + + + private: + //internal function "computing" the weight + double computeWeight(const xAOD::EventInfo*) const; + + int m_SUSYProcID; + std::string m_eventInfoName; + bool m_useTruthEvents = false; + + }; +//} + +#endif //> !DerivationFramework_SUSY_ID_WEIGHT diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkSUSY/python/DecorateSUSYProcess.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkSUSY/python/DecorateSUSYProcess.py index 2cef88fad43e154f4356abc2370fc33a4061439d..158028a1d3b877248af382a0c2d15a3a0609bee0 100644 --- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkSUSY/python/DecorateSUSYProcess.py +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkSUSY/python/DecorateSUSYProcess.py @@ -4,23 +4,59 @@ # SUSY signal process augmentation #============================================================================== -from __future__ import print_function def IsSUSYSignal(): + #from DerivationFrameworkCore.DerivationFrameworkMaster import DerivationFrameworkHasTruth from DerivationFrameworkCore.DerivationFrameworkMaster import DerivationFrameworkIsMonteCarlo + #if not DerivationFrameworkHasTruth: if not DerivationFrameworkIsMonteCarlo: return False import PyUtils.AthFile from AthenaCommon.AthenaCommonFlags import athenaCommonFlags - - fileinfo = PyUtils.AthFile.fopen(athenaCommonFlags.PoolAODInput()[0]) - + + # If someone has set evgen input, assume that they want to use it + if not athenaCommonFlags.PoolEvgenInput.isDefault(): + fileinfo = PyUtils.AthFile.fopen(athenaCommonFlags.PoolEvgenInput()[0]) + elif not athenaCommonFlags.PoolAODInput.isDefault(): + fileinfo = PyUtils.AthFile.fopen(athenaCommonFlags.PoolAODInput()[0]) + else: + fileinfo = PyUtils.AthFile.fopen(athenaCommonFlags.FilesInput()[0]) + if "mc_channel_number" in fileinfo.infos and len(fileinfo.mc_channel_number) == 1: mc_channel_number = fileinfo.mc_channel_number[0] - issusy = (370000 <= mc_channel_number < 405000) or (406000 <= mc_channel_number < 410000) # https://svnweb.cern.ch/trac/atlasoff/browser/Generators/MC15JobOptions/trunk/share/Blocks.list - print ("DecorateSUSYProcess: fileinfo.mc_channel_number", mc_channel_number, "is SUSY:", issusy) + if mc_channel_number==0: mc_channel_number = fileinfo.run_number[0] + + # with MC16, there are no dedicated SUSY DSID blocks anymore but blocks for + # each generator: see https://twiki.cern.ch/twiki/bin/view/AtlasProtected/PmgMcSoftware#DSID_blocks + if mc_channel_number >= 500000: + # there does not seem to be an elegant way to check whether its a SUSY sample + # or not, thus run the mark all MadGraph samples as SUSY for the moment + # to non-SUSY MG samples this adds only an empty decoration and does not break anything + issusy = (mc_channel_number < 600000) + print ("DecorateSUSYProcess: fileinfo.mc_channel_number", mc_channel_number, "is SUSY (aka is MG):", issusy) + # for pre-MC16 samples use the old way + else: + import os + if not os.access('/cvmfs/atlas.cern.ch/repo/sw/Generators/MC15JobOptions/latest/share/Blocks.list',os.R_OK): + # Do it the old-fashioned way + # https://svnweb.cern.ch/trac/atlasoff/browser/Generators/MC15JobOptions/trunk/share/Blocks.list + issusy = (370000 <= mc_channel_number < 405000) or (406000 <= mc_channel_number < 410000) \ + or (436000 <= mc_channel_number < 439000) or (448000 <= mc_channel_number < 450000) + else: + # Automatic detection based on cvmfs + issusy = False + blocks = open('/cvmfs/atlas.cern.ch/repo/sw/Generators/MC15JobOptions/latest/share/Blocks.list','r') + for l in blocks.readlines(): + if 'SUSY' not in l: continue + myrange = l.split()[0].replace('DSID','').replace('xxx','000',1).replace('xxx','999',1) + low = int(myrange.split('-')[0]) + high = int(myrange.split('-')[1]) if '-' in myrange else int(myrange.replace('000','999')) + if low <= mc_channel_number and mc_channel_number <= high: + issusy=True + break + print ("DecorateSUSYProcess: fileinfo.mc_channel_number", mc_channel_number, "is SUSY:", issusy) return issusy else: print ("DecorateSUSYProcess: WARNING: fileinfo.mc_channel_number not filled?") diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkSUSY/python/SUSYWeightMetadata.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkSUSY/python/SUSYWeightMetadata.py new file mode 100644 index 0000000000000000000000000000000000000000..9881e3e2843aa941ae750d7f34773474ab2c7494 --- /dev/null +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkSUSY/python/SUSYWeightMetadata.py @@ -0,0 +1,34 @@ +# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + + +def addSUSYWeights(seq, pref = ""): + + from AthenaCommon.AppMgr import ToolSvc + from ReweightUtils.ReweightUtilsConf import SumOfWeightsAlg,McEventWeight + from DerivationFrameworkSUSY.DerivationFrameworkSUSYConf import SUSYIDWeight + + #Load standard generator event weight + #mcEventWeightNom = McEventWeight(name = pref+"mcWNom") + #ToolSvc += mcEventWeightNom + + sumOfWeightsAlg = SumOfWeightsAlg(name = pref+"SUSYSumWeightsAlg") + + #Load all potential SUSY process IDs + # following Prospino conventions + # https://twiki.cern.ch/twiki/bin/view/AtlasProtected/SUSYSignalUncertainties#Subprocess_IDs + listTools = [] + susyWeight = [] + for i in range(0, 225): + + if i==0: #flat sum of all processes (i.e. sum the weight no matter what) + susyWeight.append( McEventWeight(name = pref+"SUSYWeight_ID"+"_"+str(i), UseTruthEvents = True)) + else: #add weight only to keeper associated to current process id + susyWeight.append( SUSYIDWeight(name = pref+"SUSYWeight_ID"+"_"+str(i), SUSYProcID = i, UseTruthEvents = True)) + + ToolSvc += susyWeight[i] + + listTools.append(susyWeight[i]) + + sumOfWeightsAlg.WeightTools = listTools + seq += sumOfWeightsAlg + \ No newline at end of file diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkSUSY/share/TRUTH3.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkSUSY/share/TRUTH3.py deleted file mode 100644 index 041deb073c854ee9d722fd05fdbe54c5c5ea7ecf..0000000000000000000000000000000000000000 --- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkSUSY/share/TRUTH3.py +++ /dev/null @@ -1,154 +0,0 @@ -#============================================================================== -# Set up common services and job object. -# This should appear in ALL derivation job options -#============================================================================== -from DerivationFrameworkCore.DerivationFrameworkMaster import * -# Add translator from EVGEN input to xAOD-like truth here -from DerivationFrameworkMCTruth.MCTruthCommon import * - -#==================================================================== -# JET/MET -#==================================================================== -# Set jet flags -from JetRec.JetRecFlags import jetFlags -jetFlags.useTruth = True -jetFlags.useTracks = False -# Add jet algorithms -from JetRec.JetAlgorithm import addJetRecoToAlgSequence -addJetRecoToAlgSequence(DerivationFrameworkJob,eventShapeTools=None) -from JetRec.JetRecStandard import jtm -from JetRec.JetRecConf import JetAlgorithm -jetFlags.truthFlavorTags = ["BHadronsInitial", "BHadronsFinal", "BQuarksFinal", - "CHadronsInitial", "CHadronsFinal", "CQuarksFinal", - "TausFinal", - "Partons", - ] -# Standard truth jets -# To recover jet constituents remove the last modifier. -akt4 = jtm.addJetFinder("AntiKt4TruthJets", "AntiKt", 0.4, "truth", modifiersin=[jtm.truthpartondr, jtm.partontruthlabel, jtm.removeconstit], ptmin= 20000) -akt4alg = JetAlgorithm("jetalgAntiKt4TruthJets", Tools = [akt4] ) -DerivationFrameworkJob += akt4alg - -#Large R jets -akt10 = jtm.addJetFinder("AntiKt10TruthJets", "AntiKt", 1.0, "truth", ptmin= 100000) -akt10alg = JetAlgorithm("jetalgAntiKt10TruthJets", Tools = [akt10] ) -DerivationFrameworkJob += akt10alg -akt10trim = jtm.addJetTrimmer("TrimmedAntiKt10TruthJets", rclus=0.3, ptfrac=0.05, input='AntiKt10TruthJets') -akt10trimalg = JetAlgorithm("jetalgTrimmedAntiKt10TruthJets", Tools = [akt10trim] ) -DerivationFrameworkJob += akt10trimalg - -# Add truth-based MET algorithm here -import METReconstruction.METConfig_Truth -from METReconstruction.METRecoFlags import metFlags # not sure if you even need this line -from METReconstruction.METRecoConfig import getMETRecoAlg -metAlg = getMETRecoAlg('METReconstruction') -DerivationFrameworkJob += metAlg - -#============================================================================== -# Set-up of the tols for writing special collections and decorators -#============================================================================== - -from DerivationFrameworkMCTruth.TruthObjectTools import * -from DerivationFrameworkMCTruth.TruthDecoratorTools import * - -#============================================================================== -# Truth Collections -#============================================================================== - -from DerivationFrameworkSUSY.DerivationFrameworkSUSYConf import DerivationFramework__Truth3CollectionMaker - -TRUTH3MuonTool = DerivationFramework__Truth3CollectionMaker(name = "TRUTH3MuonTool", - NewCollectionName = "TruthMuons", - ParticleSelectionString = "abs(TruthParticles.pdgId) == 13 && TruthParticles.status==1") -ToolSvc += TRUTH3MuonTool -TRUTH3ElectronTool = DerivationFramework__Truth3CollectionMaker(name = "TRUTH3ElectronTool", - NewCollectionName = "TruthElectrons", - ParticleSelectionString = "abs(TruthParticles.pdgId) == 11 && TruthParticles.status==1") -ToolSvc += TRUTH3ElectronTool - -TRUTH3PhotonTool = DerivationFramework__Truth3CollectionMaker(name = "TRUTH3PhotonTool", - NewCollectionName = "TruthPhotons", - ParticleSelectionString = "abs(TruthParticles.pdgId) == 22 && TruthParticles.pt > 50.*GeV") -ToolSvc += TRUTH3PhotonTool -TRUTH3TauTool = DerivationFramework__Truth3CollectionMaker(name = "TRUTH3TauTool", - NewCollectionName = "TruthTaus", - ParticleSelectionString = "abs(TruthParticles.pdgId) == 15") -ToolSvc += TRUTH3TauTool - -TRUTH3BosonTool = DerivationFramework__Truth3CollectionMaker(name = "TRUTH3BosonTool", - NewCollectionName = "TruthBoson", - ParticleSelectionString = "(abs(TruthParticles.pdgId) == 24 || abs(TruthParticles.pdgId) == 25 || abs(TruthParticles.pdgId) == 23) && TruthParticles.m > 20.*GeV") -ToolSvc += TRUTH3BosonTool - -TRUTH3TopTool = DerivationFramework__Truth3CollectionMaker(name = "TRUTH3TopTool", - NewCollectionName = "TruthTop", - ParticleSelectionString = "abs(TruthParticles.pdgId) == 6"); -ToolSvc += TRUTH3TopTool - -TRUTH3BSMTool = DerivationFramework__Truth3CollectionMaker(name = "TRUTH3BSMTool", - NewCollectionName = "TruthBSM", - ParticleSelectionString = "((abs(TruthParticles.pdgId) >= 1000001) && (abs(TruthParticles.pdgId) <= 1000039))"); -ToolSvc += TRUTH3BSMTool - -#TRUTH3bhadronTool = DerivationFramework__Truth3CollectionMaker(name = "TRUTH3bhadronTool", -# NewCollectionName = "Truthbhadron", -# ParticleSelectionString = "TruthParticles.isBottomHadron") -#ToolSvc += TRUTH3bhadronTool - -#============================================================================== -# Create the derivation kernel algorithm -#============================================================================== -from DerivationFrameworkCore.DerivationFrameworkCoreConf import DerivationFramework__DerivationKernel -DerivationFrameworkJob += CfgMgr.DerivationFramework__DerivationKernel("TRUTH3Kernel", - AugmentationTools = [TRUTH3PhotonTool,TRUTH3ElectronTool,TRUTH3MuonTool,TRUTH3BSMTool,TRUTH3TopTool,TRUTH3BosonTool,TRUTH3TauTool], - ThinningTools = []) - -#============================================================================== -# Set up stream -#============================================================================== -streamName = derivationFlags.WriteDAOD_TRUTH3Stream.StreamName -fileName = buildFileName( derivationFlags.WriteDAOD_TRUTH3Stream ) -TRUTH3Stream = MSMgr.NewPoolRootStream( streamName, fileName ) -augStream = MSMgr.GetStream( streamName ) -evtStream = augStream.GetEventStream() - -# Only events that pass the filters listed are written out -# AcceptAlgs = logical OR of filters -# RequireAlgs = logical AND of filters -TRUTH3Stream.AcceptAlgs(['TRUTH3Kernel']) - -#============================================================================== -# Set up slimming content list here -#============================================================================== - -from DerivationFrameworkCore.SlimmingHelper import SlimmingHelper - -TRUTH3SlimmingHelper = SlimmingHelper("TRUTH3SlimmingHelper") - -TRUTH3SlimmingHelper.ExtraVariables = ["AntiKt4TruthJets.pt,AntiKt4TruthJets.eta,AntiKt4TruthJets.phi,AntiKt4TruthJets.m,AntiKt4TruthJets.GhostBHadronsFinalCount"] -TRUTH3SlimmingHelper.AppendContentToStream(TRUTH3Stream) - -TRUTH3Stream.AddItem("xAOD::EventInfo#*") -TRUTH3Stream.AddItem("xAOD::EventAuxInfo#*") -TRUTH3Stream.AddItem("xAOD::JetContainer#TrimmedAntiKt10TruthJets*") -TRUTH3Stream.AddItem("xAOD::JetAuxContainer#TrimmedAntiKt10TruthJets*") -TRUTH3Stream.AddItem("xAOD::MissingETContainer#*") -TRUTH3Stream.AddItem("xAOD::MissingETAuxContainer#*") - -TRUTH3Stream.AddItem( "xAOD::TruthParticleContainer#TruthPhotons*") -TRUTH3Stream.AddItem( "xAOD::TruthParticleContainer#TruthElectrons*") -TRUTH3Stream.AddItem( "xAOD::TruthParticleContainer#TruthMuons*") -TRUTH3Stream.AddItem( "xAOD::TruthParticleContainer#TruthTaus*") -TRUTH3Stream.AddItem( "xAOD::TruthParticleContainer#TruthTop*") -TRUTH3Stream.AddItem( "xAOD::TruthParticleContainer#TruthBoson*") -TRUTH3Stream.AddItem( "xAOD::TruthParticleContainer#TruthBSM*") -#TRUTH3Stream.AddItem( "xAOD::TruthParticleContainer#Truthbhadron*") - -TRUTH3Stream.AddItem( "xAOD::TruthParticleAuxContainer#TruthPhotons*") -TRUTH3Stream.AddItem( "xAOD::TruthParticleAuxContainer#TruthElectrons*") -TRUTH3Stream.AddItem( "xAOD::TruthParticleAuxContainer#TruthMuons*") -TRUTH3Stream.AddItem( "xAOD::TruthParticleAuxContainer#TruthTaus*") -TRUTH3Stream.AddItem( "xAOD::TruthParticleAuxContainer#TruthTop*") -TRUTH3Stream.AddItem( "xAOD::TruthParticleAuxContainer#TruthBoson*") -TRUTH3Stream.AddItem( "xAOD::TruthParticleAuxContainer#TruthBSM*") -#TRUTH3Stream.AddItem( "xAOD::TruthParticleAuxContainer#Truthbhadron*") diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkSUSY/src/SUSYIDWeight.cxx b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkSUSY/src/SUSYIDWeight.cxx new file mode 100644 index 0000000000000000000000000000000000000000..f676c0b405e341393079bd60d478fac8201408a7 --- /dev/null +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkSUSY/src/SUSYIDWeight.cxx @@ -0,0 +1,82 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "DerivationFrameworkSUSY/SUSYIDWeight.h" +#include "xAODTruth/TruthEventContainer.h" + +//namespace DerivationFramework { + + static SG::AuxElement::Accessor<int> acc_procID("SUSY_procID"); + + SUSYIDWeight::SUSYIDWeight( const std::string& name ) + : WeightToolBase( name ), + m_SUSYProcID(0), + m_eventInfoName("EventInfo") { + declareProperty( "SUSYProcID", m_SUSYProcID = 0); + declareProperty("EventInfoName", m_eventInfoName = "EventInfo"); + declareProperty("UseTruthEvents" ,m_useTruthEvents=false, "To solve ATLASSIM-2989 we have to switch to using TruthEvents for weights"); + } + + // returns: the value that was calculated from the xAOD::IParticle composite built event + // This is the implementation of the interface + double SUSYIDWeight::evaluate( const xAOD::IParticle* /*part*/ ) const + { + ATH_MSG_DEBUG ("Evaluating " << name() << "..."); + + // Get the proper weight (from EventInfo) + return this->getWeight(); + } + + double SUSYIDWeight::computeWeight(const xAOD::EventInfo* evtInfo) const { + // don't do anything for data + if(!evtInfo->eventType(xAOD::EventInfo::IS_SIMULATION)){ + ATH_MSG_DEBUG (" Returning weight=1. for data."); + return 1.; + } + + //Check for requested Process ID, otherwise return 0. + if (acc_procID.isAvailable(*(evtInfo))) { + if( acc_procID(*(evtInfo)) != m_SUSYProcID ) + return 0.; + } + else{ + ATH_MSG_WARNING("The SUSY_procID decoration requested is not available! You need to run SUSYSignalTagger beforehand."); + return 0.; + } + + if(m_useTruthEvents) { + //access TruthEvents container instead + const xAOD::TruthEventContainer* te = 0; + if( evtStore()->retrieve( te, "TruthEvents" ).isFailure() ) { + ATH_MSG_ERROR("TruthEvents could not be retrieved. Throwing exception"); + throw std::runtime_error("SUSYIDWeight ASG Tool: TruthEvents could not be retrieved"); + } + if( te->size() == 0 ) { + ATH_MSG_ERROR("TruthEvents has no events in it. Throwing exception"); + throw std::runtime_error("SUSYIDWeight ASG Tool: TruthEvents has no events in it"); + } + const double weight = te->at(0)->weights()[0]; + ATH_MSG_DEBUG ("Got weight in SUSYIDWeight::computeWeight() = " << weight << "."); + return weight; + } + + const double weight = evtInfo->mcEventWeight(0); + ATH_MSG_DEBUG ("Got weight in SUSYIDWeight::computeWeight() = " << weight << "."); + return weight; + } + + double SUSYIDWeight::getWeight() const { + //Retrieveing eventInfo + const xAOD::EventInfo* evtInfo; + StatusCode sc = evtStore()->retrieve( evtInfo, m_eventInfoName ); + if(sc.isFailure() || !evtInfo) { + ATH_MSG_ERROR (" EventInfo could not be retrieved !!"); + return 0.; + } + + double weight = this->computeWeight(evtInfo); + ATH_MSG_VERBOSE (" " << name() << " returning weight= " << weight << "."); + return weight; + } +//} diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkSUSY/src/SUSYSignalTagger.cxx b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkSUSY/src/SUSYSignalTagger.cxx index 39b1fe9a0e11d845c0d45cc84e080ba06d23e75f..0f0ed03f0b1322b955c54e30e0e7b1f6a795d1c7 100644 --- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkSUSY/src/SUSYSignalTagger.cxx +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkSUSY/src/SUSYSignalTagger.cxx @@ -102,61 +102,61 @@ namespace DerivationFramework { //check ifSUSY particle if ((abs(tp->pdgId()) > 1000000 && abs(tp->pdgId()) < 1000007) || // squarkL - (abs(tp->pdgId()) > 1000010 && abs(tp->pdgId()) < 1000017) || // sleptonL - (abs(tp->pdgId()) > 2000000 && abs(tp->pdgId()) < 2000007) || // squarkR - (abs(tp->pdgId()) > 2000010 && abs(tp->pdgId()) < 2000017) || // sleptonR - (abs(tp->pdgId()) > 1000020 && abs(tp->pdgId()) < 1000040)) { // gauginos - - if (tp->nParents() != 0) { - if ( tp->parent(0)->absPdgId() < 1000000) { - if (!firstsp) { - firstsp = tp; - } else if (!secondsp) { - secondsp = tp; - } else { - if (firstsp->nChildren() != 0 && tp->barcode() == firstsp->child(0)->barcode()) { - firstsp = tp; - } - else if (secondsp->nChildren() != 0 && tp->barcode() == secondsp->child(0)->barcode()) { - secondsp = tp; - } - else if (firstsp->nChildren() != 0 && firstsp->child(0)->barcode() == secondsp->barcode()) { - firstsp = secondsp; - secondsp = tp; - } - else if (secondsp->nChildren() != 0 && secondsp->child(0)->barcode() == firstsp->barcode()) { - secondsp = firstsp; - firstsp = tp; - } - } - } - } + (abs(tp->pdgId()) > 1000010 && abs(tp->pdgId()) < 1000017) || // sleptonL + (abs(tp->pdgId()) > 2000000 && abs(tp->pdgId()) < 2000007) || // squarkR + (abs(tp->pdgId()) > 2000010 && abs(tp->pdgId()) < 2000017) || // sleptonR + (abs(tp->pdgId()) > 1000020 && abs(tp->pdgId()) < 1000040)) { // gauginos + + if (tp->nParents() != 0) { + if ( tp->parent(0)->absPdgId() < 1000000) { + if (!firstsp) { + firstsp = tp; + } else if (!secondsp) { + secondsp = tp; + } else { + if (firstsp->nChildren() != 0 && tp->barcode() == firstsp->child(0)->barcode()) { + firstsp = tp; + } + else if (secondsp->nChildren() != 0 && tp->barcode() == secondsp->child(0)->barcode()) { + secondsp = tp; + } + else if (firstsp->nChildren() != 0 && firstsp->child(0)->barcode() == secondsp->barcode()) { + firstsp = secondsp; + secondsp = tp; + } + else if (secondsp->nChildren() != 0 && secondsp->child(0)->barcode() == firstsp->barcode()) { + secondsp = firstsp; + firstsp = tp; + } + } + } + } } } // quit if no sparticles found if (!firstsp && !secondsp) return false; // should find none or two - if (firstsp->nChildren() == 1) { + if (firstsp && firstsp->nChildren() == 1) { for (const auto& tp : *truthP) { - if (tp->barcode() == firstsp->child(0)->barcode() && tp->pdgId() != firstsp->pdgId()) { - firstsp = tp; - break; - } + if (tp->barcode() == firstsp->child(0)->barcode() && tp->pdgId() != firstsp->pdgId()) { + firstsp = tp; + break; + } } } - if (secondsp->nChildren() == 1) { + if (secondsp && secondsp->nChildren() == 1) { for (const auto& tp : *truthP) { - if (tp->barcode() == secondsp->child(0)->barcode() && tp->pdgId() != secondsp->pdgId()) { - secondsp = tp; - break; - } + if (tp->barcode() == secondsp->child(0)->barcode() && tp->pdgId() != secondsp->pdgId()) { + secondsp = tp; + break; + } } } - if (abs(firstsp->pdgId()) > 1000000) pdgid1 = firstsp->pdgId(); - if (abs(secondsp->pdgId()) > 1000000) pdgid2 = secondsp->pdgId(); + if (firstsp && abs(firstsp->pdgId()) > 1000000) pdgid1 = firstsp->pdgId(); + if (secondsp && abs(secondsp->pdgId()) > 1000000) pdgid2 = secondsp->pdgId(); // Return gracefully: return true; diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkSUSY/src/components/DerivationFrameworkSUSY_entries.cxx b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkSUSY/src/components/DerivationFrameworkSUSY_entries.cxx index 58809f92779ebb4bd1c1aa9dd1a8c6539872f87c..bd7f117747e568e381042c9e9c4b3727537631c9 100644 --- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkSUSY/src/components/DerivationFrameworkSUSY_entries.cxx +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkSUSY/src/components/DerivationFrameworkSUSY_entries.cxx @@ -1,5 +1,6 @@ #include "DerivationFrameworkSUSY/Truth3CollectionMaker.h" #include "DerivationFrameworkSUSY/SUSYSignalTagger.h" +#include "DerivationFrameworkSUSY/SUSYIDWeight.h" #include "DerivationFrameworkSUSY/SUSYGenFilterTool.h" #include "DerivationFrameworkSUSY/TrackParticleCaloCellDecorator.h" #include "DerivationFrameworkSUSY/trackIsolationDecorator.h" @@ -8,6 +9,7 @@ using namespace DerivationFramework; DECLARE_COMPONENT( Truth3CollectionMaker ) DECLARE_COMPONENT( SUSYSignalTagger ) +DECLARE_COMPONENT( SUSYIDWeight ) DECLARE_COMPONENT( SUSYGenFilterTool ) DECLARE_COMPONENT( TrackParticleCaloCellDecorator ) DECLARE_COMPONENT( trackIsolationDecorator )