diff --git a/Reconstruction/Jet/JetMomentTools/JetMomentTools/JetCaloQualityTool.h b/Reconstruction/Jet/JetMomentTools/JetMomentTools/JetCaloQualityTool.h index 94ddbc0543c9dd052a58bfc2ef8372f33c0bccbb..34a34260d264d5c5f18288aabc8e507e323d108c 100644 --- a/Reconstruction/Jet/JetMomentTools/JetMomentTools/JetCaloQualityTool.h +++ b/Reconstruction/Jet/JetMomentTools/JetMomentTools/JetCaloQualityTool.h @@ -1,7 +1,7 @@ // this file is -*- C++ -*- /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ /** @@ -25,30 +25,37 @@ #ifndef JETREC_JETCALOQUALITYTOOL_H #define JETREC_JETCALOQUALITYTOOL_H -#include "JetRec/JetModifierBase.h" - +#include "AsgTools/AsgTool.h" +#include "JetInterface/IJetDecorator.h" #include "JetUtils/JetCaloCalculations.h" +#include "StoreGate/WriteDecorHandleKeyArray.h" #include <vector> #include <string> -class JetCaloQualityTool: public JetModifierBase { +class JetCaloQualityTool: public asg::AsgTool, + virtual public IJetDecorator { ASG_TOOL_CLASS0(JetCaloQualityTool) public: JetCaloQualityTool(const std::string & name); - virtual int modifyJet(xAOD::Jet& ) const ; + virtual StatusCode decorate(const xAOD::JetContainer& jets) const override; - virtual StatusCode initialize(); + virtual StatusCode initialize() override; protected: - /// Names of calo quantities to compute and to add as attributes - std::vector<std::string> m_calculationNames; - /// Time cuts for Out-of-time calo quantities. - std::vector <double> m_timingTimeCuts; + Gaudi::Property<std::vector<std::string> > m_calculationNames{this, "Calculations", {}, + "Name of calo quantities to compute and add as decorations"}; + Gaudi::Property<std::vector<double> > m_timingTimeCuts{this, "TimingCuts", {}, + "Time cuts for out-of-time calo quantities"}; + Gaudi::Property<std::string> m_jetContainerName{this, "JetContainer", "", + "SG key of input jet container"}; + + SG::WriteDecorHandleKeyArray<xAOD::JetContainer> m_writeDecorKeys{this, "OutputDecorKeys", {}, + "SG keys for output decorations (not to be configured manually!)"}; /// This objects holds a list of cluster-based calculators jet::JetCaloCalculations m_jetCalculations; @@ -56,7 +63,6 @@ public: // internal pointer to m_jetCalculations (this pointer is also used in the cell-based derived tool) jet::JetCaloCalculations * m_calcProcessor; - bool m_doFracSamplingMax; // internal }; #endif diff --git a/Reconstruction/Jet/JetMomentTools/JetMomentTools/JetECPSFractionTool.h b/Reconstruction/Jet/JetMomentTools/JetMomentTools/JetECPSFractionTool.h index c54cf78214f5c4a878bdaf14d48f91dc0f508f62..e341c78e4b8a5be40db1aeecaa0e7040a985aed5 100644 --- a/Reconstruction/Jet/JetMomentTools/JetMomentTools/JetECPSFractionTool.h +++ b/Reconstruction/Jet/JetMomentTools/JetMomentTools/JetECPSFractionTool.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ // JetECPSFractionTool.h @@ -21,27 +21,37 @@ /// ECPSFraction: Fraction of jet energy in the ECPS /// -#include "JetRec/JetModifierBase.h" +#include "AsgTools/AsgTool.h" +#include "StoreGate/WriteDecorHandleKey.h" +#include "JetInterface/IJetDecorator.h" + +class JetECPSFractionTool : public asg::AsgTool, + virtual public IJetDecorator{ + ASG_TOOL_CLASS(JetECPSFractionTool, IJetDecorator) -class JetECPSFractionTool : public JetModifierBase { - ASG_TOOL_CLASS(JetECPSFractionTool, IJetModifier) - public: // Constructor from tool name. JetECPSFractionTool(std::string myname); - // Inherited method to modify a jet. - // Calls width and puts the result on the jet. - int modifyJet(xAOD::Jet& jet) const; + // Inherited method to decorate a jet. + virtual StatusCode decorate(const xAOD::JetContainer& jets) const override; + + // Inherited from AsgTool + virtual StatusCode initialize() override; // Local method to calculate and return the energy fraction. double energyFraction(const xAOD::Jet& jet) const; private: - // Properties. - double m_fraclimit; + Gaudi::Property<double> m_fraclimit{this, "ECPSFractionThreshold", 0.8, + "Threshold for identifying a cluser as ECPS"}; + Gaudi::Property<std::string> m_jetContainerName{this, "JetContainer", "", + "SG key for input jet container"}; + + SG::WriteDecorHandleKey<xAOD::JetContainer> m_fracKey{this, "ECPSFractionDecorKey", "ECPSFraction", + "Name for output ECPS fraction decoration"}; }; diff --git a/Reconstruction/Jet/JetMomentTools/JetMomentTools/JetLArHVTool.h b/Reconstruction/Jet/JetMomentTools/JetMomentTools/JetLArHVTool.h index 2f75f0ca085816eebf238e7d69714c2fc9463e9c..928ec6670cd32a00664afc22f07b2b1178d06f8f 100644 --- a/Reconstruction/Jet/JetMomentTools/JetMomentTools/JetLArHVTool.h +++ b/Reconstruction/Jet/JetMomentTools/JetMomentTools/JetLArHVTool.h @@ -1,7 +1,7 @@ // this file is -*- C++ -*- /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ @@ -17,23 +17,32 @@ #ifndef JETMOMENTTOOLS_JETLARHVTOOL_H #define JETMOMENTTOOLS_JETLARHVTOOL_H -#include "JetRec/JetModifierBase.h" #include "AsgTools/ToolHandle.h" +#include "AsgTools/AsgTool.h" +#include "StoreGate/WriteDecorHandleKey.h" +#include "JetInterface/IJetDecorator.h" -class JetLArHVTool: public JetModifierBase { +class JetLArHVTool: public asg::AsgTool, + virtual public IJetDecorator{ ASG_TOOL_CLASS0(JetLArHVTool) public: JetLArHVTool(const std::string & name); - virtual int modifyJet(xAOD::Jet& ) const ; - - virtual StatusCode initialize(); + virtual StatusCode decorate(const xAOD::JetContainer& jets) const override; + + virtual StatusCode initialize() override; private: + Gaudi::Property<std::string> m_jetContainerName{this, "JetContainer", "", + "SG key for the input jet container"}; + SG::WriteDecorHandleKey<xAOD::JetContainer> m_fracKey{this, "EnergyFracDecorKey", "LArBadHVEnergyFrac", + "SG key for energy fraction decoration (not including jet container name)"}; + SG::WriteDecorHandleKey<xAOD::JetContainer> m_nCellKey{this, "NCellDecorKey", "LArBadHVNCell", + "SG key for nCell decoration (not including jet container name)"}; }; #endif diff --git a/Reconstruction/Jet/JetMomentTools/JetMomentTools/JetVoronoiMomentsTool.h b/Reconstruction/Jet/JetMomentTools/JetMomentTools/JetVoronoiMomentsTool.h index 2310dec2b53113269b7d2ba0eb67a32d48292c94..90a11066acf8aa7f792ed7ea04ba7734556854e1 100644 --- a/Reconstruction/Jet/JetMomentTools/JetMomentTools/JetVoronoiMomentsTool.h +++ b/Reconstruction/Jet/JetMomentTools/JetMomentTools/JetVoronoiMomentsTool.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ // JetVoronoiMomentsTool.h @@ -17,35 +17,45 @@ /// #include <string> -#include "JetRec/JetModifierBase.h" -#include "xAODJet/Jet.h" +#include "AsgTools/AsgTool.h" +#include "StoreGate/WriteDecorHandleKey.h" +#include "JetInterface/IJetDecorator.h" namespace JetVoronoiDiagramHelpers{ struct Diagram; } -class JetVoronoiMomentsTool : public JetModifierBase { -ASG_TOOL_CLASS(JetVoronoiMomentsTool,IJetModifier) +class JetVoronoiMomentsTool : public asg::AsgTool, + virtual public IJetDecorator { +ASG_TOOL_CLASS(JetVoronoiMomentsTool,IJetDecorator) public: // Constructor from tool name JetVoronoiMomentsTool(const std::string& name); - // Inherited methods to modify a jet container - virtual StatusCode modify(xAOD::JetContainer& jets) const; - virtual int modifyJet(xAOD::Jet& jet) const; + // Inherited from AsgTool via IJetDecorator + virtual StatusCode initialize() override; + + // Inherited method to decorate a jet container + virtual StatusCode decorate(const xAOD::JetContainer& jets) const override; private: // parameters - float m_x_min; - float m_x_max; - float m_y_min; - float m_y_max; - - int modifyJet(xAOD::Jet& jet, const JetVoronoiDiagramHelpers::Diagram & voro) const; - + Gaudi::Property<float> m_x_min{this, "AreaXmin", -10, + "Minimum x-value for Voronoi diagram"}; + Gaudi::Property<float> m_x_max{this, "AreaXmax", 10, + "Maximum x-value for Voronoi diagram"}; + Gaudi::Property<float> m_y_min{this, "AreaYmin", -4, + "Minimum y-value for Voronoi diagram"}; + Gaudi::Property<float> m_y_max{this, "AreaYmax", 4, + "Maximum y-value for Voronoi diagram"}; + Gaudi::Property<std::string> m_jetContainerName{this, "JetContainer", "", + "SG key for the input jet container"}; + + SG::WriteDecorHandleKey<xAOD::JetContainer> m_voronoiAreaKey{this, "VoronoiAreaKey", "VoronoiArea", + "SG key for Voronoi area decoration (not including jet container name)"}; }; #endif diff --git a/Reconstruction/Jet/JetMomentTools/JetMomentTools/JetWidthTool.h b/Reconstruction/Jet/JetMomentTools/JetMomentTools/JetWidthTool.h index a768a18daf6bafdaa9bf18dc72239ac8a3cb4ddf..8b4df942064856c73c433492b47a449919981c4a 100644 --- a/Reconstruction/Jet/JetMomentTools/JetMomentTools/JetWidthTool.h +++ b/Reconstruction/Jet/JetMomentTools/JetMomentTools/JetWidthTool.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ // JetWidthTool.h @@ -12,28 +12,40 @@ /// /// Tool to calculate the jet width. -#include "JetRec/JetModifierBase.h" +#include "JetInterface/IJetDecorator.h" +#include "AsgTools/AsgTool.h" #include "AsgTools/ToolHandle.h" +#include "StoreGate/WriteDecorHandleKey.h" #include "PFlowUtils/IWeightPFOTool.h" -class JetWidthTool : public JetModifierBase { - ASG_TOOL_CLASS(JetWidthTool, IJetModifier) - +class JetWidthTool : public asg::AsgTool, + virtual public IJetDecorator { + ASG_TOOL_CLASS(JetWidthTool, IJetDecorator) + public: // Constructor from tool name. JetWidthTool(std::string myname); - // Inherited method to modify a jet. - // Calls width and puts the result on the jet. - virtual int modifyJet(xAOD::Jet& jet) const; + virtual StatusCode initialize() override; + + // Inherited method to decorate a jet container. + // Calls width and puts the result on the jets. + virtual StatusCode decorate(const xAOD::JetContainer& jets) const override; // Local method to calculate and return the width. - //double width(const xAOD::Jet& jet) const; - double width(const xAOD::Jet& jet, double& widthEta, double& widthPhi) const; + float width(const xAOD::Jet& jet, float& widthEta, float& widthPhi) const; private: + + Gaudi::Property<std::string> m_jetContainerName{this, "JetContainer", "", + "SG key for the input jet container"}; + + SG::WriteDecorHandleKey<xAOD::JetContainer> m_widthKey{this, "WidthKey", "Width", + "SG key for width decoration (not including jet container name)"}; + SG::WriteDecorHandleKey<xAOD::JetContainer> m_widthPhiKey{this, "WidthPhiKey", "WidthPhi", + "SG key for width phi decoration (not including jet container name)"}; }; #endif diff --git a/Reconstruction/Jet/JetMomentTools/Root/JetCaloQualityTool.cxx b/Reconstruction/Jet/JetMomentTools/Root/JetCaloQualityTool.cxx index 2d4b5bea816c0cc91fef94d3800b2e90111157b2..fff60c74d56b5907b4e951e285605527e55ef9b3 100644 --- a/Reconstruction/Jet/JetMomentTools/Root/JetCaloQualityTool.cxx +++ b/Reconstruction/Jet/JetMomentTools/Root/JetCaloQualityTool.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ @@ -7,6 +7,7 @@ #include "JetMomentTools/JetCaloQualityTool.h" #include "xAODJet/JetAccessorMap.h" +#include "StoreGate/WriteDecorHandle.h" #include <iostream> @@ -16,50 +17,69 @@ using namespace jet; JetCaloQualityTool::JetCaloQualityTool(const std::string& name) - : JetModifierBase(name) + : asg::AsgTool(name) { - - - declareProperty("TimingCuts", m_timingTimeCuts); - declareProperty("Calculations", m_calculationNames); + declareInterface<IJetDecorator>(this); } -int JetCaloQualityTool::modifyJet( xAOD::Jet& jet ) const +StatusCode JetCaloQualityTool::decorate(const xAOD::JetContainer& jets) const { - if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Inside process() method" << endmsg; - - if(m_doFracSamplingMax==true) - { - // Special case : we want to store more than 1 value (max sampling AND its index). - // AND there's no code available for direct cell access. - // So we just use a direct function instead of a calculator for now. + if(msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Inside decorate() method" << endmsg; + + //bool checkedContainer = false; + const size_t nDecorations = m_writeDecorKeys.size(); + if(m_doFracSamplingMax==true){ + // Special case : we want to store more than 1 value (max sampling AND its index). + // AND there's no code available for direct cell access. + // So we just use a direct function instead of a calculator for now. + + // We specifically put these in last earlier + SG::WriteDecorHandle<xAOD::JetContainer, float> maxHandle(m_writeDecorKeys.at(nDecorations-2)); + SG::WriteDecorHandle<xAOD::JetContainer, int> samplingHandle(m_writeDecorKeys.at(nDecorations-1)); + + for(const xAOD::Jet* jet : jets){ int sampling=-1; - double fracSamplingMax=JetCaloQualityUtils::fracSamplingMax(&jet,sampling); + double fracSamplingMax=JetCaloQualityUtils::fracSamplingMax(jet,sampling); ATH_MSG_VERBOSE("Setting " << xAOD::JetAttribute::FracSamplingMax << " to " << fracSamplingMax); - jet.setAttribute<float>(xAOD::JetAttribute::FracSamplingMax,fracSamplingMax ); - jet.setAttribute<int>(xAOD::JetAttribute::FracSamplingMaxIndex,sampling ); + maxHandle(*jet) = fracSamplingMax; + samplingHandle(*jet) = sampling; } - + } + // Do all other calculations - std::vector<double> results = m_calcProcessor->process(&jet); - - // store them in the jet - for(size_t i=0;i < m_calcProcessor->numCalculators();i++) { - const JetCaloCalculator* calc = m_calcProcessor->at(i); - ATH_MSG_DEBUG( calc->name() << " -> "<<results[i] ); - jet.setAttribute<float>( calc->name(), results[i] ); + for(const xAOD::Jet* jet : jets){ + + std::vector<double> results = m_calcProcessor->process(jet); + + // store them in the jet + for(size_t i=0;i < m_calcProcessor->numCalculators();i++) { + // We inserted WriteDecorKeys in the same order as calculators + SG::WriteDecorHandle<xAOD::JetContainer, float> decHandle(m_writeDecorKeys.at(i)); + + const JetCaloCalculator* calc = m_calcProcessor->at(i); + ATH_MSG_DEBUG( calc->name() << " -> "<<results[i] ); + decHandle(*jet) = results[i]; + } } - - return 1; + return StatusCode::SUCCESS; } StatusCode JetCaloQualityTool::initialize() { ATH_MSG_DEBUG( "Inside initialize() method" ); + if(!m_writeDecorKeys.empty()){ + ATH_MSG_ERROR("OutputDecorKeys should not be configured manually!"); + return StatusCode::FAILURE; + } + if(m_jetContainerName.empty()){ + ATH_MSG_ERROR("JetCaloQualityTool needs to have its input jet container name configured!"); + return StatusCode::FAILURE; + } + // In this tool we're using the cluster-based calculators // (this is different in the cell-based calculation tool). m_calcProcessor = & m_jetCalculations; @@ -100,10 +120,13 @@ StatusCode JetCaloQualityTool::initialize() { } else if (calcN == "FracSamplingMax") { m_doFracSamplingMax = true; // no calculator, as this is a special case. } - }// end loop over m_calculationNames - + // Set the DecorHandleKeys with the correct strings + for(size_t i=0; i < m_jetCalculations.numCalculators(); i++){ + m_writeDecorKeys.emplace_back(m_jetContainerName + "." + m_jetCalculations.at(i)->name()); + } + // Define OOT calculators. for( double & timeCut : m_timingTimeCuts){ @@ -115,8 +138,17 @@ StatusCode JetCaloQualityTool::initialize() { c->setName(s.str()); c->timecut = timeCut; m_jetCalculations.addCalculator( c ); + m_writeDecorKeys.emplace_back(m_jetContainerName + "." + s.str()); } + // Add these last so m_jetCalculations and m_writeDecorKeys have corresponding indices + if (m_doFracSamplingMax){ + m_writeDecorKeys.emplace_back(m_jetContainerName + ".FracSamplingMax"); + m_writeDecorKeys.emplace_back(m_jetContainerName + ".FracSamplingMaxIndex"); + } + + ATH_CHECK(m_writeDecorKeys.initialize()); + return StatusCode::SUCCESS; } diff --git a/Reconstruction/Jet/JetMomentTools/Root/JetECPSFractionTool.cxx b/Reconstruction/Jet/JetMomentTools/Root/JetECPSFractionTool.cxx index 9ad518155d8a5d6c6e439aa439b3efb9e2481626..3a317b528928979150f484ad8e13d005206b92bd 100644 --- a/Reconstruction/Jet/JetMomentTools/Root/JetECPSFractionTool.cxx +++ b/Reconstruction/Jet/JetMomentTools/Root/JetECPSFractionTool.cxx @@ -1,9 +1,10 @@ /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ // JetECPSFractionTool.cxx +#include "StoreGate/WriteDecorHandle.h" #include "JetMomentTools/JetECPSFractionTool.h" #include "xAODCaloEvent/CaloCluster.h" #include "xAODPFlow/PFO.h" @@ -20,16 +21,35 @@ using xAOD::JetFourMom_t; //********************************************************************** JetECPSFractionTool::JetECPSFractionTool(std::string myname) -: JetModifierBase(myname) { - declareProperty("ECPSFractionThreshold", m_fraclimit =0.8); +: asg::AsgTool(myname) { + + declareInterface<IJetDecorator>(this); } +//********************************************************************** + +StatusCode JetECPSFractionTool::initialize(){ + + if(m_jetContainerName.empty()){ + ATH_MSG_ERROR("JetECPSFractionTool needs to have its input jet container name configured!"); + return StatusCode::FAILURE; + } + + // Prepend jet collection name + m_fracKey = m_jetContainerName + "." + m_fracKey.key(); + + ATH_CHECK(m_fracKey.initialize()); + return StatusCode::SUCCESS; +} //********************************************************************** -int JetECPSFractionTool::modifyJet(xAOD::Jet& jet) const { - jet.setAttribute("ECPSFraction", energyFraction(jet)); - return 0; +StatusCode JetECPSFractionTool::decorate(const xAOD::JetContainer& jets) const { + + SG::WriteDecorHandle<xAOD::JetContainer, float> fracHandle(m_fracKey); + + for(const xAOD::Jet* jet : jets) fracHandle(*jet) = energyFraction(*jet); + return StatusCode::SUCCESS; } //********************************************************************** diff --git a/Reconstruction/Jet/JetMomentTools/Root/JetLArHVTool.cxx b/Reconstruction/Jet/JetMomentTools/Root/JetLArHVTool.cxx index 59707dfe6c1128ec5580ddfe58e452c9c06fdf93..41cfeec79ae3fbfe7851a1eb4ebbb64da4f80a4d 100644 --- a/Reconstruction/Jet/JetMomentTools/Root/JetLArHVTool.cxx +++ b/Reconstruction/Jet/JetMomentTools/Root/JetLArHVTool.cxx @@ -1,46 +1,65 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ +#include "StoreGate/WriteDecorHandle.h" #include "JetUtils/JetDistances.h" #include "JetMomentTools/JetLArHVTool.h" #include "xAODCaloEvent/CaloCluster.h" JetLArHVTool::JetLArHVTool(const std::string& name) - : JetModifierBase(name) + : asg::AsgTool(name) { + declareInterface<IJetDecorator>(this); } StatusCode JetLArHVTool::initialize() { + if(m_fracKey.key().at(0) == '.' || m_nCellKey.key().at(0) == '.'){ + ATH_MSG_ERROR("JetLArHVTool needs to have its input jet container name configured!"); + return StatusCode::FAILURE; + } + + // Prepend jet container name + m_fracKey = m_jetContainerName + "." + m_fracKey.key(); + m_nCellKey = m_jetContainerName + "." + m_nCellKey.key(); + + ATH_CHECK(m_fracKey.initialize()); + ATH_CHECK(m_nCellKey.initialize()); return StatusCode::SUCCESS; } -int JetLArHVTool::modifyJet( xAOD::Jet& jet ) const +StatusCode JetLArHVTool::decorate(const xAOD::JetContainer& jets) const { - double energyHVaff=0; - int numCellsHVaff=0; - - // loop over raw constituents. Look for clusters - size_t num = jet.numConstituents(); - for(size_t i=0;i<num;i++) { - const xAOD::CaloCluster * cl = dynamic_cast<const xAOD::CaloCluster *>(jet.rawConstituent(i)); - if( !cl) continue; - - double m; - if(cl->retrieveMoment(xAOD::CaloCluster::ENG_BAD_HV_CELLS,m) ) energyHVaff += m; - if(cl->retrieveMoment(xAOD::CaloCluster::N_BAD_HV_CELLS, m) ) numCellsHVaff += m; - } - double emE = jet.jetP4(xAOD::JetEMScaleMomentum).E(); - // set the attributes - jet.setAttribute<float>("LArBadHVEnergyFrac", energyHVaff / emE); - jet.setAttribute<int>("LArBadHVNCell", numCellsHVaff); - - return 0; + SG::WriteDecorHandle<xAOD::JetContainer, float> fracHandle(m_fracKey); + SG::WriteDecorHandle<xAOD::JetContainer, int> nCellHandle(m_nCellKey); + + for(const xAOD::Jet* jet : jets){ + + double energyHVaff=0; + int numCellsHVaff=0; + + // loop over raw constituents. Look for clusters + size_t num = jet->numConstituents(); + for(size_t i=0;i<num;i++) { + const xAOD::CaloCluster * cl = dynamic_cast<const xAOD::CaloCluster *>(jet->rawConstituent(i)); + if( !cl) continue; + + double m; + if(cl->retrieveMoment(xAOD::CaloCluster::ENG_BAD_HV_CELLS,m) ) energyHVaff += m; + if(cl->retrieveMoment(xAOD::CaloCluster::N_BAD_HV_CELLS, m) ) numCellsHVaff += m; + } + + double emE = jet->jetP4(xAOD::JetEMScaleMomentum).E(); + // set the attributes + fracHandle(*jet) = energyHVaff / emE; + nCellHandle(*jet) = numCellsHVaff; + } + return StatusCode::SUCCESS; } diff --git a/Reconstruction/Jet/JetMomentTools/Root/JetWidthTool.cxx b/Reconstruction/Jet/JetMomentTools/Root/JetWidthTool.cxx index 823c17576ab0a8b65b75444ca4d378f538a3774d..d18ec0d813ad5d582e1590d8ca43417b9ebce4e3 100644 --- a/Reconstruction/Jet/JetMomentTools/Root/JetWidthTool.cxx +++ b/Reconstruction/Jet/JetMomentTools/Root/JetWidthTool.cxx @@ -1,11 +1,11 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ // JetWidthTool.cxx #include "JetMomentTools/JetWidthTool.h" - +#include "StoreGate/WriteDecorHandle.h" #include "xAODJet/JetConstituentVector.h" #include "JetUtils/JetDistances.h" #include "PFlowUtils/IWeightPFOTool.h" @@ -13,52 +13,47 @@ //********************************************************************** JetWidthTool::JetWidthTool(std::string myname) - : JetModifierBase(myname) + : asg::AsgTool(myname) { + declareInterface<IJetDecorator>(this); } //********************************************************************** -int JetWidthTool::modifyJet(xAOD::Jet& jet) const { +StatusCode JetWidthTool::initialize(){ + + if(m_jetContainerName.empty()){ + ATH_MSG_ERROR("JetWidthTool needs to have its input jet container name configured!"); + return StatusCode::FAILURE; + } + + // Prepend jet container name + m_widthKey = m_jetContainerName + "." + m_widthKey.key(); + m_widthPhiKey = m_jetContainerName + "." + m_widthPhiKey.key(); - double widthEta = 0, widthPhi = 0; - //jet.setAttribute("Width", width(jet)); - jet.setAttribute("Width", width(jet,widthEta,widthPhi)); - //jet.setAttribute("WidthEta",widthEta); - jet.setAttribute("WidthPhi",widthPhi); - return 0; + ATH_CHECK(m_widthKey.initialize()); + ATH_CHECK(m_widthPhiKey.initialize()); + return StatusCode::SUCCESS; } //********************************************************************** -//double JetWidthTool::width(const xAOD::Jet& jet) const { -// -// // Get the constituents of the jet -// const xAOD::JetConstituentVector constituents = jet.getConstituents(); -// xAOD::JetConstituentVector::iterator iter = constituents.begin(); -// xAOD::JetConstituentVector::iterator iEnd = constituents.end(); -// -// // TODO: Switch to using helper function once JetUtils has been updated -// // Set the width -// // jetWidth = JetKinematics::ptWeightedWidth(iter,iEnd,&jet); -// -// // Calculate the pt weighted width -// const double jetEta = jet.eta(); -// const double jetPhi = jet.phi(); -// double weightedWidth = 0; -// double ptSum = 0; -// -// for ( ; iter != iEnd; ++iter) { -// const double dR = jet::JetDistances::deltaR(jetEta, jetPhi, iter->eta(), iter->phi() ); -// const double pt = iter->pt(); -// weightedWidth += dR * pt; -// ptSum += pt; -// } -// -// return ptSum > 0 ? weightedWidth/ptSum : -1; -//} - -double JetWidthTool::width(const xAOD::Jet& jet, double& widthEta, double& widthPhi) const { +StatusCode JetWidthTool::decorate(const xAOD::JetContainer& jets) const { + + SG::WriteDecorHandle<xAOD::JetContainer, float> widthHandle(m_widthKey); + SG::WriteDecorHandle<xAOD::JetContainer, float> widthPhiHandle(m_widthPhiKey); + + for(const xAOD::Jet* jet : jets){ + float widthEta = 0, widthPhi = 0; + widthHandle(*jet) = width(*jet,widthEta,widthPhi); + widthPhiHandle(*jet) = widthPhi; + } + return StatusCode::SUCCESS; +} + +//********************************************************************** + +float JetWidthTool::width(const xAOD::Jet& jet, float& widthEta, float& widthPhi) const { // Get the constituents of the jet // TODO: Switch to using helper function once JetUtils has been updated @@ -66,19 +61,19 @@ double JetWidthTool::width(const xAOD::Jet& jet, double& widthEta, double& width // jetWidth = JetKinematics::ptWeightedWidth(iter,iEnd,&jet); // Calculate the pt weighted width - const double jetEta = jet.eta(); - const double jetPhi = jet.phi(); - double weightedWidth = 0; - double weightedWidthEta = 0; - double weightedWidthPhi = 0; - double ptSum = 0; + const float jetEta = jet.eta(); + const float jetPhi = jet.phi(); + float weightedWidth = 0; + float weightedWidthEta = 0; + float weightedWidthPhi = 0; + float ptSum = 0; const xAOD::JetConstituentVector constituents = jet.getConstituents(); for (const auto& constituent : constituents) { - const double dR = jet::JetDistances::deltaR(jetEta, jetPhi, constituent->eta(), constituent->phi() ); - const double dEta = fabs(jet::JetDistances::deltaEta(jetEta, constituent->eta() )); - const double dPhi = fabs(jet::JetDistances::deltaPhi(jetPhi, constituent->phi() )); - const double pt = constituent->pt(); + const float dR = jet::JetDistances::deltaR(jetEta, jetPhi, constituent->eta(), constituent->phi() ); + const float dEta = fabs(jet::JetDistances::deltaEta(jetEta, constituent->eta() )); + const float dPhi = fabs(jet::JetDistances::deltaPhi(jetPhi, constituent->phi() )); + const float pt = constituent->pt(); weightedWidth += dR * pt; weightedWidthEta += dEta * pt; @@ -92,5 +87,3 @@ double JetWidthTool::width(const xAOD::Jet& jet, double& widthEta, double& width return ptSum > 0 ? weightedWidth/ptSum : -1; } - -//********************************************************************** diff --git a/Reconstruction/Jet/JetMomentTools/src/JetVoronoiMomentsTool.cxx b/Reconstruction/Jet/JetMomentTools/src/JetVoronoiMomentsTool.cxx index 439da17b1a3a2d074964818b968928f32185948e..cfd83cac24b8a01e5fe2d8979944190ef592abb3 100644 --- a/Reconstruction/Jet/JetMomentTools/src/JetVoronoiMomentsTool.cxx +++ b/Reconstruction/Jet/JetMomentTools/src/JetVoronoiMomentsTool.cxx @@ -1,8 +1,9 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ +#include "StoreGate/WriteDecorHandle.h" #include "JetMomentTools/JetVoronoiMomentsTool.h" // helpers @@ -19,24 +20,29 @@ using JetVoronoiDiagramHelpers::Diagram; JetVoronoiMomentsTool::JetVoronoiMomentsTool(const std::string& name) - : JetModifierBase(name) - //, m_voronoitool("") - , m_x_min(-10.) - , m_x_max( 10.) - , m_y_min(-4. ) - , m_y_max( 4. ) - //, m_jetcontainer ("") - //, m_scaleIntFloat (1e3) + : asg::AsgTool(name) { - declareProperty("AreaXmin",m_x_min); - declareProperty("AreaXmax",m_x_max); - declareProperty("AreaYmin",m_y_min); - declareProperty("AreaYmax",m_y_max); - //declareProperty("JetContainerName",m_jetcontainer); + declareInterface<IJetDecorator>(this); +} + +StatusCode JetVoronoiMomentsTool::initialize() { + + if(m_jetContainerName.empty()){ + ATH_MSG_ERROR("JetVoronoiMomentsTool needs to have its input jet container name configured!"); + return StatusCode::FAILURE; + } + + // Prepend jet collection name + m_voronoiAreaKey = m_jetContainerName + "." + m_voronoiAreaKey.key(); + ATH_CHECK(m_voronoiAreaKey.initialize()); + return StatusCode::SUCCESS; } -StatusCode JetVoronoiMomentsTool::modify(xAOD::JetContainer& jets) const { +StatusCode JetVoronoiMomentsTool::decorate(const xAOD::JetContainer& jets) const { + + SG::WriteDecorHandle<xAOD::JetContainer, float> outputHandle(m_voronoiAreaKey); + // setup diagram class Diagram voro ("VoronoiDiagram"); voro.m_x_min = m_x_min; @@ -52,21 +58,9 @@ StatusCode JetVoronoiMomentsTool::modify(xAOD::JetContainer& jets) const { if ( voro.createVoronoiDiagram().isFailure() ) { ATH_MSG_WARNING("Could not calculate Voronoi diagram"); } - for ( xAOD::Jet *jet : jets ) modifyJet(*jet,voro); + // decorate the jets + for (const xAOD::Jet *jet : jets ){ + outputHandle(*jet) = voro.getCellArea(jet->eta(), jet->phi()); + } return StatusCode::SUCCESS; } - -int JetVoronoiMomentsTool::modifyJet(xAOD::Jet&) const { - ATH_MSG_WARNING("Don't use this function. We need to compare space with other jets."); - return 0; -} - -int JetVoronoiMomentsTool::modifyJet(xAOD::Jet& jet, const Diagram & voro) const { - // Collate info - float VoronoiArea = voro.getCellArea(jet.eta(), jet.phi() ); - // Set info - jet.setAttribute( "VoronoiArea" , VoronoiArea ); - return 0; -} - - diff --git a/Reconstruction/Jet/JetRec/python/JetToolSupport.py b/Reconstruction/Jet/JetRec/python/JetToolSupport.py index 45b155247ad0d03c7196c51472f77033b5e04f9e..f6d198b4debe2d0d9055e81cb7bbb94b294574c4 100644 --- a/Reconstruction/Jet/JetRec/python/JetToolSupport.py +++ b/Reconstruction/Jet/JetRec/python/JetToolSupport.py @@ -139,8 +139,17 @@ class JetToolManager: self.msg(0, "Error adding jet builder without area.") raise LookupError + # Configures any tools in the given modifier list with the property + # "JetContainer" to set that property to the given string containerName. + def configureContainerName(self, modifiers, containerName): + for mod in modifiers: + if "JetContainer" in mod.properties(): + print ("configuring " + mod.name() + " to have container name " + containerName) + mod.JetContainer = containerName + # Return the list of modifiers associated with a name. - # If the argument is a list, it is returned directly. + # If the argument is a list, a copy is returned directly. + # Also configures any necessary container names in the copy. def getModifiers(self, modifiersin, altname =None): if modifiersin == None: if altname in ["lctopo","emtopo"]: @@ -290,7 +299,6 @@ class JetToolManager: jetlog.info( self.prefix + "Calibration option (" + calibOpt + ") provided with multiple calibration modifiers." ) raise Exception - return outmods # Create a jet finder without a JetRecToosl. @@ -411,6 +419,7 @@ class JetToolManager: ptminSave = self.ptminFilter if ptminFilter > 0.0: self.ptminFilter = ptminFilter jetrec.JetModifiers = self.buildModifiers(modifiersin, lofinder, getters, gettersin, output, calibOpt) + self.configureContainerName(jetrec.JetModifiers, output) if consumers != None: jetrec.JetConsumers = consumers self.ptminFilter = ptminSave @@ -458,6 +467,7 @@ class JetToolManager: jetrec.InputContainer = input jetrec.OutputContainer = output jetrec.JetModifiers = self.getModifiers(modifiersin) + self.configureContainerName(jetrec.JetModifiers, output) jetrec.Trigger = isTrigger or useTriggerStore jetrec.Timer = jetFlags.timeJetRecTool() self += jetrec @@ -492,6 +502,7 @@ class JetToolManager: jetrec.InputContainer = input jetrec.OutputContainer = output jetrec.JetModifiers = self.getModifiers(modifiersin) + self.configureContainerName(jetrec.JetModifiers, output) jetrec.Trigger = isTrigger or useTriggerStore jetrec.Timer = jetFlags.timeJetRecTool() if pseudojetRetriever in self.tools: @@ -539,6 +550,7 @@ class JetToolManager: jetrec.InputContainer = input jetrec.OutputContainer = output jetrec.JetModifiers = self.getModifiers(modifiersin) + self.configureContainerName(jetrec.JetModifiers, output) jetrec.Trigger = isTrigger or useTriggerStore jetrec.Timer = jetFlags.timeJetRecTool() self += jetrec @@ -597,6 +609,7 @@ class JetToolManager: jetrec.OutputContainer = output jetrec.JetGroomer = groomer jetrec.JetModifiers = self.getModifiers(modifiersin) + self.configureContainerName(jetrec.JetModifiers, output) if consumers != None: jetrec.JetConsumers = consumers jetrec.Trigger = isTrigger or useTriggerStore @@ -628,6 +641,7 @@ class JetToolManager: Label = inp getters = [get] jetrec.JetModifiers = self.buildModifiers(modifiersin, finder, getters, None, output, calibOpt) + self.configureContainerName(jetrec.JetModifiers, output) self.ptminFilter = ptminSave jetrec.Trigger = isTrigger or useTriggerStore jetrec.Timer = jetFlags.timeJetRecTool() @@ -779,6 +793,11 @@ class JetToolManager: for m in modifiers: self.setOutputLevel(m, OutputLevel) + # Temporary hard-coded solution until this config is deprecated. + triggerPrefix = "HLT_xAOD__JetContainer_" + + self.configureContainerName(modifiers, triggerPrefix + name.split('_')[1]) + self.ptminFilter = ptminSave @@ -802,8 +821,8 @@ class JetToolManager: self += builder return builder - def addTriggerJetTrimmer(self, + output, name, rclus, ptfrac, @@ -857,6 +876,7 @@ class JetToolManager: triggerGroomerTool = TriggerJetGroomerTool(name) triggerGroomerTool.JetGroomer = trimmerTool triggerGroomerTool.JetModifiers = self.getModifiers(modifiersin) + self.configureContainerName(triggerGroomerTool.JetModifiers, name.split('_')[1]) triggerGroomerTool.OutputLevel = OutputLevel # TriggerJetGroomerTool obtains a TriggerJetGroomerTool, will pass it @@ -874,4 +894,3 @@ class JetToolManager: self.trigjetrecs += [triggerGroomerTool] return triggerGroomerTool - diff --git a/Reconstruction/Jet/JetRecConfig/python/JetRecConfig.py b/Reconstruction/Jet/JetRecConfig/python/JetRecConfig.py index 71811d6aa2a1b989904a09834be6095df0892e26..08e126ccae6104fddc0ae9d257311f7e9c9a6792 100644 --- a/Reconstruction/Jet/JetRecConfig/python/JetRecConfig.py +++ b/Reconstruction/Jet/JetRecConfig/python/JetRecConfig.py @@ -210,6 +210,14 @@ def expandPrereqs(reqtype,prereqs): return None return reqdefs +######################################################################## +# For each modifier in the given list with a configurable input container +# name ("JetContainer"), configure it to containerName. +def configureContainerName(modifiers, containerName): + for mod in modifiers: + if "JetContainer" in mod.properties(): + mod.JetContainer = containerName + ######################################################################## # Function producing an EventShapeAlg to calculate @@ -467,6 +475,7 @@ def getJetRecTool(jetname, finder, pjs, mods): JetFinder = finder, JetModifiers = mods ) + configureContainerName(jetrec.JetModifiers, jetname) return jetrec diff --git a/Trigger/TrigAlgorithms/TrigHLTJetRec/python/TrigHLTJetRecConfig.py b/Trigger/TrigAlgorithms/TrigHLTJetRec/python/TrigHLTJetRecConfig.py index ce15acea18e54feda1da3e5341119090cd462882..91fd431f7f5569ec52c1981bf116c3f6e515e515 100644 --- a/Trigger/TrigAlgorithms/TrigHLTJetRec/python/TrigHLTJetRecConfig.py +++ b/Trigger/TrigAlgorithms/TrigHLTJetRec/python/TrigHLTJetRecConfig.py @@ -810,6 +810,12 @@ def _getJetTrimmerTool2 (merge_param, make heavy use of dynamic stores, so all modifiers other than calibration are currently disabled.""" + # Output collection name isn't needed here since only calibration modifiers + # are used, but the function below requires one even if it won't be used. + # No need for a nicer solution since this whole config should be deprecated + # and phased out by 2021. + output = "DummyCollectionName" + # declare jtm as global as this function body may modify it # with the += operator @@ -877,6 +883,7 @@ def _getJetTrimmerTool2 (merge_param, try: # Ask the jtm to creat and register the trimmer jetTrimmerTool = jtm.addTriggerJetTrimmer( + output, name, rclus, ptfrac,