37 usePhiAtEcalEntranceExtrapolation_ = cfg.
getParameter<
bool>(
"usePhiAtEcalEntranceExtrapolation");
39 GsfElectrons_token = consumes<reco::GsfElectronCollection>(srcGsfElectrons_);
41 verbosity_ = ( cfg.
exists(
"verbosity") ) ?
45 produces<PFTauDiscriminator>(
"category");
50 double discriminate(
const PFTauRef&)
const override;
60 bool isInEcalCrack(
double)
const;
80 mva_->beginEvent(evt, es);
85 evt.
getByToken(GsfElectrons_token, gsfElectrons_);
92 bool isGsfElectronMatched =
false;
94 float deltaRDummy = 9.9;
96 const float ECALBarrelEndcapEtaBorder = 1.479;
97 float tauEtaAtEcalEntrance = -99.;
98 float sumEtaTimesEnergy = 0.;
100 const std::vector<reco::PFCandidatePtr>& signalPFCands = thePFTauRef->signalPFCands();
101 for ( std::vector<reco::PFCandidatePtr>::const_iterator pfCandidate = signalPFCands.begin();
102 pfCandidate != signalPFCands.end(); ++pfCandidate ) {
103 sumEtaTimesEnergy += ((*pfCandidate)->positionAtECALEntrance().eta()*(*pfCandidate)->energy());
104 sumEnergy += (*pfCandidate)->energy();
106 if ( sumEnergy > 0. ) {
107 tauEtaAtEcalEntrance = sumEtaTimesEnergy/sumEnergy;
110 float leadChargedPFCandEtaAtEcalEntrance = -99.;
111 float leadChargedPFCandPt = -99.;
112 for ( std::vector<reco::PFCandidatePtr>::const_iterator pfCandidate = signalPFCands.begin();
113 pfCandidate != signalPFCands.end(); ++pfCandidate ) {
115 if ( (*pfCandidate)->trackRef().isNonnull() ) track = (*pfCandidate)->trackRef().get();
116 else if ( (*pfCandidate)->muonRef().isNonnull() && (*pfCandidate)->muonRef()->innerTrack().isNonnull() ) track = (*pfCandidate)->muonRef()->innerTrack().get();
117 else if ( (*pfCandidate)->muonRef().isNonnull() && (*pfCandidate)->muonRef()->globalTrack().isNonnull() ) track = (*pfCandidate)->muonRef()->globalTrack().get();
118 else if ( (*pfCandidate)->muonRef().isNonnull() && (*pfCandidate)->muonRef()->outerTrack().isNonnull() ) track = (*pfCandidate)->muonRef()->outerTrack().get();
119 else if ( (*pfCandidate)->gsfTrackRef().isNonnull() ) track = (*pfCandidate)->gsfTrackRef().get();
121 if ( track->
pt() > leadChargedPFCandPt ) {
122 leadChargedPFCandEtaAtEcalEntrance = (*pfCandidate)->positionAtECALEntrance().
eta();
123 leadChargedPFCandPt = track->
pt();
128 if( (*thePFTauRef).leadPFChargedHadrCand().isNonnull()) {
130 int numSignalPFGammaCandsInSigCone = 0;
131 const std::vector<reco::PFCandidatePtr>& signalPFGammaCands = thePFTauRef->signalPFGammaCands();
133 for ( std::vector<reco::PFCandidatePtr>::const_iterator
pfGamma = signalPFGammaCands.begin();
136 double dR =
deltaR((*pfGamma)->p4(), thePFTauRef->leadPFChargedHadrCand()->p4());
140 if (dR < signalrad) {
141 numSignalPFGammaCandsInSigCone += 1;
146 for ( reco::GsfElectronCollection::const_iterator theGsfElectron = gsfElectrons_->begin();
147 theGsfElectron != gsfElectrons_->end(); ++theGsfElectron ) {
148 if ( theGsfElectron->pt() > 10. ) {
149 double deltaREleTau =
deltaR(theGsfElectron->p4(), thePFTauRef->p4());
150 deltaRDummy = deltaREleTau;
151 if ( deltaREleTau < 0.3 ) {
152 double mva_match = mva_->MVAValue(*thePFTauRef, *theGsfElectron, usePhiAtEcalEntranceExtrapolation_);
153 bool hasGsfTrack = thePFTauRef->leadPFChargedHadrCand()->gsfTrackRef().
isNonnull();
155 hasGsfTrack = theGsfElectron->gsfTrack().isNonnull();
158 if ( isInEcalCrack(tauEtaAtEcalEntrance) || isInEcalCrack(leadChargedPFCandEtaAtEcalEntrance) ) {
160 category_output_->setValue(tauIndex_, category);
166 if (
std::abs(tauEtaAtEcalEntrance) < ECALBarrelEndcapEtaBorder ) {
167 if ( numSignalPFGammaCandsInSigCone == 0 && hasGsfTrack ) {
170 else if ( numSignalPFGammaCandsInSigCone >= 1 && hasGsfTrack ) {
174 if ( numSignalPFGammaCandsInSigCone == 0 && hasGsfTrack ) {
177 else if ( numSignalPFGammaCandsInSigCone >= 1 && hasGsfTrack ) {
182 mvaValue =
std::min(mvaValue, mva_match);
183 isGsfElectronMatched =
true;
188 if ( !isGsfElectronMatched ) {
189 mvaValue = mva_->MVAValue(*thePFTauRef, usePhiAtEcalEntranceExtrapolation_);
190 bool hasGsfTrack = thePFTauRef->leadPFChargedHadrCand()->gsfTrackRef().
isNonnull();
193 if ( isInEcalCrack(tauEtaAtEcalEntrance) || isInEcalCrack(leadChargedPFCandEtaAtEcalEntrance) ) {
195 category_output_->setValue(tauIndex_, category);
201 if (
std::abs(tauEtaAtEcalEntrance) < ECALBarrelEndcapEtaBorder ) {
202 if ( numSignalPFGammaCandsInSigCone == 0 && !hasGsfTrack ) {
205 else if ( numSignalPFGammaCandsInSigCone >= 1 && !hasGsfTrack ) {
209 if ( numSignalPFGammaCandsInSigCone == 0 && !hasGsfTrack ) {
212 else if ( numSignalPFGammaCandsInSigCone >= 1 && !hasGsfTrack ) {
220 edm::LogPrint(
"PFTauAgainstEleMVA6") <<
"<PFRecoTauDiscriminationAgainstElectronMVA6::discriminate>:" ;
221 edm::LogPrint(
"PFTauAgainstEleMVA6") <<
" tau: Pt = " << thePFTauRef->pt() <<
", eta = " << thePFTauRef->eta() <<
", phi = " << thePFTauRef->phi();
222 edm::LogPrint(
"PFTauAgainstEleMVA6") <<
" deltaREleTau = " << deltaRDummy <<
", isGsfElectronMatched = " << isGsfElectronMatched;
223 edm::LogPrint(
"PFTauAgainstEleMVA6") <<
" #Prongs = " << thePFTauRef->signalPFChargedHadrCands().size();
228 category_output_->setValue(tauIndex_, category);
242 double absEta = fabs(eta);
243 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
AntiElectronIDMVA6 * mva_
#define DEFINE_FWK_MODULE(type)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
bool usePhiAtEcalEntranceExtrapolation_
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)
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
std::unique_ptr< PFTauDiscriminator > category_output_
PFRecoTauDiscriminationAgainstElectronMVA6(const edm::ParameterSet &cfg)
edm::Handle< reco::GsfElectronCollection > gsfElectrons_
void endEvent(edm::Event &) override