Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-17 01:47:59

0001 #include "RecoTauTag/RecoTau/interface/AntiElectronIDMVA6.h"
0002 
0003 #include "FWCore/Utilities/interface/Exception.h"
0004 
0005 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
0006 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
0007 #include "DataFormats/TrackReco/interface/Track.h"
0008 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
0009 #include "DataFormats/MuonReco/interface/Muon.h"
0010 
0011 #include "CondFormats/DataRecord/interface/GBRWrapperRcd.h"
0012 
0013 #include <TFile.h>
0014 #include <array>
0015 
0016 using namespace antiElecIDMVA6_blocks;
0017 
0018 namespace {
0019   const reco::Track* getTrackFromPFCand(const reco::PFCandidate* pfCandidate) {
0020     const reco::Track* track = nullptr;
0021     if (pfCandidate->trackRef().isNonnull())
0022       track = pfCandidate->trackRef().get();
0023     else if (pfCandidate->muonRef().isNonnull() && pfCandidate->muonRef()->innerTrack().isNonnull())
0024       track = pfCandidate->muonRef()->innerTrack().get();
0025     else if (pfCandidate->muonRef().isNonnull() && pfCandidate->muonRef()->globalTrack().isNonnull())
0026       track = pfCandidate->muonRef()->globalTrack().get();
0027     else if (pfCandidate->muonRef().isNonnull() && pfCandidate->muonRef()->outerTrack().isNonnull())
0028       track = pfCandidate->muonRef()->outerTrack().get();
0029     else if (pfCandidate->gsfTrackRef().isNonnull())
0030       track = pfCandidate->gsfTrackRef().get();
0031     return track;
0032   }
0033 }  // namespace
0034 
0035 template <class TauType, class ElectronType>
0036 AntiElectronIDMVA6<TauType, ElectronType>::AntiElectronIDMVA6(const edm::ParameterSet& cfg, edm::ConsumesCollector&& cc)
0037     : isInitialized_(false),
0038       mva_NoEleMatch_woGwoGSF_BL_(nullptr),
0039       mva_NoEleMatch_wGwoGSF_BL_(nullptr),
0040       mva_woGwGSF_BL_(nullptr),
0041       mva_wGwGSF_BL_(nullptr),
0042       mva_NoEleMatch_woGwoGSF_EC_(nullptr),
0043       mva_NoEleMatch_wGwoGSF_EC_(nullptr),
0044       mva_woGwGSF_EC_(nullptr),
0045       mva_wGwGSF_EC_(nullptr),
0046       mva_NoEleMatch_woGwoGSF_VFEC_(nullptr),
0047       mva_NoEleMatch_wGwoGSF_VFEC_(nullptr),
0048       mva_woGwGSF_VFEC_(nullptr),
0049       mva_wGwGSF_VFEC_(nullptr),
0050       isPhase2_(cfg.getParameter<bool>("isPhase2")),
0051       positionAtECalEntrance_(PositionAtECalEntranceComputer(cc, isPhase2_)),
0052       verbosity_(cfg.getParameter<int>("verbosity")) {
0053   loadMVAfromDB_ = cfg.exists("loadMVAfromDB") ? cfg.getParameter<bool>("loadMVAfromDB") : false;
0054   if (!loadMVAfromDB_) {
0055     if (cfg.exists("inputFileName")) {
0056       inputFileName_ = cfg.getParameter<edm::FileInPath>("inputFileName");
0057     } else
0058       throw cms::Exception("MVA input not defined")
0059           << "Requested to load tau MVA input from ROOT file but no file provided in cfg file";
0060   }
0061 
0062   mvaName_NoEleMatch_woGwoGSF_BL_ = cfg.getParameter<std::string>("mvaName_NoEleMatch_woGwoGSF_BL");
0063   mvaName_NoEleMatch_wGwoGSF_BL_ = cfg.getParameter<std::string>("mvaName_NoEleMatch_wGwoGSF_BL");
0064   mvaName_woGwGSF_BL_ = cfg.getParameter<std::string>("mvaName_woGwGSF_BL");
0065   mvaName_wGwGSF_BL_ = cfg.getParameter<std::string>("mvaName_wGwGSF_BL");
0066   mvaName_NoEleMatch_woGwoGSF_EC_ = cfg.getParameter<std::string>("mvaName_NoEleMatch_woGwoGSF_EC");
0067   mvaName_NoEleMatch_wGwoGSF_EC_ = cfg.getParameter<std::string>("mvaName_NoEleMatch_wGwoGSF_EC");
0068   mvaName_woGwGSF_EC_ = cfg.getParameter<std::string>("mvaName_woGwGSF_EC");
0069   mvaName_wGwGSF_EC_ = cfg.getParameter<std::string>("mvaName_wGwGSF_EC");
0070   if (isPhase2_) {
0071     mvaName_NoEleMatch_woGwoGSF_VFEC_ = cfg.getParameter<std::string>("mvaName_NoEleMatch_woGwoGSF_VFEC");
0072     mvaName_NoEleMatch_wGwoGSF_VFEC_ = cfg.getParameter<std::string>("mvaName_NoEleMatch_wGwoGSF_VFEC");
0073     mvaName_woGwGSF_VFEC_ = cfg.getParameter<std::string>("mvaName_woGwGSF_VFEC");
0074     mvaName_wGwGSF_VFEC_ = cfg.getParameter<std::string>("mvaName_wGwGSF_VFEC");
0075   }
0076   if (loadMVAfromDB_) {
0077     mvaToken_NoEleMatch_woGwoGSF_BL_ = cc.esConsumes(edm::ESInputTag{"", mvaName_NoEleMatch_woGwoGSF_BL_});
0078     mvaToken_NoEleMatch_wGwoGSF_BL_ = cc.esConsumes(edm::ESInputTag{"", mvaName_NoEleMatch_wGwoGSF_BL_});
0079     mvaToken_woGwGSF_BL_ = cc.esConsumes(edm::ESInputTag{"", mvaName_woGwGSF_BL_});
0080     mvaToken_wGwGSF_BL_ = cc.esConsumes(edm::ESInputTag{"", mvaName_wGwGSF_BL_});
0081     mvaToken_NoEleMatch_woGwoGSF_EC_ = cc.esConsumes(edm::ESInputTag{"", mvaName_NoEleMatch_woGwoGSF_EC_});
0082     mvaToken_NoEleMatch_wGwoGSF_EC_ = cc.esConsumes(edm::ESInputTag{"", mvaName_NoEleMatch_wGwoGSF_EC_});
0083     mvaToken_woGwGSF_EC_ = cc.esConsumes(edm::ESInputTag{"", mvaName_woGwGSF_EC_});
0084     mvaToken_wGwGSF_EC_ = cc.esConsumes(edm::ESInputTag{"", mvaName_wGwGSF_EC_});
0085     if (isPhase2_) {
0086       mvaToken_NoEleMatch_woGwoGSF_VFEC_ = cc.esConsumes(edm::ESInputTag{"", mvaName_NoEleMatch_woGwoGSF_VFEC_});
0087       mvaToken_NoEleMatch_wGwoGSF_VFEC_ = cc.esConsumes(edm::ESInputTag{"", mvaName_NoEleMatch_wGwoGSF_VFEC_});
0088       mvaToken_woGwGSF_VFEC_ = cc.esConsumes(edm::ESInputTag{"", mvaName_woGwGSF_VFEC_});
0089       mvaToken_wGwGSF_VFEC_ = cc.esConsumes(edm::ESInputTag{"", mvaName_wGwGSF_VFEC_});
0090     }
0091   }
0092   usePhiAtEcalEntranceExtrapolation_ = cfg.getParameter<bool>("usePhiAtEcalEntranceExtrapolation");
0093 
0094   if (!isPhase2_) {
0095     var_NoEleMatch_woGwoGSF_Barrel_ = std::vector<float>(10);
0096     var_NoEleMatch_wGwoGSF_Barrel_ = std::vector<float>(18);
0097     var_woGwGSF_Barrel_ = std::vector<float>(24);
0098     var_wGwGSF_Barrel_ = std::vector<float>(32);
0099     var_NoEleMatch_woGwoGSF_Endcap_ = std::vector<float>(9);
0100     var_NoEleMatch_wGwoGSF_Endcap_ = std::vector<float>(17);
0101     var_woGwGSF_Endcap_ = std::vector<float>(23);
0102     var_wGwGSF_Endcap_ = std::vector<float>(31);
0103   } else {
0104     var_NoEleMatch_woGwoGSF_Barrel_ = std::vector<float>(9);
0105     var_NoEleMatch_wGwoGSF_Barrel_ = std::vector<float>(17);
0106     var_woGwGSF_Barrel_ = std::vector<float>(27);
0107     var_wGwGSF_Barrel_ = std::vector<float>(36);
0108     var_NoEleMatch_woGwoGSF_Endcap_ = std::vector<float>(6);
0109     var_NoEleMatch_wGwoGSF_Endcap_ = std::vector<float>(14);
0110     var_woGwGSF_Endcap_ = std::vector<float>(31);
0111     var_wGwGSF_Endcap_ = std::vector<float>(38);
0112     var_NoEleMatch_woGwoGSF_VFEndcap_ = std::vector<float>(6);
0113     var_NoEleMatch_wGwoGSF_VFEndcap_ = std::vector<float>(14);
0114     var_woGwGSF_VFEndcap_ = std::vector<float>(32);
0115     var_wGwGSF_VFEndcap_ = std::vector<float>(40);
0116 
0117     //MB: Tokens for additional inputs (HGCal EleID variables) only for Phase2 and reco::GsfElectrons
0118     if (std::is_same<ElectronType, reco::GsfElectron>::value) {
0119       for (const auto& inputTag : cfg.getParameter<std::vector<edm::InputTag>>("hgcalElectronIDs")) {
0120         std::string elecIdLabel = "hgcElectronID:" + inputTag.instance();
0121         electronIds_tokens_[elecIdLabel] = cc.consumes<edm::ValueMap<float>>(
0122             inputTag);  //MB: It assumes that instances are not empty and meaningful (as for userData in patElectrons)
0123         electronIds_[elecIdLabel] = edm::Handle<edm::ValueMap<float>>();
0124       }
0125     }
0126   }
0127 }
0128 
0129 template <class TauType, class ElectronType>
0130 AntiElectronIDMVA6<TauType, ElectronType>::~AntiElectronIDMVA6() {
0131   if (!loadMVAfromDB_) {
0132     delete mva_NoEleMatch_woGwoGSF_BL_;
0133     delete mva_NoEleMatch_wGwoGSF_BL_;
0134     delete mva_woGwGSF_BL_;
0135     delete mva_wGwGSF_BL_;
0136     delete mva_NoEleMatch_woGwoGSF_EC_;
0137     delete mva_NoEleMatch_wGwoGSF_EC_;
0138     delete mva_woGwGSF_EC_;
0139     delete mva_wGwGSF_EC_;
0140     if (isPhase2_) {
0141       delete mva_NoEleMatch_woGwoGSF_VFEC_;
0142       delete mva_NoEleMatch_wGwoGSF_VFEC_;
0143       delete mva_woGwGSF_VFEC_;
0144       delete mva_wGwGSF_VFEC_;
0145     }
0146   }
0147 
0148   for (std::vector<TFile*>::iterator it = inputFilesToDelete_.begin(); it != inputFilesToDelete_.end(); ++it) {
0149     delete (*it);
0150   }
0151 }
0152 
0153 namespace {
0154   const GBRForest* loadMVAfromFile(TFile* inputFile, const std::string& mvaName) {
0155     const GBRForest* mva = (GBRForest*)inputFile->Get(mvaName.data());
0156     if (mva == nullptr)
0157       throw cms::Exception("PFRecoTauDiscriminationAgainstElectronMVA6::loadMVA")
0158           << " Failed to load MVA = " << mvaName.data() << " from file "
0159           << " !!\n";
0160 
0161     return mva;
0162   }
0163 }  // namespace
0164 
0165 template <class TauType, class ElectronType>
0166 void AntiElectronIDMVA6<TauType, ElectronType>::beginEvent(const edm::Event& evt, const edm::EventSetup& es) {
0167   if (!isInitialized_) {
0168     if (loadMVAfromDB_) {
0169       mva_NoEleMatch_woGwoGSF_BL_ = &es.getData(mvaToken_NoEleMatch_woGwoGSF_BL_);
0170       mva_NoEleMatch_wGwoGSF_BL_ = &es.getData(mvaToken_NoEleMatch_wGwoGSF_BL_);
0171       mva_woGwGSF_BL_ = &es.getData(mvaToken_woGwGSF_BL_);
0172       mva_wGwGSF_BL_ = &es.getData(mvaToken_wGwGSF_BL_);
0173       mva_NoEleMatch_woGwoGSF_EC_ = &es.getData(mvaToken_NoEleMatch_woGwoGSF_EC_);
0174       mva_NoEleMatch_wGwoGSF_EC_ = &es.getData(mvaToken_NoEleMatch_wGwoGSF_EC_);
0175       mva_woGwGSF_EC_ = &es.getData(mvaToken_woGwGSF_EC_);
0176       mva_wGwGSF_EC_ = &es.getData(mvaToken_wGwGSF_EC_);
0177       if (isPhase2_) {
0178         mva_NoEleMatch_woGwoGSF_VFEC_ = &es.getData(mvaToken_NoEleMatch_woGwoGSF_VFEC_);
0179         mva_NoEleMatch_wGwoGSF_VFEC_ = &es.getData(mvaToken_NoEleMatch_wGwoGSF_VFEC_);
0180         mva_woGwGSF_VFEC_ = &es.getData(mvaToken_woGwGSF_VFEC_);
0181         mva_wGwGSF_VFEC_ = &es.getData(mvaToken_wGwGSF_VFEC_);
0182       }
0183     } else {
0184       if (inputFileName_.location() == edm::FileInPath::Unknown)
0185         throw cms::Exception("PFRecoTauDiscriminationAgainstElectronMVA6::loadMVA")
0186             << " Failed to find File = " << inputFileName_ << " !!\n";
0187       TFile* inputFile = new TFile(inputFileName_.fullPath().data());
0188 
0189       mva_NoEleMatch_woGwoGSF_BL_ = loadMVAfromFile(inputFile, mvaName_NoEleMatch_woGwoGSF_BL_);
0190       mva_NoEleMatch_wGwoGSF_BL_ = loadMVAfromFile(inputFile, mvaName_NoEleMatch_wGwoGSF_BL_);
0191       mva_woGwGSF_BL_ = loadMVAfromFile(inputFile, mvaName_woGwGSF_BL_);
0192       mva_wGwGSF_BL_ = loadMVAfromFile(inputFile, mvaName_wGwGSF_BL_);
0193       mva_NoEleMatch_woGwoGSF_EC_ = loadMVAfromFile(inputFile, mvaName_NoEleMatch_woGwoGSF_EC_);
0194       mva_NoEleMatch_wGwoGSF_EC_ = loadMVAfromFile(inputFile, mvaName_NoEleMatch_wGwoGSF_EC_);
0195       mva_woGwGSF_EC_ = loadMVAfromFile(inputFile, mvaName_woGwGSF_EC_);
0196       mva_wGwGSF_EC_ = loadMVAfromFile(inputFile, mvaName_wGwGSF_EC_);
0197       if (isPhase2_) {
0198         mva_NoEleMatch_woGwoGSF_VFEC_ = loadMVAfromFile(inputFile, mvaName_NoEleMatch_woGwoGSF_VFEC_);
0199         mva_NoEleMatch_wGwoGSF_VFEC_ = loadMVAfromFile(inputFile, mvaName_NoEleMatch_wGwoGSF_VFEC_);
0200         mva_woGwGSF_VFEC_ = loadMVAfromFile(inputFile, mvaName_woGwGSF_VFEC_);
0201         mva_wGwGSF_VFEC_ = loadMVAfromFile(inputFile, mvaName_wGwGSF_VFEC_);
0202       }
0203       inputFilesToDelete_.push_back(inputFile);
0204     }
0205     isInitialized_ = true;
0206   }
0207   positionAtECalEntrance_.beginEvent(es);
0208   //MB: Handle additional inputs (HGCal EleID variables) only for Phase2 and reco::GsfElectrons
0209   if (isPhase2_ && std::is_same<ElectronType, reco::GsfElectron>::value) {
0210     for (const auto& eId_token : electronIds_tokens_) {
0211       electronIds_[eId_token.first] = evt.getHandle(eId_token.second);
0212     }
0213   }
0214 }
0215 
0216 template <class TauType, class ElectronType>
0217 double AntiElectronIDMVA6<TauType, ElectronType>::mvaValue(const TauVars& tauVars,
0218                                                            const TauGammaVecs& tauGammaVecs,
0219                                                            const ElecVars& elecVars) {
0220   TauGammaMoms tauGammaMoms;
0221   double sumPt = 0.;
0222   double dEta2 = 0.;
0223   double dPhi2 = 0.;
0224   tauGammaMoms.signalPFGammaCandsIn = tauGammaVecs.gammasPtInSigCone.size();
0225   for (size_t i = 0; i < tauGammaVecs.gammasPtInSigCone.size(); ++i) {
0226     double pt_i = tauGammaVecs.gammasPtInSigCone[i];
0227     double phi_i = tauGammaVecs.gammasdPhiInSigCone[i];
0228     if (tauGammaVecs.gammasdPhiInSigCone[i] > M_PI)
0229       phi_i = tauGammaVecs.gammasdPhiInSigCone[i] - 2 * M_PI;
0230     else if (tauGammaVecs.gammasdPhiInSigCone[i] < -M_PI)
0231       phi_i = tauGammaVecs.gammasdPhiInSigCone[i] + 2 * M_PI;
0232     double eta_i = tauGammaVecs.gammasdEtaInSigCone[i];
0233     sumPt += pt_i;
0234     dEta2 += (pt_i * eta_i * eta_i);
0235     dPhi2 += (pt_i * phi_i * phi_i);
0236   }
0237 
0238   tauGammaMoms.gammaEnFracIn = -99.;
0239   if (tauVars.pt > 0.) {
0240     tauGammaMoms.gammaEnFracIn = sumPt / tauVars.pt;
0241   }
0242   if (sumPt > 0.) {
0243     dEta2 /= sumPt;
0244     dPhi2 /= sumPt;
0245   }
0246   tauGammaMoms.gammaEtaMomIn = std::sqrt(dEta2 * tauGammaMoms.gammaEnFracIn) * tauVars.pt;
0247   tauGammaMoms.gammaPhiMomIn = std::sqrt(dPhi2 * tauGammaMoms.gammaEnFracIn) * tauVars.pt;
0248 
0249   sumPt = 0.;
0250   dEta2 = 0.;
0251   dPhi2 = 0.;
0252   tauGammaMoms.signalPFGammaCandsOut = tauGammaVecs.gammasPtOutSigCone.size();
0253   for (size_t i = 0; i < tauGammaVecs.gammasPtOutSigCone.size(); ++i) {
0254     double pt_i = tauGammaVecs.gammasPtOutSigCone[i];
0255     double phi_i = tauGammaVecs.gammasdPhiOutSigCone[i];
0256     if (tauGammaVecs.gammasdPhiOutSigCone[i] > M_PI)
0257       phi_i = tauGammaVecs.gammasdPhiOutSigCone[i] - 2 * M_PI;
0258     else if (tauGammaVecs.gammasdPhiOutSigCone[i] < -M_PI)
0259       phi_i = tauGammaVecs.gammasdPhiOutSigCone[i] + 2 * M_PI;
0260     double eta_i = tauGammaVecs.gammasdEtaOutSigCone[i];
0261     sumPt += pt_i;
0262     dEta2 += (pt_i * eta_i * eta_i);
0263     dPhi2 += (pt_i * phi_i * phi_i);
0264   }
0265 
0266   tauGammaMoms.gammaEnFracOut = -99.;
0267   if (tauVars.pt > 0.) {
0268     tauGammaMoms.gammaEnFracOut = sumPt / tauVars.pt;
0269   }
0270   if (sumPt > 0.) {
0271     dEta2 /= sumPt;
0272     dPhi2 /= sumPt;
0273   }
0274   tauGammaMoms.gammaEtaMomOut = std::sqrt(dEta2 * tauGammaMoms.gammaEnFracOut) * tauVars.pt;
0275   tauGammaMoms.gammaPhiMomOut = std::sqrt(dPhi2 * tauGammaMoms.gammaEnFracOut) * tauVars.pt;
0276 
0277   if (!isPhase2_) {
0278     return mvaValue(tauVars, tauGammaMoms, elecVars);
0279   } else {
0280     return mvaValuePhase2(tauVars, tauGammaMoms, elecVars);
0281   }
0282 }
0283 
0284 template <class TauType, class ElectronType>
0285 double AntiElectronIDMVA6<TauType, ElectronType>::mvaValue(const TauVars& tauVars,
0286                                                            const TauGammaMoms& tauGammaMoms,
0287                                                            const ElecVars& elecVars) {
0288   if (!isInitialized_) {
0289     throw cms::Exception("ClassNotInitialized") << " AntiElectronMVA6 not properly initialized !!\n";
0290   }
0291 
0292   double mvaValue = -99.;
0293 
0294   float elecDeltaPinPoutOverPin = (elecVars.pIn > 0.0) ? (std::abs(elecVars.pIn - elecVars.pOut) / elecVars.pIn) : 1.0;
0295   float elecEecalOverPout = (elecVars.pOut > 0.0) ? (elecVars.eEcal / elecVars.pOut) : 20.0;
0296   float elecNumHitsDiffOverSum =
0297       ((elecVars.gsfNumHits + elecVars.kfNumHits) > 0.0)
0298           ? ((elecVars.gsfNumHits - elecVars.kfNumHits) / (elecVars.gsfNumHits + elecVars.kfNumHits))
0299           : 1.0;
0300 
0301   if (deltaR(tauVars.etaAtEcalEntrance, tauVars.phi, elecVars.eta, elecVars.phi) > 0.3 &&
0302       tauGammaMoms.signalPFGammaCandsIn == 0 && tauVars.hasGsf < 0.5) {
0303     if (std::abs(tauVars.etaAtEcalEntrance) < ecalBarrelEndcapEtaBorder_) {
0304       var_NoEleMatch_woGwoGSF_Barrel_[0] = tauVars.etaAtEcalEntrance;
0305       var_NoEleMatch_woGwoGSF_Barrel_[1] = tauVars.leadChargedPFCandEtaAtEcalEntrance;
0306       var_NoEleMatch_woGwoGSF_Barrel_[2] = std::min(2.f, tauVars.leadChargedPFCandPt / std::max(1.f, tauVars.pt));
0307       var_NoEleMatch_woGwoGSF_Barrel_[3] = std::log(std::max(1.f, tauVars.pt));
0308       var_NoEleMatch_woGwoGSF_Barrel_[4] = tauVars.emFraction;
0309       var_NoEleMatch_woGwoGSF_Barrel_[5] = tauVars.leadPFChargedHadrHoP;
0310       var_NoEleMatch_woGwoGSF_Barrel_[6] = tauVars.leadPFChargedHadrEoP;
0311       var_NoEleMatch_woGwoGSF_Barrel_[7] = tauVars.visMassIn;
0312       var_NoEleMatch_woGwoGSF_Barrel_[8] = tauVars.dCrackEta;
0313       var_NoEleMatch_woGwoGSF_Barrel_[9] = tauVars.dCrackPhi;
0314       mvaValue = mva_NoEleMatch_woGwoGSF_BL_->GetClassifier(var_NoEleMatch_woGwoGSF_Barrel_.data());
0315     } else {
0316       var_NoEleMatch_woGwoGSF_Endcap_[0] = tauVars.etaAtEcalEntrance;
0317       var_NoEleMatch_woGwoGSF_Endcap_[1] = tauVars.leadChargedPFCandEtaAtEcalEntrance;
0318       var_NoEleMatch_woGwoGSF_Endcap_[2] = std::min(2.f, tauVars.leadChargedPFCandPt / std::max(1.f, tauVars.pt));
0319       var_NoEleMatch_woGwoGSF_Endcap_[3] = std::log(std::max(1.f, tauVars.pt));
0320       var_NoEleMatch_woGwoGSF_Endcap_[4] = tauVars.emFraction;
0321       var_NoEleMatch_woGwoGSF_Endcap_[5] = tauVars.leadPFChargedHadrHoP;
0322       var_NoEleMatch_woGwoGSF_Endcap_[6] = tauVars.leadPFChargedHadrEoP;
0323       var_NoEleMatch_woGwoGSF_Endcap_[7] = tauVars.visMassIn;
0324       var_NoEleMatch_woGwoGSF_Endcap_[8] = tauVars.dCrackEta;
0325       mvaValue = mva_NoEleMatch_woGwoGSF_EC_->GetClassifier(var_NoEleMatch_woGwoGSF_Endcap_.data());
0326     }
0327   } else if (deltaR(tauVars.etaAtEcalEntrance, tauVars.phi, elecVars.eta, elecVars.phi) > 0.3 &&
0328              tauGammaMoms.signalPFGammaCandsIn > 0 && tauVars.hasGsf < 0.5) {
0329     if (std::abs(tauVars.etaAtEcalEntrance) < ecalBarrelEndcapEtaBorder_) {
0330       var_NoEleMatch_wGwoGSF_Barrel_[0] = tauVars.etaAtEcalEntrance;
0331       var_NoEleMatch_wGwoGSF_Barrel_[1] = tauVars.leadChargedPFCandEtaAtEcalEntrance;
0332       var_NoEleMatch_wGwoGSF_Barrel_[2] = std::min(2.f, tauVars.leadChargedPFCandPt / std::max(1.f, tauVars.pt));
0333       var_NoEleMatch_wGwoGSF_Barrel_[3] = std::log(std::max(1.f, tauVars.pt));
0334       var_NoEleMatch_wGwoGSF_Barrel_[4] = tauVars.emFraction;
0335       var_NoEleMatch_wGwoGSF_Barrel_[5] = tauGammaMoms.signalPFGammaCandsIn;
0336       var_NoEleMatch_wGwoGSF_Barrel_[6] = tauGammaMoms.signalPFGammaCandsOut;
0337       var_NoEleMatch_wGwoGSF_Barrel_[7] = tauVars.leadPFChargedHadrHoP;
0338       var_NoEleMatch_wGwoGSF_Barrel_[8] = tauVars.leadPFChargedHadrEoP;
0339       var_NoEleMatch_wGwoGSF_Barrel_[9] = tauVars.visMassIn;
0340       var_NoEleMatch_wGwoGSF_Barrel_[10] = tauGammaMoms.gammaEtaMomIn;
0341       var_NoEleMatch_wGwoGSF_Barrel_[11] = tauGammaMoms.gammaEtaMomOut;
0342       var_NoEleMatch_wGwoGSF_Barrel_[12] = tauGammaMoms.gammaPhiMomIn;
0343       var_NoEleMatch_wGwoGSF_Barrel_[13] = tauGammaMoms.gammaPhiMomOut;
0344       var_NoEleMatch_wGwoGSF_Barrel_[14] = tauGammaMoms.gammaEnFracIn;
0345       var_NoEleMatch_wGwoGSF_Barrel_[15] = tauGammaMoms.gammaEnFracOut;
0346       var_NoEleMatch_wGwoGSF_Barrel_[16] = tauVars.dCrackEta;
0347       var_NoEleMatch_wGwoGSF_Barrel_[17] = tauVars.dCrackPhi;
0348       mvaValue = mva_NoEleMatch_wGwoGSF_BL_->GetClassifier(var_NoEleMatch_wGwoGSF_Barrel_.data());
0349     } else {
0350       var_NoEleMatch_wGwoGSF_Endcap_[0] = tauVars.etaAtEcalEntrance;
0351       var_NoEleMatch_wGwoGSF_Endcap_[1] = tauVars.leadChargedPFCandEtaAtEcalEntrance;
0352       var_NoEleMatch_wGwoGSF_Endcap_[2] = std::min(2.f, tauVars.leadChargedPFCandPt / std::max(1.f, tauVars.pt));
0353       var_NoEleMatch_wGwoGSF_Endcap_[3] = std::log(std::max(1.f, tauVars.pt));
0354       var_NoEleMatch_wGwoGSF_Endcap_[4] = tauVars.emFraction;
0355       var_NoEleMatch_wGwoGSF_Endcap_[5] = tauGammaMoms.signalPFGammaCandsIn;
0356       var_NoEleMatch_wGwoGSF_Endcap_[6] = tauGammaMoms.signalPFGammaCandsOut;
0357       var_NoEleMatch_wGwoGSF_Endcap_[7] = tauVars.leadPFChargedHadrHoP;
0358       var_NoEleMatch_wGwoGSF_Endcap_[8] = tauVars.leadPFChargedHadrEoP;
0359       var_NoEleMatch_wGwoGSF_Endcap_[9] = tauVars.visMassIn;
0360       var_NoEleMatch_wGwoGSF_Endcap_[10] = tauGammaMoms.gammaEtaMomIn;
0361       var_NoEleMatch_wGwoGSF_Endcap_[11] = tauGammaMoms.gammaEtaMomOut;
0362       var_NoEleMatch_wGwoGSF_Endcap_[12] = tauGammaMoms.gammaPhiMomIn;
0363       var_NoEleMatch_wGwoGSF_Endcap_[13] = tauGammaMoms.gammaPhiMomOut;
0364       var_NoEleMatch_wGwoGSF_Endcap_[14] = tauGammaMoms.gammaEnFracIn;
0365       var_NoEleMatch_wGwoGSF_Endcap_[15] = tauGammaMoms.gammaEnFracOut;
0366       var_NoEleMatch_wGwoGSF_Endcap_[16] = tauVars.dCrackEta;
0367       mvaValue = mva_NoEleMatch_wGwoGSF_EC_->GetClassifier(var_NoEleMatch_wGwoGSF_Endcap_.data());
0368     }
0369   } else if (tauGammaMoms.signalPFGammaCandsIn == 0 && tauVars.hasGsf > 0.5) {
0370     if (std::abs(tauVars.etaAtEcalEntrance) < ecalBarrelEndcapEtaBorder_) {
0371       var_woGwGSF_Barrel_[0] = std::max(-0.1f, elecVars.eTotOverPin);
0372       var_woGwGSF_Barrel_[1] = std::log(std::max(0.01f, elecVars.chi2NormGSF));
0373       var_woGwGSF_Barrel_[2] = elecVars.gsfNumHits;
0374       var_woGwGSF_Barrel_[3] = std::log(std::max(0.01f, elecVars.gsfTrackResol));
0375       var_woGwGSF_Barrel_[4] = elecVars.gsfTracklnPt;
0376       var_woGwGSF_Barrel_[5] = elecNumHitsDiffOverSum;
0377       var_woGwGSF_Barrel_[6] = std::log(std::max(0.01f, elecVars.chi2NormKF));
0378       var_woGwGSF_Barrel_[7] = std::min(elecDeltaPinPoutOverPin, 1.f);
0379       var_woGwGSF_Barrel_[8] = std::min(elecEecalOverPout, 20.f);
0380       var_woGwGSF_Barrel_[9] = elecVars.deltaEta;
0381       var_woGwGSF_Barrel_[10] = elecVars.deltaPhi;
0382       var_woGwGSF_Barrel_[11] = std::min(elecVars.mvaInSigmaEtaEta, 0.01f);
0383       var_woGwGSF_Barrel_[12] = std::min(elecVars.mvaInHadEnergy, 20.f);
0384       var_woGwGSF_Barrel_[13] = std::min(elecVars.mvaInDeltaEta, 0.1f);
0385       var_woGwGSF_Barrel_[14] = tauVars.etaAtEcalEntrance;
0386       var_woGwGSF_Barrel_[15] = tauVars.leadChargedPFCandEtaAtEcalEntrance;
0387       var_woGwGSF_Barrel_[16] = std::min(2.f, tauVars.leadChargedPFCandPt / std::max(1.f, tauVars.pt));
0388       var_woGwGSF_Barrel_[17] = std::log(std::max(1.f, tauVars.pt));
0389       var_woGwGSF_Barrel_[18] = tauVars.emFraction;
0390       var_woGwGSF_Barrel_[19] = tauVars.leadPFChargedHadrHoP;
0391       var_woGwGSF_Barrel_[20] = tauVars.leadPFChargedHadrEoP;
0392       var_woGwGSF_Barrel_[21] = tauVars.visMassIn;
0393       var_woGwGSF_Barrel_[22] = tauVars.dCrackEta;
0394       var_woGwGSF_Barrel_[23] = tauVars.dCrackPhi;
0395       mvaValue = mva_woGwGSF_BL_->GetClassifier(var_woGwGSF_Barrel_.data());
0396     } else {
0397       var_woGwGSF_Endcap_[0] = std::max(-0.1f, elecVars.eTotOverPin);
0398       var_woGwGSF_Endcap_[1] = std::log(std::max(0.01f, elecVars.chi2NormGSF));
0399       var_woGwGSF_Endcap_[2] = elecVars.gsfNumHits;
0400       var_woGwGSF_Endcap_[3] = std::log(std::max(0.01f, elecVars.gsfTrackResol));
0401       var_woGwGSF_Endcap_[4] = elecVars.gsfTracklnPt;
0402       var_woGwGSF_Endcap_[5] = elecNumHitsDiffOverSum;
0403       var_woGwGSF_Endcap_[6] = std::log(std::max(0.01f, elecVars.chi2NormKF));
0404       var_woGwGSF_Endcap_[7] = std::min(elecDeltaPinPoutOverPin, 1.f);
0405       var_woGwGSF_Endcap_[8] = std::min(elecEecalOverPout, 20.f);
0406       var_woGwGSF_Endcap_[9] = elecVars.deltaEta;
0407       var_woGwGSF_Endcap_[10] = elecVars.deltaPhi;
0408       var_woGwGSF_Endcap_[11] = std::min(elecVars.mvaInSigmaEtaEta, 0.01f);
0409       var_woGwGSF_Endcap_[12] = std::min(elecVars.mvaInHadEnergy, 20.f);
0410       var_woGwGSF_Endcap_[13] = std::min(elecVars.mvaInDeltaEta, 0.1f);
0411       var_woGwGSF_Endcap_[14] = tauVars.etaAtEcalEntrance;
0412       var_woGwGSF_Endcap_[15] = tauVars.leadChargedPFCandEtaAtEcalEntrance;
0413       var_woGwGSF_Endcap_[16] = std::min(2.f, tauVars.leadChargedPFCandPt / std::max(1.f, tauVars.pt));
0414       var_woGwGSF_Endcap_[17] = std::log(std::max(1.f, tauVars.pt));
0415       var_woGwGSF_Endcap_[18] = tauVars.emFraction;
0416       var_woGwGSF_Endcap_[19] = tauVars.leadPFChargedHadrHoP;
0417       var_woGwGSF_Endcap_[20] = tauVars.leadPFChargedHadrEoP;
0418       var_woGwGSF_Endcap_[21] = tauVars.visMassIn;
0419       var_woGwGSF_Endcap_[22] = tauVars.dCrackEta;
0420       mvaValue = mva_woGwGSF_EC_->GetClassifier(var_woGwGSF_Endcap_.data());
0421     }
0422   } else if (tauGammaMoms.signalPFGammaCandsIn > 0 && tauVars.hasGsf > 0.5) {
0423     if (std::abs(tauVars.etaAtEcalEntrance) < ecalBarrelEndcapEtaBorder_) {
0424       var_wGwGSF_Barrel_[0] = std::max(-0.1f, elecVars.eTotOverPin);
0425       var_wGwGSF_Barrel_[1] = std::log(std::max(0.01f, elecVars.chi2NormGSF));
0426       var_wGwGSF_Barrel_[2] = elecVars.gsfNumHits;
0427       var_wGwGSF_Barrel_[3] = std::log(std::max(0.01f, elecVars.gsfTrackResol));
0428       var_wGwGSF_Barrel_[4] = elecVars.gsfTracklnPt;
0429       var_wGwGSF_Barrel_[5] = elecNumHitsDiffOverSum;
0430       var_wGwGSF_Barrel_[6] = std::log(std::max(0.01f, elecVars.chi2NormKF));
0431       var_wGwGSF_Barrel_[7] = std::min(elecDeltaPinPoutOverPin, 1.f);
0432       var_wGwGSF_Barrel_[8] = std::min(elecEecalOverPout, 20.f);
0433       var_wGwGSF_Barrel_[9] = elecVars.deltaEta;
0434       var_wGwGSF_Barrel_[10] = elecVars.deltaPhi;
0435       var_wGwGSF_Barrel_[11] = std::min(elecVars.mvaInSigmaEtaEta, 0.01f);
0436       var_wGwGSF_Barrel_[12] = std::min(elecVars.mvaInHadEnergy, 20.f);
0437       var_wGwGSF_Barrel_[13] = std::min(elecVars.mvaInDeltaEta, 0.1f);
0438       var_wGwGSF_Barrel_[14] = tauVars.etaAtEcalEntrance;
0439       var_wGwGSF_Barrel_[15] = tauVars.leadChargedPFCandEtaAtEcalEntrance;
0440       var_wGwGSF_Barrel_[16] = std::min(2.f, tauVars.leadChargedPFCandPt / std::max(1.f, tauVars.pt));
0441       var_wGwGSF_Barrel_[17] = std::log(std::max(1.f, tauVars.pt));
0442       var_wGwGSF_Barrel_[18] = tauVars.emFraction;
0443       var_wGwGSF_Barrel_[19] = tauGammaMoms.signalPFGammaCandsIn;
0444       var_wGwGSF_Barrel_[20] = tauGammaMoms.signalPFGammaCandsOut;
0445       var_wGwGSF_Barrel_[21] = tauVars.leadPFChargedHadrHoP;
0446       var_wGwGSF_Barrel_[22] = tauVars.leadPFChargedHadrEoP;
0447       var_wGwGSF_Barrel_[23] = tauVars.visMassIn;
0448       var_wGwGSF_Barrel_[24] = tauGammaMoms.gammaEtaMomIn;
0449       var_wGwGSF_Barrel_[25] = tauGammaMoms.gammaEtaMomOut;
0450       var_wGwGSF_Barrel_[26] = tauGammaMoms.gammaPhiMomIn;
0451       var_wGwGSF_Barrel_[27] = tauGammaMoms.gammaPhiMomOut;
0452       var_wGwGSF_Barrel_[28] = tauGammaMoms.gammaEnFracIn;
0453       var_wGwGSF_Barrel_[29] = tauGammaMoms.gammaEnFracOut;
0454       var_wGwGSF_Barrel_[30] = tauVars.dCrackEta;
0455       var_wGwGSF_Barrel_[31] = tauVars.dCrackPhi;
0456       mvaValue = mva_wGwGSF_BL_->GetClassifier(var_wGwGSF_Barrel_.data());
0457     } else {
0458       var_wGwGSF_Endcap_[0] = std::max(-0.1f, elecVars.eTotOverPin);
0459       var_wGwGSF_Endcap_[1] = std::log(std::max(0.01f, elecVars.chi2NormGSF));
0460       var_wGwGSF_Endcap_[2] = elecVars.gsfNumHits;
0461       var_wGwGSF_Endcap_[3] = std::log(std::max(0.01f, elecVars.gsfTrackResol));
0462       var_wGwGSF_Endcap_[4] = elecVars.gsfTracklnPt;
0463       var_wGwGSF_Endcap_[5] = elecNumHitsDiffOverSum;
0464       var_wGwGSF_Endcap_[6] = std::log(std::max(0.01f, elecVars.chi2NormKF));
0465       var_wGwGSF_Endcap_[7] = std::min(elecDeltaPinPoutOverPin, 1.f);
0466       var_wGwGSF_Endcap_[8] = std::min(elecEecalOverPout, 20.f);
0467       var_wGwGSF_Endcap_[9] = elecVars.deltaEta;
0468       var_wGwGSF_Endcap_[10] = elecVars.deltaPhi;
0469       var_wGwGSF_Endcap_[11] = std::min(elecVars.mvaInSigmaEtaEta, 0.01f);
0470       var_wGwGSF_Endcap_[12] = std::min(elecVars.mvaInHadEnergy, 20.f);
0471       var_wGwGSF_Endcap_[13] = std::min(elecVars.mvaInDeltaEta, 0.1f);
0472       var_wGwGSF_Endcap_[14] = tauVars.etaAtEcalEntrance;
0473       var_wGwGSF_Endcap_[15] = tauVars.leadChargedPFCandEtaAtEcalEntrance;
0474       var_wGwGSF_Endcap_[16] = std::min(2.f, tauVars.leadChargedPFCandPt / std::max(1.f, tauVars.pt));
0475       var_wGwGSF_Endcap_[17] = std::log(std::max(1.f, tauVars.pt));
0476       var_wGwGSF_Endcap_[18] = tauVars.emFraction;
0477       var_wGwGSF_Endcap_[19] = tauGammaMoms.signalPFGammaCandsIn;
0478       var_wGwGSF_Endcap_[20] = tauGammaMoms.signalPFGammaCandsOut;
0479       var_wGwGSF_Endcap_[21] = tauVars.leadPFChargedHadrHoP;
0480       var_wGwGSF_Endcap_[22] = tauVars.leadPFChargedHadrEoP;
0481       var_wGwGSF_Endcap_[23] = tauVars.visMassIn;
0482       var_wGwGSF_Endcap_[24] = tauGammaMoms.gammaEtaMomIn;
0483       var_wGwGSF_Endcap_[25] = tauGammaMoms.gammaEtaMomOut;
0484       var_wGwGSF_Endcap_[26] = tauGammaMoms.gammaPhiMomIn;
0485       var_wGwGSF_Endcap_[27] = tauGammaMoms.gammaPhiMomOut;
0486       var_wGwGSF_Endcap_[28] = tauGammaMoms.gammaEnFracIn;
0487       var_wGwGSF_Endcap_[29] = tauGammaMoms.gammaEnFracOut;
0488       var_wGwGSF_Endcap_[30] = tauVars.dCrackEta;
0489       mvaValue = mva_wGwGSF_EC_->GetClassifier(var_wGwGSF_Endcap_.data());
0490     }
0491   }
0492   return mvaValue;
0493 }
0494 ////
0495 template <class TauType, class ElectronType>
0496 double AntiElectronIDMVA6<TauType, ElectronType>::mvaValuePhase2(const TauVars& tauVars,
0497                                                                  const TauGammaMoms& tauGammaMoms,
0498                                                                  const ElecVars& elecVars) {
0499   if (!isInitialized_) {
0500     throw cms::Exception("ClassNotInitialized") << " AntiElectronMVA6 not properly initialized !!\n";
0501   }
0502 
0503   double mvaValue = -99.;
0504 
0505   //do not consider tau candidates outside the HGCal border at |eta|=3
0506   if (std::abs(tauVars.etaAtEcalEntrance) > 3.0) {
0507     return mvaValue;
0508   }
0509 
0510   float elecDeltaPinPoutOverPin = (elecVars.pIn > 0.0) ? (std::abs(elecVars.pIn - elecVars.pOut) / elecVars.pIn) : 1.0;
0511   float elecEecalOverPout = (elecVars.pOut > 0.0) ? (elecVars.eEcal / elecVars.pOut) : 20.0;
0512   float elecNumHitsDiffOverSum =
0513       ((elecVars.gsfNumHits + elecVars.kfNumHits) > 0.0)
0514           ? ((elecVars.gsfNumHits - elecVars.kfNumHits) / (elecVars.gsfNumHits + elecVars.kfNumHits))
0515           : 1.0;
0516 
0517   if (tauGammaMoms.signalPFGammaCandsIn == 0 && tauVars.hasGsf < 0.5) {
0518     if (std::abs(tauVars.etaAtEcalEntrance) < ecalBarrelEndcapEtaBorder_) {
0519       var_NoEleMatch_woGwoGSF_Barrel_[0] = std::min(2.f, tauVars.leadChargedPFCandPt / std::max(1.f, tauVars.pt));
0520       var_NoEleMatch_woGwoGSF_Barrel_[1] = std::log(std::max(1.f, tauVars.pt));
0521       var_NoEleMatch_woGwoGSF_Barrel_[2] = tauVars.emFraction;
0522       var_NoEleMatch_woGwoGSF_Barrel_[3] = tauVars.leadPFChargedHadrHoP;
0523       var_NoEleMatch_woGwoGSF_Barrel_[4] = tauVars.leadPFChargedHadrEoP;
0524       var_NoEleMatch_woGwoGSF_Barrel_[5] = tauVars.visMassIn;
0525       var_NoEleMatch_woGwoGSF_Barrel_[6] = tauVars.dCrackEta;
0526       var_NoEleMatch_woGwoGSF_Barrel_[7] = tauVars.etaAtEcalEntrance;
0527       var_NoEleMatch_woGwoGSF_Barrel_[8] = tauVars.leadChargedPFCandEtaAtEcalEntrance;
0528       mvaValue = mva_NoEleMatch_woGwoGSF_BL_->GetClassifier(var_NoEleMatch_woGwoGSF_Barrel_.data());
0529     } else if (std::abs(tauVars.etaAtEcalEntrance) < ecalEndcapVFEndcapEtaBorder_) {
0530       var_NoEleMatch_woGwoGSF_Endcap_[0] = std::min(2.f, tauVars.leadChargedPFCandPt / std::max(1.f, tauVars.pt));
0531       var_NoEleMatch_woGwoGSF_Endcap_[1] = std::log(std::max(1.f, tauVars.pt));
0532       var_NoEleMatch_woGwoGSF_Endcap_[2] = tauVars.visMassIn;
0533       var_NoEleMatch_woGwoGSF_Endcap_[3] = tauVars.dCrackEta;
0534       var_NoEleMatch_woGwoGSF_Endcap_[4] = tauVars.etaAtEcalEntrance;
0535       var_NoEleMatch_woGwoGSF_Endcap_[5] = tauVars.leadChargedPFCandEtaAtEcalEntrance;
0536       mvaValue = mva_NoEleMatch_woGwoGSF_EC_->GetClassifier(var_NoEleMatch_woGwoGSF_Endcap_.data());
0537     } else {
0538       var_NoEleMatch_woGwoGSF_VFEndcap_[0] = std::min(2.f, tauVars.leadChargedPFCandPt / std::max(1.f, tauVars.pt));
0539       var_NoEleMatch_woGwoGSF_VFEndcap_[1] = std::log(std::max(1.f, tauVars.pt));
0540       var_NoEleMatch_woGwoGSF_VFEndcap_[2] = tauVars.visMassIn;
0541       var_NoEleMatch_woGwoGSF_VFEndcap_[3] = tauVars.dCrackEta;
0542       var_NoEleMatch_woGwoGSF_VFEndcap_[4] = tauVars.etaAtEcalEntrance;
0543       var_NoEleMatch_woGwoGSF_VFEndcap_[5] = tauVars.leadChargedPFCandEtaAtEcalEntrance;
0544       mvaValue = mva_NoEleMatch_woGwoGSF_VFEC_->GetClassifier(var_NoEleMatch_woGwoGSF_VFEndcap_.data());
0545     }
0546   } else if (tauGammaMoms.signalPFGammaCandsIn > 0 && tauVars.hasGsf < 0.5) {
0547     if (std::abs(tauVars.etaAtEcalEntrance) < ecalBarrelEndcapEtaBorder_) {
0548       var_NoEleMatch_wGwoGSF_Barrel_[0] = std::min(2.f, tauVars.leadChargedPFCandPt / std::max(1.f, tauVars.pt));
0549       var_NoEleMatch_wGwoGSF_Barrel_[1] = std::log(std::max(1.f, tauVars.pt));
0550       var_NoEleMatch_wGwoGSF_Barrel_[2] = tauVars.emFraction;
0551       var_NoEleMatch_wGwoGSF_Barrel_[3] = tauGammaMoms.signalPFGammaCandsIn;
0552       var_NoEleMatch_wGwoGSF_Barrel_[4] = tauGammaMoms.signalPFGammaCandsOut;
0553       var_NoEleMatch_wGwoGSF_Barrel_[5] = tauVars.leadPFChargedHadrHoP;
0554       var_NoEleMatch_wGwoGSF_Barrel_[6] = tauVars.leadPFChargedHadrEoP;
0555       var_NoEleMatch_wGwoGSF_Barrel_[7] = tauVars.visMassIn;
0556       var_NoEleMatch_wGwoGSF_Barrel_[7] = tauGammaMoms.gammaEtaMomIn;
0557       var_NoEleMatch_wGwoGSF_Barrel_[9] = tauGammaMoms.gammaEtaMomOut;
0558       var_NoEleMatch_wGwoGSF_Barrel_[10] = tauGammaMoms.gammaPhiMomIn;
0559       var_NoEleMatch_wGwoGSF_Barrel_[11] = tauGammaMoms.gammaPhiMomOut;
0560       var_NoEleMatch_wGwoGSF_Barrel_[12] = tauGammaMoms.gammaEnFracIn;
0561       var_NoEleMatch_wGwoGSF_Barrel_[13] = tauGammaMoms.gammaEnFracOut;
0562       var_NoEleMatch_wGwoGSF_Barrel_[14] = tauVars.dCrackEta;
0563       var_NoEleMatch_wGwoGSF_Barrel_[15] = tauVars.etaAtEcalEntrance;
0564       var_NoEleMatch_wGwoGSF_Barrel_[16] = tauVars.leadChargedPFCandEtaAtEcalEntrance;
0565       mvaValue = mva_NoEleMatch_wGwoGSF_BL_->GetClassifier(var_NoEleMatch_wGwoGSF_Barrel_.data());
0566     } else if (std::abs(tauVars.etaAtEcalEntrance) < ecalEndcapVFEndcapEtaBorder_) {
0567       var_NoEleMatch_wGwoGSF_Endcap_[0] = std::min(2.f, tauVars.leadChargedPFCandPt / std::max(1.f, tauVars.pt));
0568       var_NoEleMatch_wGwoGSF_Endcap_[1] = std::log(std::max(1.f, tauVars.pt));
0569       var_NoEleMatch_wGwoGSF_Endcap_[2] = tauGammaMoms.signalPFGammaCandsIn;
0570       var_NoEleMatch_wGwoGSF_Endcap_[3] = tauGammaMoms.signalPFGammaCandsOut;
0571       var_NoEleMatch_wGwoGSF_Endcap_[4] = tauVars.visMassIn;
0572       var_NoEleMatch_wGwoGSF_Endcap_[5] = tauGammaMoms.gammaEtaMomIn;
0573       var_NoEleMatch_wGwoGSF_Endcap_[6] = tauGammaMoms.gammaEtaMomOut;
0574       var_NoEleMatch_wGwoGSF_Endcap_[7] = tauGammaMoms.gammaPhiMomIn;
0575       var_NoEleMatch_wGwoGSF_Endcap_[8] = tauGammaMoms.gammaPhiMomOut;
0576       var_NoEleMatch_wGwoGSF_Endcap_[9] = tauGammaMoms.gammaEnFracIn;
0577       var_NoEleMatch_wGwoGSF_Endcap_[10] = tauGammaMoms.gammaEnFracOut;
0578       var_NoEleMatch_wGwoGSF_Endcap_[11] = tauVars.dCrackEta;
0579       var_NoEleMatch_wGwoGSF_Endcap_[12] = tauVars.etaAtEcalEntrance;
0580       var_NoEleMatch_wGwoGSF_Endcap_[13] = tauVars.leadChargedPFCandEtaAtEcalEntrance;
0581       mvaValue = mva_NoEleMatch_wGwoGSF_EC_->GetClassifier(var_NoEleMatch_wGwoGSF_Endcap_.data());
0582     } else {
0583       var_NoEleMatch_wGwoGSF_VFEndcap_[0] = std::min(2.f, tauVars.leadChargedPFCandPt / std::max(1.f, tauVars.pt));
0584       var_NoEleMatch_wGwoGSF_VFEndcap_[1] = std::log(std::max(1.f, tauVars.pt));
0585       var_NoEleMatch_wGwoGSF_VFEndcap_[2] = tauGammaMoms.signalPFGammaCandsIn;
0586       var_NoEleMatch_wGwoGSF_VFEndcap_[3] = tauGammaMoms.signalPFGammaCandsOut;
0587       var_NoEleMatch_wGwoGSF_VFEndcap_[4] = tauVars.visMassIn;
0588       var_NoEleMatch_wGwoGSF_VFEndcap_[5] = tauGammaMoms.gammaEtaMomIn;
0589       var_NoEleMatch_wGwoGSF_VFEndcap_[6] = tauGammaMoms.gammaEtaMomOut;
0590       var_NoEleMatch_wGwoGSF_VFEndcap_[7] = tauGammaMoms.gammaPhiMomIn;
0591       var_NoEleMatch_wGwoGSF_VFEndcap_[8] = tauGammaMoms.gammaPhiMomOut;
0592       var_NoEleMatch_wGwoGSF_VFEndcap_[9] = tauGammaMoms.gammaEnFracIn;
0593       var_NoEleMatch_wGwoGSF_VFEndcap_[10] = tauGammaMoms.gammaEnFracOut;
0594       var_NoEleMatch_wGwoGSF_VFEndcap_[11] = tauVars.dCrackEta;
0595       var_NoEleMatch_wGwoGSF_VFEndcap_[12] = tauVars.etaAtEcalEntrance;
0596       var_NoEleMatch_wGwoGSF_VFEndcap_[13] = tauVars.leadChargedPFCandEtaAtEcalEntrance;
0597       mvaValue = mva_NoEleMatch_wGwoGSF_VFEC_->GetClassifier(var_NoEleMatch_wGwoGSF_VFEndcap_.data());
0598     }
0599   } else if (tauGammaMoms.signalPFGammaCandsIn == 0 && tauVars.hasGsf > 0.5) {
0600     if (std::abs(tauVars.etaAtEcalEntrance) < ecalBarrelEndcapEtaBorder_) {
0601       var_woGwGSF_Barrel_[0] = std::log(std::max(0.1f, elecVars.chi2NormGSF));
0602       var_woGwGSF_Barrel_[1] = elecVars.gsfNumHits;
0603       var_woGwGSF_Barrel_[2] = std::log(std::max(0.1f, elecVars.gsfTrackResol));
0604       var_woGwGSF_Barrel_[3] = elecVars.gsfTracklnPt;
0605       var_woGwGSF_Barrel_[4] = elecNumHitsDiffOverSum;
0606       var_woGwGSF_Barrel_[5] = std::log(std::max(0.1f, elecVars.chi2NormKF));
0607       var_woGwGSF_Barrel_[6] = std::min(elecDeltaPinPoutOverPin, 1.f);
0608       var_woGwGSF_Barrel_[7] = std::min(elecEecalOverPout, 20.f);
0609       var_woGwGSF_Barrel_[8] = std::min(elecVars.mvaInSigmaEtaEta, 0.01f);
0610       var_woGwGSF_Barrel_[9] = std::min(elecVars.mvaInHadEnergy, 20.f);
0611       var_woGwGSF_Barrel_[10] = std::min(elecVars.mvaInDeltaEta, 0.1f);
0612       var_woGwGSF_Barrel_[11] = std::min(2.f, tauVars.leadChargedPFCandPt / std::max(1.f, tauVars.pt));
0613       var_woGwGSF_Barrel_[12] = std::log(std::max(1.f, tauVars.pt));
0614       var_woGwGSF_Barrel_[13] = tauVars.emFraction;
0615       var_woGwGSF_Barrel_[14] = tauVars.leadPFChargedHadrHoP;
0616       var_woGwGSF_Barrel_[15] = tauVars.leadPFChargedHadrEoP;
0617       var_woGwGSF_Barrel_[16] = tauVars.visMassIn;
0618       var_woGwGSF_Barrel_[17] = tauVars.dCrackEta;
0619       var_woGwGSF_Barrel_[18] = tauVars.etaAtEcalEntrance;
0620       var_woGwGSF_Barrel_[19] = tauVars.leadChargedPFCandEtaAtEcalEntrance;
0621       var_woGwGSF_Barrel_[20] = elecVars.deltaEta;
0622       var_woGwGSF_Barrel_[21] = elecVars.deltaPhi;
0623       var_woGwGSF_Barrel_[22] = elecVars.sigmaIEtaIEta5x5;
0624       var_woGwGSF_Barrel_[23] = elecVars.showerCircularity;
0625       var_woGwGSF_Barrel_[24] = elecVars.r9;
0626       var_woGwGSF_Barrel_[25] = elecVars.superClusterEtaWidth;
0627       var_woGwGSF_Barrel_[26] = elecVars.superClusterPhiWidth;
0628       mvaValue = mva_woGwGSF_BL_->GetClassifier(var_woGwGSF_Barrel_.data());
0629     } else if (std::abs(tauVars.etaAtEcalEntrance) < ecalEndcapVFEndcapEtaBorder_) {
0630       var_woGwGSF_Endcap_[0] = std::log(std::max(0.1f, elecVars.chi2NormGSF));
0631       var_woGwGSF_Endcap_[1] = elecVars.gsfNumHits;
0632       var_woGwGSF_Endcap_[2] = std::log(std::max(0.1f, elecVars.gsfTrackResol));
0633       var_woGwGSF_Endcap_[3] = elecVars.gsfTracklnPt;
0634       var_woGwGSF_Endcap_[4] = elecNumHitsDiffOverSum;
0635       var_woGwGSF_Endcap_[5] = std::log(std::max(0.1f, elecVars.chi2NormKF));
0636       var_woGwGSF_Endcap_[6] = elecVars.eEcal;
0637       var_woGwGSF_Endcap_[7] = std::min(2.f, tauVars.leadChargedPFCandPt / std::max(1.f, tauVars.pt));
0638       var_woGwGSF_Endcap_[8] = std::log(std::max(1.f, tauVars.pt));
0639       var_woGwGSF_Endcap_[9] = tauVars.visMassIn;
0640       var_woGwGSF_Endcap_[10] = tauVars.dCrackEta;
0641       var_woGwGSF_Endcap_[11] = tauVars.etaAtEcalEntrance;
0642       var_woGwGSF_Endcap_[12] = tauVars.leadChargedPFCandEtaAtEcalEntrance;
0643       var_woGwGSF_Endcap_[13] = elecVars.hgcalSigmaUU;
0644       var_woGwGSF_Endcap_[14] = elecVars.hgcalSigmaVV;
0645       var_woGwGSF_Endcap_[15] = elecVars.hgcalSigmaEE;
0646       var_woGwGSF_Endcap_[16] = elecVars.hgcalSigmaPP;
0647       var_woGwGSF_Endcap_[17] = elecVars.hgcalNLayers;
0648       var_woGwGSF_Endcap_[18] = elecVars.hgcalLastLayer;
0649       var_woGwGSF_Endcap_[19] = elecVars.hgcalLayerEfrac10;
0650       var_woGwGSF_Endcap_[20] = elecVars.hgcalLayerEfrac90;
0651       var_woGwGSF_Endcap_[21] = elecVars.hgcalEcEnergyEE;
0652       var_woGwGSF_Endcap_[22] = elecVars.hgcalEcEnergyFH;
0653       var_woGwGSF_Endcap_[23] = elecVars.hgcalMeasuredDepth;
0654       var_woGwGSF_Endcap_[24] = elecVars.hgcalExpectedDepth;
0655       var_woGwGSF_Endcap_[25] = elecVars.hgcalDepthCompatibility;
0656       var_woGwGSF_Endcap_[26] = elecVars.deltaEta;
0657       var_woGwGSF_Endcap_[27] = elecVars.deltaPhi;
0658       var_woGwGSF_Endcap_[28] = elecVars.eSeedClusterOverPout;
0659       var_woGwGSF_Endcap_[29] = elecVars.superClusterEtaWidth;
0660       var_woGwGSF_Endcap_[30] = elecVars.superClusterPhiWidth;
0661       mvaValue = mva_woGwGSF_EC_->GetClassifier(var_woGwGSF_Endcap_.data());
0662     } else {
0663       var_woGwGSF_VFEndcap_[0] = std::log(std::max(0.1f, elecVars.chi2NormGSF));
0664       var_woGwGSF_VFEndcap_[1] = elecVars.gsfNumHits;
0665       var_woGwGSF_VFEndcap_[2] = std::log(std::max(0.1f, elecVars.gsfTrackResol));
0666       var_woGwGSF_VFEndcap_[3] = elecVars.gsfTracklnPt;
0667       var_woGwGSF_VFEndcap_[4] = elecNumHitsDiffOverSum;
0668       var_woGwGSF_VFEndcap_[5] = std::log(std::max(0.1f, elecVars.chi2NormKF));
0669       var_woGwGSF_VFEndcap_[6] = elecVars.eEcal;
0670       var_woGwGSF_VFEndcap_[7] = std::min(2.f, tauVars.leadChargedPFCandPt / std::max(1.f, tauVars.pt));
0671       var_woGwGSF_VFEndcap_[8] = std::log(std::max(1.f, tauVars.pt));
0672       var_woGwGSF_VFEndcap_[9] = tauVars.visMassIn;
0673       var_woGwGSF_VFEndcap_[10] = tauVars.dCrackEta;
0674       var_woGwGSF_VFEndcap_[11] = tauVars.etaAtEcalEntrance;
0675       var_woGwGSF_VFEndcap_[12] = tauVars.leadChargedPFCandEtaAtEcalEntrance;
0676       var_woGwGSF_VFEndcap_[13] = elecVars.hgcalSigmaUU;
0677       var_woGwGSF_VFEndcap_[14] = elecVars.hgcalSigmaVV;
0678       var_woGwGSF_VFEndcap_[15] = elecVars.hgcalSigmaEE;
0679       var_woGwGSF_VFEndcap_[16] = elecVars.hgcalSigmaPP;
0680       var_woGwGSF_VFEndcap_[17] = elecVars.hgcalNLayers;
0681       var_woGwGSF_VFEndcap_[18] = elecVars.hgcalLastLayer;
0682       var_woGwGSF_VFEndcap_[19] = elecVars.hgcalLayerEfrac10;
0683       var_woGwGSF_VFEndcap_[20] = elecVars.hgcalLayerEfrac90;
0684       var_woGwGSF_VFEndcap_[21] = elecVars.hgcalEcEnergyEE;
0685       var_woGwGSF_VFEndcap_[22] = elecVars.hgcalEcEnergyFH;
0686       var_woGwGSF_VFEndcap_[23] = elecVars.hgcalMeasuredDepth;
0687       var_woGwGSF_VFEndcap_[24] = elecVars.hgcalExpectedDepth;
0688       var_woGwGSF_VFEndcap_[25] = elecVars.hgcalExpectedSigma;
0689       var_woGwGSF_VFEndcap_[26] = elecVars.hgcalDepthCompatibility;
0690       var_woGwGSF_VFEndcap_[27] = elecVars.deltaEta;
0691       var_woGwGSF_VFEndcap_[28] = elecVars.deltaPhi;
0692       var_woGwGSF_VFEndcap_[29] = elecVars.eSeedClusterOverPout;
0693       var_woGwGSF_VFEndcap_[30] = elecVars.superClusterEtaWidth;
0694       var_woGwGSF_VFEndcap_[31] = elecVars.superClusterPhiWidth;
0695       mvaValue = mva_woGwGSF_VFEC_->GetClassifier(var_woGwGSF_VFEndcap_.data());
0696     }
0697   } else if (tauGammaMoms.signalPFGammaCandsIn > 0 && tauVars.hasGsf > 0.5) {
0698     if (std::abs(tauVars.etaAtEcalEntrance) < ecalBarrelEndcapEtaBorder_) {
0699       var_wGwGSF_Barrel_[0] = std::log(std::max(0.1f, elecVars.chi2NormGSF));
0700       var_wGwGSF_Barrel_[1] = elecVars.gsfNumHits;
0701       var_wGwGSF_Barrel_[2] = std::log(std::max(0.1f, elecVars.gsfTrackResol));
0702       var_wGwGSF_Barrel_[3] = elecVars.gsfTracklnPt;
0703       var_wGwGSF_Barrel_[4] = elecNumHitsDiffOverSum;
0704       var_wGwGSF_Barrel_[5] = std::log(std::max(0.1f, elecVars.chi2NormKF));
0705       var_wGwGSF_Barrel_[6] = std::min(elecDeltaPinPoutOverPin, 1.f);
0706       var_wGwGSF_Barrel_[7] = std::min(elecEecalOverPout, 20.f);
0707       var_wGwGSF_Barrel_[8] = std::min(elecVars.mvaInSigmaEtaEta, 0.01f);
0708       var_wGwGSF_Barrel_[9] = std::min(elecVars.mvaInHadEnergy, 20.f);
0709       var_wGwGSF_Barrel_[10] = std::min(elecVars.mvaInDeltaEta, 0.1f);
0710       var_wGwGSF_Barrel_[11] = std::min(2.f, tauVars.leadChargedPFCandPt / std::max(1.f, tauVars.pt));
0711       var_wGwGSF_Barrel_[12] = std::log(std::max(1.f, tauVars.pt));
0712       var_wGwGSF_Barrel_[13] = tauVars.emFraction;
0713       var_wGwGSF_Barrel_[14] = tauGammaMoms.signalPFGammaCandsIn;
0714       var_wGwGSF_Barrel_[15] = tauGammaMoms.signalPFGammaCandsOut;
0715       var_wGwGSF_Barrel_[16] = tauVars.leadPFChargedHadrHoP;
0716       var_wGwGSF_Barrel_[17] = tauVars.leadPFChargedHadrEoP;
0717       var_wGwGSF_Barrel_[18] = tauVars.visMassIn;
0718       var_wGwGSF_Barrel_[19] = tauGammaMoms.gammaEtaMomIn;
0719       var_wGwGSF_Barrel_[20] = tauGammaMoms.gammaEtaMomOut;
0720       var_wGwGSF_Barrel_[21] = tauGammaMoms.gammaPhiMomIn;
0721       var_wGwGSF_Barrel_[22] = tauGammaMoms.gammaPhiMomOut;
0722       var_wGwGSF_Barrel_[23] = tauGammaMoms.gammaEnFracIn;
0723       var_wGwGSF_Barrel_[24] = tauGammaMoms.gammaEnFracOut;
0724       var_wGwGSF_Barrel_[25] = tauVars.dCrackEta;
0725       var_wGwGSF_Barrel_[26] = tauVars.etaAtEcalEntrance;
0726       var_wGwGSF_Barrel_[27] = tauVars.leadChargedPFCandEtaAtEcalEntrance;
0727       var_wGwGSF_Barrel_[28] = elecVars.deltaEta;
0728       var_wGwGSF_Barrel_[29] = elecVars.deltaPhi;
0729       var_wGwGSF_Barrel_[30] = elecVars.sigmaIPhiIPhi5x5;
0730       var_wGwGSF_Barrel_[31] = elecVars.sigmaIEtaIEta5x5;
0731       var_wGwGSF_Barrel_[32] = elecVars.showerCircularity;
0732       var_wGwGSF_Barrel_[33] = elecVars.eSeedClusterOverPout;
0733       var_wGwGSF_Barrel_[34] = elecVars.superClusterEtaWidth;
0734       var_wGwGSF_Barrel_[35] = elecVars.superClusterPhiWidth;
0735       mvaValue = mva_wGwGSF_BL_->GetClassifier(var_wGwGSF_Barrel_.data());
0736     } else if (std::abs(tauVars.etaAtEcalEntrance) < ecalEndcapVFEndcapEtaBorder_) {
0737       var_wGwGSF_Endcap_[0] = std::log(std::max(0.1f, elecVars.chi2NormGSF));
0738       var_wGwGSF_Endcap_[1] = elecVars.gsfNumHits;
0739       var_wGwGSF_Endcap_[2] = std::log(std::max(0.1f, elecVars.gsfTrackResol));
0740       var_wGwGSF_Endcap_[3] = elecVars.gsfTracklnPt;
0741       var_wGwGSF_Endcap_[4] = elecNumHitsDiffOverSum;
0742       var_wGwGSF_Endcap_[5] = std::log(std::max(0.1f, elecVars.chi2NormKF));
0743       var_wGwGSF_Endcap_[6] = elecVars.eEcal;
0744       var_wGwGSF_Endcap_[7] = std::min(2.f, tauVars.leadChargedPFCandPt / std::max(1.f, tauVars.pt));
0745       var_wGwGSF_Endcap_[8] = std::log(std::max(1.f, tauVars.pt));
0746       var_wGwGSF_Endcap_[9] = tauGammaMoms.signalPFGammaCandsIn;
0747       var_wGwGSF_Endcap_[10] = tauGammaMoms.signalPFGammaCandsOut;
0748       var_wGwGSF_Endcap_[11] = tauVars.visMassIn;
0749       var_wGwGSF_Endcap_[12] = tauGammaMoms.gammaEtaMomIn;
0750       var_wGwGSF_Endcap_[13] = tauGammaMoms.gammaEtaMomOut;
0751       var_wGwGSF_Endcap_[14] = tauGammaMoms.gammaPhiMomIn;
0752       var_wGwGSF_Endcap_[15] = tauGammaMoms.gammaPhiMomOut;
0753       var_wGwGSF_Endcap_[16] = tauGammaMoms.gammaEnFracIn;
0754       var_wGwGSF_Endcap_[17] = tauGammaMoms.gammaEnFracOut;
0755       var_wGwGSF_Endcap_[18] = tauVars.dCrackEta;
0756       var_wGwGSF_Endcap_[19] = tauVars.etaAtEcalEntrance;
0757       var_wGwGSF_Endcap_[20] = tauVars.leadChargedPFCandEtaAtEcalEntrance;
0758       var_wGwGSF_Endcap_[21] = elecVars.hgcalSigmaVV;
0759       var_wGwGSF_Endcap_[22] = elecVars.hgcalSigmaEE;
0760       var_wGwGSF_Endcap_[23] = elecVars.hgcalSigmaPP;
0761       var_wGwGSF_Endcap_[24] = elecVars.hgcalNLayers;
0762       var_wGwGSF_Endcap_[25] = elecVars.hgcalFirstLayer;
0763       var_wGwGSF_Endcap_[26] = elecVars.hgcalLastLayer;
0764       var_wGwGSF_Endcap_[27] = elecVars.hgcalLayerEfrac10;
0765       var_wGwGSF_Endcap_[28] = elecVars.hgcalLayerEfrac90;
0766       var_wGwGSF_Endcap_[29] = elecVars.hgcalEcEnergyEE;
0767       var_wGwGSF_Endcap_[30] = elecVars.hgcalEcEnergyFH;
0768       var_wGwGSF_Endcap_[31] = elecVars.hgcalMeasuredDepth;
0769       var_wGwGSF_Endcap_[32] = elecVars.hgcalExpectedDepth;
0770       var_wGwGSF_Endcap_[33] = elecVars.deltaEta;
0771       var_wGwGSF_Endcap_[34] = elecVars.deltaPhi;
0772       var_wGwGSF_Endcap_[35] = elecVars.eSeedClusterOverPout;
0773       var_wGwGSF_Endcap_[36] = elecVars.superClusterEtaWidth;
0774       var_wGwGSF_Endcap_[37] = elecVars.superClusterPhiWidth;
0775       mvaValue = mva_wGwGSF_EC_->GetClassifier(var_wGwGSF_Endcap_.data());
0776     } else {
0777       var_wGwGSF_VFEndcap_[0] = std::log(std::max(0.1f, elecVars.chi2NormGSF));
0778       var_wGwGSF_VFEndcap_[1] = elecVars.gsfNumHits;
0779       var_wGwGSF_VFEndcap_[2] = std::log(std::max(0.1f, elecVars.gsfTrackResol));
0780       var_wGwGSF_VFEndcap_[3] = elecVars.gsfTracklnPt;
0781       var_wGwGSF_VFEndcap_[4] = elecNumHitsDiffOverSum;
0782       var_wGwGSF_VFEndcap_[5] = std::log(std::max(0.1f, elecVars.chi2NormKF));
0783       var_wGwGSF_VFEndcap_[6] = elecVars.eEcal;
0784       var_wGwGSF_VFEndcap_[7] = std::min(2.f, tauVars.leadChargedPFCandPt / std::max(1.f, tauVars.pt));
0785       var_wGwGSF_VFEndcap_[8] = std::log(std::max(1.f, tauVars.pt));
0786       var_wGwGSF_VFEndcap_[9] = tauGammaMoms.signalPFGammaCandsIn;
0787       var_wGwGSF_VFEndcap_[10] = tauGammaMoms.signalPFGammaCandsOut;
0788       var_wGwGSF_VFEndcap_[11] = tauVars.visMassIn;
0789       var_wGwGSF_VFEndcap_[12] = tauGammaMoms.gammaEtaMomIn;
0790       var_wGwGSF_VFEndcap_[13] = tauGammaMoms.gammaEtaMomOut;
0791       var_wGwGSF_VFEndcap_[14] = tauGammaMoms.gammaPhiMomIn;
0792       var_wGwGSF_VFEndcap_[15] = tauGammaMoms.gammaPhiMomOut;
0793       var_wGwGSF_VFEndcap_[16] = tauGammaMoms.gammaEnFracIn;
0794       var_wGwGSF_VFEndcap_[17] = tauGammaMoms.gammaEnFracOut;
0795       var_wGwGSF_VFEndcap_[18] = tauVars.dCrackEta;
0796       var_wGwGSF_VFEndcap_[19] = tauVars.etaAtEcalEntrance;
0797       var_wGwGSF_VFEndcap_[20] = tauVars.leadChargedPFCandEtaAtEcalEntrance;
0798       var_wGwGSF_VFEndcap_[21] = elecVars.hgcalSigmaUU;
0799       var_wGwGSF_VFEndcap_[22] = elecVars.hgcalSigmaVV;
0800       var_wGwGSF_VFEndcap_[23] = elecVars.hgcalSigmaEE;
0801       var_wGwGSF_VFEndcap_[24] = elecVars.hgcalSigmaPP;
0802       var_wGwGSF_VFEndcap_[25] = elecVars.hgcalNLayers;
0803       var_wGwGSF_VFEndcap_[26] = elecVars.hgcalLastLayer;
0804       var_wGwGSF_VFEndcap_[27] = elecVars.hgcalLayerEfrac10;
0805       var_wGwGSF_VFEndcap_[28] = elecVars.hgcalLayerEfrac90;
0806       var_wGwGSF_VFEndcap_[29] = elecVars.hgcalEcEnergyEE;
0807       var_wGwGSF_VFEndcap_[30] = elecVars.hgcalEcEnergyFH;
0808       var_wGwGSF_VFEndcap_[31] = elecVars.hgcalMeasuredDepth;
0809       var_wGwGSF_VFEndcap_[32] = elecVars.hgcalExpectedDepth;
0810       var_wGwGSF_VFEndcap_[33] = elecVars.hgcalExpectedSigma;
0811       var_wGwGSF_VFEndcap_[34] = elecVars.hgcalDepthCompatibility;
0812       var_wGwGSF_VFEndcap_[35] = elecVars.deltaEta;
0813       var_wGwGSF_VFEndcap_[36] = elecVars.deltaPhi;
0814       var_wGwGSF_VFEndcap_[37] = elecVars.eSeedClusterOverPout;
0815       var_wGwGSF_VFEndcap_[38] = elecVars.superClusterEtaWidth;
0816       var_wGwGSF_VFEndcap_[39] = elecVars.superClusterPhiWidth;
0817       mvaValue = mva_wGwGSF_VFEC_->GetClassifier(var_wGwGSF_VFEndcap_.data());
0818     }
0819   }
0820   return mvaValue;
0821 }
0822 ////
0823 template <class TauType, class ElectronType>
0824 double AntiElectronIDMVA6<TauType, ElectronType>::mvaValue(const TauType& theTau, const ElectronRef& theEleRef)
0825 
0826 {
0827   // === tau variables ===
0828   TauVars tauVars = AntiElectronIDMVA6<TauType, ElectronType>::getTauVars(theTau);
0829   TauGammaVecs tauGammaVecs = AntiElectronIDMVA6<TauType, ElectronType>::getTauGammaVecs(theTau);
0830 
0831   // === electron variables ===
0832   ElecVars elecVars = AntiElectronIDMVA6<TauType, ElectronType>::getElecVars(theEleRef);
0833 
0834   return mvaValue(tauVars, tauGammaVecs, elecVars);
0835 }
0836 
0837 template <class TauType, class ElectronType>
0838 double AntiElectronIDMVA6<TauType, ElectronType>::mvaValue(const TauType& theTau) {
0839   // === tau variables ===
0840   TauVars tauVars = AntiElectronIDMVA6<TauType, ElectronType>::getTauVars(theTau);
0841   TauGammaVecs tauGammaVecs = AntiElectronIDMVA6<TauType, ElectronType>::getTauGammaVecs(theTau);
0842 
0843   // === electron variables ===
0844   ElecVars elecVars;
0845   elecVars.eta = 9.9;  // Dummy value used in MVA training
0846 
0847   return mvaValue(tauVars, tauGammaVecs, elecVars);
0848 }
0849 
0850 template <class TauType, class ElectronType>
0851 TauVars AntiElectronIDMVA6<TauType, ElectronType>::getTauVars(const TauType& theTau) {
0852   TauVars tauVars;
0853   if (std::is_same<TauType, reco::PFTau>::value || std::is_same<TauType, pat::Tau>::value)
0854     tauVars = getTauVarsTypeSpecific(theTau);
0855   else
0856     throw cms::Exception("AntiElectronIDMVA6")
0857         << "Unsupported TauType used. You must use either reco::PFTau or pat::Tau.";
0858 
0859   tauVars.pt = theTau.pt();
0860 
0861   reco::Candidate::LorentzVector pfGammaSum(0, 0, 0, 0);
0862   reco::Candidate::LorentzVector pfChargedSum(0, 0, 0, 0);
0863   float signalrad = std::clamp(3.0 / std::max(1.0, theTau.pt()), 0.05, 0.10);
0864   for (const auto& gamma : theTau.signalGammaCands()) {
0865     float dR = deltaR(gamma->p4(), theTau.leadChargedHadrCand()->p4());
0866     // pfGammas inside the tau signal cone
0867     if (dR < signalrad) {
0868       pfGammaSum += gamma->p4();
0869     }
0870   }
0871   for (const auto& charged : theTau.signalChargedHadrCands()) {
0872     float dR = deltaR(charged->p4(), theTau.leadChargedHadrCand()->p4());
0873     // charged particles inside the tau signal cone
0874     if (dR < signalrad) {
0875       pfChargedSum += charged->p4();
0876     }
0877   }
0878   tauVars.visMassIn = (pfGammaSum + pfChargedSum).mass();
0879 
0880   tauVars.hasGsf = 0;
0881   if (theTau.leadChargedHadrCand().isNonnull()) {
0882     const pat::PackedCandidate* packedLeadChCand =
0883         dynamic_cast<const pat::PackedCandidate*>(theTau.leadChargedHadrCand().get());
0884     if (packedLeadChCand != nullptr) {
0885       if (std::abs(packedLeadChCand->pdgId()) == 11)
0886         tauVars.hasGsf = 1;
0887     } else {
0888       const reco::PFCandidate* pfLeadChCand =
0889           dynamic_cast<const reco::PFCandidate*>(theTau.leadChargedHadrCand().get());
0890       if (pfLeadChCand != nullptr && pfLeadChCand->gsfTrackRef().isNonnull())
0891         tauVars.hasGsf = 1;
0892     }
0893   }
0894   tauVars.dCrackPhi = dCrackPhi(tauVars.phi, tauVars.etaAtEcalEntrance);
0895   tauVars.dCrackEta = dCrackEta(tauVars.etaAtEcalEntrance);
0896 
0897   return tauVars;
0898 }
0899 
0900 template <class TauType, class ElectronType>
0901 TauGammaVecs AntiElectronIDMVA6<TauType, ElectronType>::getTauGammaVecs(const TauType& theTau) {
0902   TauGammaVecs tauGammaVecs;
0903 
0904   float signalrad = std::clamp(3.0 / std::max(1.0, theTau.pt()), 0.05, 0.10);
0905   for (const auto& gamma : theTau.signalGammaCands()) {
0906     float dR = deltaR(gamma->p4(), theTau.leadChargedHadrCand()->p4());
0907     // pfGammas inside the tau signal cone
0908     if (dR < signalrad) {
0909       tauGammaVecs.gammasdEtaInSigCone.push_back(gamma->eta() - theTau.leadChargedHadrCand()->eta());
0910       tauGammaVecs.gammasdPhiInSigCone.push_back(gamma->phi() - theTau.leadChargedHadrCand()->phi());
0911       tauGammaVecs.gammasPtInSigCone.push_back(gamma->pt());
0912     }
0913     // pfGammas outside the tau signal cone
0914     else {
0915       tauGammaVecs.gammasdEtaOutSigCone.push_back(gamma->eta() - theTau.leadChargedHadrCand()->eta());
0916       tauGammaVecs.gammasdPhiOutSigCone.push_back(gamma->phi() - theTau.leadChargedHadrCand()->phi());
0917       tauGammaVecs.gammasPtOutSigCone.push_back(gamma->pt());
0918     }
0919   }
0920   return tauGammaVecs;
0921 }
0922 
0923 template <class TauType, class ElectronType>
0924 ElecVars AntiElectronIDMVA6<TauType, ElectronType>::getElecVars(const ElectronRef& theEleRef) {
0925   ElecVars elecVars;
0926 
0927   elecVars.eta = theEleRef->eta();
0928   elecVars.phi = theEleRef->phi();
0929 
0930   // Variables related to the electron Cluster
0931   float elecEe = 0.;
0932   float elecEgamma = 0.;
0933   reco::SuperClusterRef pfSuperCluster = theEleRef->superCluster();
0934   if (pfSuperCluster.isNonnull() && pfSuperCluster.isAvailable()) {
0935     if (!isPhase2_) {
0936       for (reco::CaloCluster_iterator pfCluster = pfSuperCluster->clustersBegin();
0937            pfCluster != pfSuperCluster->clustersEnd();
0938            ++pfCluster) {
0939         double pfClusterEn = (*pfCluster)->energy();
0940         if (pfCluster == pfSuperCluster->clustersBegin())
0941           elecEe += pfClusterEn;
0942         else
0943           elecEgamma += pfClusterEn;
0944       }
0945     }
0946     elecVars.superClusterEtaWidth = pfSuperCluster->etaWidth();
0947     elecVars.superClusterPhiWidth = pfSuperCluster->phiWidth();
0948   }
0949   elecVars.eSeedClusterOverPout = theEleRef->eSeedClusterOverPout();
0950   elecVars.showerCircularity = 1. - theEleRef->e1x5() / theEleRef->e5x5();
0951   elecVars.r9 = theEleRef->r9();
0952   elecVars.sigmaIEtaIEta5x5 = theEleRef->full5x5_sigmaIetaIeta();
0953   elecVars.sigmaIPhiIPhi5x5 = theEleRef->full5x5_sigmaIphiIphi();
0954 
0955   elecVars.pIn = std::sqrt(theEleRef->trackMomentumAtVtx().Mag2());
0956   elecVars.pOut = std::sqrt(theEleRef->trackMomentumOut().Mag2());
0957   elecVars.eTotOverPin = (elecVars.pIn > 0.0) ? ((elecEe + elecEgamma) / elecVars.pIn) : -0.1;
0958   elecVars.eEcal = theEleRef->ecalEnergy();
0959   if (!isPhase2_) {
0960     elecVars.deltaEta = theEleRef->deltaEtaSeedClusterTrackAtCalo();
0961     elecVars.deltaPhi = theEleRef->deltaPhiSeedClusterTrackAtCalo();
0962   } else {
0963     elecVars.deltaEta = theEleRef->deltaEtaEleClusterTrackAtCalo();
0964     elecVars.deltaPhi = theEleRef->deltaPhiEleClusterTrackAtCalo();
0965   }
0966   elecVars.mvaInSigmaEtaEta = theEleRef->mvaInput().sigmaEtaEta;
0967   elecVars.mvaInHadEnergy = theEleRef->mvaInput().hadEnergy;
0968   elecVars.mvaInDeltaEta = theEleRef->mvaInput().deltaEta;
0969 
0970   // Variables related to the GsfTrack
0971   elecVars.chi2NormGSF = -99.;
0972   elecVars.gsfNumHits = -99.;
0973   elecVars.gsfTrackResol = -99.;
0974   elecVars.gsfTracklnPt = -99.;
0975   if (theEleRef->gsfTrack().isNonnull()) {
0976     elecVars.chi2NormGSF = theEleRef->gsfTrack()->normalizedChi2();
0977     elecVars.gsfNumHits = theEleRef->gsfTrack()->numberOfValidHits();
0978     if (theEleRef->gsfTrack()->pt() > 0.) {
0979       elecVars.gsfTrackResol = theEleRef->gsfTrack()->ptError() / theEleRef->gsfTrack()->pt();
0980       elecVars.gsfTracklnPt = log(theEleRef->gsfTrack()->pt()) * M_LN10;
0981     }
0982   }
0983 
0984   // Variables related to the CtfTrack
0985   elecVars.chi2NormKF = -99.;
0986   elecVars.kfNumHits = -99.;
0987   if (theEleRef->closestCtfTrackRef().isNonnull()) {
0988     elecVars.chi2NormKF = theEleRef->closestCtfTrackRef()->normalizedChi2();
0989     elecVars.kfNumHits = theEleRef->closestCtfTrackRef()->numberOfValidHits();
0990   }
0991 
0992   // Variables related to HGCal
0993   if (isPhase2_ && !theEleRef->isEB()) {
0994     if (std::is_same<ElectronType, reco::GsfElectron>::value || std::is_same<ElectronType, pat::Electron>::value)
0995       getElecVarsHGCalTypeSpecific(theEleRef, elecVars);
0996     else
0997       throw cms::Exception("AntiElectronIDMVA6")
0998           << "Unsupported ElectronType used. You must use either reco::GsfElectron or pat::Electron.";
0999   }
1000 
1001   return elecVars;
1002 }
1003 
1004 template <class TauType, class ElectronType>
1005 double AntiElectronIDMVA6<TauType, ElectronType>::minimum(double a, double b) {
1006   if (std::abs(b) < std::abs(a))
1007     return b;
1008   else
1009     return a;
1010 }
1011 
1012 namespace {
1013 
1014   // IN: define locations of the 18 phi-cracks
1015   std::array<double, 18> fill_cPhi() {
1016     constexpr double pi = M_PI;  // 3.14159265358979323846;
1017     std::array<double, 18> cPhi;
1018     // IN: define locations of the 18 phi-cracks
1019     cPhi[0] = 2.97025;
1020     for (unsigned iCrack = 1; iCrack <= 17; ++iCrack) {
1021       cPhi[iCrack] = cPhi[0] - 2. * iCrack * pi / 18;
1022     }
1023     return cPhi;
1024   }
1025 
1026   const std::array<double, 18> cPhi = fill_cPhi();
1027 
1028 }  // namespace
1029 
1030 template <class TauType, class ElectronType>
1031 double AntiElectronIDMVA6<TauType, ElectronType>::dCrackPhi(double phi, double eta) {
1032   //--- compute the (unsigned) distance to the closest phi-crack in the ECAL barrel
1033 
1034   constexpr double pi = M_PI;  // 3.14159265358979323846;
1035 
1036   // IN: shift of this location if eta < 0
1037   constexpr double delta_cPhi = 0.00638;
1038 
1039   double retVal = 99.;
1040 
1041   if (eta >= -1.47464 && eta <= 1.47464) {
1042     // the location is shifted
1043     if (eta < 0.)
1044       phi += delta_cPhi;
1045 
1046     // CV: need to bring-back phi into interval [-pi,+pi]
1047     if (phi > pi)
1048       phi -= 2. * pi;
1049     if (phi < -pi)
1050       phi += 2. * pi;
1051 
1052     if (phi >= -pi && phi <= pi) {
1053       // the problem of the extrema:
1054       if (phi < cPhi[17] || phi >= cPhi[0]) {
1055         if (phi < 0.)
1056           phi += 2. * pi;
1057         retVal = minimum(phi - cPhi[0], phi - cPhi[17] - 2. * pi);
1058       } else {
1059         // between these extrema...
1060         bool OK = false;
1061         unsigned iCrack = 16;
1062         while (!OK) {
1063           if (phi < cPhi[iCrack]) {
1064             retVal = minimum(phi - cPhi[iCrack + 1], phi - cPhi[iCrack]);
1065             OK = true;
1066           } else {
1067             iCrack -= 1;
1068           }
1069         }
1070       }
1071     } else {
1072       retVal = 0.;  // IN: if there is a problem, we assume that we are in a crack
1073     }
1074   } else {
1075     return -99.;
1076   }
1077 
1078   return std::abs(retVal);
1079 }
1080 
1081 template <class TauType, class ElectronType>
1082 double AntiElectronIDMVA6<TauType, ElectronType>::dCrackEta(double eta) {
1083   //--- compute the (unsigned) distance to the closest eta-crack in the ECAL barrel
1084 
1085   // IN: define locations of the eta-cracks
1086   double cracks[5] = {0., 4.44747e-01, 7.92824e-01, 1.14090e+00, 1.47464e+00};
1087 
1088   double retVal = 99.;
1089 
1090   for (int iCrack = 0; iCrack < 5; ++iCrack) {
1091     double d = minimum(eta - cracks[iCrack], eta + cracks[iCrack]);
1092     if (std::abs(d) < std::abs(retVal)) {
1093       retVal = d;
1094     }
1095   }
1096 
1097   return std::abs(retVal);
1098 }
1099 
1100 // pat::Tau
1101 template <class TauType, class ElectronType>
1102 TauVars AntiElectronIDMVA6<TauType, ElectronType>::getTauVarsTypeSpecific(const pat::Tau& theTau) {
1103   TauVars tauVars;
1104   tauVars.etaAtEcalEntrance = theTau.etaAtEcalEntrance();
1105   tauVars.leadChargedPFCandEtaAtEcalEntrance = theTau.etaAtEcalEntranceLeadChargedCand();
1106   tauVars.leadChargedPFCandPt = theTau.ptLeadChargedCand();
1107   tauVars.phi = theTau.phi();
1108   if (!isPhase2_) {
1109     if (!usePhiAtEcalEntranceExtrapolation_) {
1110       tauVars.phi = theTau.phiAtEcalEntrance();
1111     } else {
1112       float etaAtECal = 0.;
1113       float phiAtECal = 0.;
1114       bool success = energyWeightedEtaAndPhiAtECal(theTau, etaAtECal, phiAtECal);
1115       if (success) {
1116         tauVars.phi = phiAtECal;
1117       }
1118     }
1119     tauVars.emFraction = std::max(theTau.emFraction_MVA(), 0.f);
1120   } else {
1121     if (std::abs(theTau.eta()) >= ecalBarrelEndcapEtaBorder_) {  //HGCal
1122       tauVars.etaAtEcalEntrance = -99.;
1123       tauVars.leadChargedPFCandEtaAtEcalEntrance = -99.;
1124       bool success = false;
1125       reco::Candidate::Point posAtECal = positionAtECalEntrance_(theTau.leadChargedHadrCand().get(), success);
1126       if (success) {
1127         tauVars.leadChargedPFCandEtaAtEcalEntrance = posAtECal.eta();
1128       }
1129       float phiAtECal = 0.;
1130       float etaAtECal = 0.;
1131       success = energyWeightedEtaAndPhiAtECal(theTau, etaAtECal, phiAtECal);
1132       if (success) {
1133         tauVars.etaAtEcalEntrance = etaAtECal;
1134       }
1135     }
1136     tauVars.emFraction = std::max(theTau.ecalEnergyLeadChargedHadrCand() /
1137                                       (theTau.ecalEnergyLeadChargedHadrCand() + theTau.hcalEnergyLeadChargedHadrCand()),
1138                                   0.f);
1139   }
1140   tauVars.leadPFChargedHadrHoP = 0.;
1141   tauVars.leadPFChargedHadrEoP = 0.;
1142   if (theTau.leadChargedHadrCand()->p() > 0.) {
1143     tauVars.leadPFChargedHadrHoP = theTau.hcalEnergyLeadChargedHadrCand() / theTau.leadChargedHadrCand()->p();
1144     tauVars.leadPFChargedHadrEoP = theTau.ecalEnergyLeadChargedHadrCand() / theTau.leadChargedHadrCand()->p();
1145   }
1146 
1147   return tauVars;
1148 }
1149 
1150 // reco::PFTau
1151 template <class TauType, class ElectronType>
1152 TauVars AntiElectronIDMVA6<TauType, ElectronType>::getTauVarsTypeSpecific(const reco::PFTau& theTau) {
1153   TauVars tauVars;
1154   tauVars.etaAtEcalEntrance = -99.;
1155   tauVars.leadChargedPFCandEtaAtEcalEntrance = -99.;
1156   tauVars.leadChargedPFCandPt = -99.;
1157   float sumEtaTimesEnergy = 0.;
1158   float sumPhiTimesEnergy = 0.;
1159   float sumEnergy = 0.;
1160   tauVars.phi = theTau.phi();
1161   // Check type of candidates building tau to avoid dynamic casts further
1162   bool isFromPFCands =
1163       (theTau.leadCand().isNonnull() && dynamic_cast<const reco::PFCandidate*>(theTau.leadCand().get()) != nullptr);
1164   if (!isPhase2_) {
1165     for (const auto& candidate : theTau.signalCands()) {
1166       float etaAtECalEntrance = candidate->eta();
1167       float phiAtECalEntrance = candidate->phi();
1168       const reco::Track* track = nullptr;
1169       if (isFromPFCands) {
1170         const reco::PFCandidate* pfCandidate = static_cast<const reco::PFCandidate*>(candidate.get());
1171         etaAtECalEntrance = pfCandidate->positionAtECALEntrance().eta();
1172         if (!usePhiAtEcalEntranceExtrapolation_) {
1173           phiAtECalEntrance = pfCandidate->positionAtECALEntrance().phi();
1174         } else {
1175           bool success = false;
1176           reco::Candidate::Point posAtECal = positionAtECalEntrance_(candidate.get(), success);
1177           if (success) {
1178             phiAtECalEntrance = posAtECal.phi();
1179           }
1180         }
1181         track = getTrackFromPFCand(pfCandidate);
1182       } else {
1183         bool success = false;
1184         reco::Candidate::Point posAtECal = positionAtECalEntrance_(candidate.get(), success);
1185         if (success) {
1186           etaAtECalEntrance = posAtECal.eta();
1187           phiAtECalEntrance = posAtECal.phi();
1188         }
1189         track = candidate->bestTrack();
1190       }
1191       if (track != nullptr) {
1192         if (track->pt() > tauVars.leadChargedPFCandPt) {
1193           tauVars.leadChargedPFCandEtaAtEcalEntrance = etaAtECalEntrance;
1194           tauVars.leadChargedPFCandPt = track->pt();
1195         }
1196       }
1197       sumEtaTimesEnergy += etaAtECalEntrance * candidate->energy();
1198       sumPhiTimesEnergy += phiAtECalEntrance * candidate->energy();
1199       sumEnergy += candidate->energy();
1200     }
1201     if (sumEnergy > 0.) {
1202       tauVars.etaAtEcalEntrance = sumEtaTimesEnergy / sumEnergy;
1203       tauVars.phi = sumPhiTimesEnergy / sumEnergy;
1204     }
1205     tauVars.emFraction = std::max(theTau.emFraction(), 0.f);
1206   } else {  // Phase2
1207     for (const auto& candidate : theTau.signalCands()) {
1208       float etaAtECalEntrance = candidate->eta();
1209       const reco::Track* track = nullptr;
1210       if (isFromPFCands) {
1211         const reco::PFCandidate* pfCandidate = static_cast<const reco::PFCandidate*>(candidate.get());
1212         etaAtECalEntrance = pfCandidate->positionAtECALEntrance().eta();
1213         if (std::abs(theTau.eta()) >= ecalBarrelEndcapEtaBorder_) {  //HGCal
1214           bool success = false;
1215           reco::Candidate::Point posAtECal = positionAtECalEntrance_(candidate.get(), success);
1216           if (success) {
1217             etaAtECalEntrance = posAtECal.eta();
1218           }
1219         }
1220         track = getTrackFromPFCand(pfCandidate);
1221       } else {
1222         bool success = false;
1223         reco::Candidate::Point posAtECal = positionAtECalEntrance_(candidate.get(), success);
1224         if (success) {
1225           etaAtECalEntrance = posAtECal.eta();
1226         }
1227         track = candidate->bestTrack();
1228       }
1229       if (track != nullptr) {
1230         if (track->pt() > tauVars.leadChargedPFCandPt) {
1231           tauVars.leadChargedPFCandEtaAtEcalEntrance = etaAtECalEntrance;
1232           tauVars.leadChargedPFCandPt = track->pt();
1233         }
1234       }
1235       sumEtaTimesEnergy += etaAtECalEntrance * candidate->energy();
1236       sumEnergy += candidate->energy();
1237     }
1238     if (sumEnergy > 0.) {
1239       tauVars.etaAtEcalEntrance = sumEtaTimesEnergy / sumEnergy;
1240     }
1241     if (isFromPFCands) {
1242       const reco::PFCandidate* pfLeadCandidte =
1243           static_cast<const reco::PFCandidate*>(theTau.leadChargedHadrCand().get());
1244       tauVars.emFraction =
1245           std::max(pfLeadCandidte->ecalEnergy() / (pfLeadCandidte->ecalEnergy() + pfLeadCandidte->hcalEnergy()), 0.);
1246     } else {
1247       const pat::PackedCandidate* patLeadCandiate =
1248           dynamic_cast<const pat::PackedCandidate*>(theTau.leadChargedHadrCand().get());
1249       if (patLeadCandiate != nullptr) {
1250         tauVars.emFraction = std::max(1. - patLeadCandiate->hcalFraction(), 0.);
1251       }
1252     }
1253   }
1254   tauVars.leadPFChargedHadrHoP = 0.;
1255   tauVars.leadPFChargedHadrEoP = 0.;
1256   if (theTau.leadChargedHadrCand()->p() > 0.) {
1257     if (isFromPFCands) {
1258       const reco::PFCandidate* pfLeadCandiate =
1259           static_cast<const reco::PFCandidate*>(theTau.leadChargedHadrCand().get());
1260       tauVars.leadPFChargedHadrHoP = pfLeadCandiate->hcalEnergy() / pfLeadCandiate->p();
1261       tauVars.leadPFChargedHadrEoP = pfLeadCandiate->ecalEnergy() / pfLeadCandiate->p();
1262     } else {
1263       const pat::PackedCandidate* patLeadCandiate =
1264           dynamic_cast<const pat::PackedCandidate*>(theTau.leadChargedHadrCand().get());
1265       if (patLeadCandiate != nullptr) {
1266         tauVars.leadPFChargedHadrHoP = patLeadCandiate->caloFraction() * patLeadCandiate->energy() *
1267                                        patLeadCandiate->hcalFraction() / patLeadCandiate->p();
1268         tauVars.leadPFChargedHadrEoP = patLeadCandiate->caloFraction() * patLeadCandiate->energy() *
1269                                        (1. - patLeadCandiate->hcalFraction()) / patLeadCandiate->p();
1270       }
1271     }
1272   }
1273 
1274   return tauVars;
1275 }
1276 
1277 // reco::GsfElectron
1278 template <class TauType, class ElectronType>
1279 void AntiElectronIDMVA6<TauType, ElectronType>::getElecVarsHGCalTypeSpecific(
1280     const reco::GsfElectronRef& theEleRef, antiElecIDMVA6_blocks::ElecVars& elecVars) {
1281   //MB: Assumed that presence of one of the HGCal EleID variables guarantee presence of all
1282   if (!(electronIds_.find("hgcElectronID:sigmaUU") != electronIds_.end() &&
1283         electronIds_.at("hgcElectronID:sigmaUU").isValid()))
1284     return;
1285 
1286   elecVars.hgcalSigmaUU = (*electronIds_.at("hgcElectronID:sigmaUU"))[theEleRef];
1287   elecVars.hgcalSigmaVV = (*electronIds_.at("hgcElectronID:sigmaVV"))[theEleRef];
1288   elecVars.hgcalSigmaEE = (*electronIds_.at("hgcElectronID:sigmaEE"))[theEleRef];
1289   elecVars.hgcalSigmaPP = (*electronIds_.at("hgcElectronID:sigmaPP"))[theEleRef];
1290   elecVars.hgcalNLayers = (*electronIds_.at("hgcElectronID:nLayers"))[theEleRef];
1291   elecVars.hgcalFirstLayer = (*electronIds_.at("hgcElectronID:firstLayer"))[theEleRef];
1292   elecVars.hgcalLastLayer = (*electronIds_.at("hgcElectronID:lastLayer"))[theEleRef];
1293   elecVars.hgcalLayerEfrac10 = (*electronIds_.at("hgcElectronID:layerEfrac10"))[theEleRef];
1294   elecVars.hgcalLayerEfrac90 = (*electronIds_.at("hgcElectronID:layerEfrac90"))[theEleRef];
1295   elecVars.hgcalEcEnergyEE = (*electronIds_.at("hgcElectronID:ecEnergyEE"))[theEleRef];
1296   elecVars.hgcalEcEnergyFH = (*electronIds_.at("hgcElectronID:ecEnergyFH"))[theEleRef];
1297   elecVars.hgcalMeasuredDepth = (*electronIds_.at("hgcElectronID:measuredDepth"))[theEleRef];
1298   elecVars.hgcalExpectedDepth = (*electronIds_.at("hgcElectronID:expectedDepth"))[theEleRef];
1299   elecVars.hgcalExpectedSigma = (*electronIds_.at("hgcElectronID:expectedSigma"))[theEleRef];
1300   elecVars.hgcalDepthCompatibility = (*electronIds_.at("hgcElectronID:depthCompatibility"))[theEleRef];
1301 }
1302 
1303 // pat::Electron
1304 template <class TauType, class ElectronType>
1305 void AntiElectronIDMVA6<TauType, ElectronType>::getElecVarsHGCalTypeSpecific(
1306     const pat::ElectronRef& theEleRef, antiElecIDMVA6_blocks::ElecVars& elecVars) {
1307   //MB: Assumed that presence of one of the HGCal EleID variables guarantee presence of all
1308   if (!theEleRef->hasUserFloat("hgcElectronID:sigmaUU"))
1309     return;
1310 
1311   elecVars.hgcalSigmaUU = theEleRef->userFloat("hgcElectronID:sigmaUU");
1312   elecVars.hgcalSigmaVV = theEleRef->userFloat("hgcElectronID:sigmaVV");
1313   elecVars.hgcalSigmaEE = theEleRef->userFloat("hgcElectronID:sigmaEE");
1314   elecVars.hgcalSigmaPP = theEleRef->userFloat("hgcElectronID:sigmaPP");
1315   elecVars.hgcalNLayers = theEleRef->userFloat("hgcElectronID:nLayers");
1316   elecVars.hgcalFirstLayer = theEleRef->userFloat("hgcElectronID:firstLayer");
1317   elecVars.hgcalLastLayer = theEleRef->userFloat("hgcElectronID:lastLayer");
1318   elecVars.hgcalLayerEfrac10 = theEleRef->userFloat("hgcElectronID:layerEfrac10");
1319   elecVars.hgcalLayerEfrac90 = theEleRef->userFloat("hgcElectronID:layerEfrac90");
1320   elecVars.hgcalEcEnergyEE = theEleRef->userFloat("hgcElectronID:ecEnergyEE");
1321   elecVars.hgcalEcEnergyFH = theEleRef->userFloat("hgcElectronID:ecEnergyFH");
1322   elecVars.hgcalMeasuredDepth = theEleRef->userFloat("hgcElectronID:measuredDepth");
1323   elecVars.hgcalExpectedDepth = theEleRef->userFloat("hgcElectronID:expectedDepth");
1324   elecVars.hgcalExpectedSigma = theEleRef->userFloat("hgcElectronID:expectedSigma");
1325   elecVars.hgcalDepthCompatibility = theEleRef->userFloat("hgcElectronID:depthCompatibility");
1326 }
1327 
1328 template <class TauType, class ElectronType>
1329 bool AntiElectronIDMVA6<TauType, ElectronType>::energyWeightedEtaAndPhiAtECal(const pat::Tau& theTau,
1330                                                                               float& eta,
1331                                                                               float& phi) {
1332   eta = 0.;
1333   phi = 0.;
1334   float sumEnergy = 0.;
1335   for (const auto& candidate : theTau.signalCands()) {
1336     float etaAtECalEntrance = candidate->eta();
1337     float phiAtECalEntrance = candidate->phi();
1338     bool success = false;
1339     reco::Candidate::Point posAtECal = positionAtECalEntrance_(candidate.get(), success);
1340     if (success) {
1341       etaAtECalEntrance = posAtECal.eta();
1342       phiAtECalEntrance = posAtECal.phi();
1343     }
1344     eta += etaAtECalEntrance * candidate->energy();
1345     phi += phiAtECalEntrance * candidate->energy();
1346     sumEnergy += candidate->energy();
1347   }
1348   if (sumEnergy > 0.) {
1349     eta = eta / sumEnergy;
1350     phi = phi / sumEnergy;
1351   } else {
1352     eta = -99.;
1353     phi = -99.;
1354   }
1355   return (sumEnergy > 0.);
1356 }
1357 
1358 // compile desired types and make available to linker
1359 template class AntiElectronIDMVA6<reco::PFTau, reco::GsfElectron>;
1360 template class AntiElectronIDMVA6<pat::Tau, pat::Electron>;