34 moduleLabel_(
pset.getParameter<
std::
string>(
"@module_label")),
36 includeTracks_ =
pset.getParameter<
bool>(
"ApplyDiscriminationByTrackerIsolation");
37 includeGammas_ =
pset.getParameter<
bool>(
"ApplyDiscriminationByECALIsolation");
39 calculateWeights_ =
pset.getParameter<
bool>(
"ApplyDiscriminationByWeightedECALIsolation");
44 weightGammas_ =
pset.getParameter<
double>(
"WeightECALIsolation");
47 minPtForNoIso_ =
pset.getParameter<
double>(
"minTauPtForNoIso");
49 applyOccupancyCut_ =
pset.getParameter<
bool>(
"applyOccupancyCut");
50 maximumOccupancy_ =
pset.getParameter<uint32_t>(
"maximumOccupancy");
52 applySumPtCut_ =
pset.getParameter<
bool>(
"applySumPtCut");
53 maximumSumPt_ =
pset.getParameter<
double>(
"maximumSumPtCut");
55 applyRelativeSumPtCut_ =
pset.getParameter<
bool>(
"applyRelativeSumPtCut");
56 maximumRelativeSumPt_ =
pset.getParameter<
double>(
"relativeSumPtCut");
57 offsetRelativeSumPt_ =
pset.getParameter<
double>(
"relativeSumPtOffset");
59 storeRawOccupancy_ =
pset.getParameter<
bool>(
"storeRawOccupancy");
60 storeRawSumPt_ =
pset.getParameter<
bool>(
"storeRawSumPt");
61 storeRawPUsumPt_ =
pset.getParameter<
bool>(
"storeRawPUsumPt");
62 storeRawFootprintCorrection_ =
pset.getParameter<
bool>(
"storeRawFootprintCorrection");
63 storeRawPhotonSumPt_outsideSignalCone_ =
pset.getParameter<
bool>(
"storeRawPhotonSumPt_outsideSignalCone");
67 if (applySumPtCut_ || applyOccupancyCut_ || applyRelativeSumPtCut_) {
68 if (storeRawSumPt_ || storeRawOccupancy_ || storeRawPUsumPt_) {
69 throw cms::Exception(
"BadIsoConfig") <<
"A 'store raw' and a 'apply cut' option have been set to true "
70 <<
"simultaneously. These options are mutually exclusive.";
75 if (includeGammas_ && calculateWeights_) {
77 <<
"Both 'ApplyDiscriminationByECALIsolation' and 'ApplyDiscriminationByWeightedECALIsolation' "
78 <<
"have been set to true. These options are mutually exclusive.";
82 int numStoreOptions = 0;
85 if (storeRawOccupancy_)
89 if (storeRawFootprintCorrection_)
91 if (storeRawPhotonSumPt_outsideSignalCone_)
93 if (numStoreOptions > 1) {
94 throw cms::Exception(
"BadIsoConfig") <<
"Multiple 'store sum pt' and/or 'store occupancy' options are set."
95 <<
" These options are mutually exclusive.";
98 customIsoCone_ =
pset.getParameter<
double>(
"customOuterCone");
100 applyPhotonPtSumOutsideSignalConeCut_ =
pset.getParameter<
bool>(
"applyPhotonPtSumOutsideSignalConeCut");
101 if (applyPhotonPtSumOutsideSignalConeCut_) {
102 maxAbsPhotonSumPt_outsideSignalCone_ =
pset.getParameter<
double>(
"maxAbsPhotonSumPt_outsideSignalCone");
103 maxRelPhotonSumPt_outsideSignalCone_ =
pset.getParameter<
double>(
"maxRelPhotonSumPt_outsideSignalCone");
106 applyFootprintCorrection_ =
pset.getParameter<
bool>(
"applyFootprintCorrection");
107 if (applyFootprintCorrection_ || storeRawFootprintCorrection_) {
109 for (edm::VParameterSet::const_iterator cfgFootprintCorrection = cfgFootprintCorrections.begin();
110 cfgFootprintCorrection != cfgFootprintCorrections.end();
111 ++cfgFootprintCorrection) {
115 footprintCorrections_.push_back(
std::move(footprintCorrection));
122 qcuts_ = std::make_unique<tau::RecoTauQualityCuts>(isolationQCuts);
124 vertexAssociator_ = std::make_unique<tau::RecoTauVertexAssociator>(qualityCutsPSet_, consumesCollector());
126 applyDeltaBeta_ =
pset.getParameter<
bool>(
"applyDeltaBetaCorrection");
128 if (applyDeltaBeta_ || calculateWeights_) {
131 std::pair<edm::ParameterSet, edm::ParameterSet> puFactorizedIsoQCuts =
143 puFactorizedIsoQCuts.second.addParameter<
double>(
"minTrackPt",
147 pileupQcutsPUTrackSelection_ = std::make_unique<tau::RecoTauQualityCuts>(puFactorizedIsoQCuts.first);
149 pileupQcutsGeneralQCuts_ = std::make_unique<tau::RecoTauQualityCuts>(puFactorizedIsoQCuts.second);
152 pfCand_token = consumes<edm::View<reco::Candidate> >(pfCandSrc_);
154 vertex_token = consumes<reco::VertexCollection>(vertexSrc_);
155 deltaBetaCollectionCone_ =
pset.getParameter<
double>(
"isoConeSizeForDeltaBeta");
156 std::string deltaBetaFactorFormula =
pset.getParameter<
string>(
"deltaBetaFactor");
157 deltaBetaFormula_ = std::make_unique<TFormula>(
"DB_corr", deltaBetaFactorFormula.c_str());
160 applyRhoCorrection_ =
pset.getParameter<
bool>(
"applyRhoCorrection");
161 if (applyRhoCorrection_) {
163 rho_token = consumes<double>(rhoProducer_);
164 rhoConeSize_ =
pset.getParameter<
double>(
"rhoConeSize");
165 rhoUEOffsetCorrection_ =
pset.getParameter<
double>(
"rhoUEOffsetCorrection");
167 useAllPFCands_ =
pset.getParameter<
bool>(
"UseAllPFCandsForWeights");
169 verbosity_ =
pset.getParameter<
int>(
"verbosity");
175 double discriminate(
const PFTauRef& pfTau)
const override;
177 inline double weightedSum(
const std::vector<CandidatePtr>& inColl_,
double eta,
double phi)
const {
179 for (
auto const& inObj_ : inColl_) {
180 double sum = (inObj_->pt() * inObj_->pt()) / (
deltaR2(
eta, phi, inObj_->eta(), inObj_->phi()));
193 std::unique_ptr<tau::RecoTauQualityCuts>
qcuts_;
273 vertexAssociator_->setEvent(
event);
277 if (applyDeltaBeta_ || calculateWeights_) {
281 chargedPFCandidatesInEvent_.clear();
282 chargedPFCandidatesInEvent_.reserve(
pfCandidates->size());
284 for (
size_t i = 0;
i < numPFCandidates; ++
i) {
286 if (pfCandidate->
charge() != 0) {
287 chargedPFCandidatesInEvent_.push_back(pfCandidate);
293 event.getByToken(vertex_token,
vertices);
294 size_t nVtxThisEvent =
vertices->size();
295 deltaBetaFactorThisEvent_ = deltaBetaFormula_->Eval(nVtxThisEvent);
298 if (applyRhoCorrection_) {
300 event.getByToken(rho_token, rhoHandle_);
301 rhoThisEvent_ = (*rhoHandle_ - rhoUEOffsetCorrection_) * (3.14159) * rhoConeSize_ * rhoConeSize_;
306 LogDebug(
"discriminate") <<
" tau: Pt = " << pfTau->pt() <<
", eta = " << pfTau->eta() <<
", phi = " << pfTau->phi();
310 std::vector<CandidatePtr> isoCharged_;
311 std::vector<CandidatePtr> isoNeutral_;
312 std::vector<CandidatePtr> isoPU_;
314 std::vector<CandidatePtr> chPV_;
315 isoCharged_.
reserve(pfTau->isolationChargedHadrCands().size());
316 isoNeutral_.reserve(pfTau->isolationGammaCands().size());
317 isoPU_.reserve(
std::min(100UL, chargedPFCandidatesInEvent_.size()));
318 isoNeutralWeight_.
reserve(pfTau->isolationGammaCands().size());
320 chPV_.reserve(
std::min(50UL, chargedPFCandidatesInEvent_.size()));
327 if (
pv.isNonnull()) {
328 LogTrace(
"discriminate") <<
"pv: x = " <<
pv->position().x() <<
", y = " <<
pv->position().y()
329 <<
", z = " <<
pv->position().z();
331 LogTrace(
"discriminate") <<
"pv: N/A";
333 if (pfTau->leadChargedHadrCand().
isNonnull()) {
334 LogTrace(
"discriminate") <<
"leadPFChargedHadron:"
335 <<
" Pt = " << pfTau->leadChargedHadrCand()->pt() <<
","
336 <<
" eta = " << pfTau->leadChargedHadrCand()->eta() <<
","
337 <<
" phi = " << pfTau->leadChargedHadrCand()->phi();
339 LogTrace(
"discriminate") <<
"leadPFChargedHadron: N/A";
344 if (!(
pv.isNonnull() && pfTau->leadChargedHadrCand().
isNonnull()))
348 qcuts_->setLeadTrack(*pfTau->leadChargedHadrCand());
350 if (applyDeltaBeta_ || calculateWeights_) {
351 pileupQcutsGeneralQCuts_->setPV(
pv);
352 pileupQcutsGeneralQCuts_->setLeadTrack(*pfTau->leadChargedHadrCand());
353 pileupQcutsPUTrackSelection_->setPV(
pv);
354 pileupQcutsPUTrackSelection_->setLeadTrack(*pfTau->leadChargedHadrCand());
358 if (includeTracks_) {
359 for (
auto const&
cand : pfTau->isolationChargedHadrCands()) {
360 if (qcuts_->filterCandRef(
cand)) {
361 LogTrace(
"discriminate") <<
"adding charged iso cand with pt " <<
cand->pt();
362 isoCharged_.push_back(
cand);
366 if (includeGammas_ || calculateWeights_) {
367 for (
auto const&
cand : pfTau->isolationGammaCands()) {
368 if (qcuts_->filterCandRef(
cand)) {
369 LogTrace(
"discriminate") <<
"adding neutral iso cand with pt " <<
cand->pt();
370 isoNeutral_.push_back(
cand);
379 if (applyDeltaBeta_ || calculateWeights_) {
382 std::cout <<
"Initial PFCands: " << chargedPFCandidatesInEvent_.size() << std::endl;
385 std::vector<CandidatePtr> allPU = pileupQcutsPUTrackSelection_->filterCandRefs(chargedPFCandidatesInEvent_,
true);
387 std::vector<CandidatePtr> allNPU = pileupQcutsPUTrackSelection_->filterCandRefs(chargedPFCandidatesInEvent_);
388 LogTrace(
"discriminate") <<
"After track cuts: " << allPU.size();
391 if (!useAllPFCands_) {
392 std::vector<CandidatePtr> cleanPU = pileupQcutsGeneralQCuts_->filterCandRefs(allPU);
394 std::vector<CandidatePtr> cleanNPU = pileupQcutsGeneralQCuts_->filterCandRefs(allNPU);
396 LogTrace(
"discriminate") <<
"After cleaning cuts: " << cleanPU.size();
399 DRFilter deltaBetaFilter(pfTau->p4(), 0, deltaBetaCollectionCone_);
400 for (
auto const&
cand : cleanPU) {
401 if (deltaBetaFilter(
cand))
402 isoPU_.push_back(
cand);
405 for (
auto const&
cand : cleanNPU) {
406 if (deltaBetaFilter(
cand))
407 chPV_.push_back(
cand);
409 LogTrace(
"discriminate") <<
"After cone cuts: " << isoPU_.size() <<
" " << chPV_.size();
416 if (calculateWeights_) {
417 for (
auto const& isoObject : isoNeutral_) {
418 if (isoObject->charge() != 0) {
424 double eta = isoObject->eta();
425 double phi = isoObject->phi();
426 double sumNPU = 0.5 *
log(weightedSum(chPV_,
eta, phi));
428 double sumPU = 0.5 *
log(weightedSum(isoPU_,
eta, phi));
430 if ((sumNPU + sumPU) > 0)
431 neutral.
setP4(((sumNPU) / (sumNPU + sumPU)) * neutral.
p4());
438 if (customIsoCone_ >= 0.) {
439 DRFilter
filter(pfTau->p4(), 0, customIsoCone_);
440 DRFilter2 filter2(pfTau->p4(), 0, customIsoCone_);
441 std::vector<CandidatePtr> isoCharged_filter;
442 std::vector<CandidatePtr> isoNeutral_filter;
445 for (
auto const& isoObject : isoCharged_) {
449 if (!calculateWeights_) {
450 for (
auto const& isoObject : isoNeutral_) {
452 isoNeutral_filter.push_back(isoObject);
454 isoNeutral_ = isoNeutral_filter;
456 for (
auto const& isoObject : isoNeutralWeight_) {
457 if (filter2(isoObject))
458 isoNeutralWeight_filter.
push_back(isoObject);
460 isoNeutralWeight_ = isoNeutralWeight_filter;
462 isoCharged_ = isoCharged_filter;
465 bool failsOccupancyCut =
false;
466 bool failsSumPtCut =
false;
467 bool failsRelativeSumPtCut =
false;
470 int neutrals = isoNeutral_.
size();
472 if (applyDeltaBeta_) {
473 neutrals -= TMath::Nint(deltaBetaFactorThisEvent_ * isoPU_.size());
479 size_t nOccupants = isoCharged_.size() + neutrals;
481 failsOccupancyCut = (nOccupants > maximumOccupancy_);
483 double footprintCorrection_value = 0.;
484 if (applyFootprintCorrection_ || storeRawFootprintCorrection_) {
485 for (
std::vector<std::unique_ptr<FootprintCorrection> >::const_iterator footprintCorrection =
486 footprintCorrections_.begin();
487 footprintCorrection != footprintCorrections_.end();
488 ++footprintCorrection) {
489 if ((*footprintCorrection)->selection_(*pfTau)) {
490 footprintCorrection_value = (*footprintCorrection)->offset_(*pfTau);
498 if (applySumPtCut_ || applyRelativeSumPtCut_ || storeRawSumPt_ || storeRawPUsumPt_) {
499 double chargedPt = 0.;
500 double neutralPt = 0.;
501 double weightedNeutralPt = 0.;
502 for (
auto const& isoObject : isoCharged_) {
503 chargedPt += isoObject->pt();
505 if (!calculateWeights_) {
506 for (
auto const& isoObject : isoNeutral_) {
507 neutralPt += isoObject->pt();
510 for (
auto const& isoObject : isoNeutralWeight_) {
511 weightedNeutralPt += isoObject.pt();
514 for (
auto const& isoObject : isoPU_) {
515 puPt += isoObject->pt();
517 LogTrace(
"discriminate") <<
"chargedPt = " << chargedPt;
518 LogTrace(
"discriminate") <<
"neutralPt = " << neutralPt;
519 LogTrace(
"discriminate") <<
"weighted neutral Pt = " << weightedNeutralPt;
520 LogTrace(
"discriminate") <<
"puPt = " << puPt <<
" (delta-beta corr. = " << (deltaBetaFactorThisEvent_ * puPt)
523 if (calculateWeights_) {
524 neutralPt = weightedNeutralPt;
527 if (applyDeltaBeta_) {
528 neutralPt -= (deltaBetaFactorThisEvent_ * puPt);
531 if (applyFootprintCorrection_) {
532 neutralPt -= footprintCorrection_value;
535 if (applyRhoCorrection_) {
536 neutralPt -= rhoThisEvent_;
539 if (neutralPt < 0.) {
543 totalPt = chargedPt + weightGammas_ * neutralPt;
544 LogTrace(
"discriminate") <<
"totalPt = " << totalPt <<
" (cut = " << maximumSumPt_ <<
")";
546 failsSumPtCut = (totalPt > maximumSumPt_);
549 failsRelativeSumPtCut = (totalPt > ((pfTau->pt() - offsetRelativeSumPt_) * maximumRelativeSumPt_));
552 bool failsPhotonPtSumOutsideSignalConeCut =
false;
553 double photonSumPt_outsideSignalCone = 0.;
554 if (applyPhotonPtSumOutsideSignalConeCut_ || storeRawPhotonSumPt_outsideSignalCone_) {
555 const std::vector<reco::CandidatePtr>& signalGammas = pfTau->signalGammaCands();
556 for (std::vector<reco::CandidatePtr>::const_iterator signalGamma = signalGammas.begin();
557 signalGamma != signalGammas.end();
559 double dR =
deltaR(pfTau->eta(), pfTau->phi(), (*signalGamma)->eta(), (*signalGamma)->phi());
560 if (
dR > pfTau->signalConeSize())
561 photonSumPt_outsideSignalCone += (*signalGamma)->pt();
563 if (photonSumPt_outsideSignalCone > maxAbsPhotonSumPt_outsideSignalCone_ ||
564 photonSumPt_outsideSignalCone > (maxRelPhotonSumPt_outsideSignalCone_ * pfTau->pt())) {
565 failsPhotonPtSumOutsideSignalConeCut =
true;
569 bool fails = (applyOccupancyCut_ && failsOccupancyCut) || (applySumPtCut_ && failsSumPtCut) ||
570 (applyRelativeSumPtCut_ && failsRelativeSumPtCut) ||
571 (applyPhotonPtSumOutsideSignalConeCut_ && failsPhotonPtSumOutsideSignalConeCut);
573 if (pfTau->pt() > minPtForNoIso_ && minPtForNoIso_ > 0.) {
575 LogDebug(
"discriminate") <<
"tau pt = " << pfTau->pt() <<
"\t min cutoff pt = " << minPtForNoIso_;
579 if (storeRawSumPt_) {
581 }
else if (storeRawPUsumPt_) {
584 else if (applyRhoCorrection_)
585 return rhoThisEvent_;
588 }
else if (storeRawOccupancy_) {
590 }
else if (storeRawFootprintCorrection_) {
591 return footprintCorrection_value;
592 }
else if (storeRawPhotonSumPt_outsideSignalCone_) {
593 return photonSumPt_outsideSignalCone;
595 return (fails ? 0. : 1.);
602 desc.add<
bool>(
"storeRawFootprintCorrection",
false);
604 desc.add<
bool>(
"storeRawOccupancy",
false);
605 desc.add<
double>(
"maximumSumPtCut", 6.0);
611 desc.add<
double>(
"minTauPtForNoIso", -99.0);
612 desc.add<
double>(
"maxAbsPhotonSumPt_outsideSignalCone", 1000000000.0);
614 desc.add<
bool>(
"applySumPtCut",
false);
615 desc.add<
double>(
"rhoConeSize", 0.5);
616 desc.add<
bool>(
"ApplyDiscriminationByTrackerIsolation",
true);
617 desc.add<
bool>(
"storeRawPhotonSumPt_outsideSignalCone",
false);
624 desc.addVPSet(
"footprintCorrections", vpsd1, {});
628 desc.add<
bool>(
"applyFootprintCorrection",
false);
629 desc.add<
bool>(
"UseAllPFCandsForWeights",
false);
630 desc.add<
double>(
"relativeSumPtCut", 0.0);
636 psd1.
add<
double>(
"cut");
652 psd1.
add<
double>(
"cut");
665 psd1.
add<
double>(
"cut");
672 desc.add<
unsigned int>(
"maximumOccupancy", 0);
673 desc.add<
int>(
"verbosity", 0);
675 desc.add<
bool>(
"applyOccupancyCut",
true);
676 desc.add<
bool>(
"applyDeltaBetaCorrection",
false);
677 desc.add<
bool>(
"applyRelativeSumPtCut",
false);
678 desc.add<
bool>(
"storeRawPUsumPt",
false);
679 desc.add<
bool>(
"applyPhotonPtSumOutsideSignalConeCut",
false);
680 desc.add<
bool>(
"deltaBetaPUTrackPtCutOverride",
false);
681 desc.add<
bool>(
"ApplyDiscriminationByWeightedECALIsolation",
false);
682 desc.add<
bool>(
"storeRawSumPt",
false);
683 desc.add<
bool>(
"ApplyDiscriminationByECALIsolation",
true);
684 desc.add<
bool>(
"applyRhoCorrection",
false);
686 desc.add<
double>(
"WeightECALIsolation", 1.0);
687 desc.add<
double>(
"rhoUEOffsetCorrection", 1.0);
688 desc.add<
double>(
"maxRelPhotonSumPt_outsideSignalCone", 0.1);
689 desc.add<
double>(
"deltaBetaPUTrackPtCutOverride_val", -1.5);
690 desc.add<
double>(
"isoConeSizeForDeltaBeta", 0.5);
691 desc.add<
double>(
"relativeSumPtOffset", 0.0);
692 desc.add<
double>(
"customOuterCone", -1.0);
695 descriptions.
add(
"pfRecoTauDiscriminationByIsolation",
desc);