32 moduleLabel_(
pset.getParameter<
std::
string>(
"@module_label")),
34 includeTracks_ =
pset.getParameter<
bool>(
"ApplyDiscriminationByTrackerIsolation");
35 includeGammas_ =
pset.getParameter<
bool>(
"ApplyDiscriminationByECALIsolation");
37 calculateWeights_ =
pset.getParameter<
bool>(
"ApplyDiscriminationByWeightedECALIsolation");
42 weightGammas_ =
pset.getParameter<
double>(
"WeightECALIsolation");
45 minPtForNoIso_ =
pset.getParameter<
double>(
"minTauPtForNoIso");
47 applyOccupancyCut_ =
pset.getParameter<
bool>(
"applyOccupancyCut");
48 maximumOccupancy_ =
pset.getParameter<uint32_t>(
"maximumOccupancy");
50 applySumPtCut_ =
pset.getParameter<
bool>(
"applySumPtCut");
51 maximumSumPt_ =
pset.getParameter<
double>(
"maximumSumPtCut");
53 applyRelativeSumPtCut_ =
pset.getParameter<
bool>(
"applyRelativeSumPtCut");
54 maximumRelativeSumPt_ =
pset.getParameter<
double>(
"relativeSumPtCut");
55 offsetRelativeSumPt_ =
pset.getParameter<
double>(
"relativeSumPtOffset");
57 storeRawOccupancy_ =
pset.getParameter<
bool>(
"storeRawOccupancy");
58 storeRawSumPt_ =
pset.getParameter<
bool>(
"storeRawSumPt");
59 storeRawPUsumPt_ =
pset.getParameter<
bool>(
"storeRawPUsumPt");
60 storeRawFootprintCorrection_ =
pset.getParameter<
bool>(
"storeRawFootprintCorrection");
61 storeRawPhotonSumPt_outsideSignalCone_ =
pset.getParameter<
bool>(
"storeRawPhotonSumPt_outsideSignalCone");
65 if (applySumPtCut_ || applyOccupancyCut_ || applyRelativeSumPtCut_) {
66 if (storeRawSumPt_ || storeRawOccupancy_ || storeRawPUsumPt_) {
67 throw cms::Exception(
"BadIsoConfig") <<
"A 'store raw' and a 'apply cut' option have been set to true "
68 <<
"simultaneously. These options are mutually exclusive.";
73 if (includeGammas_ && calculateWeights_) {
75 <<
"Both 'ApplyDiscriminationByECALIsolation' and 'ApplyDiscriminationByWeightedECALIsolation' "
76 <<
"have been set to true. These options are mutually exclusive.";
80 int numStoreOptions = 0;
83 if (storeRawOccupancy_)
87 if (storeRawFootprintCorrection_)
89 if (storeRawPhotonSumPt_outsideSignalCone_)
91 if (numStoreOptions > 1) {
92 throw cms::Exception(
"BadIsoConfig") <<
"Multiple 'store sum pt' and/or 'store occupancy' options are set."
93 <<
" These options are mutually exclusive.";
96 customIsoCone_ =
pset.getParameter<
double>(
"customOuterCone");
98 applyPhotonPtSumOutsideSignalConeCut_ =
pset.getParameter<
bool>(
"applyPhotonPtSumOutsideSignalConeCut");
99 if (applyPhotonPtSumOutsideSignalConeCut_) {
100 maxAbsPhotonSumPt_outsideSignalCone_ =
pset.getParameter<
double>(
"maxAbsPhotonSumPt_outsideSignalCone");
101 maxRelPhotonSumPt_outsideSignalCone_ =
pset.getParameter<
double>(
"maxRelPhotonSumPt_outsideSignalCone");
104 applyFootprintCorrection_ =
pset.getParameter<
bool>(
"applyFootprintCorrection");
105 if (applyFootprintCorrection_ || storeRawFootprintCorrection_) {
107 for (edm::VParameterSet::const_iterator cfgFootprintCorrection = cfgFootprintCorrections.begin();
108 cfgFootprintCorrection != cfgFootprintCorrections.end();
109 ++cfgFootprintCorrection) {
113 footprintCorrections_.push_back(
std::move(footprintCorrection));
124 applyDeltaBeta_ =
pset.getParameter<
bool>(
"applyDeltaBetaCorrection");
126 if (applyDeltaBeta_ || calculateWeights_) {
129 std::pair<edm::ParameterSet, edm::ParameterSet> puFactorizedIsoQCuts =
141 puFactorizedIsoQCuts.second.addParameter<
double>(
"minTrackPt",
150 pfCand_token = consumes<edm::View<reco::Candidate> >(pfCandSrc_);
152 vertex_token = consumes<reco::VertexCollection>(vertexSrc_);
153 deltaBetaCollectionCone_ =
pset.getParameter<
double>(
"isoConeSizeForDeltaBeta");
154 std::string deltaBetaFactorFormula =
pset.getParameter<
string>(
"deltaBetaFactor");
155 deltaBetaFormula_.reset(
new TFormula(
"DB_corr", deltaBetaFactorFormula.c_str()));
158 applyRhoCorrection_ =
pset.getParameter<
bool>(
"applyRhoCorrection");
159 if (applyRhoCorrection_) {
161 rho_token = consumes<double>(rhoProducer_);
162 rhoConeSize_ =
pset.getParameter<
double>(
"rhoConeSize");
163 rhoUEOffsetCorrection_ =
pset.getParameter<
double>(
"rhoUEOffsetCorrection");
165 useAllPFCands_ =
pset.getParameter<
bool>(
"UseAllPFCandsForWeights");
167 verbosity_ =
pset.getParameter<
int>(
"verbosity");
173 double discriminate(
const PFTauRef& pfTau)
const override;
175 inline double weightedSum(
const std::vector<CandidatePtr>& inColl_,
double eta,
double phi)
const {
177 for (
auto const& inObj_ : inColl_) {
178 double sum = (inObj_->pt() * inObj_->pt()) / (
deltaR2(
eta, phi, inObj_->eta(), inObj_->phi()));
191 std::unique_ptr<tau::RecoTauQualityCuts>
qcuts_;
271 vertexAssociator_->setEvent(
event);
275 if (applyDeltaBeta_ || calculateWeights_) {
279 chargedPFCandidatesInEvent_.clear();
280 chargedPFCandidatesInEvent_.reserve(
pfCandidates->size());
282 for (
size_t i = 0;
i < numPFCandidates; ++
i) {
284 if (pfCandidate->
charge() != 0) {
285 chargedPFCandidatesInEvent_.push_back(pfCandidate);
291 event.getByToken(vertex_token,
vertices);
292 size_t nVtxThisEvent =
vertices->size();
293 deltaBetaFactorThisEvent_ = deltaBetaFormula_->Eval(nVtxThisEvent);
296 if (applyRhoCorrection_) {
298 event.getByToken(rho_token, rhoHandle_);
299 rhoThisEvent_ = (*rhoHandle_ - rhoUEOffsetCorrection_) * (3.14159) * rhoConeSize_ * rhoConeSize_;
304 LogDebug(
"discriminate") <<
" tau: Pt = " << pfTau->pt() <<
", eta = " << pfTau->eta() <<
", phi = " << pfTau->phi();
308 std::vector<CandidatePtr> isoCharged_;
309 std::vector<CandidatePtr> isoNeutral_;
310 std::vector<CandidatePtr> isoPU_;
312 std::vector<CandidatePtr> chPV_;
313 isoCharged_.
reserve(pfTau->isolationChargedHadrCands().size());
314 isoNeutral_.reserve(pfTau->isolationGammaCands().size());
315 isoPU_.reserve(
std::min(100UL, chargedPFCandidatesInEvent_.size()));
316 isoNeutralWeight_.
reserve(pfTau->isolationGammaCands().size());
318 chPV_.reserve(
std::min(50UL, chargedPFCandidatesInEvent_.size()));
325 if (
pv.isNonnull()) {
326 LogTrace(
"discriminate") <<
"pv: x = " <<
pv->position().x() <<
", y = " <<
pv->position().y()
327 <<
", z = " <<
pv->position().z();
329 LogTrace(
"discriminate") <<
"pv: N/A";
331 if (pfTau->leadChargedHadrCand().
isNonnull()) {
332 LogTrace(
"discriminate") <<
"leadPFChargedHadron:"
333 <<
" Pt = " << pfTau->leadChargedHadrCand()->pt() <<
","
334 <<
" eta = " << pfTau->leadChargedHadrCand()->eta() <<
","
335 <<
" phi = " << pfTau->leadChargedHadrCand()->phi();
337 LogTrace(
"discriminate") <<
"leadPFChargedHadron: N/A";
342 if (!(
pv.isNonnull() && pfTau->leadChargedHadrCand().
isNonnull()))
346 qcuts_->setLeadTrack(*pfTau->leadChargedHadrCand());
348 if (applyDeltaBeta_ || calculateWeights_) {
349 pileupQcutsGeneralQCuts_->setPV(
pv);
350 pileupQcutsGeneralQCuts_->setLeadTrack(*pfTau->leadChargedHadrCand());
351 pileupQcutsPUTrackSelection_->setPV(
pv);
352 pileupQcutsPUTrackSelection_->setLeadTrack(*pfTau->leadChargedHadrCand());
356 if (includeTracks_) {
357 for (
auto const&
cand : pfTau->isolationChargedHadrCands()) {
358 if (qcuts_->filterCandRef(
cand)) {
359 LogTrace(
"discriminate") <<
"adding charged iso cand with pt " <<
cand->pt();
360 isoCharged_.push_back(
cand);
364 if (includeGammas_ || calculateWeights_) {
365 for (
auto const&
cand : pfTau->isolationGammaCands()) {
366 if (qcuts_->filterCandRef(
cand)) {
367 LogTrace(
"discriminate") <<
"adding neutral iso cand with pt " <<
cand->pt();
368 isoNeutral_.push_back(
cand);
377 if (applyDeltaBeta_ || calculateWeights_) {
380 std::cout <<
"Initial PFCands: " << chargedPFCandidatesInEvent_.size() << std::endl;
383 std::vector<CandidatePtr> allPU = pileupQcutsPUTrackSelection_->filterCandRefs(chargedPFCandidatesInEvent_,
true);
385 std::vector<CandidatePtr> allNPU = pileupQcutsPUTrackSelection_->filterCandRefs(chargedPFCandidatesInEvent_);
386 LogTrace(
"discriminate") <<
"After track cuts: " << allPU.size();
389 if (!useAllPFCands_) {
390 std::vector<CandidatePtr> cleanPU = pileupQcutsGeneralQCuts_->filterCandRefs(allPU);
392 std::vector<CandidatePtr> cleanNPU = pileupQcutsGeneralQCuts_->filterCandRefs(allNPU);
394 LogTrace(
"discriminate") <<
"After cleaning cuts: " << cleanPU.size();
397 DRFilter deltaBetaFilter(pfTau->p4(), 0, deltaBetaCollectionCone_);
398 for (
auto const&
cand : cleanPU) {
399 if (deltaBetaFilter(
cand))
400 isoPU_.push_back(
cand);
403 for (
auto const&
cand : cleanNPU) {
404 if (deltaBetaFilter(
cand))
405 chPV_.push_back(
cand);
407 LogTrace(
"discriminate") <<
"After cone cuts: " << isoPU_.size() <<
" " << chPV_.size();
414 if (calculateWeights_) {
415 for (
auto const& isoObject : isoNeutral_) {
416 if (isoObject->charge() != 0) {
422 double eta = isoObject->eta();
423 double phi = isoObject->phi();
424 double sumNPU = 0.5 *
log(weightedSum(chPV_,
eta, phi));
426 double sumPU = 0.5 *
log(weightedSum(isoPU_,
eta, phi));
428 if ((sumNPU + sumPU) > 0)
429 neutral.
setP4(((sumNPU) / (sumNPU + sumPU)) * neutral.
p4());
436 if (customIsoCone_ >= 0.) {
437 DRFilter
filter(pfTau->p4(), 0, customIsoCone_);
438 DRFilter2 filter2(pfTau->p4(), 0, customIsoCone_);
439 std::vector<CandidatePtr> isoCharged_filter;
440 std::vector<CandidatePtr> isoNeutral_filter;
443 for (
auto const& isoObject : isoCharged_) {
447 if (!calculateWeights_) {
448 for (
auto const& isoObject : isoNeutral_) {
450 isoNeutral_filter.push_back(isoObject);
452 isoNeutral_ = isoNeutral_filter;
454 for (
auto const& isoObject : isoNeutralWeight_) {
455 if (filter2(isoObject))
456 isoNeutralWeight_filter.
push_back(isoObject);
458 isoNeutralWeight_ = isoNeutralWeight_filter;
460 isoCharged_ = isoCharged_filter;
463 bool failsOccupancyCut =
false;
464 bool failsSumPtCut =
false;
465 bool failsRelativeSumPtCut =
false;
468 int neutrals = isoNeutral_.
size();
470 if (applyDeltaBeta_) {
471 neutrals -= TMath::Nint(deltaBetaFactorThisEvent_ * isoPU_.size());
477 size_t nOccupants = isoCharged_.size() + neutrals;
479 failsOccupancyCut = (nOccupants > maximumOccupancy_);
481 double footprintCorrection_value = 0.;
482 if (applyFootprintCorrection_ || storeRawFootprintCorrection_) {
483 for (std::vector<std::unique_ptr<FootprintCorrection> >::const_iterator footprintCorrection =
484 footprintCorrections_.begin();
485 footprintCorrection != footprintCorrections_.end();
486 ++footprintCorrection) {
487 if ((*footprintCorrection)->selection_(*pfTau)) {
488 footprintCorrection_value = (*footprintCorrection)->offset_(*pfTau);
496 if (applySumPtCut_ || applyRelativeSumPtCut_ || storeRawSumPt_ || storeRawPUsumPt_) {
497 double chargedPt = 0.;
498 double neutralPt = 0.;
499 double weightedNeutralPt = 0.;
500 for (
auto const& isoObject : isoCharged_) {
501 chargedPt += isoObject->pt();
503 if (!calculateWeights_) {
504 for (
auto const& isoObject : isoNeutral_) {
505 neutralPt += isoObject->pt();
508 for (
auto const& isoObject : isoNeutralWeight_) {
509 weightedNeutralPt += isoObject.pt();
512 for (
auto const& isoObject : isoPU_) {
513 puPt += isoObject->pt();
515 LogTrace(
"discriminate") <<
"chargedPt = " << chargedPt;
516 LogTrace(
"discriminate") <<
"neutralPt = " << neutralPt;
517 LogTrace(
"discriminate") <<
"weighted neutral Pt = " << weightedNeutralPt;
518 LogTrace(
"discriminate") <<
"puPt = " << puPt <<
" (delta-beta corr. = " << (deltaBetaFactorThisEvent_ * puPt)
521 if (calculateWeights_) {
522 neutralPt = weightedNeutralPt;
525 if (applyDeltaBeta_) {
526 neutralPt -= (deltaBetaFactorThisEvent_ * puPt);
529 if (applyFootprintCorrection_) {
530 neutralPt -= footprintCorrection_value;
533 if (applyRhoCorrection_) {
534 neutralPt -= rhoThisEvent_;
537 if (neutralPt < 0.) {
541 totalPt = chargedPt + weightGammas_ * neutralPt;
542 LogTrace(
"discriminate") <<
"totalPt = " << totalPt <<
" (cut = " << maximumSumPt_ <<
")";
544 failsSumPtCut = (totalPt > maximumSumPt_);
547 failsRelativeSumPtCut = (totalPt > ((pfTau->pt() - offsetRelativeSumPt_) * maximumRelativeSumPt_));
550 bool failsPhotonPtSumOutsideSignalConeCut =
false;
551 double photonSumPt_outsideSignalCone = 0.;
552 if (applyPhotonPtSumOutsideSignalConeCut_ || storeRawPhotonSumPt_outsideSignalCone_) {
553 const std::vector<reco::CandidatePtr>& signalGammas = pfTau->signalGammaCands();
554 for (std::vector<reco::CandidatePtr>::const_iterator signalGamma = signalGammas.begin();
555 signalGamma != signalGammas.end();
557 double dR =
deltaR(pfTau->eta(), pfTau->phi(), (*signalGamma)->eta(), (*signalGamma)->phi());
558 if (
dR > pfTau->signalConeSize())
559 photonSumPt_outsideSignalCone += (*signalGamma)->pt();
561 if (photonSumPt_outsideSignalCone > maxAbsPhotonSumPt_outsideSignalCone_ ||
562 photonSumPt_outsideSignalCone > (maxRelPhotonSumPt_outsideSignalCone_ * pfTau->pt())) {
563 failsPhotonPtSumOutsideSignalConeCut =
true;
567 bool fails = (applyOccupancyCut_ && failsOccupancyCut) || (applySumPtCut_ && failsSumPtCut) ||
568 (applyRelativeSumPtCut_ && failsRelativeSumPtCut) ||
569 (applyPhotonPtSumOutsideSignalConeCut_ && failsPhotonPtSumOutsideSignalConeCut);
571 if (pfTau->pt() > minPtForNoIso_ && minPtForNoIso_ > 0.) {
573 LogDebug(
"discriminate") <<
"tau pt = " << pfTau->pt() <<
"\t min cutoff pt = " << minPtForNoIso_;
577 if (storeRawSumPt_) {
579 }
else if (storeRawPUsumPt_) {
582 else if (applyRhoCorrection_)
583 return rhoThisEvent_;
586 }
else if (storeRawOccupancy_) {
588 }
else if (storeRawFootprintCorrection_) {
589 return footprintCorrection_value;
590 }
else if (storeRawPhotonSumPt_outsideSignalCone_) {
591 return photonSumPt_outsideSignalCone;
593 return (fails ? 0. : 1.);
600 desc.
add<
bool>(
"storeRawFootprintCorrection",
false);
602 desc.
add<
bool>(
"storeRawOccupancy",
false);
603 desc.
add<
double>(
"maximumSumPtCut", 6.0);
607 pset_signalQualityCuts.
add<
double>(
"maxDeltaZ", 0.4);
608 pset_signalQualityCuts.
add<
double>(
"minTrackPt", 0.5);
609 pset_signalQualityCuts.
add<
double>(
"minTrackVertexWeight", -1.0);
610 pset_signalQualityCuts.
add<
double>(
"maxTrackChi2", 100.0);
611 pset_signalQualityCuts.
add<
unsigned int>(
"minTrackPixelHits", 0);
612 pset_signalQualityCuts.
add<
double>(
"minGammaEt", 1.0);
613 pset_signalQualityCuts.
add<
unsigned int>(
"minTrackHits", 3);
614 pset_signalQualityCuts.
add<
double>(
"minNeutralHadronEt", 30.0);
615 pset_signalQualityCuts.
add<
double>(
"maxTransverseImpactParameter", 0.1);
616 pset_signalQualityCuts.
addOptional<
bool>(
"useTracksInsteadOfPFHadrons");
619 pset_vxAssocQualityCuts.
add<
double>(
"minTrackPt", 0.5);
620 pset_vxAssocQualityCuts.add<
double>(
"minTrackVertexWeight", -1.0);
621 pset_vxAssocQualityCuts.add<
double>(
"maxTrackChi2", 100.0);
622 pset_vxAssocQualityCuts.add<
unsigned int>(
"minTrackPixelHits", 0);
623 pset_vxAssocQualityCuts.add<
double>(
"minGammaEt", 1.0);
624 pset_vxAssocQualityCuts.add<
unsigned int>(
"minTrackHits", 3);
625 pset_vxAssocQualityCuts.add<
double>(
"maxTransverseImpactParameter", 0.1);
626 pset_vxAssocQualityCuts.addOptional<
bool>(
"useTracksInsteadOfPFHadrons");
629 pset_isolationQualityCuts.
add<
double>(
"maxDeltaZ", 0.2);
630 pset_isolationQualityCuts.add<
double>(
"minTrackPt", 1.0);
631 pset_isolationQualityCuts.add<
double>(
"minTrackVertexWeight", -1.0);
632 pset_isolationQualityCuts.add<
double>(
"maxTrackChi2", 100.0);
633 pset_isolationQualityCuts.add<
unsigned int>(
"minTrackPixelHits", 0);
634 pset_isolationQualityCuts.add<
double>(
"minGammaEt", 1.5);
635 pset_isolationQualityCuts.add<
unsigned int>(
"minTrackHits", 8);
636 pset_isolationQualityCuts.add<
double>(
"maxTransverseImpactParameter", 0.03);
637 pset_isolationQualityCuts.addOptional<
bool>(
"useTracksInsteadOfPFHadrons");
643 pset_qualityCuts.
add<
std::string>(
"leadingTrkOrPFCandOption",
"leadPFCand");
644 pset_qualityCuts.add<
std::string>(
"pvFindingAlgo",
"closestInDeltaZ");
646 pset_qualityCuts.add<
bool>(
"vertexTrackFiltering",
false);
647 pset_qualityCuts.add<
bool>(
"recoverLeadingTrk",
false);
652 desc.
add<
double>(
"minTauPtForNoIso", -99.0);
653 desc.
add<
double>(
"maxAbsPhotonSumPt_outsideSignalCone", 1000000000.0);
655 desc.
add<
bool>(
"applySumPtCut",
false);
656 desc.
add<
double>(
"rhoConeSize", 0.5);
657 desc.
add<
bool>(
"ApplyDiscriminationByTrackerIsolation",
true);
658 desc.
add<
bool>(
"storeRawPhotonSumPt_outsideSignalCone",
false);
665 desc.
addVPSet(
"footprintCorrections", vpsd1, {});
669 desc.
add<
bool>(
"applyFootprintCorrection",
false);
670 desc.
add<
bool>(
"UseAllPFCandsForWeights",
false);
671 desc.
add<
double>(
"relativeSumPtCut", 0.0);
677 psd1.
add<
double>(
"cut");
693 psd1.
add<
double>(
"cut");
706 psd1.
add<
double>(
"cut");
713 desc.
add<
unsigned int>(
"maximumOccupancy", 0);
714 desc.
add<
int>(
"verbosity", 0);
716 desc.
add<
bool>(
"applyOccupancyCut",
true);
717 desc.
add<
bool>(
"applyDeltaBetaCorrection",
false);
718 desc.
add<
bool>(
"applyRelativeSumPtCut",
false);
719 desc.
add<
bool>(
"storeRawPUsumPt",
false);
720 desc.
add<
bool>(
"applyPhotonPtSumOutsideSignalConeCut",
false);
721 desc.
add<
bool>(
"deltaBetaPUTrackPtCutOverride",
false);
722 desc.
add<
bool>(
"ApplyDiscriminationByWeightedECALIsolation",
false);
723 desc.
add<
bool>(
"storeRawSumPt",
false);
724 desc.
add<
bool>(
"ApplyDiscriminationByECALIsolation",
true);
725 desc.
add<
bool>(
"applyRhoCorrection",
false);
727 desc.
add<
double>(
"WeightECALIsolation", 1.0);
728 desc.
add<
double>(
"rhoUEOffsetCorrection", 1.0);
729 desc.
add<
double>(
"maxRelPhotonSumPt_outsideSignalCone", 0.1);
730 desc.
add<
double>(
"deltaBetaPUTrackPtCutOverride_val", -1.5);
731 desc.
add<
double>(
"isoConeSizeForDeltaBeta", 0.5);
732 desc.
add<
double>(
"relativeSumPtOffset", 0.0);
733 desc.
add<
double>(
"customOuterCone", -1.0);
736 descriptions.
add(
"pfRecoTauDiscriminationByIsolation", desc);