diff --git a/PhysicsAnalysis/ElectronPhotonID/EgammaAnalysisHelpers/EgammaAnalysisHelpers/AsgEGammaConfigHelper.h b/PhysicsAnalysis/ElectronPhotonID/EgammaAnalysisHelpers/EgammaAnalysisHelpers/AsgEGammaConfigHelper.h index c99faa4d49ac8669d3c1231de0f7914d6829bcb5..741b1ddd8be717468f7a7866aaf8c60f5871d390 100644 --- a/PhysicsAnalysis/ElectronPhotonID/EgammaAnalysisHelpers/EgammaAnalysisHelpers/AsgEGammaConfigHelper.h +++ b/PhysicsAnalysis/ElectronPhotonID/EgammaAnalysisHelpers/EgammaAnalysisHelpers/AsgEGammaConfigHelper.h @@ -1,30 +1,38 @@ /* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ - // Dear emacs, this is -*-c++-*- #ifndef ASGELEGAMMACONFIGHELPER_H #define ASGELEGAMMACONFIGHELPER_H /** - @brief Tool to simplify the configuration of some egamma tools based on TEnv input - @author Christos Anastopoulos (2017) Nils Gillwald (DESY, 2020) nils.gillwald@desy.de + @brief Tool to simplify the configuration of some egamma tools based on TEnv + input + @author Christos Anastopoulos (2017) Nils Gillwald (DESY, 2020) + nils.gillwald@desy.de @date February 2020 */ +#include <map> #include <string> #include <vector> -#include <map> class TEnv; -namespace AsgConfigHelper{ - std::string findConfigFile (const std::string& input, const std::map<std::string,std::string>& configmap); - unsigned int findMask (const std::string& input, const std::map<std::string,unsigned int>& maskmap); - std::vector<double> HelperDouble(const std::string& input, TEnv& env); - std::vector<float> HelperFloat(const std::string& input, TEnv& env); - std::vector<int> HelperInt(const std::string& input, TEnv& env); - std::vector<std::string> HelperString(const std::string& input, TEnv& env); +namespace AsgConfigHelper { +std::string +findConfigFile(const std::string& input, + const std::map<std::string, std::string>& configmap); +unsigned int +findMask(const std::string& input, + const std::map<std::string, unsigned int>& maskmap); +std::vector<double> +HelperDouble(const std::string& input, TEnv& env); +std::vector<float> +HelperFloat(const std::string& input, TEnv& env); +std::vector<int> +HelperInt(const std::string& input, TEnv& env); +std::vector<std::string> +HelperString(const std::string& input, TEnv& env); } - -#endif //ASGEGAMMACONFIGHELPER_H +#endif // ASGEGAMMACONFIGHELPER_H diff --git a/PhysicsAnalysis/ElectronPhotonID/EgammaAnalysisHelpers/Root/AsgEGammaConfigHelper.cxx b/PhysicsAnalysis/ElectronPhotonID/EgammaAnalysisHelpers/Root/AsgEGammaConfigHelper.cxx index 545b8e4b20bcc9d35e9c470dd700313e6db1220d..896fc07757ac47add829f25acc7da095bfae226d 100644 --- a/PhysicsAnalysis/ElectronPhotonID/EgammaAnalysisHelpers/Root/AsgEGammaConfigHelper.cxx +++ b/PhysicsAnalysis/ElectronPhotonID/EgammaAnalysisHelpers/Root/AsgEGammaConfigHelper.cxx @@ -1,117 +1,126 @@ /* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ #include "EgammaAnalysisHelpers/AsgEGammaConfigHelper.h" #include "AsgMessaging/AsgMessaging.h" #include "TEnv.h" #include <iostream> -#include <sstream> +#include <sstream> -namespace AsgConfigHelper{ +namespace AsgConfigHelper { - std::string findConfigFile (const std::string& input, const std::map<std::string,std::string>& configmap){ - auto confFile_itr=configmap.find(input); - if(confFile_itr == configmap.end()){ - static const asg::AsgMessaging msg("Egamma::AsgConfigHelper"); - msg.msg(MSG::WARNING)<<"Key "<<input<<" not found in map, no config file returned"<<endmsg; - return ""; - } - return confFile_itr->second; - } - - unsigned int findMask (const std::string& input, const std::map<std::string,unsigned int>& maskmap){ - auto mask_itr=maskmap.find(input); - if(mask_itr==maskmap.end()){ - static const asg::AsgMessaging msg("Egamma::AsgConfigHelper"); - msg.msg(MSG::WARNING)<<"Key "<<input<<" not found in map, egammaPID::EgPidUndefined mask returned"<<endmsg; - // mask has the choice to default to all 1 or all 0 bits, choose the former - return std::numeric_limits<unsigned int>::max(); - } - return static_cast < unsigned int> (mask_itr->second); +std::string +findConfigFile(const std::string& input, + const std::map<std::string, std::string>& configmap) +{ + auto confFile_itr = configmap.find(input); + if (confFile_itr == configmap.end()) { + static const asg::AsgMessaging msg("Egamma::AsgConfigHelper"); + msg.msg(MSG::WARNING) << "Key " << input + << " not found in map, no config file returned" + << endmsg; + return ""; } + return confFile_itr->second; +} - template <typename T> - bool strtof(const std::string& input, T& f){ - int diff = 0 ; - std::string tmp = input; - std::string::size_type first(0); - std::string::size_type last(0); - first = ( input.find('#') ) ; - - //if we do not find a comment character "#" we are fine - if (first == std::string::npos) { - std::istringstream buffer (tmp); - buffer>>f; - return true; - } - else { - //if we have found comment character check if it is inlined between two "#" - last = (input.find('#',first+1) ); - //if nor error - if (last == std::string::npos) { - static const asg::AsgMessaging msg("Egamma::AsgConfigHelper"); - msg.msg(MSG::WARNING)<<" Improper comment format , inline comment should be enclosed between two # "<<endmsg; - return false; - } - //else if between two "#" remove this part - diff = last - first ; - tmp= tmp.erase(first,diff+1); - std::istringstream buffer (tmp); - buffer>>f; - return true; - } +unsigned int +findMask(const std::string& input, + const std::map<std::string, unsigned int>& maskmap) +{ + auto mask_itr = maskmap.find(input); + if (mask_itr == maskmap.end()) { + static const asg::AsgMessaging msg("Egamma::AsgConfigHelper"); + msg.msg(MSG::WARNING) + << "Key " << input + << " not found in map, egammaPID::EgPidUndefined mask returned" + << endmsg; + // mask has the choice to default to all 1 or all 0 bits, choose the former + return std::numeric_limits<unsigned int>::max(); } + return static_cast<unsigned int>(mask_itr->second); +} - template <typename T> - std::vector<T> Helper (const std::string& input, TEnv& env){ - std::vector<T> CutVector; - std::string env_input(env.GetValue(input.c_str(), "")); - if (!env_input.empty()) { - std::string::size_type end; - do { - end = env_input.find(';'); - T myValue(0); - if(AsgConfigHelper::strtof(env_input.substr(0,end),myValue)){ - CutVector.push_back(myValue); - } - if (end != std::string::npos) { - env_input= env_input.substr(end+1); - } - } while (end != std::string::npos); +template<typename T> +bool +strtof(const std::string& input, T& f) +{ + int diff = 0; + std::string tmp = input; + std::string::size_type first(0); + std::string::size_type last(0); + first = (input.find('#')); + + // if we do not find a comment character "#" we are fine + if (first == std::string::npos) { + std::istringstream buffer(tmp); + buffer >> f; + return true; + } else { + // if we have found comment character check if it is inlined between two "#" + last = (input.find('#', first + 1)); + // if nor error + if (last == std::string::npos) { + static const asg::AsgMessaging msg("Egamma::AsgConfigHelper"); + msg.msg(MSG::WARNING) << " Improper comment format , inline comment " + "should be enclosed between two # " + << endmsg; + return false; } - return CutVector; + // else if between two "#" remove this part + diff = last - first; + tmp = tmp.erase(first, diff + 1); + std::istringstream buffer(tmp); + buffer >> f; + return true; } } -//use the specializations -std::vector<double> AsgConfigHelper::HelperDouble(const std::string& input, TEnv& env){ - return AsgConfigHelper::Helper<double> ( input,env); -} -std::vector<float> AsgConfigHelper::HelperFloat(const std::string& input, TEnv& env){ - return AsgConfigHelper::Helper<float> (input, env); -} -std::vector<int> AsgConfigHelper::HelperInt(const std::string& input, TEnv& env){ - return AsgConfigHelper::Helper<int> (input, env); -} -// template does not work for std::string because of the T myValue(0); declaration, so implement it again for std::string -std::vector<std::string> AsgConfigHelper::HelperString(const std::string& input, TEnv& env){ - std::vector<std::string> CutVector; +template<typename T> +std::vector<T> +Helper(const std::string& input, TEnv& env) +{ + std::vector<T> CutVector; std::string env_input(env.GetValue(input.c_str(), "")); if (!env_input.empty()) { std::string::size_type end; do { - end = env_input.find(';'); - std::string myValue(""); - if(AsgConfigHelper::strtof(env_input.substr(0,end),myValue)){ - CutVector.push_back(myValue); - } - if (end != std::string::npos) { - env_input= env_input.substr(end+1); - } + end = env_input.find(';'); + T myValue{}; //default init + if (AsgConfigHelper::strtof(env_input.substr(0, end), myValue)) { + CutVector.push_back(myValue); + } + if (end != std::string::npos) { + env_input = env_input.substr(end + 1); + } } while (end != std::string::npos); } return CutVector; } +} +// use the specializations +std::vector<double> +AsgConfigHelper::HelperDouble(const std::string& input, TEnv& env) +{ + return AsgConfigHelper::Helper<double>(input, env); +} +std::vector<float> +AsgConfigHelper::HelperFloat(const std::string& input, TEnv& env) +{ + return AsgConfigHelper::Helper<float>(input, env); +} +std::vector<int> +AsgConfigHelper::HelperInt(const std::string& input, TEnv& env) +{ + return AsgConfigHelper::Helper<int>(input, env); +} +// template does not work for std::string because of the T myValue(0); +// declaration, so implement it again for std::string +std::vector<std::string> +AsgConfigHelper::HelperString(const std::string& input, TEnv& env) +{ + return AsgConfigHelper::Helper<std::string>(input, env); +} diff --git a/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/ElectronPhotonSelectorTools/AsgElectronSelectorTool.h b/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/ElectronPhotonSelectorTools/AsgElectronSelectorTool.h index 099dc03f13cc73590c2243d96e1db1cb1a67ce48..ad9c9c2c10e306062e8fa8f82e1e631ca8c47f15 100644 --- a/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/ElectronPhotonSelectorTools/AsgElectronSelectorTool.h +++ b/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/ElectronPhotonSelectorTools/AsgElectronSelectorTool.h @@ -24,7 +24,7 @@ class AsgElectronSelectorTool final : public asg::AsgTool, public: /** Standard constructor */ - AsgElectronSelectorTool( const std::string myname ); + AsgElectronSelectorTool( const std::string& myname ); /** Standard destructor */ diff --git a/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/Root/AsgElectronSelectorTool.cxx b/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/Root/AsgElectronSelectorTool.cxx index 78af09403266eb927ec3f6c8d126a4a62207ffc0..f7c313efb57e44be9d318e248a8b625c5b22ec04 100644 --- a/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/Root/AsgElectronSelectorTool.cxx +++ b/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/Root/AsgElectronSelectorTool.cxx @@ -35,7 +35,7 @@ //============================================================================= // Standard constructor //============================================================================= -AsgElectronSelectorTool::AsgElectronSelectorTool( std::string myname ) : +AsgElectronSelectorTool::AsgElectronSelectorTool( const std::string& myname ) : AsgTool(myname), m_configFile{""}, m_mvaTool(nullptr) @@ -86,7 +86,7 @@ StatusCode AsgElectronSelectorTool::initialize() if (!m_configFile.empty()){ std::string configFile = PathResolverFindCalibFile(m_configFile); - if (configFile==""){ + if (configFile.empty()){ ATH_MSG_ERROR("Could not locate " << m_configFile); return StatusCode::FAILURE; } @@ -170,7 +170,7 @@ StatusCode AsgElectronSelectorTool::initialize() return StatusCode::FAILURE; } - if (m_cutSCT.size()){ + if (!m_cutSCT.empty()){ if (m_cutSCT.size() != numberOfExpectedEtaBins){ ATH_MSG_ERROR("Configuration issue : cutSCT expected size " << numberOfExpectedEtaBins << " input size " << m_cutSCT.size()); @@ -178,7 +178,7 @@ StatusCode AsgElectronSelectorTool::initialize() } } - if (m_cutPi.size()){ + if (!m_cutPi.empty()){ if (m_cutPi.size() != numberOfExpectedEtaBins){ ATH_MSG_ERROR("Configuration issue : cutPi expected size " << numberOfExpectedEtaBins << " input size " << m_cutPi.size()); @@ -186,7 +186,7 @@ StatusCode AsgElectronSelectorTool::initialize() } } - if (m_cutBL.size()){ + if (!m_cutBL.empty()){ if (m_cutBL.size() != numberOfExpectedEtaBins){ ATH_MSG_ERROR("Configuration issue : cutBL expected size " << numberOfExpectedEtaBins << " input size " << m_cutBL.size()); @@ -194,7 +194,7 @@ StatusCode AsgElectronSelectorTool::initialize() } } - if (m_cutAmbiguity.size()){ + if (!m_cutAmbiguity.empty()){ if (m_cutAmbiguity.size() != numberOfExpectedEtaBins){ ATH_MSG_ERROR("Configuration issue : cutAmbiguity expected size " << numberOfExpectedEtaBins << " input size " << m_cutAmbiguity.size()); @@ -364,7 +364,7 @@ asg::AcceptData AsgElectronSelectorTool::accept( const EventContext& ctx, const if (!passKine){return acceptData;} // ambiguity bit - if (m_cutAmbiguity.size()){ + if (!m_cutAmbiguity.empty()){ if (!ElectronSelectorHelpers::passAmbiguity((xAOD::AmbiguityTool::AmbiguityType)ambiguityBit, m_cutAmbiguity[etaBin])){ ATH_MSG_DEBUG("MVA macro: ambiguity Bit Failed."); passAmbiguity = false; @@ -372,21 +372,21 @@ asg::AcceptData AsgElectronSelectorTool::accept( const EventContext& ctx, const } // blayer cut - if (m_cutBL.size()) { + if (!m_cutBL.empty()) { if(m_cutBL[etaBin] == 1 && !passBLayerRequirement){ ATH_MSG_DEBUG("MVA macro: Blayer cut failed."); passNBlayer = false; } } // pixel cut - if (m_cutPi.size()){ + if (!m_cutPi.empty()){ if (nPixHitsPlusDeadSensors < m_cutPi[etaBin]){ ATH_MSG_DEBUG("MVA macro: Pixels Failed."); passNPixel = false; } } // SCT cut - if (m_cutSCT.size()){ + if (!m_cutSCT.empty()){ if (nSiHitsPlusDeadSensors < m_cutSCT[etaBin]){ ATH_MSG_DEBUG( "MVA macro: Silicon Failed."); passNSilicon = false; @@ -396,7 +396,7 @@ asg::AcceptData AsgElectronSelectorTool::accept( const EventContext& ctx, const double cutDiscriminant; unsigned int ibin_combinedMVA = etBin*s_fnDiscEtaBins+etaBin; // Must change if number of eta bins changes!. - if (m_cutSelector.size()){ + if (!m_cutSelector.empty()){ // To protect against a binning mismatch, which should never happen if (ibin_combinedMVA >= m_cutSelector.size()){ throw std::runtime_error("AsgElectronSelectorTool: The desired eta/pt bin is outside of the range specified by the input. This should never happen! This indicates a mismatch between the binning in the configuration file and the tool implementation." ); diff --git a/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/Root/ElectronDNNCalculator.cxx b/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/Root/ElectronDNNCalculator.cxx index 82ff89af492f6ff9cb06b92677c3aacc25e28ec0..4397863948ed5e4fa49d5f2e11e894c2e5bb6706 100644 --- a/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/Root/ElectronDNNCalculator.cxx +++ b/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/Root/ElectronDNNCalculator.cxx @@ -31,7 +31,7 @@ ElectronDNNCalculator::ElectronDNNCalculator(AsgElectronSelectorTool* owner, { ATH_MSG_INFO("Initializing ElectronDNNCalculator..."); - if (modelFileName.size() == 0){ + if (modelFileName.empty()){ throw std::runtime_error("No file found at '" + modelFileName + "'"); } @@ -56,7 +56,7 @@ ElectronDNNCalculator::ElectronDNNCalculator(AsgElectronSelectorTool* owner, m_graph = std::make_unique<lwt::generic::FastGraph<float>>(parsedGraph, order); - if (quantileFileName.size() == 0){ + if (quantileFileName.empty()){ throw std::runtime_error("No file found at '" + quantileFileName + "'"); } @@ -150,7 +150,7 @@ int ElectronDNNCalculator::readQuantileTransformer( TTree* tree, const std::vect sc = tree->SetBranchAddress("references", &references) == -5 ? 0 : 1; std::map<std::string, double> readVars; - for ( auto var : variables ){ + for ( const auto& var : variables ){ sc = tree->SetBranchAddress(TString(var), &readVars[var]) == -5 ? 0 : 1; } for (int i = 0; i < tree->GetEntries(); i++){