Skip to content
Snippets Groups Projects
Commit 5d10651b authored by Johannes Junggeburth's avatar Johannes Junggeburth :dog2: Committed by Stefan Richter
Browse files

GenFilterTool - Declare data dependenies

GenFilterTool - Declare data dependenies
parent b58dafd6
No related branches found
No related tags found
No related merge requests found
......@@ -6,8 +6,6 @@
#include "GenFilterTool.h"
// EDM includes
#include "xAODEventInfo/EventInfo.h"
#include "xAODJet/JetContainer.h"
#include "TruthUtils/MagicNumbers.h"
// Tool handle interface
......@@ -47,24 +45,14 @@ namespace DerivationFramework {
static const SG::AuxElement::Decorator<float> dec_genFiltFatJ("GenFiltFatJ");
GenFilterTool::GenFilterTool(const std::string& t, const std::string& n, const IInterface* p)
: AthAlgTool(t,n,p)
, m_classif("MCTruthClassifier/DFCommonTruthClassifier")
{
: AthAlgTool(t,n,p) {
declareInterface<DerivationFramework::IAugmentationTool>(this);
declareProperty("EventInfoName",m_eventInfoName="EventInfo");
declareProperty("MCCollectionName",m_mcName="TruthParticles");
declareProperty("TruthJetCollectionName",m_truthJetsName="AntiKt4TruthWZJets");
declareProperty("MinJetPt",m_MinJetPt = 35e3);
declareProperty("MaxJetEta",m_MaxJetEta = 2.5);
declareProperty("MinLeptonPt",m_MinLepPt = 25e3);
declareProperty("MaxLeptonEta",m_MaxLepEta = 2.5);
}
GenFilterTool::~GenFilterTool(){}
GenFilterTool::~GenFilterTool() = default;
bool GenFilterTool::isPrompt( const xAOD::TruthParticle* tp ) const
{
......@@ -96,24 +84,31 @@ namespace DerivationFramework {
}
return true;
}
StatusCode GenFilterTool::initialize() {
ATH_CHECK(m_eventInfoKey.initialize());
ATH_CHECK(m_mcKey.initialize());
ATH_CHECK(m_truthJetsKey.initialize());
ATH_CHECK(m_truthFatJetsKey.initialize());
for (const SG::AuxElement::Decorator<float>& dec : {
dec_genFiltHT, dec_genFiltHTinclNu, dec_genFiltMET, dec_genFiltPTZ, dec_genFiltFatJ
}) {
m_decorKeys.emplace_back(m_eventInfoKey.key() + "." + SG::AuxTypeRegistry::instance().getName(dec.auxid()));
}
ATH_CHECK(m_decorKeys.initialize());
return StatusCode::SUCCESS;
}
StatusCode GenFilterTool::addBranches() const{
ATH_MSG_VERBOSE("GenFilterTool::addBranches()");
const xAOD::EventInfo* eventInfo;
if (evtStore()->retrieve(eventInfo,m_eventInfoName).isFailure()) {
ATH_MSG_ERROR("could not retrieve event info " <<m_eventInfoName);
const EventContext& ctx = Gaudi::Hive::currentContext();
SG::ReadHandle<xAOD::EventInfo> eventInfo{m_eventInfoKey, ctx};
if (!eventInfo.isValid()) {
ATH_MSG_ERROR("could not retrieve event info " <<m_eventInfoKey.fullKey());
return StatusCode::FAILURE;
}
const xAOD::TruthParticleContainer* truthPC = nullptr;
if (evtStore()->retrieve(truthPC,m_mcName).isFailure()) {
ATH_MSG_ERROR("WARNING could not retrieve TruthParticleContainer " <<m_mcName);
return StatusCode::FAILURE;
}
float genFiltHT(0.), genFiltHTinclNu(0.), genFiltMET(0.), genFiltPTZ(0.), genFiltFatJ(0.);
ATH_CHECK( getGenFiltVars(truthPC, genFiltHT, genFiltHTinclNu, genFiltMET, genFiltPTZ, genFiltFatJ) );
float genFiltHT{0.f}, genFiltHTinclNu{0.f}, genFiltMET{0.f}, genFiltPTZ{0.f}, genFiltFatJ{0.f};
ATH_CHECK( getGenFiltVars(ctx, genFiltHT, genFiltHTinclNu, genFiltMET, genFiltPTZ, genFiltFatJ) );
ATH_MSG_DEBUG("Computed generator filter quantities: HT " << genFiltHT/1e3 << ", HTinclNu " << genFiltHTinclNu/1e3 << ", MET " << genFiltMET/1e3 << ", PTZ " << genFiltPTZ/1e3 << ", FatJ " << genFiltFatJ/1e3 );
......@@ -126,11 +121,18 @@ namespace DerivationFramework {
return StatusCode::SUCCESS;
}
StatusCode GenFilterTool::getGenFiltVars(const xAOD::TruthParticleContainer* tpc, float& genFiltHT, float& genFiltHTinclNu, float& genFiltMET, float& genFiltPTZ, float& genFiltFatJ) const {
StatusCode GenFilterTool::getGenFiltVars(const EventContext& ctx, float& genFiltHT, float& genFiltHTinclNu, float& genFiltMET, float& genFiltPTZ, float& genFiltFatJ) const {
// Get jet container out
const xAOD::JetContainer* truthjets = nullptr;
if ( evtStore()->retrieve( truthjets, m_truthJetsName).isFailure() || !truthjets ){
ATH_MSG_ERROR( "No xAOD::JetContainer found in StoreGate with key " << m_truthJetsName );
SG::ReadHandle<xAOD::TruthParticleContainer> tpc{m_mcKey, ctx} ;
if (!tpc.isValid()) {
ATH_MSG_ERROR("WARNING could not retrieve TruthParticleContainer " <<m_mcKey.fullKey());
return StatusCode::FAILURE;
}
SG::ReadHandle<xAOD::JetContainer> truthjets{m_truthJetsKey, ctx};
if (!truthjets.isValid()){
ATH_MSG_ERROR( "No xAOD::JetContainer found in StoreGate with key " << m_truthJetsKey );
return StatusCode::FAILURE;
}
......@@ -231,9 +233,9 @@ namespace DerivationFramework {
//Get FatJ
// Get correct jet container
const xAOD::JetContainer* truthjets10 = nullptr;
if ( evtStore()->retrieve( truthjets10, "AntiKt10TruthJets").isFailure() || !truthjets10 ){
ATH_MSG_ERROR( "No xAOD::JetContainer found in StoreGate with key AntiKt10TruthJets" );
SG::ReadHandle<xAOD::JetContainer> truthjets10{m_truthFatJetsKey, ctx} ;
if ( !truthjets10.isValid()){
ATH_MSG_ERROR( "No xAOD::JetContainer found in StoreGate with key "<<m_truthFatJetsKey.fullKey() );
return StatusCode::FAILURE;
}
genFiltFatJ=0.;
......
......@@ -15,19 +15,17 @@
// Base classes
#include "AthenaBaseComps/AthAlgTool.h"
#include "DerivationFrameworkInterfaces/IAugmentationTool.h"
// Tool handle for the MC truth classifier
#include "GaudiKernel/ToolHandle.h"
#include "GaudiKernel/SystemOfUnits.h"
// EDM include -- typedef, so has to be included
#include "xAODTruth/TruthParticleContainer.h"
#include "xAODEventInfo/EventInfo.h"
#include "xAODJet/JetContainer.h"
#include "StoreGate/ReadHandleKey.h"
#include "StoreGate/WriteDecorHandleKeyArray.h"
// Defs for the particle origin
#include "MCTruthClassifier/MCTruthClassifierDefs.h"
// STL includes
#include <string>
class IMCTruthClassifier;
namespace DerivationFramework {
......@@ -37,23 +35,29 @@ namespace DerivationFramework {
public:
GenFilterTool(const std::string& t, const std::string& n, const IInterface* p);
~GenFilterTool();
virtual StatusCode addBranches() const override;
virtual StatusCode addBranches() const override final;
virtual StatusCode initialize() override final;
private:
StatusCode getGenFiltVars(const xAOD::TruthParticleContainer* tpc, float& genFiltHT, float& genFiltHTinclNu, float& genFiltMET, float& genFiltPTZ, float& genFiltFatJ) const;
StatusCode getGenFiltVars(const EventContext& ctx, float& genFiltHT, float& genFiltHTinclNu, float& genFiltMET, float& genFiltPTZ, float& genFiltFatJ) const;
bool isPrompt( const xAOD::TruthParticle* tp ) const;
std::string m_eventInfoName;
std::string m_mcName;
std::string m_truthJetsName;
float m_MinJetPt; //!< Min pT for the truth jets
float m_MaxJetEta; //!< Max eta for the truth jets
float m_MinLepPt; //!< Min pT for the truth leptons
float m_MaxLepEta; //!< Max eta for the truth leptons
SG::ReadHandleKey<xAOD::EventInfo>m_eventInfoKey{this,"EventInfoName" , "EventInfo"};
SG::ReadHandleKey<xAOD::TruthParticleContainer>m_mcKey{this, "MCCollectionName", "TruthParticles"};
SG::ReadHandleKey<xAOD::JetContainer>m_truthJetsKey{this, "TruthJetCollectionName", "AntiKt4TruthWZJets"};
SG::ReadHandleKey<xAOD::JetContainer>m_truthFatJetsKey{this, "TruthFatJetCollectionName", "AntiKt10TruthJets"};
SG::WriteDecorHandleKeyArray<xAOD::EventInfo> m_decorKeys{this, "DecorationKeys", {} , "Decorations added to the eventinfo"};
Gaudi::Property<float> m_MinJetPt{this, "MinJetPt", 35.* Gaudi::Units::GeV}; //!< Min pT for the truth jets
Gaudi::Property<float> m_MaxJetEta{this, "MaxJetEta", 2.5}; //!< Max eta for the truth jets
Gaudi::Property<float> m_MinLepPt{this,"MinLeptonPt", 25.*Gaudi::Units::GeV}; //!< Min pT for the truth leptons
Gaudi::Property<float> m_MaxLepEta{this, "MaxLeptonEta", 2.5}; //!< Max eta for the truth leptons
ToolHandle<IMCTruthClassifier> m_classif;
PublicToolHandle<IMCTruthClassifier> m_classif{this, "TruthClassifier", "MCTruthClassifier/DFCommonTruthClassifier"};
}; /// class
} /// namespace
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment