File indexing completed on 2024-04-06 12:25:02
0001 #ifndef RecoEgamma_EgammaTools_EleEnergyRetriever_h
0002 #define RecoEgamma_EgammaTools_EleEnergyRetriever_h
0003
0004 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
0005 #include "FWCore/Utilities/interface/Exception.h"
0006
0007 class EleEnergyRetriever {
0008 public:
0009 enum class EnergyType { EcalTrk, Ecal, SuperCluster, SuperClusterRaw };
0010
0011 EleEnergyRetriever(const std::string& typeStr) : type_(convertFromStr(typeStr)) {}
0012
0013 static EnergyType convertFromStr(const std::string& typeStr) {
0014 if (typeStr == "EcalTrk")
0015 return EnergyType::EcalTrk;
0016 else if (typeStr == "Ecal")
0017 return EnergyType::Ecal;
0018 else if (typeStr == "SuperCluster")
0019 return EnergyType::SuperCluster;
0020 else if (typeStr == "SuperClusterRaw")
0021 return EnergyType::SuperClusterRaw;
0022 else {
0023 throw cms::Exception("ConfigError")
0024 << " type \"" << typeStr << "\" not recognised, must be of type EcalTrk,Ecal,SuperCluster,SuperClusterRaw";
0025 }
0026 }
0027
0028 float operator()(const reco::GsfElectron& ele) const {
0029 switch (type_) {
0030 case EnergyType::EcalTrk:
0031 return ele.energy();
0032 case EnergyType::Ecal:
0033 return ele.ecalEnergy();
0034 case EnergyType::SuperCluster:
0035 return ele.superCluster()->energy();
0036 case EnergyType::SuperClusterRaw:
0037 return ele.superCluster()->rawEnergy();
0038 }
0039 return 0.;
0040 }
0041
0042 private:
0043 EnergyType type_;
0044 };
0045
0046 #endif