32 qualityCutsPSet_(pset.getParameter<edm::
ParameterSet>(
"qualityCuts"))
35 "ApplyDiscriminationByTrackerIsolation");
37 "ApplyDiscriminationByECALIsolation");
39 calculateWeights_ = pset.
exists(
"ApplyDiscriminationByWeightedECALIsolation") ?
40 pset.
getParameter<
bool>(
"ApplyDiscriminationByWeightedECALIsolation") :
false;
43 minPtForNoIso_ = pset.
exists(
"minTauPtForNoIso") ?
46 applyOccupancyCut_ = pset.
getParameter<
bool>(
"applyOccupancyCut");
47 maximumOccupancy_ = pset.
getParameter<uint32_t>(
"maximumOccupancy");
49 applySumPtCut_ = pset.
getParameter<
bool>(
"applySumPtCut");
50 maximumSumPt_ = pset.
getParameter<
double>(
"maximumSumPtCut");
53 "applyRelativeSumPtCut");
56 offsetRelativeSumPt_ = pset.
exists(
"relativeSumPtOffset") ?
59 storeRawOccupancy_ = pset.
exists(
"storeRawOccupancy") ?
61 storeRawSumPt_ = pset.
exists(
"storeRawSumPt") ?
63 storeRawPUsumPt_ = pset.
exists(
"storeRawPUsumPt") ?
65 storeRawFootprintCorrection_ = pset.
exists(
"storeRawFootprintCorrection") ?
66 pset.
getParameter<
bool>(
"storeRawFootprintCorrection") :
false;
67 storeRawPhotonSumPt_outsideSignalCone_ = pset.
exists(
"storeRawPhotonSumPt_outsideSignalCone") ?
68 pset.
getParameter<
bool>(
"storeRawPhotonSumPt_outsideSignalCone") :
false;
72 if ( applySumPtCut_ || applyOccupancyCut_ || applyRelativeSumPtCut_ ) {
73 if ( storeRawSumPt_ || storeRawOccupancy_ || storeRawPUsumPt_ ) {
75 <<
"A 'store raw' and a 'apply cut' option have been set to true "
76 <<
"simultaneously. These options are mutually exclusive.";
81 if ( includeGammas_ && calculateWeights_ ) {
83 <<
"Both 'ApplyDiscriminationByECALIsolation' and 'ApplyDiscriminationByWeightedECALIsolation' "
84 <<
"have been set to true. These options are mutually exclusive.";
88 int numStoreOptions = 0;
89 if ( storeRawSumPt_ ) ++numStoreOptions;
90 if ( storeRawOccupancy_ ) ++numStoreOptions;
91 if ( storeRawPUsumPt_ ) ++numStoreOptions;
92 if ( storeRawFootprintCorrection_ ) ++numStoreOptions;
93 if ( storeRawPhotonSumPt_outsideSignalCone_ ) ++numStoreOptions;
94 if ( numStoreOptions > 1 ) {
96 <<
"Multiple 'store sum pt' and/or 'store occupancy' options are set."
97 <<
" These options are mutually exclusive.";
100 if ( pset.
exists(
"customOuterCone") ) {
101 customIsoCone_ = pset.
getParameter<
double>(
"customOuterCone");
106 applyPhotonPtSumOutsideSignalConeCut_ = ( pset.
exists(
"applyPhotonPtSumOutsideSignalConeCut") ) ?
107 pset.
getParameter<
bool>(
"applyPhotonPtSumOutsideSignalConeCut") :
false;
108 if ( applyPhotonPtSumOutsideSignalConeCut_ ) {
109 maxAbsPhotonSumPt_outsideSignalCone_ = pset.
getParameter<
double>(
"maxAbsPhotonSumPt_outsideSignalCone");
110 maxRelPhotonSumPt_outsideSignalCone_ = pset.
getParameter<
double>(
"maxRelPhotonSumPt_outsideSignalCone");
113 applyFootprintCorrection_ = ( pset.
exists(
"applyFootprintCorrection") ) ?
114 pset.
getParameter<
bool>(
"applyFootprintCorrection") :
false;
115 if ( applyFootprintCorrection_ || storeRawFootprintCorrection_ ) {
117 for ( edm::VParameterSet::const_iterator cfgFootprintCorrection = cfgFootprintCorrections.begin();
118 cfgFootprintCorrection != cfgFootprintCorrections.end(); ++cfgFootprintCorrection ) {
122 footprintCorrections_.push_back(
std::move(footprintCorrection));
128 "isolationQualityCuts");
132 vertexAssociator_.reset(
135 applyDeltaBeta_ = pset.
exists(
"applyDeltaBetaCorrection") ?
136 pset.
getParameter<
bool>(
"applyDeltaBetaCorrection") :
false;
138 if ( applyDeltaBeta_ || calculateWeights_ ) {
141 std::pair<edm::ParameterSet, edm::ParameterSet> puFactorizedIsoQCuts =
146 if ( pset.
exists(
"deltaBetaPUTrackPtCutOverride") ) {
147 puFactorizedIsoQCuts.second.addParameter<
double>(
149 pset.
getParameter<
double>(
"deltaBetaPUTrackPtCutOverride"));
152 puFactorizedIsoQCuts.second.addParameter<
double>(
158 puFactorizedIsoQCuts.first));
161 puFactorizedIsoQCuts.second));
164 pfCand_token = consumes<reco::PFCandidateCollection>(pfCandSrc_);
166 vertex_token = consumes<reco::VertexCollection>(vertexSrc_);
168 "isoConeSizeForDeltaBeta");
171 deltaBetaFormula_.reset(
172 new TFormula(
"DB_corr", deltaBetaFactorFormula.c_str()));
175 applyRhoCorrection_ = pset.
exists(
"applyRhoCorrection") ?
177 if ( applyRhoCorrection_ ) {
179 rho_token=consumes<double>(rhoProducer_);
180 rhoConeSize_ = pset.
getParameter<
double>(
"rhoConeSize");
181 rhoUEOffsetCorrection_ =
184 useAllPFCands_ = pset.
exists(
"UseAllPFCandsForWeights") ?
185 pset.
getParameter<
bool>(
"UseAllPFCandsForWeights") :
false;
187 verbosity_ = ( pset.
exists(
"verbosity") ) ?
196 double discriminate(
const PFTauRef& pfTau)
const override;
198 inline double weightedSum(
const std::vector<PFCandidatePtr>& inColl_,
double eta,
double phi)
const {
200 for (
auto const & inObj_ : inColl_){
201 double sum = (inObj_->pt()*inObj_->pt())/(
deltaR2(eta,phi,inObj_->eta(),inObj_->phi()));
202 if(sum > 1.0) out *= sum;
211 std::auto_ptr<tau::RecoTauQualityCuts>
qcuts_;
241 : selection_(selection),
294 vertexAssociator_->setEvent(event);
298 if ( applyDeltaBeta_ || calculateWeights_ ) {
301 event.getByToken(pfCand_token, pfCandidates);
302 chargedPFCandidatesInEvent_.clear();
303 chargedPFCandidatesInEvent_.reserve(pfCandidates->size());
304 size_t numPFCandidates = pfCandidates->size();
305 for (
size_t i = 0;
i < numPFCandidates; ++
i ) {
307 if ( pfCandidate->charge() != 0 ) {
308 chargedPFCandidatesInEvent_.push_back(pfCandidate);
314 event.getByToken(vertex_token, vertices);
315 size_t nVtxThisEvent = vertices->size();
316 deltaBetaFactorThisEvent_ = deltaBetaFormula_->Eval(nVtxThisEvent);
319 if ( applyRhoCorrection_ ) {
321 event.getByToken(rho_token, rhoHandle_);
322 rhoThisEvent_ = (*rhoHandle_ - rhoUEOffsetCorrection_)*
323 (3.14159)*rhoConeSize_*rhoConeSize_;
330 LogDebug(
"discriminate") <<
" tau: Pt = " << pfTau->pt() <<
", eta = " << pfTau->eta() <<
", phi = " << pfTau->phi();
331 LogDebug(
"discriminate") << *pfTau ;
334 std::vector<PFCandidatePtr> isoCharged_;
335 std::vector<PFCandidatePtr> isoNeutral_;
336 std::vector<PFCandidatePtr> isoPU_;
338 std::vector<PFCandidatePtr> chPV_;
339 isoCharged_.reserve(pfTau->isolationPFChargedHadrCands().size());
340 isoNeutral_.reserve(pfTau->isolationPFGammaCands().size());
341 isoPU_.reserve(
std::min(100UL, chargedPFCandidatesInEvent_.size()));
342 isoNeutralWeight_.reserve(pfTau->isolationPFGammaCands().size());
344 chPV_.reserve(
std::min(50UL, chargedPFCandidatesInEvent_.size()));
352 LogTrace(
"discriminate") <<
"pv: x = " << pv->position().x() <<
", y = " << pv->position().y() <<
", z = " << pv->position().z() ;
354 LogTrace(
"discriminate") <<
"pv: N/A" ;
356 if ( pfTau->leadPFChargedHadrCand().
isNonnull() ) {
357 LogTrace(
"discriminate") <<
"leadPFChargedHadron:"
358 <<
" Pt = " << pfTau->leadPFChargedHadrCand()->pt() <<
","
359 <<
" eta = " << pfTau->leadPFChargedHadrCand()->eta() <<
","
360 <<
" phi = " << pfTau->leadPFChargedHadrCand()->phi() ;
362 LogTrace(
"discriminate") <<
"leadPFChargedHadron: N/A" ;
370 qcuts_->setLeadTrack(pfTau->leadPFChargedHadrCand());
372 if ( applyDeltaBeta_ || calculateWeights_) {
373 pileupQcutsGeneralQCuts_->setPV(pv);
374 pileupQcutsGeneralQCuts_->setLeadTrack(pfTau->leadPFChargedHadrCand());
375 pileupQcutsPUTrackSelection_->setPV(pv);
376 pileupQcutsPUTrackSelection_->setLeadTrack(pfTau->leadPFChargedHadrCand());
380 if ( includeTracks_ ) {
381 for(
auto const & cand : pfTau->isolationPFChargedHadrCands() ) {
382 if ( qcuts_->filterCandRef(cand) ) {
383 LogTrace(
"discriminate") <<
"adding charged iso cand with pt " << cand->pt() ;
384 isoCharged_.push_back(cand);
388 if ( includeGammas_ || calculateWeights_ ) {
389 for(
auto const & cand : pfTau->isolationPFGammaCands() ) {
390 if ( qcuts_->filterCandRef(cand) ) {
391 LogTrace(
"discriminate") <<
"adding neutral iso cand with pt " << cand->pt() ;
392 isoNeutral_.push_back(cand);
401 if ( applyDeltaBeta_ || calculateWeights_) {
404 std::cout <<
"Initial PFCands: " << chargedPFCandidatesInEvent_.size() << std::endl;
407 std::vector<PFCandidatePtr> allPU =
408 pileupQcutsPUTrackSelection_->filterCandRefs(
409 chargedPFCandidatesInEvent_,
true);
411 std::vector<PFCandidatePtr> allNPU =
412 pileupQcutsPUTrackSelection_->filterCandRefs(
413 chargedPFCandidatesInEvent_);
414 LogTrace(
"discriminate") <<
"After track cuts: " << allPU.size() ;
417 if ( !useAllPFCands_ ) {
418 std::vector<PFCandidatePtr> cleanPU =
419 pileupQcutsGeneralQCuts_->filterCandRefs(allPU);
421 std::vector<PFCandidatePtr> cleanNPU =
422 pileupQcutsGeneralQCuts_->filterCandRefs(allNPU);
424 LogTrace(
"discriminate") <<
"After cleaning cuts: " << cleanPU.size() ;
427 DRFilter deltaBetaFilter(pfTau->p4(), 0, deltaBetaCollectionCone_);
428 for (
auto const & cand : cleanPU ) {
429 if ( deltaBetaFilter(cand) ) isoPU_.push_back(cand);
432 for (
auto const & cand : cleanNPU ) {
433 if ( deltaBetaFilter(cand) ) chPV_.push_back(cand);
435 LogTrace(
"discriminate") <<
"After cone cuts: " << isoPU_.size() <<
" " << chPV_.size() ;
442 if ( calculateWeights_ ) {
443 for (
auto const & isoObject : isoNeutral_ ) {
444 if ( isoObject->charge() != 0 ) {
446 isoNeutralWeight_.push_back(*isoObject);
450 double eta = isoObject->eta();
451 double phi = isoObject->phi();
452 double sumNPU = 0.5*
log(weightedSum(chPV_, eta, phi));
454 double sumPU = 0.5*
log(weightedSum(isoPU_, eta, phi));
456 if ( (sumNPU + sumPU) > 0 ) neutral.
setP4(((sumNPU)/(sumNPU + sumPU))*neutral.
p4());
458 isoNeutralWeight_.push_back(neutral);
463 if ( customIsoCone_ >= 0. ) {
464 DRFilter
filter(pfTau->p4(), 0, customIsoCone_);
465 DRFilter2 filter2(pfTau->p4(), 0, customIsoCone_);
466 std::vector<PFCandidatePtr> isoCharged_filter;
467 std::vector<PFCandidatePtr> isoNeutral_filter;
470 for(
auto const & isoObject : isoCharged_ ) {
471 if (
filter(isoObject) ) isoCharged_filter.push_back(isoObject);
473 if(!calculateWeights_){
474 for(
auto const & isoObject : isoNeutral_ ) {
475 if (
filter(isoObject) ) isoNeutral_filter.push_back(isoObject);
477 isoNeutral_ = isoNeutral_filter;
479 for(
auto const & isoObject : isoNeutralWeight_){
480 if ( filter2(isoObject) ) isoNeutralWeight_filter.push_back(isoObject);
482 isoNeutralWeight_ = isoNeutralWeight_filter;
484 isoCharged_ = isoCharged_filter;
487 bool failsOccupancyCut =
false;
488 bool failsSumPtCut =
false;
489 bool failsRelativeSumPtCut =
false;
492 int neutrals = isoNeutral_.size();
494 if ( applyDeltaBeta_ ) {
495 neutrals -= TMath::Nint(deltaBetaFactorThisEvent_*isoPU_.size());
497 if ( neutrals < 0 ) {
501 size_t nOccupants = isoCharged_.size() + neutrals;
503 failsOccupancyCut = ( nOccupants > maximumOccupancy_ );
505 double footprintCorrection_value = 0.;
506 if ( applyFootprintCorrection_ || storeRawFootprintCorrection_ ) {
507 for ( std::vector<std::unique_ptr<FootprintCorrection> >::const_iterator
footprintCorrection = footprintCorrections_.begin();
509 if ( (*footprintCorrection)->selection_(*pfTau) ) {
510 footprintCorrection_value = (*footprintCorrection)->offset_(*pfTau);
518 if ( applySumPtCut_ || applyRelativeSumPtCut_ || storeRawSumPt_ || storeRawPUsumPt_ ) {
519 double chargedPt = 0.;
520 double neutralPt = 0.;
521 double weightedNeutralPt = 0.;
522 for (
auto const & isoObject : isoCharged_ ) {
523 chargedPt += isoObject->pt();
525 if ( !calculateWeights_ ) {
526 for (
auto const & isoObject : isoNeutral_ ) {
527 neutralPt += isoObject->pt();
530 for (
auto const & isoObject : isoNeutralWeight_ ) {
531 weightedNeutralPt += isoObject.pt();
534 for (
auto const & isoObject : isoPU_ ) {
535 puPt += isoObject->pt();
537 LogTrace(
"discriminate") <<
"chargedPt = " << chargedPt ;
538 LogTrace(
"discriminate") <<
"neutralPt = " << neutralPt ;
539 LogTrace(
"discriminate") <<
"weighted neutral Pt = " << weightedNeutralPt ;
540 LogTrace(
"discriminate") <<
"puPt = " << puPt <<
" (delta-beta corr. = " << (deltaBetaFactorThisEvent_*puPt) <<
")" ;
542 if ( calculateWeights_ ) {
543 neutralPt = weightedNeutralPt;
546 if ( applyDeltaBeta_ ) {
547 neutralPt -= (deltaBetaFactorThisEvent_*puPt);
550 if ( applyFootprintCorrection_ ) {
551 neutralPt -= footprintCorrection_value;
554 if ( applyRhoCorrection_ ) {
555 neutralPt -= rhoThisEvent_;
558 if ( neutralPt < 0. ) {
562 totalPt = chargedPt + neutralPt;
563 LogTrace(
"discriminate") <<
"totalPt = " << totalPt <<
" (cut = " << maximumSumPt_ <<
")" ;
565 failsSumPtCut = (totalPt > maximumSumPt_);
568 failsRelativeSumPtCut = (totalPt > ((pfTau->pt() - offsetRelativeSumPt_)*maximumRelativeSumPt_));
571 bool failsPhotonPtSumOutsideSignalConeCut =
false;
572 double photonSumPt_outsideSignalCone = 0.;
573 if ( applyPhotonPtSumOutsideSignalConeCut_ || storeRawPhotonSumPt_outsideSignalCone_ ) {
574 const std::vector<reco::PFCandidatePtr>& signalPFGammas = pfTau->signalPFGammaCands();
575 for ( std::vector<reco::PFCandidatePtr>::const_iterator signalPFGamma = signalPFGammas.begin();
576 signalPFGamma != signalPFGammas.end(); ++signalPFGamma ) {
577 double dR =
deltaR(pfTau->eta(), pfTau->phi(), (*signalPFGamma)->eta(), (*signalPFGamma)->phi());
578 if ( dR > pfTau->signalConeSize() ) photonSumPt_outsideSignalCone += (*signalPFGamma)->pt();
580 if ( photonSumPt_outsideSignalCone > maxAbsPhotonSumPt_outsideSignalCone_ || photonSumPt_outsideSignalCone > (maxRelPhotonSumPt_outsideSignalCone_*pfTau->pt()) ) {
581 failsPhotonPtSumOutsideSignalConeCut =
true;
585 bool fails = (applyOccupancyCut_ && failsOccupancyCut) ||
586 (applySumPtCut_ && failsSumPtCut) ||
587 (applyRelativeSumPtCut_ && failsRelativeSumPtCut) ||
588 (applyPhotonPtSumOutsideSignalConeCut_ && failsPhotonPtSumOutsideSignalConeCut);
591 if (pfTau->pt() > minPtForNoIso_ && minPtForNoIso_ > 0.){
593 LogDebug(
"discriminate") <<
"tau pt = " << pfTau->pt() <<
"\t min cutoff pt = " << minPtForNoIso_ ;
597 if ( storeRawSumPt_ ) {
599 }
else if ( storeRawPUsumPt_ ) {
600 if ( applyDeltaBeta_ )
return puPt;
601 else if ( applyRhoCorrection_ )
return rhoThisEvent_;
603 }
else if ( storeRawOccupancy_ ) {
605 }
else if ( storeRawFootprintCorrection_ ) {
606 return footprintCorrection_value;
607 }
else if ( storeRawPhotonSumPt_outsideSignalCone_ ) {
608 return photonSumPt_outsideSignalCone;
610 return (fails ? 0. : 1.);
PFRecoTauDiscriminationByIsolation(const edm::ParameterSet &pset)
T getParameter(std::string const &) const
edm::EDGetTokenT< double > rho_token
bool isNonnull() const
Checks for non-null.
std::auto_ptr< tau::RecoTauQualityCuts > pileupQcutsGeneralQCuts_
bool applyPhotonPtSumOutsideSignalConeCut_
#define DEFINE_FWK_MODULE(type)
std::vector< ParameterSet > VParameterSet
~PFRecoTauDiscriminationByIsolation()
void beginEvent(const edm::Event &evt, const edm::EventSetup &evtSetup) override
bool exists(std::string const ¶meterName) const
checks if a parameter exists
double weightedSum(const std::vector< PFCandidatePtr > &inColl_, double eta, double phi) const
double rhoUEOffsetCorrection_
double maximumRelativeSumPt_
bool applyRelativeSumPtCut_
std::vector< PFCandidatePtr > pfCandidates(const PFJet &jet, int particleId, bool sort=true)
double rhoCorrectionThisEvent_
double deltaBetaFactorThisEvent_
bool applyFootprintCorrection_
double offsetRelativeSumPt_
std::vector< std::unique_ptr< FootprintCorrection > > footprintCorrections_
edm::EDGetTokenT< reco::PFCandidateCollection > pfCand_token
auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
std::vector< reco::PFCandidatePtr > chargedPFCandidatesInEvent_
bool storeRawFootprintCorrection_
std::pair< edm::ParameterSet, edm::ParameterSet > factorizePUQCuts(const edm::ParameterSet &inputSet)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
double discriminate(const PFTauRef &pfTau) const override
std::auto_ptr< tau::RecoTauQualityCuts > qcuts_
std::auto_ptr< tau::RecoTauQualityCuts > pileupQcutsPUTrackSelection_
double deltaBetaCollectionCone_
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
ParameterSet const & getParameterSet(std::string const &) const
virtual void setP4(const LorentzVector &p4) final
set 4-momentum
uint32_t maximumOccupancy_
Geom::Phi< T > phi() const
T1 deltaR2(T1 eta1, T2 phi1, T3 eta2, T4 phi2)
double maxRelPhotonSumPt_outsideSignalCone_
Particle reconstructed by the particle flow algorithm.
tuple footprintCorrection
std::auto_ptr< tau::RecoTauVertexAssociator > vertexAssociator_
edm::InputTag rhoProducer_
std::auto_ptr< TFormula > deltaBetaFormula_
double maxAbsPhotonSumPt_outsideSignalCone_
bool storeRawPhotonSumPt_outsideSignalCone_
edm::ParameterSet qualityCutsPSet_
virtual const LorentzVector & p4() const final
four-momentum Lorentz vector
edm::EDGetTokenT< reco::VertexCollection > vertex_token