35 mva_ = std::make_unique<AntiElectronIDMVA6>(
cfg);
38 GsfElectrons_token = consumes<reco::GsfElectronCollection>(srcGsfElectrons_);
39 vetoEcalCracks_ = cfg.
getParameter<
bool>(
"vetoEcalCracks");
40 verbosity_ = ( cfg.
exists(
"verbosity") ) ?
44 produces<PFTauDiscriminator>(
"category");
49 double discriminate(
const PFTauRef&)
const override;
56 bool isInEcalCrack(
double)
const;
59 std::unique_ptr<AntiElectronIDMVA6>
mva_;
75 mva_->beginEvent(evt, es);
80 evt.
getByToken(GsfElectrons_token, gsfElectrons_);
87 bool isGsfElectronMatched =
false;
89 float deltaRDummy = 9.9;
91 const float ECALBarrelEndcapEtaBorder = 1.479;
92 float tauEtaAtEcalEntrance = -99.;
93 float sumEtaTimesEnergy = 0.;
95 const std::vector<reco::PFCandidatePtr>& signalPFCands = thePFTauRef->signalPFCands();
96 for (
const auto & pfCandidate : signalPFCands ) {
97 sumEtaTimesEnergy += (pfCandidate->positionAtECALEntrance().eta()*pfCandidate->energy());
98 sumEnergy += pfCandidate->energy();
100 if ( sumEnergy > 0. ) {
101 tauEtaAtEcalEntrance = sumEtaTimesEnergy/sumEnergy;
104 float leadChargedPFCandEtaAtEcalEntrance = -99.;
105 float leadChargedPFCandPt = -99.;
106 for (
const auto & pfCandidate : signalPFCands ) {
108 if ( pfCandidate->trackRef().isNonnull() ) track = pfCandidate->trackRef().get();
109 else if ( pfCandidate->muonRef().isNonnull() && pfCandidate->muonRef()->innerTrack().isNonnull() ) track = pfCandidate->muonRef()->innerTrack().get();
110 else if ( pfCandidate->muonRef().isNonnull() && pfCandidate->muonRef()->globalTrack().isNonnull() ) track = pfCandidate->muonRef()->globalTrack().get();
111 else if ( pfCandidate->muonRef().isNonnull() && pfCandidate->muonRef()->outerTrack().isNonnull() ) track = pfCandidate->muonRef()->outerTrack().get();
112 else if ( pfCandidate->gsfTrackRef().isNonnull() ) track = pfCandidate->gsfTrackRef().get();
114 if ( track->
pt() > leadChargedPFCandPt ) {
115 leadChargedPFCandEtaAtEcalEntrance = pfCandidate->positionAtECALEntrance().
eta();
116 leadChargedPFCandPt = track->
pt();
121 if( (*thePFTauRef).leadPFChargedHadrCand().isNonnull()) {
123 int numSignalPFGammaCandsInSigCone = 0;
124 const std::vector<reco::PFCandidatePtr>& signalPFGammaCands = thePFTauRef->signalPFGammaCands();
126 for (
const auto &
pfGamma : signalPFGammaCands ) {
128 double dR =
deltaR(
pfGamma->p4(), thePFTauRef->leadPFChargedHadrCand()->p4());
132 if (dR < signalrad) {
133 numSignalPFGammaCandsInSigCone += 1;
138 for (
const auto & theGsfElectron : *gsfElectrons_ ) {
139 if ( theGsfElectron.pt() > 10. ) {
140 double deltaREleTau =
deltaR(theGsfElectron.p4(), thePFTauRef->p4());
141 deltaRDummy = deltaREleTau;
142 if ( deltaREleTau < 0.3 ) {
143 double mva_match = mva_->MVAValue(*thePFTauRef, theGsfElectron);
144 bool hasGsfTrack = thePFTauRef->leadPFChargedHadrCand()->gsfTrackRef().
isNonnull();
146 hasGsfTrack = theGsfElectron.gsfTrack().isNonnull();
149 if ( vetoEcalCracks_ && (isInEcalCrack(tauEtaAtEcalEntrance) || isInEcalCrack(leadChargedPFCandEtaAtEcalEntrance)) ) {
151 category_output_->setValue(tauIndex_, category);
157 if (
std::abs(tauEtaAtEcalEntrance) < ECALBarrelEndcapEtaBorder ) {
158 if ( numSignalPFGammaCandsInSigCone == 0 && hasGsfTrack ) {
161 else if ( numSignalPFGammaCandsInSigCone >= 1 && hasGsfTrack ) {
165 if ( numSignalPFGammaCandsInSigCone == 0 && hasGsfTrack ) {
168 else if ( numSignalPFGammaCandsInSigCone >= 1 && hasGsfTrack ) {
173 mvaValue =
std::min(mvaValue, mva_match);
174 isGsfElectronMatched =
true;
179 if ( !isGsfElectronMatched ) {
180 mvaValue = mva_->MVAValue(*thePFTauRef);
181 bool hasGsfTrack = thePFTauRef->leadPFChargedHadrCand()->gsfTrackRef().
isNonnull();
184 if ( vetoEcalCracks_ && (isInEcalCrack(tauEtaAtEcalEntrance) || isInEcalCrack(leadChargedPFCandEtaAtEcalEntrance)) ) {
186 category_output_->setValue(tauIndex_, category);
192 if (
std::abs(tauEtaAtEcalEntrance) < ECALBarrelEndcapEtaBorder ) {
193 if ( numSignalPFGammaCandsInSigCone == 0 && !hasGsfTrack ) {
196 else if ( numSignalPFGammaCandsInSigCone >= 1 && !hasGsfTrack ) {
200 if ( numSignalPFGammaCandsInSigCone == 0 && !hasGsfTrack ) {
203 else if ( numSignalPFGammaCandsInSigCone >= 1 && !hasGsfTrack ) {
211 edm::LogPrint(
"PFTauAgainstEleMVA6") <<
"<PFRecoTauDiscriminationAgainstElectronMVA6::discriminate>:" ;
212 edm::LogPrint(
"PFTauAgainstEleMVA6") <<
" tau: Pt = " << thePFTauRef->pt() <<
", eta = " << thePFTauRef->eta() <<
", phi = " << thePFTauRef->phi();
213 edm::LogPrint(
"PFTauAgainstEleMVA6") <<
" deltaREleTau = " << deltaRDummy <<
", isGsfElectronMatched = " << isGsfElectronMatched;
214 edm::LogPrint(
"PFTauAgainstEleMVA6") <<
" #Prongs = " << thePFTauRef->signalPFChargedHadrCands().size();
219 category_output_->setValue(tauIndex_, category);
233 double absEta = fabs(eta);
234 return (absEta > 1.460 && absEta < 1.558);
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
edm::RefProd< TauCollection > TauRefProd
bool isNonnull() const
Checks for non-null.
double discriminate(const PFTauRef &) const override
~PFRecoTauDiscriminationAgainstElectronMVA6() override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
#define DEFINE_FWK_MODULE(type)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
edm::EDGetTokenT< reco::GsfElectronCollection > GsfElectrons_token
void beginEvent(const edm::Event &, const edm::EventSetup &) override
edm::Handle< TauCollection > taus_
bool isInEcalCrack(double) const
double eta() const
pseudorapidity of momentum vector
double pt() const
track transverse momentum
edm::InputTag srcGsfElectrons_
Abs< T >::type abs(const T &t)
auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
std::unique_ptr< PFTauDiscriminator > category_output_
PFRecoTauDiscriminationAgainstElectronMVA6(const edm::ParameterSet &cfg)
std::unique_ptr< AntiElectronIDMVA6 > mva_
edm::Handle< reco::GsfElectronCollection > gsfElectrons_
void endEvent(edm::Event &) override