32 qualityCutsPSet_(pset.getParameter<edm::
ParameterSet>(
"qualityCuts"))
35 "ApplyDiscriminationByTrackerIsolation");
37 "ApplyDiscriminationByECALIsolation");
39 calculateWeights_ = pset.
exists(
"ApplyDiscriminationByWeightedECALIsolation") ?
40 pset.
getParameter<
bool>(
"ApplyDiscriminationByWeightedECALIsolation") :
false;
42 applyOccupancyCut_ = pset.
getParameter<
bool>(
"applyOccupancyCut");
43 maximumOccupancy_ = pset.
getParameter<uint32_t>(
"maximumOccupancy");
45 applySumPtCut_ = pset.
getParameter<
bool>(
"applySumPtCut");
46 maximumSumPt_ = pset.
getParameter<
double>(
"maximumSumPtCut");
49 "applyRelativeSumPtCut");
52 offsetRelativeSumPt_ = pset.
exists(
"relativeSumPtOffset") ?
55 storeRawOccupancy_ = pset.
exists(
"storeRawOccupancy") ?
57 storeRawSumPt_ = pset.
exists(
"storeRawSumPt") ?
59 storeRawPUsumPt_ = pset.
exists(
"storeRawPUsumPt") ?
61 storeRawFootprintCorrection_ = pset.
exists(
"storeRawFootprintCorrection") ?
62 pset.
getParameter<
bool>(
"storeRawFootprintCorrection") :
false;
63 storeRawPhotonSumPt_outsideSignalCone_ = pset.
exists(
"storeRawPhotonSumPt_outsideSignalCone") ?
64 pset.
getParameter<
bool>(
"storeRawPhotonSumPt_outsideSignalCone") :
false;
68 if ( applySumPtCut_ || applyOccupancyCut_ || applyRelativeSumPtCut_ ) {
69 if ( storeRawSumPt_ || storeRawOccupancy_ || storeRawPUsumPt_ ) {
71 <<
"A 'store raw' and a 'apply cut' option have been set to true "
72 <<
"simultaneously. These options are mutually exclusive.";
77 if ( includeGammas_ && calculateWeights_ ) {
79 <<
"Both 'ApplyDiscriminationByECALIsolation' and 'ApplyDiscriminationByWeightedECALIsolation' "
80 <<
"have been set to true. These options are mutually exclusive.";
84 int numStoreOptions = 0;
85 if ( storeRawSumPt_ ) ++numStoreOptions;
86 if ( storeRawOccupancy_ ) ++numStoreOptions;
87 if ( storeRawPUsumPt_ ) ++numStoreOptions;
88 if ( storeRawFootprintCorrection_ ) ++numStoreOptions;
89 if ( storeRawPhotonSumPt_outsideSignalCone_ ) ++numStoreOptions;
90 if ( numStoreOptions > 1 ) {
92 <<
"Multiple 'store sum pt' and/or 'store occupancy' options are set."
93 <<
" These options are mutually exclusive.";
96 if ( pset.
exists(
"customOuterCone") ) {
97 customIsoCone_ = pset.
getParameter<
double>(
"customOuterCone");
102 applyPhotonPtSumOutsideSignalConeCut_ = ( pset.
exists(
"applyPhotonPtSumOutsideSignalConeCut") ) ?
103 pset.
getParameter<
bool>(
"applyPhotonPtSumOutsideSignalConeCut") :
false;
104 if ( applyPhotonPtSumOutsideSignalConeCut_ ) {
105 maxAbsPhotonSumPt_outsideSignalCone_ = pset.
getParameter<
double>(
"maxAbsPhotonSumPt_outsideSignalCone");
106 maxRelPhotonSumPt_outsideSignalCone_ = pset.
getParameter<
double>(
"maxRelPhotonSumPt_outsideSignalCone");
109 applyFootprintCorrection_ = ( pset.
exists(
"applyFootprintCorrection") ) ?
110 pset.
getParameter<
bool>(
"applyFootprintCorrection") :
false;
111 if ( applyFootprintCorrection_ || storeRawFootprintCorrection_ ) {
113 for ( edm::VParameterSet::const_iterator cfgFootprintCorrection = cfgFootprintCorrections.begin();
114 cfgFootprintCorrection != cfgFootprintCorrections.end(); ++cfgFootprintCorrection ) {
117 std::unique_ptr<FootprintCorrection> footprintCorrection(
new FootprintCorrection(selection, offset));
118 footprintCorrections_.push_back(
std::move(footprintCorrection));
124 "isolationQualityCuts");
128 vertexAssociator_.reset(
131 applyDeltaBeta_ = pset.
exists(
"applyDeltaBetaCorrection") ?
132 pset.
getParameter<
bool>(
"applyDeltaBetaCorrection") :
false;
134 if ( applyDeltaBeta_ || calculateWeights_ ) {
137 std::pair<edm::ParameterSet, edm::ParameterSet> puFactorizedIsoQCuts =
142 if ( pset.
exists(
"deltaBetaPUTrackPtCutOverride") ) {
143 puFactorizedIsoQCuts.second.addParameter<
double>(
145 pset.
getParameter<
double>(
"deltaBetaPUTrackPtCutOverride"));
148 puFactorizedIsoQCuts.second.addParameter<
double>(
154 puFactorizedIsoQCuts.first));
157 puFactorizedIsoQCuts.second));
160 pfCand_token = consumes<reco::PFCandidateCollection>(pfCandSrc_);
162 vertex_token = consumes<reco::VertexCollection>(vertexSrc_);
164 "isoConeSizeForDeltaBeta");
167 deltaBetaFormula_.reset(
168 new TFormula(
"DB_corr", deltaBetaFactorFormula.c_str()));
171 applyRhoCorrection_ = pset.
exists(
"applyRhoCorrection") ?
173 if ( applyRhoCorrection_ ) {
175 rho_token=consumes<double>(rhoProducer_);
176 rhoConeSize_ = pset.
getParameter<
double>(
"rhoConeSize");
177 rhoUEOffsetCorrection_ =
180 useAllPFCands_ = pset.
exists(
"UseAllPFCandsForWeights") ?
181 pset.
getParameter<
bool>(
"UseAllPFCandsForWeights") :
false;
183 verbosity_ = ( pset.
exists(
"verbosity") ) ?
192 double discriminate(
const PFTauRef& pfTau)
const override;
196 for (
auto const & inObj_ : inColl_){
197 double sum = (inObj_->pt()*inObj_->pt())/(
deltaR2(eta,phi,inObj_->eta(),inObj_->phi()));
198 if(sum > 1.0) out *= sum;
207 std::auto_ptr<tau::RecoTauQualityCuts>
qcuts_;
235 : selection_(selection),
288 vertexAssociator_->setEvent(event);
292 if ( applyDeltaBeta_ || calculateWeights_ ) {
295 event.getByToken(pfCand_token, pfCandidates);
296 chargedPFCandidatesInEvent_.clear();
297 chargedPFCandidatesInEvent_.reserve(pfCandidates->size());
298 size_t numPFCandidates = pfCandidates->size();
299 for (
size_t i = 0;
i < numPFCandidates; ++
i ) {
301 if ( pfCandidate->charge() != 0 ) {
302 chargedPFCandidatesInEvent_.push_back(pfCandidate);
308 event.getByToken(vertex_token, vertices);
309 size_t nVtxThisEvent = vertices->size();
310 deltaBetaFactorThisEvent_ = deltaBetaFormula_->Eval(nVtxThisEvent);
313 if ( applyRhoCorrection_ ) {
315 event.getByToken(rho_token, rhoHandle_);
316 rhoThisEvent_ = (*rhoHandle_ - rhoUEOffsetCorrection_)*
317 (3.14159)*rhoConeSize_*rhoConeSize_;
324 LogDebug(
"discriminate") <<
" tau: Pt = " << pfTau->pt() <<
", eta = " << pfTau->eta() <<
", phi = " << pfTau->phi();
325 LogDebug(
"discriminate") << *pfTau ;
328 std::vector<PFCandidatePtr> isoCharged_;
329 std::vector<PFCandidatePtr> isoNeutral_;
330 std::vector<PFCandidatePtr> isoPU_;
332 std::vector<PFCandidatePtr> chPV_;
333 isoCharged_.reserve(pfTau->isolationPFChargedHadrCands().size());
334 isoNeutral_.reserve(pfTau->isolationPFGammaCands().size());
335 isoPU_.reserve(chargedPFCandidatesInEvent_.size());
336 isoNeutralWeight_.reserve(pfTau->isolationPFGammaCands().size());
338 chPV_.reserve(chargedPFCandidatesInEvent_.size());
346 LogTrace(
"discriminate") <<
"pv: x = " << pv->position().x() <<
", y = " << pv->position().y() <<
", z = " << pv->position().z() ;
348 LogTrace(
"discriminate") <<
"pv: N/A" ;
350 if ( pfTau->leadPFChargedHadrCand().
isNonnull() ) {
351 LogTrace(
"discriminate") <<
"leadPFChargedHadron:"
352 <<
" Pt = " << pfTau->leadPFChargedHadrCand()->pt() <<
","
353 <<
" eta = " << pfTau->leadPFChargedHadrCand()->eta() <<
","
354 <<
" phi = " << pfTau->leadPFChargedHadrCand()->phi() ;
356 LogTrace(
"discriminate") <<
"leadPFChargedHadron: N/A" ;
364 qcuts_->setLeadTrack(pfTau->leadPFChargedHadrCand());
366 if ( applyDeltaBeta_ || calculateWeights_) {
367 pileupQcutsGeneralQCuts_->setPV(pv);
368 pileupQcutsGeneralQCuts_->setLeadTrack(pfTau->leadPFChargedHadrCand());
369 pileupQcutsPUTrackSelection_->setPV(pv);
370 pileupQcutsPUTrackSelection_->setLeadTrack(pfTau->leadPFChargedHadrCand());
374 if ( includeTracks_ ) {
375 for(
auto const & cand : pfTau->isolationPFChargedHadrCands() ) {
376 if ( qcuts_->filterCandRef(cand) ) {
377 LogTrace(
"discriminate") <<
"adding charged iso cand with pt " << cand->pt() ;
378 isoCharged_.push_back(cand);
382 if ( includeGammas_ || calculateWeights_ ) {
383 for(
auto const & cand : pfTau->isolationPFGammaCands() ) {
384 if ( qcuts_->filterCandRef(cand) ) {
385 LogTrace(
"discriminate") <<
"adding neutral iso cand with pt " << cand->pt() ;
386 isoNeutral_.push_back(cand);
395 if ( applyDeltaBeta_ || calculateWeights_) {
398 std::cout <<
"Initial PFCands: " << chargedPFCandidatesInEvent_.size() << std::endl;
401 std::vector<PFCandidatePtr> allPU =
402 pileupQcutsPUTrackSelection_->filterCandRefs(
403 chargedPFCandidatesInEvent_,
true);
405 std::vector<PFCandidatePtr> allNPU =
406 pileupQcutsPUTrackSelection_->filterCandRefs(
407 chargedPFCandidatesInEvent_);
408 LogTrace(
"discriminate") <<
"After track cuts: " << allPU.size() ;
411 if ( !useAllPFCands_ ) {
412 std::vector<PFCandidatePtr> cleanPU =
413 pileupQcutsGeneralQCuts_->filterCandRefs(allPU);
415 std::vector<PFCandidatePtr> cleanNPU =
416 pileupQcutsGeneralQCuts_->filterCandRefs(allNPU);
418 LogTrace(
"discriminate") <<
"After cleaning cuts: " << cleanPU.size() ;
421 DRFilter deltaBetaFilter(pfTau->p4(), 0, deltaBetaCollectionCone_);
422 for (
auto const & cand : cleanPU ) {
423 if ( deltaBetaFilter(cand) ) isoPU_.push_back(cand);
426 for (
auto const & cand : cleanNPU ) {
427 if ( deltaBetaFilter(cand) ) chPV_.push_back(cand);
429 LogTrace(
"discriminate") <<
"After cone cuts: " << isoPU_.size() <<
" " << chPV_.size() ;
436 if ( calculateWeights_ ) {
437 for (
auto const & isoObject : isoNeutral_ ) {
438 if ( isoObject->charge() != 0 ) {
440 isoNeutralWeight_.push_back(*isoObject);
444 double eta = isoObject->eta();
445 double phi = isoObject->phi();
446 double sumNPU = 0.5*
log(weightedSum(chPV_, eta, phi));
448 double sumPU = 0.5*
log(weightedSum(isoPU_, eta, phi));
450 if ( (sumNPU + sumPU) > 0 ) neutral.
setP4(((sumNPU)/(sumNPU + sumPU))*neutral.
p4());
452 isoNeutralWeight_.push_back(neutral);
457 if ( customIsoCone_ >= 0. ) {
458 DRFilter
filter(pfTau->p4(), 0, customIsoCone_);
459 DRFilter2 filter2(pfTau->p4(), 0, customIsoCone_);
460 std::vector<PFCandidatePtr> isoCharged_filter;
461 std::vector<PFCandidatePtr> isoNeutral_filter;
464 for(
auto const & isoObject : isoCharged_ ) {
465 if (
filter(isoObject) ) isoCharged_filter.push_back(isoObject);
467 if(!calculateWeights_){
468 for(
auto const & isoObject : isoNeutral_ ) {
469 if (
filter(isoObject) ) isoNeutral_filter.push_back(isoObject);
471 isoNeutral_ = isoNeutral_filter;
473 for(
auto const & isoObject : isoNeutralWeight_){
474 if ( filter2(isoObject) ) isoNeutralWeight_filter.push_back(isoObject);
476 isoNeutralWeight_ = isoNeutralWeight_filter;
478 isoCharged_ = isoCharged_filter;
481 bool failsOccupancyCut =
false;
482 bool failsSumPtCut =
false;
483 bool failsRelativeSumPtCut =
false;
486 int neutrals = isoNeutral_.size();
488 if ( applyDeltaBeta_ ) {
489 neutrals -= TMath::Nint(deltaBetaFactorThisEvent_*isoPU_.size());
491 if ( neutrals < 0 ) {
495 size_t nOccupants = isoCharged_.size() + neutrals;
497 failsOccupancyCut = ( nOccupants > maximumOccupancy_ );
499 double footprintCorrection_value = 0.;
500 if ( applyFootprintCorrection_ || storeRawFootprintCorrection_ ) {
501 for ( std::vector<std::unique_ptr<FootprintCorrection> >::const_iterator footprintCorrection = footprintCorrections_.begin();
502 footprintCorrection != footprintCorrections_.end(); ++footprintCorrection ) {
503 if ( (*footprintCorrection)->selection_(*pfTau) ) {
504 footprintCorrection_value = (*footprintCorrection)->offset_(*pfTau);
512 if ( applySumPtCut_ || applyRelativeSumPtCut_ || storeRawSumPt_ || storeRawPUsumPt_ ) {
513 double chargedPt = 0.;
514 double neutralPt = 0.;
515 double weightedNeutralPt = 0.;
516 for (
auto const & isoObject : isoCharged_ ) {
517 chargedPt += isoObject->pt();
519 if ( !calculateWeights_ ) {
520 for (
auto const & isoObject : isoNeutral_ ) {
521 neutralPt += isoObject->pt();
524 for (
auto const & isoObject : isoNeutralWeight_ ) {
525 weightedNeutralPt += isoObject.pt();
528 for (
auto const & isoObject : isoPU_ ) {
529 puPt += isoObject->pt();
531 LogTrace(
"discriminate") <<
"chargedPt = " << chargedPt ;
532 LogTrace(
"discriminate") <<
"neutralPt = " << neutralPt ;
533 LogTrace(
"discriminate") <<
"weighted neutral Pt = " << weightedNeutralPt ;
534 LogTrace(
"discriminate") <<
"puPt = " << puPt <<
" (delta-beta corr. = " << (deltaBetaFactorThisEvent_*puPt) <<
")" ;
536 if ( calculateWeights_ ) {
537 neutralPt = weightedNeutralPt;
540 if ( applyDeltaBeta_ ) {
541 neutralPt -= (deltaBetaFactorThisEvent_*puPt);
544 if ( applyFootprintCorrection_ ) {
545 neutralPt -= footprintCorrection_value;
548 if ( applyRhoCorrection_ ) {
549 neutralPt -= rhoThisEvent_;
552 if ( neutralPt < 0. ) {
556 totalPt = chargedPt + neutralPt;
557 LogTrace(
"discriminate") <<
"totalPt = " << totalPt <<
" (cut = " << maximumSumPt_ <<
")" ;
559 failsSumPtCut = (totalPt > maximumSumPt_);
562 failsRelativeSumPtCut = (totalPt > ((pfTau->pt() - offsetRelativeSumPt_)*maximumRelativeSumPt_));
565 bool failsPhotonPtSumOutsideSignalConeCut =
false;
566 double photonSumPt_outsideSignalCone = 0.;
567 if ( applyPhotonPtSumOutsideSignalConeCut_ || storeRawPhotonSumPt_outsideSignalCone_ ) {
568 const std::vector<reco::PFCandidatePtr>& signalPFGammas = pfTau->signalPFGammaCands();
569 for ( std::vector<reco::PFCandidatePtr>::const_iterator signalPFGamma = signalPFGammas.begin();
570 signalPFGamma != signalPFGammas.end(); ++signalPFGamma ) {
571 double dR =
deltaR(pfTau->eta(), pfTau->phi(), (*signalPFGamma)->eta(), (*signalPFGamma)->phi());
572 if ( dR > pfTau->signalConeSize() ) photonSumPt_outsideSignalCone += (*signalPFGamma)->pt();
574 if ( photonSumPt_outsideSignalCone > maxAbsPhotonSumPt_outsideSignalCone_ || photonSumPt_outsideSignalCone > (maxRelPhotonSumPt_outsideSignalCone_*pfTau->pt()) ) {
575 failsPhotonPtSumOutsideSignalConeCut =
true;
579 bool fails = (applyOccupancyCut_ && failsOccupancyCut) ||
580 (applySumPtCut_ && failsSumPtCut) ||
581 (applyRelativeSumPtCut_ && failsRelativeSumPtCut) ||
582 (applyPhotonPtSumOutsideSignalConeCut_ && failsPhotonPtSumOutsideSignalConeCut);
585 if ( storeRawSumPt_ ) {
587 }
else if ( storeRawPUsumPt_ ) {
588 if ( applyDeltaBeta_ )
return puPt;
589 else if ( applyRhoCorrection_ )
return rhoThisEvent_;
591 }
else if ( storeRawOccupancy_ ) {
593 }
else if ( storeRawFootprintCorrection_ ) {
594 return footprintCorrection_value;
595 }
else if ( storeRawPhotonSumPt_outsideSignalCone_ ) {
596 return photonSumPt_outsideSignalCone;
598 return (fails ? 0. : 1.);
PFRecoTauDiscriminationByIsolation(const edm::ParameterSet &pset)
T getParameter(std::string const &) const
double weightedSum(std::vector< PFCandidatePtr > inColl_, double eta, double phi) 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
virtual void setP4(const LorentzVector &p4)
set 4-momentum
double deltaR(const T1 &t1, const T2 &t2)
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
double deltaR2(const T1 &t1, const T2 &t2)
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
uint32_t maximumOccupancy_
double maxRelPhotonSumPt_outsideSignalCone_
Particle reconstructed by the particle flow algorithm.
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
four-momentum Lorentz vector
edm::EDGetTokenT< reco::VertexCollection > vertex_token