38 mva_ = std::make_unique<AntiElectronIDMVA6>(
cfg);
41 GsfElectrons_token = consumes<reco::GsfElectronCollection>(srcGsfElectrons_);
42 vetoEcalCracks_ = cfg.
getParameter<
bool>(
"vetoEcalCracks");
47 produces<PFTauDiscriminator>(
"category");
52 double discriminate(
const PFTauRef&)
const override;
61 bool isInEcalCrack(
double)
const;
64 std::unique_ptr<AntiElectronIDMVA6>
mva_;
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 for (
const auto & pfCandidate : thePFTauRef->signalPFCands() ) {
101 sumEtaTimesEnergy += (pfCandidate->positionAtECALEntrance().eta()*pfCandidate->energy());
102 sumEnergy += pfCandidate->energy();
104 if ( sumEnergy > 0. ) {
105 tauEtaAtEcalEntrance = sumEtaTimesEnergy/sumEnergy;
108 float leadChargedPFCandEtaAtEcalEntrance = -99.;
109 float leadChargedPFCandPt = -99.;
110 for (
const auto & pfCandidate : thePFTauRef->signalPFCands() ) {
112 if ( pfCandidate->trackRef().isNonnull() ) track = pfCandidate->trackRef().get();
113 else if ( pfCandidate->muonRef().isNonnull() && pfCandidate->muonRef()->innerTrack().isNonnull() ) track = pfCandidate->muonRef()->innerTrack().get();
114 else if ( pfCandidate->muonRef().isNonnull() && pfCandidate->muonRef()->globalTrack().isNonnull() ) track = pfCandidate->muonRef()->globalTrack().get();
115 else if ( pfCandidate->muonRef().isNonnull() && pfCandidate->muonRef()->outerTrack().isNonnull() ) track = pfCandidate->muonRef()->outerTrack().get();
116 else if ( pfCandidate->gsfTrackRef().isNonnull() ) track = pfCandidate->gsfTrackRef().get();
118 if ( track->
pt() > leadChargedPFCandPt ) {
119 leadChargedPFCandEtaAtEcalEntrance = pfCandidate->positionAtECALEntrance().
eta();
120 leadChargedPFCandPt = track->
pt();
125 if( (*thePFTauRef).leadChargedHadrCand().isNonnull()) {
127 int numSignalGammaCandsInSigCone = 0;
128 const std::vector<reco::CandidatePtr>& signalGammaCands = thePFTauRef->signalGammaCands();
130 for (
const auto &
pfGamma : signalGammaCands ) {
132 double dR =
deltaR(
pfGamma->p4(), thePFTauRef->leadChargedHadrCand()->p4());
136 if (dR < signalrad) {
137 numSignalGammaCandsInSigCone += 1;
142 for (
const auto & theGsfElectron : *gsfElectrons_ ) {
143 if ( theGsfElectron.pt() > 10. ) {
144 double deltaREleTau =
deltaR(theGsfElectron.p4(), thePFTauRef->p4());
145 deltaRDummy = deltaREleTau;
146 if ( deltaREleTau < 0.3 ) {
147 double mva_match = mva_->MVAValue(*thePFTauRef, theGsfElectron);
149 bool hasGsfTrack =
false;
154 hasGsfTrack = theGsfElectron.gsfTrack().isNonnull();
157 if ( vetoEcalCracks_ && (isInEcalCrack(tauEtaAtEcalEntrance) || isInEcalCrack(leadChargedPFCandEtaAtEcalEntrance)) ) {
159 category_output_->setValue(tauIndex_, category);
165 if (
std::abs(tauEtaAtEcalEntrance) < ECALBarrelEndcapEtaBorder ) {
166 if ( numSignalGammaCandsInSigCone == 0 && hasGsfTrack ) {
169 else if ( numSignalGammaCandsInSigCone >= 1 && hasGsfTrack ) {
173 if ( numSignalGammaCandsInSigCone == 0 && hasGsfTrack ) {
176 else if ( numSignalGammaCandsInSigCone >= 1 && hasGsfTrack ) {
181 mvaValue =
std::min(mvaValue, mva_match);
182 isGsfElectronMatched =
true;
187 if ( !isGsfElectronMatched ) {
188 mvaValue = mva_->MVAValue(*thePFTauRef);
190 bool hasGsfTrack =
false;
196 if ( vetoEcalCracks_ && (isInEcalCrack(tauEtaAtEcalEntrance) || isInEcalCrack(leadChargedPFCandEtaAtEcalEntrance)) ) {
198 category_output_->setValue(tauIndex_, category);
204 if (
std::abs(tauEtaAtEcalEntrance) < ECALBarrelEndcapEtaBorder ) {
205 if ( numSignalGammaCandsInSigCone == 0 && !hasGsfTrack ) {
208 else if ( numSignalGammaCandsInSigCone >= 1 && !hasGsfTrack ) {
212 if ( numSignalGammaCandsInSigCone == 0 && !hasGsfTrack ) {
215 else if ( numSignalGammaCandsInSigCone >= 1 && !hasGsfTrack ) {
223 edm::LogPrint(
"PFTauAgainstEleMVA6") <<
"<PFRecoTauDiscriminationAgainstElectronMVA6::discriminate>:" ;
224 edm::LogPrint(
"PFTauAgainstEleMVA6") <<
" tau: Pt = " << thePFTauRef->pt() <<
", eta = " << thePFTauRef->eta() <<
", phi = " << thePFTauRef->phi();
225 edm::LogPrint(
"PFTauAgainstEleMVA6") <<
" deltaREleTau = " << deltaRDummy <<
", isGsfElectronMatched = " << isGsfElectronMatched;
226 edm::LogPrint(
"PFTauAgainstEleMVA6") <<
" #Prongs = " << thePFTauRef->signalChargedHadrCands().size();
231 category_output_->setValue(tauIndex_, category);
245 double absEta = fabs(eta);
246 return (absEta > 1.460 && absEta < 1.558);
253 desc.
add<
double>(
"minMVANoEleMatchWOgWOgsfBL", 0.0);
255 desc.
add<
double>(
"minMVANoEleMatchWgWOgsfBL", 0.0);
257 desc.
add<
double>(
"minMVAWgWgsfBL", 0.0);
259 desc.
add<
double>(
"minMVAWOgWgsfEC", 0.0);
262 desc.
add<
bool>(
"returnMVA",
true);
263 desc.
add<
bool>(
"loadMVAfromDB",
true);
269 psd1.
add<
double>(
"cut");
277 psd1.
add<
double>(
"cut");
283 desc.
add<
std::string>(
"mvaName_NoEleMatch_woGwoGSF_BL",
"gbr_NoEleMatch_woGwoGSF_BL");
284 desc.
add<
bool>(
"vetoEcalCracks",
true);
285 desc.
add<
bool>(
"usePhiAtEcalEntranceExtrapolation",
false);
286 desc.
add<
std::string>(
"mvaName_NoEleMatch_wGwoGSF_BL",
"gbr_NoEleMatch_wGwoGSF_BL");
287 desc.
add<
double>(
"minMVANoEleMatchWOgWOgsfEC", 0.0);
288 desc.
add<
double>(
"minMVAWOgWgsfBL", 0.0);
289 desc.
add<
double>(
"minMVAWgWgsfEC", 0.0);
290 desc.
add<
int>(
"verbosity", 0);
291 desc.
add<
std::string>(
"mvaName_NoEleMatch_wGwoGSF_EC",
"gbr_NoEleMatch_wGwoGSF_EC");
294 desc.
add<
std::string>(
"mvaName_NoEleMatch_woGwoGSF_EC",
"gbr_NoEleMatch_woGwoGSF_EC");
295 desc.
add<
double>(
"minMVANoEleMatchWgWOgsfEC", 0.0);
296 descriptions.
add(
"pfRecoTauDiscriminationAgainstElectronMVA6", desc);
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
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
edm::EDGetTokenT< reco::GsfElectronCollection > GsfElectrons_token
void beginEvent(const edm::Event &, const edm::EventSetup &) override
edm::Handle< TauCollection > taus_
bool isInEcalCrack(double) const
#define DEFINE_FWK_MODULE(type)
double eta() const
pseudorapidity of momentum vector
double pt() const
track transverse momentum
edm::InputTag srcGsfElectrons_
Abs< T >::type abs(const T &t)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool isNonnull() const
Checks for non-null.
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
std::unique_ptr< PFTauDiscriminator > category_output_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
PFRecoTauDiscriminationAgainstElectronMVA6(const edm::ParameterSet &cfg)
std::unique_ptr< AntiElectronIDMVA6 > mva_
reco::GsfTrackRef gsfTrackRef() const
edm::Handle< reco::GsfElectronCollection > gsfElectrons_
void endEvent(edm::Event &) override