diff --git a/Generators/GeneratorFilters/GeneratorFilters/xAODTauFilter.h b/Generators/GeneratorFilters/GeneratorFilters/xAODTauFilter.h index 5ff0bfc350beeab2da7f1a57498790dd001352c5..8097e053c302e4aedf9a7802003afeb0e349b623 100644 --- a/Generators/GeneratorFilters/GeneratorFilters/xAODTauFilter.h +++ b/Generators/GeneratorFilters/GeneratorFilters/xAODTauFilter.h @@ -33,6 +33,7 @@ private: CLHEP::HepRandomEngine* getRandomEngine(const std::string& streamName, const EventContext& ctx) const; + SG::ReadHandleKey<xAOD::TruthParticleContainer> m_truthPartContKey{this, "TruthParticleContainerKey", "TruthTaus"}; ServiceHandle<IAthRNGSvc> m_rndmSvc{this, "RndmSvc", "AthRNGSvc"};// Random number generator IntegerProperty m_Ntau{this, "Ntaus", 1}; diff --git a/Generators/GeneratorFilters/src/xAODTauFilter.cxx b/Generators/GeneratorFilters/src/xAODTauFilter.cxx index 225baee52445bfdb6543b042d2e7bf613770b65e..2146fbce7a347a7100b32c755bc29b0027571904 100644 --- a/Generators/GeneratorFilters/src/xAODTauFilter.cxx +++ b/Generators/GeneratorFilters/src/xAODTauFilter.cxx @@ -19,6 +19,7 @@ xAODTauFilter::xAODTauFilter( const std::string& name, ISvcLocator* pSvcLocator) StatusCode xAODTauFilter::filterInitialize() { + ATH_CHECK(m_truthPartContKey.initialize()); m_eventse = 0; m_eventsmu = 0; m_eventshad = 0; @@ -81,8 +82,11 @@ StatusCode xAODTauFilter::filterEvent() { double weight = 1; - const xAOD::TruthParticleContainer* vtruth = nullptr; - ATH_CHECK( evtStore()->retrieve( vtruth, "TruthTaus" ) ); + SG::ReadHandle<xAOD::TruthParticleContainer> xTruthParticleContainer{m_truthPartContKey}; + if (!xTruthParticleContainer.isValid()) { + ATH_MSG_ERROR("No TruthParticle collection with name " << m_truthPartContKey.key() << " found in StoreGate!"); + return StatusCode::FAILURE; + } //get the weight of the event from McEventCollection setFilterPassed(false); @@ -102,7 +106,7 @@ StatusCode xAODTauFilter::filterEvent() { } - for (const auto * truthtau : *vtruth) { + for (const auto * truthtau : *xTruthParticleContainer) { // Look for the first physical tau if (MC::isTau(truthtau) && MC::isPhysical(truthtau)) { const xAOD::TruthParticle* tau = truthtau; @@ -259,7 +263,7 @@ StatusCode xAODTauFilter::filterEvent() { if(m_NewOpt && m_HasTightRegion) { // Get MC event collection for setting weight const McEventCollection* mecc = 0; - if ( evtStore()->retrieve( mecc ).isFailure() || !mecc ){ + if ( evtStore()->retrieve( mecc ).isFailure() || !mecc ){ // FIXME keyless retrieve setFilterPassed(false); ATH_MSG_ERROR("Could not retrieve MC Event Collection - weight might not work"); return StatusCode::SUCCESS;