diff --git a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/JetQuarkLabel.h b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/JetQuarkLabel.h index 26df4eef542fce227b40353b09940bb400c06425..a20f3aafae700b3f1892c781e83e91b050fc437a 100644 --- a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/JetQuarkLabel.h +++ b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/JetQuarkLabel.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ //Dear emacs, this is -*-c++-*- @@ -56,7 +56,8 @@ class JetQuarkLabel : public asg::AsgTool, virtual public IJetTruthMatching { inline short EventSelection() const { return m_inTime; } private: - std::string m_mcEventCollection; + SG::ReadHandleKey<xAOD::TruthEventContainer> m_truthEventContainerKey{this,"McEventCollection","TruthEvents","ReadHandleKey for xAOD::TruthEventContainer"}; + std::string m_mcEventCollection; double m_deltaRCut; //!< deltaR cut value of the cone matching (max distance between Jet axis and momentum of truth particel) double m_ptCut; //!< pT cut for partons bool m_noDoc; diff --git a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/ParticleJetDeltaRLabelTool.h b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/ParticleJetDeltaRLabelTool.h index 7926ce7336d9fbea01b895f2f14196fd61437f31..638796283e1f96f1d60a04a11c706d9ca1227a3f 100644 --- a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/ParticleJetDeltaRLabelTool.h +++ b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/ParticleJetDeltaRLabelTool.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ #ifndef PARTICLEJETDELTARLABELTOOL_H @@ -18,6 +18,8 @@ public: /// Constructor ParticleJetDeltaRLabelTool(const std::string& name); + StatusCode initialize(); + StatusCode modify(xAOD::JetContainer& jets) const; std::vector<std::vector<const xAOD::TruthParticle*> > match( @@ -39,6 +41,11 @@ protected: std::string m_bottompartcollection; std::string m_charmpartcollection; + /// Read handles particle collections for labeling + SG::ReadHandleKey<xAOD::TruthParticleContainer> m_tauPartCollectionKey{this,"TauParticleCollection","","ReadHandleKey for tauPartCollection"}; + SG::ReadHandleKey<xAOD::TruthParticleContainer> m_bottomPartCollectionKey{this,"BParticleCollection","","ReadHandleKey for bottomPartCollection"}; + SG::ReadHandleKey<xAOD::TruthParticleContainer> m_charmPartCollectionKey{this,"CParticleCollection","","ReadHandleKey for charmPartCollection"}; + /// Minimum pT for particle selection (in MeV) double m_partptmin; diff --git a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/Root/JetQuarkLabel.cxx b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/Root/JetQuarkLabel.cxx index 034dad3b4679c5f472fab4799947ba7766ebbf53..905fd47861976ea5520d8a6a70cb905f9d1c6c07 100644 --- a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/Root/JetQuarkLabel.cxx +++ b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/Root/JetQuarkLabel.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ /////////////////////////////////////////////////////////////////// @@ -30,13 +30,11 @@ namespace Analysis { JetQuarkLabel::JetQuarkLabel(const std::string& name) : AsgTool(name), - m_mcEventCollection("TruthEvents"), m_deltaRCut(0.3), m_ptCut(5.*GeVtoMeV), m_noDoc(true), m_inTime(-1) { - declareProperty("McEventCollection", m_mcEventCollection); declareProperty("deltaRCut", m_deltaRCut); declareProperty("pTmin", m_ptCut); declareProperty("NoUseDoc", m_noDoc); @@ -46,6 +44,7 @@ JetQuarkLabel::JetQuarkLabel(const std::string& name) JetQuarkLabel::~JetQuarkLabel() {} StatusCode JetQuarkLabel::initialize() { + ATH_CHECK(m_truthEventContainerKey.initialize()); return StatusCode::SUCCESS; } @@ -55,27 +54,14 @@ bool JetQuarkLabel::matchJet(const xAOD::Jet& myJet, if (info) *info = MatchInfo(); - /* ----------------------------------------------------------------------------------- */ - /* Retrieve McEventCollection */ - /* ----------------------------------------------------------------------------------- */ -/* - const McEventCollection* myMcEventCollection(0); - StatusCode sc = evtStore()->retrieve(myMcEventCollection, m_mcEventCollection); - if (sc.isFailure()) { - ATH_MSG_DEBUG(m_mcEventCollection << " not found in StoreGate."); - return false; - } - return testJet(myJet,myMcEventCollection); -*/ + SG::ReadHandle<xAOD::TruthEventContainer> truthEventContainerReadHandle(m_truthEventContainerKey); -//retrieve xAOD::TruthEvent - const xAOD::TruthEventContainer* truthEventContainer = NULL; - StatusCode sc = evtStore()->retrieve(truthEventContainer, m_mcEventCollection); - if (sc.isFailure()) { - ATH_MSG_DEBUG(m_mcEventCollection << " not found in StoreGate."); + if (!truthEventContainerReadHandle.isValid()){ + ATH_MSG_DEBUG(" Invalid ReadHandle for xAOD::TruthEventContainer with key: " << truthEventContainerReadHandle.key()); return false; } - return testJet(myJet,truthEventContainer, info); + + return testJet(myJet,truthEventContainerReadHandle.cptr(), info); } diff --git a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/Root/ParticleJetDeltaRLabelTool.cxx b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/Root/ParticleJetDeltaRLabelTool.cxx index 77c98a38ab473a84ef1a6c7e79d01beb1343bcfd..3ed484a63c6a21c8859c0fac081db70879f67c8c 100644 --- a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/Root/ParticleJetDeltaRLabelTool.cxx +++ b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/Root/ParticleJetDeltaRLabelTool.cxx @@ -16,9 +16,6 @@ ParticleJetDeltaRLabelTool::ParticleJetDeltaRLabelTool(const std::string& name) declareProperty("BLabelName", m_bottomlabelname="", "Name of the attribute to be added for matched B hadrons."); declareProperty("CLabelName", m_charmlabelname="", "Name of the attribute to be added for matched C hadrons."); declareProperty("TauLabelName", m_taulabelname="", "Name of the attribute to be added for matched taus."); - declareProperty("BParticleCollection", m_bottompartcollection="", "Name of the particle collection used for matching B hadrons"); - declareProperty("CParticleCollection", m_charmpartcollection="", "Name of the particle collection used for matching C hadrons"); - declareProperty("TauParticleCollection", m_taupartcollection="", "Name of the particle collection used for matching taus"); declareProperty("PartPtMin", m_partptmin=5000, "Minimum pT of particles for labeling (MeV)"); declareProperty("JetPtMin", m_jetptmin=10000, "Minimum pT of jets to be lebeled (MeV)"); declareProperty("DRMax", m_drmax=0.3, "Maximum deltaR between a particle and jet to be labeled"); @@ -108,22 +105,41 @@ namespace { } +StatusCode ParticleJetDeltaRLabelTool::initialize(){ + ATH_CHECK(m_tauPartCollectionKey.initialize()); + ATH_CHECK(m_bottomPartCollectionKey.initialize()); + ATH_CHECK(m_charmPartCollectionKey.initialize()); + return StatusCode::SUCCESS; +} + StatusCode ParticleJetDeltaRLabelTool::modify(JetContainer& jets) const { ATH_MSG_VERBOSE("In " << name() << "::modify()"); // Retrieve the particle and jet containers - const TruthParticleContainer* taus = NULL; - const TruthParticleContainer* bs = NULL; - const TruthParticleContainer* cs = NULL; - ASG_CHECK( evtStore()->retrieve( taus, m_taupartcollection) ); - ASG_CHECK( evtStore()->retrieve( bs, m_bottompartcollection) ); - ASG_CHECK( evtStore()->retrieve( cs, m_charmpartcollection) ); - - vector<vector<const TruthParticle*> > jetlabelpartsb = match(*bs, jets); - vector<vector<const TruthParticle*> > jetlabelpartsc = match(*cs, jets); - vector<vector<const TruthParticle*> > jetlabelpartstau = match(*taus, jets); + SG::ReadHandle<xAOD::TruthParticleContainer> truthtausReadHandle(m_tauPartCollectionKey); + SG::ReadHandle<xAOD::TruthParticleContainer> truthbsReadHandle(m_bottomPartCollectionKey); + SG::ReadHandle<xAOD::TruthParticleContainer> truthcsReadHandle(m_charmPartCollectionKey); + + if (!truthtausReadHandle.isValid()){ + ATH_MSG_DEBUG(" Invalid ReadHandle for xAOD::ParticleContainer with key: " << truthtausReadHandle.key()); + return StatusCode::FAILURE; + } + + if (!truthbsReadHandle.isValid()){ + ATH_MSG_DEBUG(" Invalid ReadHandle for xAOD::ParticleContainer with key: " << truthbsReadHandle.key()); + return StatusCode::FAILURE; + } + + if (!truthcsReadHandle.isValid()){ + ATH_MSG_DEBUG(" Invalid ReadHandle for xAOD::ParticleContainer with key: " << truthcsReadHandle.key()); + return StatusCode::FAILURE; + } + + vector<vector<const TruthParticle*> > jetlabelpartsb = match(*truthbsReadHandle, jets); + vector<vector<const TruthParticle*> > jetlabelpartsc = match(*truthcsReadHandle, jets); + vector<vector<const TruthParticle*> > jetlabelpartstau = match(*truthtausReadHandle, jets); for (unsigned int iJet = 0; iJet < jets.size(); iJet++) { // remove children whose parent hadrons are also in the jet.