39 throw cms::Exception(
"PFRecoTauDiscriminationAgainstElectronMVA5GBR")
40 <<
" Failed to find File = " << gbrFile_ <<
" !!\n";
43 minMVANoEleMatchWOgWOgsfBL_ = iConfig.
getParameter<
double>(
"minMVANoEleMatchWOgWOgsfBL");
44 minMVANoEleMatchWOgWgsfBL_ = iConfig.
getParameter<
double>(
"minMVANoEleMatchWOgWgsfBL");
45 minMVANoEleMatchWgWOgsfBL_ = iConfig.
getParameter<
double>(
"minMVANoEleMatchWgWOgsfBL");
46 minMVANoEleMatchWgWgsfBL_ = iConfig.
getParameter<
double>(
"minMVANoEleMatchWgWgsfBL");
47 minMVAWOgWOgsfBL_ = iConfig.
getParameter<
double>(
"minMVAWOgWOgsfBL");
48 minMVAWOgWgsfBL_ = iConfig.
getParameter<
double>(
"minMVAWOgWgsfBL");
49 minMVAWgWOgsfBL_ = iConfig.
getParameter<
double>(
"minMVAWgWOgsfBL");
50 minMVAWgWgsfBL_ = iConfig.
getParameter<
double>(
"minMVAWgWgsfBL");
51 minMVANoEleMatchWOgWOgsfEC_ = iConfig.
getParameter<
double>(
"minMVANoEleMatchWOgWOgsfEC");
52 minMVANoEleMatchWOgWgsfEC_ = iConfig.
getParameter<
double>(
"minMVANoEleMatchWOgWgsfEC");
53 minMVANoEleMatchWgWOgsfEC_ = iConfig.
getParameter<
double>(
"minMVANoEleMatchWgWOgsfEC");
54 minMVANoEleMatchWgWgsfEC_ = iConfig.
getParameter<
double>(
"minMVANoEleMatchWgWgsfEC");
55 minMVAWOgWOgsfEC_ = iConfig.
getParameter<
double>(
"minMVAWOgWOgsfEC");
56 minMVAWOgWgsfEC_ = iConfig.
getParameter<
double>(
"minMVAWOgWgsfEC");
57 minMVAWgWOgsfEC_ = iConfig.
getParameter<
double>(
"minMVAWgWOgsfEC");
58 minMVAWgWgsfEC_ = iConfig.
getParameter<
double>(
"minMVAWgWgsfEC");
61 GsfElectrons_token = consumes<reco::GsfElectronCollection>(srcGsfElectrons_);
64 mva_->Initialize_from_file(method_, gbrFile_.fullPath().data());
66 verbosity_ = ( iConfig.
exists(
"verbosity") ) ?
71 produces<PFTauDiscriminator>(
"category");
77 double discriminate(
const PFTauRef&);
87 bool isInEcalCrack(
double)
const;
126 evt.
getByToken(GsfElectrons_token, gsfElectrons_);
132 double workingPoint = 1.;
134 bool isGsfElectronMatched =
false;
136 float deltaRDummy = 9.9;
137 float mvaCutDummy = 999;
139 float tauEtaAtEcalEntrance = -99.;
140 float sumEtaTimesEnergy = 0.;
141 float sumEnergy = 0.;
142 const std::vector<reco::PFCandidatePtr>& signalPFCands = thePFTauRef->signalPFCands();
143 for ( std::vector<reco::PFCandidatePtr>::const_iterator pfCandidate = signalPFCands.begin();
144 pfCandidate != signalPFCands.end(); ++pfCandidate ) {
145 sumEtaTimesEnergy += ((*pfCandidate)->positionAtECALEntrance().eta()*(*pfCandidate)->energy());
146 sumEnergy += (*pfCandidate)->energy();
148 if ( sumEnergy > 0. ) {
149 tauEtaAtEcalEntrance = sumEtaTimesEnergy/sumEnergy;
152 float leadChargedPFCandEtaAtEcalEntrance = -99.;
153 float leadChargedPFCandPt = -99.;
154 for ( std::vector<reco::PFCandidatePtr>::const_iterator pfCandidate = signalPFCands.begin();
155 pfCandidate != signalPFCands.end(); ++pfCandidate ) {
157 if ( (*pfCandidate)->trackRef().isNonnull() ) track = (*pfCandidate)->trackRef().get();
158 else if ( (*pfCandidate)->muonRef().isNonnull() && (*pfCandidate)->muonRef()->innerTrack().isNonnull() ) track = (*pfCandidate)->muonRef()->innerTrack().get();
159 else if ( (*pfCandidate)->muonRef().isNonnull() && (*pfCandidate)->muonRef()->globalTrack().isNonnull() ) track = (*pfCandidate)->muonRef()->globalTrack().get();
160 else if ( (*pfCandidate)->muonRef().isNonnull() && (*pfCandidate)->muonRef()->outerTrack().isNonnull() ) track = (*pfCandidate)->muonRef()->outerTrack().get();
161 else if ( (*pfCandidate)->gsfTrackRef().isNonnull() ) track = (*pfCandidate)->gsfTrackRef().get();
163 if ( track->
pt() > leadChargedPFCandPt ) {
164 leadChargedPFCandEtaAtEcalEntrance = (*pfCandidate)->positionAtECALEntrance().
eta();
165 leadChargedPFCandPt = track->
pt();
170 if( (*thePFTauRef).leadPFChargedHadrCand().isNonnull()) {
171 for ( reco::GsfElectronCollection::const_iterator theGsfElectron = gsfElectrons_->begin();
172 theGsfElectron != gsfElectrons_->end(); ++theGsfElectron ) {
173 if ( theGsfElectron->pt() > 10. ) {
174 double deltaREleTau =
deltaR(theGsfElectron->p4(), thePFTauRef->p4());
175 deltaRDummy = deltaREleTau;
176 if ( deltaREleTau < 0.3 ) {
177 double mva_match = mva_->MVAValue(*thePFTauRef, *theGsfElectron);
178 double workingPoint_match = 0.;
179 size_t numSignalPFGammaCands = thePFTauRef->signalPFGammaCands().size();
180 bool hasGsfTrack = thePFTauRef->leadPFChargedHadrCand()->gsfTrackRef().
isNonnull();
183 if ( isInEcalCrack(tauEtaAtEcalEntrance) || isInEcalCrack(leadChargedPFCandEtaAtEcalEntrance) ) {
186 category_output_->setValue(tauIndex_, category);
197 double mvaCut = 999.;
198 if ( TMath::Abs(tauEtaAtEcalEntrance) < 1.479 ) {
199 if ( numSignalPFGammaCands == 0 && !hasGsfTrack ) {
201 mvaCut = minMVAWOgWOgsfBL_;
202 }
else if ( numSignalPFGammaCands == 0 && hasGsfTrack ) {
204 mvaCut = minMVAWOgWgsfBL_;
205 }
else if ( numSignalPFGammaCands >= 1 && !hasGsfTrack ) {
207 mvaCut = minMVAWgWOgsfBL_;
208 }
else if ( numSignalPFGammaCands >= 1 && hasGsfTrack ) {
210 mvaCut = minMVAWgWgsfBL_;
213 if ( numSignalPFGammaCands == 0 && !hasGsfTrack ) {
215 mvaCut = minMVAWOgWOgsfEC_;
216 }
else if ( numSignalPFGammaCands == 0 && hasGsfTrack ) {
218 mvaCut = minMVAWOgWgsfEC_;
219 }
else if ( numSignalPFGammaCands >= 1 && !hasGsfTrack ) {
221 mvaCut = minMVAWgWOgsfEC_;
222 }
else if ( numSignalPFGammaCands >= 1 && hasGsfTrack ) {
224 mvaCut = minMVAWgWgsfEC_;
227 workingPoint_match = (mva_match > mvaCut);
228 mvaCutDummy = mvaCut;
231 workingPoint =
TMath::Min(workingPoint, workingPoint_match);
232 isGsfElectronMatched =
true;
237 if ( !isGsfElectronMatched ) {
238 mva = mva_->MVAValue(*thePFTauRef);
239 size_t numSignalPFGammaCands = thePFTauRef->signalPFGammaCands().size();
240 bool hasGsfTrack = thePFTauRef->leadPFChargedHadrCand()->gsfTrackRef().
isNonnull();
243 if ( isInEcalCrack(tauEtaAtEcalEntrance) || isInEcalCrack(leadChargedPFCandEtaAtEcalEntrance) ) {
246 category_output_->setValue(tauIndex_, category);
257 double mvaCut = 999.;
258 if ( TMath::Abs(tauEtaAtEcalEntrance) < 1.479 ) {
259 if ( numSignalPFGammaCands == 0 && !hasGsfTrack ) {
261 mvaCut = minMVANoEleMatchWOgWOgsfBL_;
262 }
else if ( numSignalPFGammaCands == 0 && hasGsfTrack ) {
264 mvaCut = minMVANoEleMatchWOgWgsfBL_;
265 }
else if ( numSignalPFGammaCands >= 1 && !hasGsfTrack ) {
267 mvaCut = minMVANoEleMatchWgWOgsfBL_;
268 }
else if ( numSignalPFGammaCands >= 1 && hasGsfTrack ) {
270 mvaCut = minMVANoEleMatchWgWgsfBL_;
273 if ( numSignalPFGammaCands == 0 && !hasGsfTrack ) {
275 mvaCut = minMVANoEleMatchWOgWOgsfEC_;
276 }
else if ( numSignalPFGammaCands == 0 && hasGsfTrack ) {
278 mvaCut = minMVANoEleMatchWOgWgsfEC_;
279 }
else if ( numSignalPFGammaCands >= 1 && !hasGsfTrack ) {
281 mvaCut = minMVANoEleMatchWgWOgsfEC_;
282 }
else if ( numSignalPFGammaCands >= 1 && hasGsfTrack ) {
284 mvaCut = minMVANoEleMatchWgWgsfEC_;
287 workingPoint = (mva > mvaCut);
288 mvaCutDummy = mvaCut;
293 edm::LogPrint(
"PFTauAgainstEleMVA5") <<
" Taus : "<<TauProducer_;
294 edm::LogPrint(
"PFTauAgainstEleMVA5") <<
"<PFRecoTauDiscriminationAgainstElectronMVA5::discriminate>:" ;
295 edm::LogPrint(
"PFTauAgainstEleMVA5") <<
" tau: Pt = " << thePFTauRef->pt() <<
", eta = " << thePFTauRef->eta() <<
", phi = " << thePFTauRef->phi() ;
296 edm::LogPrint(
"PFTauAgainstEleMVA5") <<
" mva = " << mva <<
", mvaCut = " << mvaCutDummy <<
", isGsfElectronMatched = " << isGsfElectronMatched ;
297 edm::LogPrint(
"PFTauAgainstEleMVA5") <<
" category = " << category <<
": workingPoint = " << workingPoint ;
298 edm::LogPrint(
"PFTauAgainstEleMVA5") <<
" deltaREleTau = " << deltaRDummy ;
299 edm::LogPrint(
"PFTauAgainstEleMVA5") <<
" charged hadron in tau: "<<(*thePFTauRef).leadPFChargedHadrCand().isNonnull() ;
300 edm::LogPrint(
"PFTauAgainstEleMVA5") <<
" Prongs in tau: " << thePFTauRef->signalPFChargedHadrCands().size() ;
306 category_output_->setValue(tauIndex_, category);
319 evt.
put(category_output_,
"category");
326 double absEta = fabs(eta);
327 return (absEta > 1.460 && absEta < 1.558);
T getParameter(std::string const &) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
double minMVANoEleMatchWgWOgsfBL_
double minMVANoEleMatchWgWOgsfEC_
edm::InputTag srcGsfElectrons_
bool exists(std::string const ¶meterName) const
checks if a parameter exists
double minMVANoEleMatchWOgWOgsfBL_
bool isNonnull() const
Checks for non-null.
double eta() const
pseudorapidity of momentum vector
AntiElectronIDMVA5GBR * mva_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
double pt() const
track transverse momentum
double minMVANoEleMatchWOgWOgsfEC_
auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
PFRecoTauDiscriminationAgainstElectronMVA5GBR(const edm::ParameterSet &iConfig)
std::auto_ptr< PFTauDiscriminator > category_output_
edm::Handle< TauCollection > taus_
double minMVANoEleMatchWgWgsfEC_
double discriminate(const PFTauRef &)
DEFINE_FWK_MODULE(CosmicTrackingParticleSelector)
double minMVANoEleMatchWOgWgsfEC_
bool isInEcalCrack(double) const
double minMVANoEleMatchWOgWgsfBL_
edm::Handle< reco::GsfElectronCollection > gsfElectrons_
~PFRecoTauDiscriminationAgainstElectronMVA5GBR()
edm::EDGetTokenT< reco::GsfElectronCollection > GsfElectrons_token
double minMVANoEleMatchWgWgsfBL_
void endEvent(edm::Event &)
void beginEvent(const edm::Event &, const edm::EventSetup &)