File indexing completed on 2024-11-25 02:29:55
0001 #include "RecoEgamma/PhotonIdentification/interface/PhotonDNNEstimator.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003 #include "FWCore/Utilities/interface/FileInPath.h"
0004
0005 #include <iostream>
0006 #include <fstream>
0007 #include <memory>
0008
0009 using namespace std::placeholders;
0010
0011 inline uint photonModelSelector(const std::map<std::string, float>& vars, float etaThr) {
0012
0013
0014
0015 const auto absEta = std::abs(vars.at("eta"));
0016 if (absEta <= etaThr) {
0017 return 0;
0018 } else {
0019 return 1;
0020 }
0021 }
0022
0023 PhotonDNNEstimator::PhotonDNNEstimator(const egammaTools::DNNConfiguration& cfg, const bool useEBModelInGap)
0024 : dnnHelper_(cfg,
0025 std::bind(photonModelSelector,
0026 _1,
0027 (useEBModelInGap) ? PhotonDNNEstimator::ecalBarrelMaxEtaWithGap
0028 : PhotonDNNEstimator::ecalBarrelMaxEtaNoGap),
0029 PhotonDNNEstimator::dnnAvaibleInputs),
0030 useEBModelInGap_(useEBModelInGap) {}
0031
0032 const std::vector<std::string> PhotonDNNEstimator::dnnAvaibleInputs = {{"pt",
0033 "eta",
0034 "hadTowOverEm",
0035 "trkSumPtHollowConeDR03",
0036 "EcalRecHit",
0037 "SigmaIetaIeta",
0038 "SigmaIetaIetaFull5x5",
0039 "SigmaIEtaIPhiFull5x5",
0040 "EcalPFClusterIso",
0041 "HcalPFClusterIso",
0042 "HasPixelSeed",
0043 "R9Full5x5",
0044 "hcalTower"}};
0045
0046 std::map<std::string, float> PhotonDNNEstimator::getInputsVars(const reco::Photon& photon) const {
0047
0048 std::map<std::string, float> variables;
0049 variables["pt"] = photon.pt();
0050 variables["eta"] = photon.eta();
0051 variables["hadTowOverEm"] = photon.hadTowOverEmValid() ? photon.hadTowOverEm() : 0;
0052 variables["trkSumPtHollowConeDR03"] = photon.trkSumPtHollowConeDR03();
0053 variables["EcalRecHit"] = photon.ecalRecHitSumEtConeDR03();
0054 variables["SigmaIetaIeta"] = photon.sigmaIetaIeta();
0055 variables["SigmaIetaIetaFull5x5"] = photon.full5x5_sigmaIetaIeta();
0056 variables["SigmaIEtaIPhiFull5x5"] = photon.full5x5_showerShapeVariables().sigmaIetaIphi;
0057 variables["EcalPFClusterIso"] = photon.ecalPFClusterIso();
0058 variables["HcalPFClusterIso"] = photon.hcalPFClusterIso();
0059 variables["HasPixelSeed"] = (Int_t)photon.hasPixelSeed();
0060 variables["R9Full5x5"] = photon.full5x5_r9();
0061 variables["hcalTower"] = photon.hcalTowerSumEtConeDR03();
0062 variables["R9Full5x5"] = photon.full5x5_r9();
0063
0064 return variables;
0065 }
0066
0067 std::vector<std::pair<uint, std::vector<float>>> PhotonDNNEstimator::evaluate(
0068 const reco::PhotonCollection& photons) const {
0069
0070
0071 std::vector<std::map<std::string, float>> inputs;
0072 for (const auto& photon : photons) {
0073 inputs.push_back(getInputsVars(photon));
0074 }
0075 return dnnHelper_.evaluate(inputs);
0076 }