File indexing completed on 2024-04-06 12:27:45
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef RECOTAUTAG_RECOTAU_AntiElectronIDMVA6_H
0011 #define RECOTAUTAG_RECOTAU_AntiElectronIDMVA6_H
0012
0013 #include "FWCore/Framework/interface/Event.h"
0014 #include "FWCore/Framework/interface/EventSetup.h"
0015 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0016 #include "FWCore/Framework/interface/ConsumesCollector.h"
0017 #include "FWCore/ParameterSet/interface/FileInPath.h"
0018
0019 #include "DataFormats/TauReco/interface/PFTau.h"
0020 #include "DataFormats/TrackReco/interface/Track.h"
0021 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0022 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
0023 #include "DataFormats/GsfTrackReco/interface/GsfTrackFwd.h"
0024 #include "CondFormats/GBRForest/interface/GBRForest.h"
0025 #include "DataFormats/PatCandidates/interface/Tau.h"
0026 #include "DataFormats/PatCandidates/interface/Electron.h"
0027 #include "DataFormats/PatCandidates/interface/PackedCandidate.h"
0028 #include "RecoTauTag/RecoTau/interface/PositionAtECalEntranceComputer.h"
0029
0030 #include "TMVA/Tools.h"
0031 #include "TMVA/Reader.h"
0032
0033 #include "DataFormats/Math/interface/deltaR.h"
0034
0035 #include <vector>
0036
0037 class GBRWrapperRcd;
0038
0039 namespace antiElecIDMVA6_blocks {
0040 struct TauVars {
0041 float pt = 0;
0042 float etaAtEcalEntrance = 0;
0043 float phi = 0;
0044 float leadChargedPFCandPt = 0;
0045 float leadChargedPFCandEtaAtEcalEntrance = 0;
0046 float emFraction = 0;
0047 float leadPFChargedHadrHoP = 0;
0048 float leadPFChargedHadrEoP = 0;
0049 float visMassIn = 0;
0050 float dCrackEta = 0;
0051 float dCrackPhi = 0;
0052 float hasGsf = 0;
0053 };
0054 struct TauGammaVecs {
0055 std::vector<float> gammasdEtaInSigCone;
0056 std::vector<float> gammasdPhiInSigCone;
0057 std::vector<float> gammasPtInSigCone;
0058 std::vector<float> gammasdEtaOutSigCone;
0059 std::vector<float> gammasdPhiOutSigCone;
0060 std::vector<float> gammasPtOutSigCone;
0061 };
0062 struct TauGammaMoms {
0063 int signalPFGammaCandsIn = 0;
0064 int signalPFGammaCandsOut = 0;
0065 float gammaEtaMomIn = 0;
0066 float gammaEtaMomOut = 0;
0067 float gammaPhiMomIn = 0;
0068 float gammaPhiMomOut = 0;
0069 float gammaEnFracIn = 0;
0070 float gammaEnFracOut = 0;
0071 };
0072 struct ElecVars {
0073 float eta = 0;
0074 float phi = 0;
0075 float eTotOverPin = 0;
0076 float chi2NormGSF = 0;
0077 float chi2NormKF = 0;
0078 float gsfNumHits = 0;
0079 float kfNumHits = 0;
0080 float gsfTrackResol = 0;
0081 float gsfTracklnPt = 0;
0082 float pIn = 0;
0083 float pOut = 0;
0084 float eEcal = 0;
0085 float deltaEta = 0;
0086 float deltaPhi = 0;
0087 float mvaInSigmaEtaEta = 0;
0088 float mvaInHadEnergy = 0;
0089 float mvaInDeltaEta = 0;
0090 float eSeedClusterOverPout = 0;
0091 float superClusterEtaWidth = 0;
0092 float superClusterPhiWidth = 0;
0093 float sigmaIEtaIEta5x5 = 0;
0094 float sigmaIPhiIPhi5x5 = 0;
0095 float showerCircularity = 0;
0096 float r9 = 0;
0097 float hgcalSigmaUU = 0;
0098 float hgcalSigmaVV = 0;
0099 float hgcalSigmaEE = 0;
0100 float hgcalSigmaPP = 0;
0101 float hgcalNLayers = 0;
0102 float hgcalFirstLayer = 0;
0103 float hgcalLastLayer = 0;
0104 float hgcalLayerEfrac10 = 0;
0105 float hgcalLayerEfrac90 = 0;
0106 float hgcalEcEnergyEE = 0;
0107 float hgcalEcEnergyFH = 0;
0108 float hgcalMeasuredDepth = 0;
0109 float hgcalExpectedDepth = 0;
0110 float hgcalExpectedSigma = 0;
0111 float hgcalDepthCompatibility = 0;
0112 };
0113 }
0114
0115 template <class TauType, class ElectronType>
0116 class AntiElectronIDMVA6 {
0117 public:
0118 typedef std::vector<ElectronType> ElectronCollection;
0119 typedef edm::Ref<ElectronCollection> ElectronRef;
0120
0121 AntiElectronIDMVA6(const edm::ParameterSet&, edm::ConsumesCollector&&);
0122 ~AntiElectronIDMVA6();
0123
0124 void beginEvent(const edm::Event&, const edm::EventSetup&);
0125
0126 double mvaValue(const antiElecIDMVA6_blocks::TauVars& tauVars,
0127 const antiElecIDMVA6_blocks::TauGammaVecs& tauGammaVecs,
0128 const antiElecIDMVA6_blocks::ElecVars& elecVars);
0129
0130 double mvaValue(const antiElecIDMVA6_blocks::TauVars& tauVars,
0131 const antiElecIDMVA6_blocks::TauGammaMoms& tauGammaMoms,
0132 const antiElecIDMVA6_blocks::ElecVars& elecVars);
0133
0134 double mvaValuePhase2(const antiElecIDMVA6_blocks::TauVars& tauVars,
0135 const antiElecIDMVA6_blocks::TauGammaMoms& tauGammaMoms,
0136 const antiElecIDMVA6_blocks::ElecVars& elecVars);
0137
0138
0139 double mvaValue(const TauType& theTau, const ElectronRef& theEleRef);
0140
0141 double mvaValue(const TauType& theTau);
0142
0143
0144 antiElecIDMVA6_blocks::TauVars getTauVarsTypeSpecific(const reco::PFTau& theTau);
0145 antiElecIDMVA6_blocks::TauVars getTauVarsTypeSpecific(const pat::Tau& theTau);
0146 antiElecIDMVA6_blocks::TauVars getTauVars(const TauType& theTau);
0147 antiElecIDMVA6_blocks::TauGammaVecs getTauGammaVecs(const TauType& theTau);
0148 antiElecIDMVA6_blocks::ElecVars getElecVars(const ElectronRef& theEleRef);
0149
0150 void getElecVarsHGCalTypeSpecific(const reco::GsfElectronRef& theEleRef, antiElecIDMVA6_blocks::ElecVars& elecVars);
0151 void getElecVarsHGCalTypeSpecific(const pat::ElectronRef& theEleRef, antiElecIDMVA6_blocks::ElecVars& elecVars);
0152
0153 private:
0154 double dCrackEta(double eta);
0155 double minimum(double a, double b);
0156 double dCrackPhi(double phi, double eta);
0157 bool energyWeightedEtaAndPhiAtECal(
0158 const pat::Tau& theTau,
0159 float& eta,
0160 float& phi);
0161
0162 static constexpr float ecalBarrelEndcapEtaBorder_ = 1.479;
0163 static constexpr float ecalEndcapVFEndcapEtaBorder_ = 2.4;
0164
0165 bool isInitialized_;
0166 bool loadMVAfromDB_;
0167 edm::FileInPath inputFileName_;
0168
0169 std::string mvaName_NoEleMatch_woGwoGSF_BL_;
0170 std::string mvaName_NoEleMatch_wGwoGSF_BL_;
0171 std::string mvaName_woGwGSF_BL_;
0172 std::string mvaName_wGwGSF_BL_;
0173 std::string mvaName_NoEleMatch_woGwoGSF_EC_;
0174 std::string mvaName_NoEleMatch_wGwoGSF_EC_;
0175 std::string mvaName_woGwGSF_EC_;
0176 std::string mvaName_wGwGSF_EC_;
0177 std::string mvaName_NoEleMatch_woGwoGSF_VFEC_;
0178 std::string mvaName_NoEleMatch_wGwoGSF_VFEC_;
0179 std::string mvaName_woGwGSF_VFEC_;
0180 std::string mvaName_wGwGSF_VFEC_;
0181
0182 edm::ESGetToken<GBRForest, GBRWrapperRcd> mvaToken_NoEleMatch_woGwoGSF_BL_;
0183 edm::ESGetToken<GBRForest, GBRWrapperRcd> mvaToken_NoEleMatch_wGwoGSF_BL_;
0184 edm::ESGetToken<GBRForest, GBRWrapperRcd> mvaToken_woGwGSF_BL_;
0185 edm::ESGetToken<GBRForest, GBRWrapperRcd> mvaToken_wGwGSF_BL_;
0186 edm::ESGetToken<GBRForest, GBRWrapperRcd> mvaToken_NoEleMatch_woGwoGSF_EC_;
0187 edm::ESGetToken<GBRForest, GBRWrapperRcd> mvaToken_NoEleMatch_wGwoGSF_EC_;
0188 edm::ESGetToken<GBRForest, GBRWrapperRcd> mvaToken_woGwGSF_EC_;
0189 edm::ESGetToken<GBRForest, GBRWrapperRcd> mvaToken_wGwGSF_EC_;
0190 edm::ESGetToken<GBRForest, GBRWrapperRcd> mvaToken_NoEleMatch_woGwoGSF_VFEC_;
0191 edm::ESGetToken<GBRForest, GBRWrapperRcd> mvaToken_NoEleMatch_wGwoGSF_VFEC_;
0192 edm::ESGetToken<GBRForest, GBRWrapperRcd> mvaToken_woGwGSF_VFEC_;
0193 edm::ESGetToken<GBRForest, GBRWrapperRcd> mvaToken_wGwGSF_VFEC_;
0194
0195 bool usePhiAtEcalEntranceExtrapolation_;
0196
0197 std::vector<float> var_NoEleMatch_woGwoGSF_Barrel_;
0198 std::vector<float> var_NoEleMatch_wGwoGSF_Barrel_;
0199 std::vector<float> var_woGwGSF_Barrel_;
0200 std::vector<float> var_wGwGSF_Barrel_;
0201 std::vector<float> var_NoEleMatch_woGwoGSF_Endcap_;
0202 std::vector<float> var_NoEleMatch_wGwoGSF_Endcap_;
0203 std::vector<float> var_woGwGSF_Endcap_;
0204 std::vector<float> var_wGwGSF_Endcap_;
0205 std::vector<float> var_NoEleMatch_woGwoGSF_VFEndcap_;
0206 std::vector<float> var_NoEleMatch_wGwoGSF_VFEndcap_;
0207 std::vector<float> var_woGwGSF_VFEndcap_;
0208 std::vector<float> var_wGwGSF_VFEndcap_;
0209
0210 const GBRForest* mva_NoEleMatch_woGwoGSF_BL_;
0211 const GBRForest* mva_NoEleMatch_wGwoGSF_BL_;
0212 const GBRForest* mva_woGwGSF_BL_;
0213 const GBRForest* mva_wGwGSF_BL_;
0214 const GBRForest* mva_NoEleMatch_woGwoGSF_EC_;
0215 const GBRForest* mva_NoEleMatch_wGwoGSF_EC_;
0216 const GBRForest* mva_woGwGSF_EC_;
0217 const GBRForest* mva_wGwGSF_EC_;
0218 const GBRForest* mva_NoEleMatch_woGwoGSF_VFEC_;
0219 const GBRForest* mva_NoEleMatch_wGwoGSF_VFEC_;
0220 const GBRForest* mva_woGwGSF_VFEC_;
0221 const GBRForest* mva_wGwGSF_VFEC_;
0222
0223 std::vector<TFile*> inputFilesToDelete_;
0224
0225 const bool isPhase2_;
0226
0227 PositionAtECalEntranceComputer positionAtECalEntrance_;
0228
0229 std::map<std::string, edm::EDGetTokenT<edm::ValueMap<float>>> electronIds_tokens_;
0230 std::map<std::string, edm::Handle<edm::ValueMap<float>>> electronIds_;
0231
0232 const int verbosity_;
0233 };
0234
0235 #endif