File indexing completed on 2024-04-06 12:25:08
0001 #include "RecoEgamma/ElectronIdentification/interface/SoftElectronMVAEstimator.h"
0002 #include "DataFormats/TrackReco/interface/Track.h"
0003 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0004 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
0005 #include "DataFormats/GsfTrackReco/interface/GsfTrackFwd.h"
0006 #include "CommonTools/MVAUtils/interface/GBRForestTools.h"
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008
0009 SoftElectronMVAEstimator::SoftElectronMVAEstimator(const Configuration& cfg) : cfg_(cfg) {
0010
0011 if (ExpectedNBins != cfg_.vweightsfiles.size()) {
0012 edm::LogError("Soft Electron MVA Error")
0013 << "Expected Number of bins = " << ExpectedNBins
0014 << " does not equal to weightsfiles.size() = " << cfg_.vweightsfiles.size() << std::endl;
0015 }
0016
0017 for (auto& weightsfile : cfg_.vweightsfiles) {
0018
0019
0020 gbr_.push_back(createGBRForest(weightsfile));
0021 }
0022 }
0023
0024 SoftElectronMVAEstimator::~SoftElectronMVAEstimator() {}
0025
0026 double SoftElectronMVAEstimator::mva(const reco::GsfElectron& myElectron, const reco::VertexCollection& pvc) const {
0027 float vars[25];
0028
0029 vars[0] = myElectron.fbrem();
0030 vars[1] = myElectron.eSuperClusterOverP();
0031 vars[2] = myElectron.eEleClusterOverPout();
0032
0033 float etot = myElectron.eSuperClusterOverP() * myElectron.trackMomentumAtVtx().R();
0034 float eEcal = myElectron.eEleClusterOverPout() * myElectron.trackMomentumAtEleClus().R();
0035 float dP = myElectron.trackMomentumAtVtx().R() - myElectron.trackMomentumAtEleClus().R();
0036 vars[3] = (etot - eEcal) / dP;
0037 vars[4] = std::log(myElectron.sigmaEtaEta());
0038 vars[5] = myElectron.deltaEtaEleClusterTrackAtCalo();
0039 vars[6] = myElectron.hcalOverEcalBc();
0040
0041 bool validKF = false;
0042 reco::TrackRef myTrackRef = myElectron.closestCtfTrackRef();
0043 validKF = (myTrackRef.isAvailable() && myTrackRef.isNonnull());
0044 vars[7] = myElectron.gsfTrack()->normalizedChi2();
0045 vars[8] = (validKF) ? myTrackRef->normalizedChi2() : 0;
0046 vars[9] = (validKF) ? myTrackRef->hitPattern().trackerLayersWithMeasurement() : -1.;
0047
0048 vars[10] = myElectron.gsfTrack().get()->ptModeError() / myElectron.gsfTrack().get()->ptMode();
0049 vars[11] = myElectron.deltaEtaSuperClusterTrackAtVtx();
0050 vars[12] = myElectron.deltaPhiSuperClusterTrackAtVtx();
0051 vars[13] = myElectron.deltaEtaSeedClusterTrackAtCalo();
0052 vars[14] = myElectron.sigmaIetaIeta();
0053 vars[15] = myElectron.sigmaIphiIphi();
0054 vars[16] = myElectron.r9();
0055 vars[17] = myElectron.superCluster()->etaWidth();
0056 vars[18] = myElectron.superCluster()->phiWidth();
0057 vars[19] = (myElectron.e5x5()) != 0. ? 1. - (myElectron.e1x5() / myElectron.e5x5()) : -1.;
0058 vars[20] = (1.0 / myElectron.ecalEnergy()) - (1.0 / myElectron.p());
0059 vars[21] = myElectron.superCluster()->preshowerEnergy() / myElectron.superCluster()->rawEnergy();
0060 vars[22] = pvc.size();
0061 vars[23] = myElectron.pt();
0062 vars[24] = myElectron.eta();
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088 bindVariables(vars);
0089
0090 double result = gbr_[0]->GetClassifier(vars);
0091
0092 return result;
0093 }
0094
0095 void SoftElectronMVAEstimator::bindVariables(float vars[25]) const {
0096 if (vars[0] < -1.)
0097 vars[0] = -1.;
0098
0099 vars[11] = std::abs(vars[11]);
0100 if (vars[11] > 0.06)
0101 vars[11] = 0.06;
0102
0103 vars[12] = std::abs(vars[12]);
0104 if (vars[12] > 0.6)
0105 vars[12] = 0.6;
0106
0107
0108
0109
0110 if (vars[2] > 20.)
0111 vars[2] = 20.;
0112
0113 vars[13] = std::abs(vars[13]);
0114 if (vars[13] > 0.2)
0115 vars[13] = 0.2;
0116
0117 if (vars[19] < -1.)
0118 vars[19] = -1;
0119
0120 if (vars[19] > 2.)
0121 vars[19] = 2.;
0122
0123 if (vars[7] > 200.)
0124 vars[7] = 200;
0125
0126 if (vars[8] > 10.)
0127 vars[8] = 10.;
0128 }