ATLAS Offline Software
Loading...
Searching...
No Matches
JetSorter.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "JetRec/JetSorter.h"
6
8// Comparison functions
9bool ptCompare(const xAOD::Jet* j1, const xAOD::Jet* j2){ return j1->pt() > j2->pt() ;}
10
11// A global map for comparison functions
12using compFunc = bool (*)(const xAOD::Jet *, const xAOD::Jet *);
13const std::map<std::string, compFunc> g_compFuncMap = {
14 {"ByPtDown", ptCompare}
15};
16
17JetSorter::JetSorter(const std::string& n) :
18 asg::AsgTool(n)
19 ,m_sortType("ByPtDown")
20{
21 declareProperty("SortingType", m_sortType);
22}
23
24StatusCode JetSorter::modify(xAOD::JetContainer& jets) const {
25 ATH_MSG_DEBUG(" Sorting : "<< m_sortType << " "<< jets.size() );
26 // leave early if empty otherwise sort() throws an exception.
27 if(jets.empty() ) return StatusCode::SUCCESS;
28
29 const auto itr = g_compFuncMap.find(m_sortType);
30 if (itr == g_compFuncMap.end()) {
31 ATH_MSG_ERROR("Unsupported SortingType " << m_sortType);
32 return StatusCode::FAILURE;
33 }
34 jets.sort( *itr->second );
35 return StatusCode::SUCCESS;
36}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
const std::map< std::string, compFunc > g_compFuncMap
Definition JetSorter.cxx:13
bool(*)(const xAOD::Jet *, const xAOD::Jet *) compFunc
Definition JetSorter.cxx:12
bool ptCompare(const xAOD::Jet *j1, const xAOD::Jet *j2)
Definition JetSorter.cxx:9
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
virtual StatusCode modify(xAOD::JetContainer &jets) const
Method to modify a jet collection.
Definition JetSorter.cxx:24
std::string m_sortType
Definition JetSorter.h:32
JetSorter(const std::string &t)
Definition JetSorter.cxx:17
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
Jet_v1 Jet
Definition of the current "jet version".
JetContainer_v1 JetContainer
Definition of the current "jet container version".