17 : isInitialized_(
false),
18 mva_NoEleMatch_woGwoGSF_BL_(
nullptr),
19 mva_NoEleMatch_woGwGSF_BL_(
nullptr),
20 mva_NoEleMatch_wGwoGSF_BL_(
nullptr),
21 mva_NoEleMatch_wGwGSF_BL_(
nullptr),
26 mva_NoEleMatch_woGwoGSF_EC_(
nullptr),
27 mva_NoEleMatch_woGwGSF_EC_(
nullptr),
28 mva_NoEleMatch_wGwoGSF_EC_(
nullptr),
29 mva_NoEleMatch_wGwGSF_EC_(
nullptr),
37 if(cfg.
exists(
"inputFileName")){
39 }
else throw cms::Exception(
"MVA input not defined") <<
"Requested to load tau MVA input from ROOT file but no file provided in cfg file";
129 throw cms::Exception(
"PFRecoTauDiscriminationAgainstMuonMVA::loadMVA")
130 <<
" Failed to load MVA = " << mvaName.data() <<
" from file " <<
" !!\n";
192 Float_t TauLeadChargedPFCandEtaAtEcalEntrance,
193 Float_t TauLeadChargedPFCandPt,
194 Float_t TaudCrackEta,
195 Float_t TaudCrackPhi,
196 Float_t TauEmFraction,
197 Float_t TauSignalPFGammaCands,
198 Float_t TauLeadPFChargedHadrHoP,
199 Float_t TauLeadPFChargedHadrEoP,
202 const std::vector<Float_t>& GammasdEta,
203 const std::vector<Float_t>& GammasdPhi,
204 const std::vector<Float_t>& GammasPt,
205 Float_t TauKFNumHits,
206 Float_t TauGSFNumHits,
208 Float_t TauGSFTrackResol,
209 Float_t TauGSFTracklnPt,
210 Float_t TauGSFTrackEta,
212 Float_t TauSignalPFChargedCands,
223 Float_t ElecGSFNumHits,
224 Float_t ElecGSFTrackResol,
225 Float_t ElecGSFTracklnPt,
226 Float_t ElecGSFTrackEta)
231 for (
unsigned int i = 0 ;
i < GammasPt.size() ; ++
i ) {
232 double pt_i = GammasPt[
i];
233 double phi_i = GammasdPhi[
i];
234 if ( GammasdPhi[
i] >
M_PI ) phi_i = GammasdPhi[
i] - 2*
M_PI;
235 else if ( GammasdPhi[
i] < -M_PI ) phi_i = GammasdPhi[
i] + 2*
M_PI;
236 double eta_i = GammasdEta[
i];
238 dEta2 += (pt_i*eta_i*eta_i);
239 dPhi2 += (pt_i*phi_i*phi_i);
242 Float_t TauGammaEnFrac = sumPt/TauPt;
252 return MVAValue(TauEtaAtEcalEntrance,
254 TauLeadChargedPFCandEtaAtEcalEntrance,
255 TauLeadChargedPFCandPt,
259 TauSignalPFGammaCands,
260 TauLeadPFChargedHadrHoP,
261 TauLeadPFChargedHadrEoP,
274 TauSignalPFChargedCands,
293 Float_t TauLeadChargedPFCandEtaAtEcalEntrance,
294 Float_t TauLeadChargedPFCandPt,
295 Float_t TaudCrackEta,
296 Float_t TaudCrackPhi,
298 Float_t TauSignalPFGammaCands,
299 Float_t TauLeadPFChargedHadrHoP,
300 Float_t TauLeadPFChargedHadrEoP,
303 Float_t TauGammaEtaMom,
304 Float_t TauGammaPhiMom,
305 Float_t TauGammaEnFrac,
306 Float_t TauKFNumHits,
307 Float_t TauGSFNumHits,
309 Float_t TauGSFTrackResol,
310 Float_t TauGSFTracklnPt,
311 Float_t TauGSFTrackEta,
313 Float_t TauSignalPFChargedCands,
324 Float_t ElecGSFNumHits,
325 Float_t ElecGSFTrackResol,
326 Float_t ElecGSFTracklnPt,
327 Float_t ElecGSFTrackEta)
331 <<
" AntiElectronMVA not properly initialized !!\n";
334 Float_t TauEmFraction =
std::max(TauEmFract,
float(0.));
335 Float_t TauNumHitsVariable = (TauGSFNumHits - TauKFNumHits)/(TauGSFNumHits + TauKFNumHits);
336 Float_t ElecEtotOverPin = (ElecEe + ElecEgamma)/ElecPin;
337 Float_t ElecEgammaOverPdif = ElecEgamma/(ElecPin - ElecPout);
339 double mvaValue = -99.;
340 if (
deltaR(TauEtaAtEcalEntrance, TauPhi, ElecEta, ElecPhi) > 0.3 && TauSignalPFGammaCands == 0 && TauHasGsf < 0.5) {
341 if (
std::abs(TauEtaAtEcalEntrance) < 1.479 ){
365 }
else if (
deltaR(TauEtaAtEcalEntrance, TauPhi, ElecEta, ElecPhi) > 0.3 && TauSignalPFGammaCands == 0 && TauHasGsf > 0.5) {
366 if (
std::abs(TauEtaAtEcalEntrance) < 1.479 ){
402 }
else if (
deltaR(TauEtaAtEcalEntrance, TauPhi, ElecEta, ElecPhi) > 0.3 && TauSignalPFGammaCands > 0 && TauHasGsf < 0.5 ) {
403 if (
std::abs(TauEtaAtEcalEntrance) < 1.479 ){
436 else if (
deltaR(TauEtaAtEcalEntrance, TauPhi, ElecEta, ElecPhi) > 0.3 && TauSignalPFGammaCands > 0 && TauHasGsf > 0.5 ) {
437 if (
std::abs(TauEtaAtEcalEntrance) < 1.479 ) {
481 }
else if ( TauSignalPFGammaCands == 0 && TauHasGsf < 0.5 ) {
482 if (
std::abs(TauEtaAtEcalEntrance) < 1.479 ) {
522 }
else if ( TauSignalPFGammaCands == 0 && TauHasGsf > 0.5 ) {
523 if (
std::abs(TauEtaAtEcalEntrance) < 1.479 ) {
575 }
else if ( TauSignalPFGammaCands > 0 && TauHasGsf < 0.5 ) {
576 if (
std::abs(TauEtaAtEcalEntrance) < 1.479 ) {
624 }
else if ( TauSignalPFGammaCands > 0 && TauHasGsf > 0.5 ) {
625 if (
std::abs(TauEtaAtEcalEntrance) < 1.479 ) {
693 Float_t TauEtaAtEcalEntrance = -99.;
694 float sumEtaTimesEnergy = 0.;
695 float sumEnergy = 0.;
696 const std::vector<reco::PFCandidatePtr>& signalPFCands = thePFTau.
signalPFCands();
697 for ( std::vector<reco::PFCandidatePtr>::const_iterator pfCandidate = signalPFCands.begin();
698 pfCandidate != signalPFCands.end(); ++pfCandidate ) {
699 sumEtaTimesEnergy += (*pfCandidate)->positionAtECALEntrance().eta()*(*pfCandidate)->energy();
700 sumEnergy += (*pfCandidate)->energy();
702 if ( sumEnergy > 0. ) {
703 TauEtaAtEcalEntrance = sumEtaTimesEnergy/sumEnergy;
706 float TauLeadChargedPFCandEtaAtEcalEntrance = -99.;
707 float TauLeadChargedPFCandPt = -99.;
708 for ( std::vector<reco::PFCandidatePtr>::const_iterator pfCandidate = signalPFCands.begin();
709 pfCandidate != signalPFCands.end(); ++pfCandidate ) {
711 if ( (*pfCandidate)->trackRef().isNonnull() ) track = (*pfCandidate)->trackRef().get();
712 else if ( (*pfCandidate)->muonRef().isNonnull() && (*pfCandidate)->muonRef()->innerTrack().isNonnull() ) track = (*pfCandidate)->muonRef()->innerTrack().get();
713 else if ( (*pfCandidate)->muonRef().isNonnull() && (*pfCandidate)->muonRef()->globalTrack().isNonnull() ) track = (*pfCandidate)->muonRef()->globalTrack().get();
714 else if ( (*pfCandidate)->muonRef().isNonnull() && (*pfCandidate)->muonRef()->outerTrack().isNonnull() ) track = (*pfCandidate)->muonRef()->outerTrack().get();
715 else if ( (*pfCandidate)->gsfTrackRef().isNonnull() ) track = (*pfCandidate)->gsfTrackRef().get();
717 if ( track->
pt() > TauLeadChargedPFCandPt ) {
718 TauLeadChargedPFCandEtaAtEcalEntrance = (*pfCandidate)->positionAtECALEntrance().
eta();
719 TauLeadChargedPFCandPt = track->
pt();
724 Float_t TauPt = thePFTau.
pt();
727 Float_t TauLeadPFChargedHadrHoP = 0.;
728 Float_t TauLeadPFChargedHadrEoP = 0.;
733 Float_t TauVisMass = thePFTau.
mass();
735 std::vector<Float_t> GammasdEta;
736 std::vector<Float_t> GammasdPhi;
737 std::vector<Float_t> GammasPt;
744 GammasdEta.push_back(gamma->eta() - thePFTau.
eta());
745 GammasdPhi.push_back(gamma->phi() - thePFTau.
phi());
747 GammasPt.push_back(gamma->pt());
749 Float_t TauKFNumHits = -99.;
753 Float_t TauGSFNumHits = -99.;
754 Float_t TauGSFChi2 = -99.;
755 Float_t TauGSFTrackResol = -99.;
756 Float_t TauGSFTracklnPt = -99.;
757 Float_t TauGSFTrackEta = -99.;
767 Float_t TauPhi = thePFTau.
phi();
768 float sumPhiTimesEnergy = 0.;
769 float sumEnergyPhi = 0.;
770 for ( std::vector<reco::PFCandidatePtr>::const_iterator pfCandidate = signalPFCands.begin();
771 pfCandidate != signalPFCands.end(); ++pfCandidate ) {
772 sumPhiTimesEnergy += (*pfCandidate)->positionAtECALEntrance().phi()*(*pfCandidate)->energy();
773 sumEnergyPhi += (*pfCandidate)->energy();
775 if ( sumEnergyPhi > 0. ) {
776 TauPhi = sumPhiTimesEnergy/sumEnergyPhi;
778 Float_t TaudCrackPhi =
dCrackPhi(TauPhi, TauEtaAtEcalEntrance);
779 Float_t TaudCrackEta =
dCrackEta(TauEtaAtEcalEntrance);
783 Float_t ElecEta = theGsfEle.
eta();
784 Float_t ElecPhi = theGsfEle.
phi();
785 Float_t ElecPt = theGsfEle.
pt();
788 Float_t ElecEgamma = 0.;
792 pfCluster != pfSuperCluster->clustersEnd(); ++pfCluster ) {
793 double pfClusterEn = (*pfCluster)->energy();
794 if ( pfCluster == pfSuperCluster->clustersBegin() ) ElecEe += pfClusterEn;
795 else ElecEgamma += pfClusterEn;
800 Float_t ElecFbrem = theGsfEle.
fbrem();
802 Float_t ElecChi2GSF = -99.;
803 Float_t ElecGSFNumHits = -99.;
804 Float_t ElecGSFTrackResol = -99.;
805 Float_t ElecGSFTracklnPt = -99.;
806 Float_t ElecGSFTrackEta = -99.;
808 ElecChi2GSF = (theGsfEle).gsfTrack()->normalizedChi2();
809 ElecGSFNumHits = (theGsfEle).gsfTrack()->numberOfValidHits();
810 if ( theGsfEle.
gsfTrack()->pt() > 0. ) {
811 ElecGSFTrackResol = theGsfEle.
gsfTrack()->ptError()/theGsfEle.
gsfTrack()->pt();
812 ElecGSFTracklnPt =
log(theGsfEle.
gsfTrack()->pt())*M_LN10;
814 ElecGSFTrackEta = theGsfEle.
gsfTrack()->eta();
817 return MVAValue(TauEtaAtEcalEntrance,
819 TauLeadChargedPFCandEtaAtEcalEntrance,
820 TauLeadChargedPFCandPt,
824 TauSignalPFGammaCands,
825 TauLeadPFChargedHadrHoP,
826 TauLeadPFChargedHadrEoP,
839 TauSignalPFChargedCands,
858 Float_t TauEtaAtEcalEntrance = -99.;
859 float sumEtaTimesEnergy = 0.;
860 float sumEnergy = 0.;
861 const std::vector<reco::PFCandidatePtr>& signalPFCands = thePFTau.
signalPFCands();
862 for ( std::vector<reco::PFCandidatePtr>::const_iterator pfCandidate = signalPFCands.begin();
863 pfCandidate != signalPFCands.end(); ++pfCandidate ) {
864 sumEtaTimesEnergy += (*pfCandidate)->positionAtECALEntrance().eta()*(*pfCandidate)->energy();
865 sumEnergy += (*pfCandidate)->energy();
867 if ( sumEnergy > 0. ) {
868 TauEtaAtEcalEntrance = sumEtaTimesEnergy/sumEnergy;
871 float TauLeadChargedPFCandEtaAtEcalEntrance = -99.;
872 float TauLeadChargedPFCandPt = -99.;
873 for ( std::vector<reco::PFCandidatePtr>::const_iterator pfCandidate = signalPFCands.begin();
874 pfCandidate != signalPFCands.end(); ++pfCandidate ) {
876 if ( (*pfCandidate)->trackRef().isNonnull() ) track = (*pfCandidate)->trackRef().get();
877 else if ( (*pfCandidate)->muonRef().isNonnull() && (*pfCandidate)->muonRef()->innerTrack().isNonnull() ) track = (*pfCandidate)->muonRef()->innerTrack().get();
878 else if ( (*pfCandidate)->muonRef().isNonnull() && (*pfCandidate)->muonRef()->globalTrack().isNonnull() ) track = (*pfCandidate)->muonRef()->globalTrack().get();
879 else if ( (*pfCandidate)->muonRef().isNonnull() && (*pfCandidate)->muonRef()->outerTrack().isNonnull() ) track = (*pfCandidate)->muonRef()->outerTrack().get();
880 else if ( (*pfCandidate)->gsfTrackRef().isNonnull() ) track = (*pfCandidate)->gsfTrackRef().get();
882 if ( track->
pt() > TauLeadChargedPFCandPt ) {
883 TauLeadChargedPFCandEtaAtEcalEntrance = (*pfCandidate)->positionAtECALEntrance().
eta();
884 TauLeadChargedPFCandPt = track->
pt();
889 Float_t TauPt = thePFTau.
pt();
892 Float_t TauLeadPFChargedHadrHoP = 0.;
893 Float_t TauLeadPFChargedHadrEoP = 0.;
898 Float_t TauVisMass = thePFTau.
mass();
900 std::vector<Float_t> GammasdEta;
901 std::vector<Float_t> GammasdPhi;
902 std::vector<Float_t> GammasPt;
909 GammasdEta.push_back(gamma->eta() - thePFTau.
eta());
910 GammasdPhi.push_back(gamma->phi() - thePFTau.
phi());
912 GammasPt.push_back(gamma->pt());
914 Float_t TauKFNumHits = -99.;
918 Float_t TauGSFNumHits = -99.;
919 Float_t TauGSFChi2 = -99.;
920 Float_t TauGSFTrackResol = -99.;
921 Float_t TauGSFTracklnPt = -99.;
922 Float_t TauGSFTrackEta = -99.;
932 Float_t TauPhi = thePFTau.
phi();
933 float sumPhiTimesEnergy = 0.;
934 float sumEnergyPhi = 0.;
935 for ( std::vector<reco::PFCandidatePtr>::const_iterator pfCandidate = signalPFCands.begin();
936 pfCandidate != signalPFCands.end(); ++pfCandidate ) {
937 sumPhiTimesEnergy += (*pfCandidate)->positionAtECALEntrance().phi()*(*pfCandidate)->energy();
938 sumEnergyPhi += (*pfCandidate)->energy();
940 if ( sumEnergyPhi > 0. ) {
941 TauPhi = sumPhiTimesEnergy/sumEnergyPhi;
943 Float_t TaudCrackPhi =
dCrackPhi(TauPhi,TauEtaAtEcalEntrance) ;
944 Float_t TaudCrackEta =
dCrackEta(TauEtaAtEcalEntrance) ;
948 Float_t dummyElecEta = 9.9;
950 return MVAValue(TauEtaAtEcalEntrance,
952 TauLeadChargedPFCandEtaAtEcalEntrance,
953 TauLeadChargedPFCandPt,
957 TauSignalPFGammaCands,
958 TauLeadPFChargedHadrHoP,
959 TauLeadPFChargedHadrEoP,
972 TauSignalPFChargedCands,
1000 std::array<double,18> fill_cPhi() {
1002 std::array<double,18> cPhi;
1005 for (
unsigned iCrack = 1; iCrack <= 17; ++iCrack )
1006 cPhi[iCrack] = cPhi[0] - 2.*iCrack*pi/18;
1010 const std::array<double,18> cPhi = fill_cPhi();
1025 double retVal = 99.;
1027 if ( eta >= -1.47464 && eta <= 1.47464 ) {
1030 if ( eta < 0. ) phi += delta_cPhi;
1033 if ( phi > pi ) phi -= 2.*
pi;
1034 if ( phi < -pi ) phi += 2.*
pi;
1036 if ( phi >= -pi && phi <= pi ) {
1039 if ( phi < cPhi[17] || phi >= cPhi[0] ) {
1040 if ( phi < 0. ) phi += 2.*
pi;
1041 retVal =
minimum(phi - cPhi[0], phi - cPhi[17] - 2.*pi);
1045 unsigned iCrack = 16;
1047 if ( phi < cPhi[iCrack] ) {
1048 retVal =
minimum(phi - cPhi[iCrack + 1], phi - cPhi[iCrack]);
1070 double cracks[5] = { 0., 4.44747e-01, 7.92824e-01, 1.14090e+00, 1.47464e+00 };
1072 double retVal = 99.;
1074 for (
int iCrack = 0; iCrack < 5 ; ++iCrack ) {
1075 double d =
minimum(eta - cracks[iCrack], eta + cracks[iCrack]);
const GBRForest * mva_woGwGSF_BL_
T getParameter(std::string const &) const
GsfTrackRef gsfTrack() const override
reference to a GsfTrack
Float_t * Var_NoEleMatch_woGwoGSF_Endcap_
Float_t * Var_woGwGSF_Endcap_
Float_t * Var_NoEleMatch_wGwoGSF_Barrel_
bool isNonnull() const
Checks for non-null.
double eta() const final
momentum pseudorapidity
virtual SuperClusterRef parentSuperCluster() const
const PFCandidatePtr & leadPFChargedHadrCand() const
const GBRForest * mva_woGwoGSF_BL_
Float_t * Var_wGwGSF_Barrel_
double minimum(double a, double b)
edm::FileInPath inputFileName_
const GBRForest * mva_wGwoGSF_EC_
std::string mvaName_woGwoGSF_BL_
math::XYZVectorF trackMomentumAtVtx() const
const std::vector< reco::PFCandidatePtr > & signalPFGammaCands() const
Gamma candidates in signal region.
const GBRForest * mva_NoEleMatch_woGwGSF_EC_
std::string mvaName_NoEleMatch_woGwoGSF_EC_
bool exists(std::string const ¶meterName) const
checks if a parameter exists
double pt() const final
transverse momentum
Float_t * Var_NoEleMatch_woGwoGSF_Barrel_
std::string mvaName_NoEleMatch_woGwGSF_BL_
const GBRForest * mva_NoEleMatch_wGwGSF_EC_
const std::vector< reco::PFCandidatePtr > & signalPFCands() const
PFCandidates in signal region.
std::string mvaName_woGwoGSF_EC_
std::string mvaName_NoEleMatch_woGwGSF_EC_
std::string mvaName_wGwoGSF_EC_
const GBRForest * mva_NoEleMatch_woGwoGSF_EC_
void beginEvent(const edm::Event &, const edm::EventSetup &)
double eta() const
pseudorapidity of momentum vector
const GBRForest * mva_woGwoGSF_EC_
const GBRForest * mva_NoEleMatch_wGwGSF_BL_
const GBRForest * mva_NoEleMatch_woGwoGSF_BL_
std::string mvaName_wGwoGSF_BL_
math::XYZVectorF trackMomentumOut() const
Float_t * Var_wGwoGSF_Barrel_
double pt() const
track transverse momentum
std::string mvaName_woGwGSF_EC_
std::string mvaName_woGwGSF_BL_
const GBRForest * mva_woGwGSF_EC_
Abs< T >::type abs(const T &t)
std::string mvaName_wGwGSF_EC_
std::string mvaName_NoEleMatch_wGwoGSF_BL_
Float_t * Var_NoEleMatch_woGwGSF_Endcap_
Float_t * Var_woGwGSF_Barrel_
std::vector< TFile * > inputFilesToDelete_
LocationCode location() const
Where was the file found?
Float_t * Var_wGwGSF_Endcap_
std::string mvaName_NoEleMatch_woGwoGSF_BL_
double dCrackEta(double eta)
bool isNonnull() const
Checks for non-null.
double deltaR(double eta1, double eta2, double phi1, double phi2)
const GBRForest * mva_wGwoGSF_BL_
std::string mvaName_wGwGSF_BL_
std::pair< int, edm::FunctionWithDict > OK
double MVAValue(Float_t TauEtaAtEcalEntrance, Float_t TauPt, Float_t TauLeadChargedPFCandEtaAtEcalEntrance, Float_t TauLeadChargedPFCandPt, Float_t TaudCrackEta, Float_t TaudCrackPhi, Float_t TauEmFraction, Float_t TauSignalPFGammaCands, Float_t TauLeadPFChargedHadrHoP, Float_t TauLeadPFChargedHadrEoP, Float_t TauVisMass, Float_t TauHadrMva, const std::vector< Float_t > &GammasdEta, const std::vector< Float_t > &GammasdPhi, const std::vector< Float_t > &GammasPt, Float_t TauKFNumHits, Float_t TauGSFNumHits, Float_t TauGSFChi2, Float_t TauGSFTrackResol, Float_t TauGSFTracklnPt, Float_t TauGSFTrackEta, Float_t TauPhi, Float_t TauSignalPFChargedCands, Float_t TauHasGsf, Float_t ElecEta, Float_t ElecPhi, Float_t ElecPt, Float_t ElecEe, Float_t ElecEgamma, Float_t ElecPin, Float_t ElecPout, Float_t ElecFbrem, Float_t ElecChi2GSF, Float_t ElecGSFNumHits, Float_t ElecGSFTrackResol, Float_t ElecGSFTracklnPt, Float_t ElecGSFTrackEta)
const GBRForest * mva_NoEleMatch_woGwGSF_BL_
const GBRForest * mva_NoEleMatch_wGwoGSF_BL_
std::string mvaName_NoEleMatch_wGwGSF_BL_
Float_t * Var_NoEleMatch_woGwGSF_Barrel_
const GBRForest * mva_wGwGSF_BL_
Float_t * Var_NoEleMatch_wGwGSF_Endcap_
Float_t * Var_wGwoGSF_Endcap_
const GBRForest * mva_NoEleMatch_wGwoGSF_EC_
const GBRForest * mva_wGwGSF_EC_
double dCrackPhi(double phi, double eta)
std::string mvaName_NoEleMatch_wGwoGSF_EC_
std::string fullPath() const
Float_t * Var_woGwoGSF_Endcap_
Float_t * Var_woGwoGSF_Barrel_
std::string mvaName_NoEleMatch_wGwGSF_EC_
Float_t * Var_NoEleMatch_wGwGSF_Barrel_
AntiElectronIDMVA5(const edm::ParameterSet &)
double GetClassifier(const float *vector) const
float electronPreIDOutput() const
double phi() const final
momentum azimuthal angle
T const * product() const
Float_t * Var_NoEleMatch_wGwoGSF_Endcap_
const std::vector< reco::PFCandidatePtr > & signalPFChargedHadrCands() const
Charged hadrons in signal region.
double mass() const final
mass