Commit 0ba0d394 authored by Vakhtang Tsulaia's avatar Vakhtang Tsulaia
Browse files

Merge branch 'JetDecorators_190729' into 'master'

Migrate jet moment tools to IJetDecorator interface

See merge request atlas/athena!25234
parents 89d17ed7 0a9c79db
// 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
......
/*
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"};
};
......
// 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
......
/*
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
......
/*
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
/*
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;
}
......
/*
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;
}
//**********************************************************************
......
/*
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;
}
/*
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)