CMS 3D CMS Logo

PFRecoTauDiscriminationByIsolation.cc
Go to the documentation of this file.
1 #include <functional>
2 #include <memory>
3 
14 
15 #include "TMath.h"
16 #include "TFormula.h"
17 
18 /* class PFRecoTauDiscriminationByIsolation
19  * created : Jul 23 2007,
20  * revised : Thu Aug 13 14:44:40 PDT 2009
21  * contributors : Ludovic Houchu (IPHC, Strasbourg),
22  * Christian Veelken (UC Davis),
23  * Evan K. Friis (UC Davis)
24  * Michalis Bachtis (UW Madison)
25  */
26 
27 using namespace reco;
28 using namespace std;
29 
31 public:
34  moduleLabel_(pset.getParameter<std::string>("@module_label")),
35  qualityCutsPSet_(pset.getParameter<edm::ParameterSet>("qualityCuts")) {
36  includeTracks_ = pset.getParameter<bool>("ApplyDiscriminationByTrackerIsolation");
37  includeGammas_ = pset.getParameter<bool>("ApplyDiscriminationByECALIsolation");
38 
39  calculateWeights_ = pset.getParameter<bool>("ApplyDiscriminationByWeightedECALIsolation");
40 
41  enableHGCalWorkaround_ = pset.getParameter<bool>("enableHGCalWorkaround");
42 
43  // RIC: multiply neutral isolation by a flat factor.
44  // Useful, for instance, to combine charged and neutral isolations
45  // with different relative weights
46  weightGammas_ = pset.getParameter<double>("WeightECALIsolation");
47 
48  // RIC: allow to relax the isolation completely beyond a given tau pt
49  minPtForNoIso_ = pset.getParameter<double>("minTauPtForNoIso");
50 
51  applyOccupancyCut_ = pset.getParameter<bool>("applyOccupancyCut");
52  maximumOccupancy_ = pset.getParameter<uint32_t>("maximumOccupancy");
53 
54  applySumPtCut_ = pset.getParameter<bool>("applySumPtCut");
55  maximumSumPt_ = pset.getParameter<double>("maximumSumPtCut");
56 
57  applyRelativeSumPtCut_ = pset.getParameter<bool>("applyRelativeSumPtCut");
58  maximumRelativeSumPt_ = pset.getParameter<double>("relativeSumPtCut");
59  offsetRelativeSumPt_ = pset.getParameter<double>("relativeSumPtOffset");
60 
61  storeRawOccupancy_ = pset.getParameter<bool>("storeRawOccupancy");
62  storeRawSumPt_ = pset.getParameter<bool>("storeRawSumPt");
63  storeRawPUsumPt_ = pset.getParameter<bool>("storeRawPUsumPt");
64  storeRawFootprintCorrection_ = pset.getParameter<bool>("storeRawFootprintCorrection");
65  storeRawPhotonSumPt_outsideSignalCone_ = pset.getParameter<bool>("storeRawPhotonSumPt_outsideSignalCone");
66 
67  // Sanity check on requested options. We can't apply cuts and store the
68  // raw output at the same time
69  if (applySumPtCut_ || applyOccupancyCut_ || applyRelativeSumPtCut_) {
70  if (storeRawSumPt_ || storeRawOccupancy_ || storeRawPUsumPt_) {
71  throw cms::Exception("BadIsoConfig") << "A 'store raw' and a 'apply cut' option have been set to true "
72  << "simultaneously. These options are mutually exclusive.";
73  }
74  }
75 
76  // sanity check2 - can't use weighted and unweighted iso at the same time
77  if (includeGammas_ && calculateWeights_) {
78  throw cms::Exception("BasIsoConfig")
79  << "Both 'ApplyDiscriminationByECALIsolation' and 'ApplyDiscriminationByWeightedECALIsolation' "
80  << "have been set to true. These options are mutually exclusive.";
81  }
82 
83  // Can only store one type
84  int numStoreOptions = 0;
85  if (storeRawSumPt_)
86  ++numStoreOptions;
87  if (storeRawOccupancy_)
88  ++numStoreOptions;
89  if (storeRawPUsumPt_)
90  ++numStoreOptions;
91  if (storeRawFootprintCorrection_)
92  ++numStoreOptions;
93  if (storeRawPhotonSumPt_outsideSignalCone_)
94  ++numStoreOptions;
95  if (numStoreOptions > 1) {
96  throw cms::Exception("BadIsoConfig") << "Multiple 'store sum pt' and/or 'store occupancy' options are set."
97  << " These options are mutually exclusive.";
98  }
99 
100  customIsoCone_ = pset.getParameter<double>("customOuterCone");
101 
102  applyPhotonPtSumOutsideSignalConeCut_ = pset.getParameter<bool>("applyPhotonPtSumOutsideSignalConeCut");
103  if (applyPhotonPtSumOutsideSignalConeCut_) {
104  maxAbsPhotonSumPt_outsideSignalCone_ = pset.getParameter<double>("maxAbsPhotonSumPt_outsideSignalCone");
105  maxRelPhotonSumPt_outsideSignalCone_ = pset.getParameter<double>("maxRelPhotonSumPt_outsideSignalCone");
106  }
107 
108  applyFootprintCorrection_ = pset.getParameter<bool>("applyFootprintCorrection");
109  if (applyFootprintCorrection_ || storeRawFootprintCorrection_) {
110  edm::VParameterSet cfgFootprintCorrections = pset.getParameter<edm::VParameterSet>("footprintCorrections");
111  for (edm::VParameterSet::const_iterator cfgFootprintCorrection = cfgFootprintCorrections.begin();
112  cfgFootprintCorrection != cfgFootprintCorrections.end();
113  ++cfgFootprintCorrection) {
114  std::string selection = cfgFootprintCorrection->getParameter<std::string>("selection");
115  std::string offset = cfgFootprintCorrection->getParameter<std::string>("offset");
116  auto footprintCorrection(std::make_unique<FootprintCorrection>(selection, offset));
117  footprintCorrections_.push_back(std::move(footprintCorrection));
118  }
119  }
120 
121  // Get the quality cuts specific to the isolation region
122  edm::ParameterSet isolationQCuts = qualityCutsPSet_.getParameterSet("isolationQualityCuts");
123 
124  qcuts_ = std::make_unique<tau::RecoTauQualityCuts>(isolationQCuts);
125 
126  vertexAssociator_ = std::make_unique<tau::RecoTauVertexAssociator>(qualityCutsPSet_, consumesCollector());
127 
128  applyDeltaBeta_ = pset.getParameter<bool>("applyDeltaBetaCorrection");
129 
130  if (applyDeltaBeta_ || calculateWeights_) {
131  // Factorize the isolation QCuts into those that are used to
132  // select PU and those that are not.
133  std::pair<edm::ParameterSet, edm::ParameterSet> puFactorizedIsoQCuts =
134  reco::tau::factorizePUQCuts(isolationQCuts);
135 
136  // Determine the pt threshold for the PU tracks
137  // First check if the user specifies explicitly the cut.
138  // For that the user has to provide a >= 0 value for the PtCutOverride.
139  bool deltaBetaPUTrackPtCutOverride = pset.getParameter<bool>("deltaBetaPUTrackPtCutOverride");
141  double deltaBetaPUTrackPtCutOverride_val = pset.getParameter<double>("deltaBetaPUTrackPtCutOverride_val");
142  puFactorizedIsoQCuts.second.addParameter<double>("minTrackPt", deltaBetaPUTrackPtCutOverride_val);
143  } else {
144  // Secondly take it from the minGammaEt
145  puFactorizedIsoQCuts.second.addParameter<double>("minTrackPt",
146  isolationQCuts.getParameter<double>("minGammaEt"));
147  }
148 
149  pileupQcutsPUTrackSelection_ = std::make_unique<tau::RecoTauQualityCuts>(puFactorizedIsoQCuts.first);
150 
151  pileupQcutsGeneralQCuts_ = std::make_unique<tau::RecoTauQualityCuts>(puFactorizedIsoQCuts.second);
152 
153  pfCandSrc_ = pset.getParameter<edm::InputTag>("particleFlowSrc");
154  pfCand_token = consumes<edm::View<reco::Candidate> >(pfCandSrc_);
155  vertexSrc_ = pset.getParameter<edm::InputTag>("vertexSrc");
156  vertex_token = consumes<reco::VertexCollection>(vertexSrc_);
157  deltaBetaCollectionCone_ = pset.getParameter<double>("isoConeSizeForDeltaBeta");
158  std::string deltaBetaFactorFormula = pset.getParameter<string>("deltaBetaFactor");
159  deltaBetaFormula_ = std::make_unique<TFormula>("DB_corr", deltaBetaFactorFormula.c_str());
160  }
161 
162  applyRhoCorrection_ = pset.getParameter<bool>("applyRhoCorrection");
163  if (applyRhoCorrection_) {
164  rhoProducer_ = pset.getParameter<edm::InputTag>("rhoProducer");
165  rho_token = consumes<double>(rhoProducer_);
166  rhoConeSize_ = pset.getParameter<double>("rhoConeSize");
167  rhoUEOffsetCorrection_ = pset.getParameter<double>("rhoUEOffsetCorrection");
168  }
169  useAllPFCands_ = pset.getParameter<bool>("UseAllPFCandsForWeights");
170 
171  verbosity_ = pset.getParameter<int>("verbosity");
172  }
173 
175 
176  void beginEvent(const edm::Event& evt, const edm::EventSetup& evtSetup) override;
177  double discriminate(const PFTauRef& pfTau) const override;
178 
179  inline double weightedSum(const std::vector<CandidatePtr>& inColl_, double eta, double phi) const {
180  double out = 1.0;
181  for (auto const& inObj_ : inColl_) {
182  double sum = (inObj_->pt() * inObj_->pt()) / (deltaR2(eta, phi, inObj_->eta(), inObj_->phi()));
183  if (sum > 1.0)
184  out *= sum;
185  }
186  return out;
187  }
188 
189  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
190 
191 private:
193 
195  std::unique_ptr<tau::RecoTauQualityCuts> qcuts_;
196 
197  // Inverted QCut which selects tracks with bad DZ/trackWeight
198  std::unique_ptr<tau::RecoTauQualityCuts> pileupQcutsPUTrackSelection_;
199  std::unique_ptr<tau::RecoTauQualityCuts> pileupQcutsGeneralQCuts_;
200 
201  std::unique_ptr<tau::RecoTauVertexAssociator> vertexAssociator_;
202 
216  // RIC:
218 
222 
226  : selection_(selection), offset_(offset) {}
230  };
231  std::vector<std::unique_ptr<FootprintCorrection> > footprintCorrections_;
232 
233  // Options to store the raw value in the discriminator instead of boolean pass/fail flag
239 
240  /* **********************************************************************
241  **** Pileup Subtraction Parameters ***********************************
242  **********************************************************************/
243 
244  // Delta Beta correction
248  // Keep track of how many vertices are in the event
251  std::vector<reco::CandidatePtr> chargedPFCandidatesInEvent_;
252  // Size of cone used to collect PU tracks
254  std::unique_ptr<TFormula> deltaBetaFormula_;
256 
257  // Rho correction
262  double rhoConeSize_;
266 
267  // Flag to enable/disable debug output
269 };
270 
272  // NB: The use of the PV in this context is necessitated by its use in
273  // applying quality cuts to the different objects in the isolation cone
274  // The vertex associator contains the logic to select the appropriate vertex
275  // We need to pass it the event so it can load the vertices.
276  vertexAssociator_->setEvent(event);
277 
278  // If we are applying the delta beta correction, we need to get the PF
279  // candidates from the event so we can find the PU tracks.
280  if (applyDeltaBeta_ || calculateWeights_) {
281  // Collect all the PF pile up tracks
283  event.getByToken(pfCand_token, pfCandidates);
284  chargedPFCandidatesInEvent_.clear();
285  chargedPFCandidatesInEvent_.reserve(pfCandidates->size());
286  size_t numPFCandidates = pfCandidates->size();
287  for (size_t i = 0; i < numPFCandidates; ++i) {
288  reco::CandidatePtr pfCandidate(pfCandidates, i);
289  if (pfCandidate->charge() != 0) {
290  chargedPFCandidatesInEvent_.push_back(pfCandidate);
291  }
292  }
293  // Count all the vertices in the event, to parameterize the DB
294  // correction factor
296  event.getByToken(vertex_token, vertices);
297  size_t nVtxThisEvent = vertices->size();
298  deltaBetaFactorThisEvent_ = deltaBetaFormula_->Eval(nVtxThisEvent);
299  }
300 
301  if (applyRhoCorrection_) {
302  edm::Handle<double> rhoHandle_;
303  event.getByToken(rho_token, rhoHandle_);
304  rhoThisEvent_ = (*rhoHandle_ - rhoUEOffsetCorrection_) * (3.14159) * rhoConeSize_ * rhoConeSize_;
305  }
306 }
307 
309  LogDebug("discriminate") << " tau: Pt = " << pfTau->pt() << ", eta = " << pfTau->eta() << ", phi = " << pfTau->phi();
310  LogDebug("discriminate") << *pfTau;
311 
312  // collect the objects we are working with (ie tracks, tracks+gammas, etc)
313  std::vector<CandidatePtr> isoCharged_;
314  std::vector<CandidatePtr> isoNeutral_;
315  std::vector<CandidatePtr> isoPU_;
316  CandidateCollection isoNeutralWeight_;
317  std::vector<CandidatePtr> chPV_;
318  isoCharged_.reserve(pfTau->isolationChargedHadrCands().size());
319  isoNeutral_.reserve(pfTau->isolationGammaCands().size());
320  isoPU_.reserve(std::min(100UL, chargedPFCandidatesInEvent_.size()));
321  isoNeutralWeight_.reserve(pfTau->isolationGammaCands().size());
322 
323  chPV_.reserve(std::min(50UL, chargedPFCandidatesInEvent_.size()));
324 
325  // Get the primary vertex associated to this tau
326  reco::VertexRef pv = vertexAssociator_->associatedVertex(*pfTau);
327  // Let the quality cuts know which the vertex to use when applying selections
328  // on dz, etc.
329  if (verbosity_) {
330  if (pv.isNonnull()) {
331  LogTrace("discriminate") << "pv: x = " << pv->position().x() << ", y = " << pv->position().y()
332  << ", z = " << pv->position().z();
333  } else {
334  LogTrace("discriminate") << "pv: N/A";
335  }
336  if (pfTau->leadChargedHadrCand().isNonnull()) {
337  LogTrace("discriminate") << "leadPFChargedHadron:"
338  << " Pt = " << pfTau->leadChargedHadrCand()->pt() << ","
339  << " eta = " << pfTau->leadChargedHadrCand()->eta() << ","
340  << " phi = " << pfTau->leadChargedHadrCand()->phi();
341  } else {
342  LogTrace("discriminate") << "leadPFChargedHadron: N/A";
343  }
344  }
345 
346  // CV: isolation is not well defined in case primary vertex or leading charged hadron do not exist
347  if (!(pv.isNonnull() && pfTau->leadChargedHadrCand().isNonnull()))
348  return 0.;
349 
350  qcuts_->setPV(pv);
351  qcuts_->setLeadTrack(*pfTau->leadChargedHadrCand());
352 
353  if (applyDeltaBeta_ || calculateWeights_) {
354  pileupQcutsGeneralQCuts_->setPV(pv);
355  pileupQcutsGeneralQCuts_->setLeadTrack(*pfTau->leadChargedHadrCand());
356  pileupQcutsPUTrackSelection_->setPV(pv);
357  pileupQcutsPUTrackSelection_->setLeadTrack(*pfTau->leadChargedHadrCand());
358  }
359 
360  // Load the tracks if they are being used.
361  if (includeTracks_) {
362  for (auto const& cand : pfTau->isolationChargedHadrCands()) {
363  if (qcuts_->filterCandRef(cand)) {
364  LogTrace("discriminate") << "adding charged iso cand with pt " << cand->pt();
365  isoCharged_.push_back(cand);
366  }
367  }
368  }
369  if (includeGammas_ || calculateWeights_) {
370  for (auto const& cand : pfTau->isolationGammaCands()) {
371  if (qcuts_->filterCandRef(cand)) {
372  LogTrace("discriminate") << "adding neutral iso cand with pt " << cand->pt();
373  isoNeutral_.push_back(cand);
374  }
375  }
376  }
377 
380 
381  // If desired, get PU tracks.
382  if (applyDeltaBeta_ || calculateWeights_) {
383  // First select by inverted the DZ/track weight cuts. True = invert
384  if (verbosity_) {
385  std::cout << "Initial PFCands: " << chargedPFCandidatesInEvent_.size() << std::endl;
386  }
387 
388  std::vector<CandidatePtr> allPU = pileupQcutsPUTrackSelection_->filterCandRefs(chargedPFCandidatesInEvent_, true);
389 
390  std::vector<CandidatePtr> allNPU = pileupQcutsPUTrackSelection_->filterCandRefs(chargedPFCandidatesInEvent_);
391  LogTrace("discriminate") << "After track cuts: " << allPU.size();
392 
393  // Now apply the rest of the cuts, like pt, and TIP, tracker hits, etc
394  if (!useAllPFCands_) {
395  std::vector<CandidatePtr> cleanPU = pileupQcutsGeneralQCuts_->filterCandRefs(allPU);
396 
397  std::vector<CandidatePtr> cleanNPU = pileupQcutsGeneralQCuts_->filterCandRefs(allNPU);
398 
399  LogTrace("discriminate") << "After cleaning cuts: " << cleanPU.size();
400 
401  // Only select PU tracks inside the isolation cone.
402  DRFilter deltaBetaFilter(pfTau->p4(), 0, deltaBetaCollectionCone_);
403  for (auto const& cand : cleanPU) {
404  if (deltaBetaFilter(cand))
405  isoPU_.push_back(cand);
406  }
407 
408  for (auto const& cand : cleanNPU) {
409  if (deltaBetaFilter(cand))
410  chPV_.push_back(cand);
411  }
412  LogTrace("discriminate") << "After cone cuts: " << isoPU_.size() << " " << chPV_.size();
413  } else {
414  isoPU_ = std::move(allPU);
415  chPV_ = std::move(allNPU);
416  }
417  }
418 
419  if (calculateWeights_) {
420  for (auto const& isoObject : isoNeutral_) {
421  if (isoObject->charge() != 0) {
422  // weight only neutral objects
423  isoNeutralWeight_.push_back(*isoObject);
424  continue;
425  }
426 
427  double eta = isoObject->eta();
428  double phi = isoObject->phi();
429  double sumNPU = 0.5 * log(weightedSum(chPV_, eta, phi));
430 
431  double sumPU = 0.5 * log(weightedSum(isoPU_, eta, phi));
432  LeafCandidate neutral(*isoObject);
433  if ((sumNPU + sumPU) > 0)
434  neutral.setP4(((sumNPU) / (sumNPU + sumPU)) * neutral.p4());
435 
436  isoNeutralWeight_.push_back(neutral);
437  }
438  }
439 
440  // Check if we want a custom iso cone
441  if (customIsoCone_ >= 0.) {
442  DRFilter filter(pfTau->p4(), 0, customIsoCone_);
443  DRFilter2 filter2(pfTau->p4(), 0, customIsoCone_);
444  std::vector<CandidatePtr> isoCharged_filter;
445  std::vector<CandidatePtr> isoNeutral_filter;
446  CandidateCollection isoNeutralWeight_filter;
447  // Remove all the objects not in our iso cone
448  for (auto const& isoObject : isoCharged_) {
449  if (filter(isoObject))
450  isoCharged_filter.push_back(isoObject);
451  }
452  if (!calculateWeights_) {
453  for (auto const& isoObject : isoNeutral_) {
454  if (filter(isoObject))
455  isoNeutral_filter.push_back(isoObject);
456  }
457  isoNeutral_ = isoNeutral_filter;
458  } else {
459  for (auto const& isoObject : isoNeutralWeight_) {
460  if (filter2(isoObject))
461  isoNeutralWeight_filter.push_back(isoObject);
462  }
463  isoNeutralWeight_ = isoNeutralWeight_filter;
464  }
465  isoCharged_ = isoCharged_filter;
466  }
467 
468  bool failsOccupancyCut = false;
469  bool failsSumPtCut = false;
470  bool failsRelativeSumPtCut = false;
471 
472  //--- nObjects requirement
473  int neutrals = isoNeutral_.size();
474 
475  if (applyDeltaBeta_) {
476  neutrals -= TMath::Nint(deltaBetaFactorThisEvent_ * isoPU_.size());
477  }
478  if (neutrals < 0) {
479  neutrals = 0;
480  }
481 
482  size_t nOccupants = isoCharged_.size() + neutrals;
483 
484  failsOccupancyCut = (nOccupants > maximumOccupancy_);
485 
486  double footprintCorrection_value = 0.;
487  if (applyFootprintCorrection_ || storeRawFootprintCorrection_) {
488  for (std::vector<std::unique_ptr<FootprintCorrection> >::const_iterator footprintCorrection =
489  footprintCorrections_.begin();
490  footprintCorrection != footprintCorrections_.end();
491  ++footprintCorrection) {
492  if ((*footprintCorrection)->selection_(*pfTau)) {
493  footprintCorrection_value = (*footprintCorrection)->offset_(*pfTau);
494  }
495  }
496  }
497 
498  double totalPt = 0.;
499  double puPt = 0.;
500  //--- Sum PT requirement
501  if (applySumPtCut_ || applyRelativeSumPtCut_ || storeRawSumPt_ || storeRawPUsumPt_) {
502  double chargedPt = 0.;
503  double neutralPt = 0.;
504  double weightedNeutralPt = 0.;
505  for (auto const& isoObject : isoCharged_) {
506  //-------------------------------------------------------------------------
507  // CV: fix for Phase-2 HLT tau trigger studies
508  // (pT of PFCandidates within HGCal acceptance is significantly higher than track pT !!)
509  if (enableHGCalWorkaround_) {
510  double trackPt = (isoObject->bestTrack()) ? isoObject->bestTrack()->pt() : 0.;
511  double pfCandPt = isoObject->pt();
512  if (pfCandPt > trackPt) {
513  chargedPt += trackPt;
514  neutralPt += pfCandPt - trackPt;
515  } else {
516  chargedPt += isoObject->pt();
517  }
518  } else {
519  chargedPt += isoObject->pt();
520  }
521  //-------------------------------------------------------------------------
522  }
523  if (!calculateWeights_) {
524  for (auto const& isoObject : isoNeutral_) {
525  neutralPt += isoObject->pt();
526  }
527  } else {
528  for (auto const& isoObject : isoNeutralWeight_) {
529  weightedNeutralPt += isoObject.pt();
530  }
531  }
532  for (auto const& isoObject : isoPU_) {
533  puPt += isoObject->pt();
534  }
535  LogTrace("discriminate") << "chargedPt = " << chargedPt;
536  LogTrace("discriminate") << "neutralPt = " << neutralPt;
537  LogTrace("discriminate") << "weighted neutral Pt = " << weightedNeutralPt;
538  LogTrace("discriminate") << "puPt = " << puPt << " (delta-beta corr. = " << (deltaBetaFactorThisEvent_ * puPt)
539  << ")";
540 
541  if (calculateWeights_) {
542  neutralPt = weightedNeutralPt;
543  }
544 
545  if (applyDeltaBeta_) {
546  neutralPt -= (deltaBetaFactorThisEvent_ * puPt);
547  }
548 
549  if (applyFootprintCorrection_) {
550  neutralPt -= footprintCorrection_value;
551  }
552 
553  if (applyRhoCorrection_) {
554  neutralPt -= rhoThisEvent_;
555  }
556 
557  if (neutralPt < 0.) {
558  neutralPt = 0.;
559  }
560 
561  totalPt = chargedPt + weightGammas_ * neutralPt;
562  LogTrace("discriminate") << "totalPt = " << totalPt << " (cut = " << maximumSumPt_ << ")";
563 
564  failsSumPtCut = (totalPt > maximumSumPt_);
565 
566  //--- Relative Sum PT requirement
567  failsRelativeSumPtCut = (totalPt > ((pfTau->pt() - offsetRelativeSumPt_) * maximumRelativeSumPt_));
568  }
569 
570  bool failsPhotonPtSumOutsideSignalConeCut = false;
571  double photonSumPt_outsideSignalCone = 0.;
572  if (applyPhotonPtSumOutsideSignalConeCut_ || storeRawPhotonSumPt_outsideSignalCone_) {
573  const std::vector<reco::CandidatePtr>& signalGammas = pfTau->signalGammaCands();
574  for (std::vector<reco::CandidatePtr>::const_iterator signalGamma = signalGammas.begin();
575  signalGamma != signalGammas.end();
576  ++signalGamma) {
577  double dR = deltaR(pfTau->eta(), pfTau->phi(), (*signalGamma)->eta(), (*signalGamma)->phi());
578  if (dR > pfTau->signalConeSize())
579  photonSumPt_outsideSignalCone += (*signalGamma)->pt();
580  }
581  if (photonSumPt_outsideSignalCone > maxAbsPhotonSumPt_outsideSignalCone_ ||
582  photonSumPt_outsideSignalCone > (maxRelPhotonSumPt_outsideSignalCone_ * pfTau->pt())) {
583  failsPhotonPtSumOutsideSignalConeCut = true;
584  }
585  }
586 
587  bool fails = (applyOccupancyCut_ && failsOccupancyCut) || (applySumPtCut_ && failsSumPtCut) ||
588  (applyRelativeSumPtCut_ && failsRelativeSumPtCut) ||
589  (applyPhotonPtSumOutsideSignalConeCut_ && failsPhotonPtSumOutsideSignalConeCut);
590 
591  if (pfTau->pt() > minPtForNoIso_ && minPtForNoIso_ > 0.) {
592  return 1.;
593  LogDebug("discriminate") << "tau pt = " << pfTau->pt() << "\t min cutoff pt = " << minPtForNoIso_;
594  }
595 
596  // We did error checking in the constructor, so this is safe.
597  if (storeRawSumPt_) {
598  return totalPt;
599  } else if (storeRawPUsumPt_) {
600  if (applyDeltaBeta_)
601  return puPt;
602  else if (applyRhoCorrection_)
603  return rhoThisEvent_;
604  else
605  return 0.;
606  } else if (storeRawOccupancy_) {
607  return nOccupants;
608  } else if (storeRawFootprintCorrection_) {
609  return footprintCorrection_value;
610  } else if (storeRawPhotonSumPt_outsideSignalCone_) {
611  return photonSumPt_outsideSignalCone;
612  } else {
613  return (fails ? 0. : 1.);
614  }
615 }
616 
618  // pfRecoTauDiscriminationByIsolation
620  desc.add<bool>("storeRawFootprintCorrection", false);
621  desc.add<edm::InputTag>("PFTauProducer", edm::InputTag("pfRecoTauProducer"));
622  desc.add<bool>("storeRawOccupancy", false);
623  desc.add<double>("maximumSumPtCut", 6.0);
624 
625  edm::ParameterSetDescription desc_qualityCuts;
627  desc.add<edm::ParameterSetDescription>("qualityCuts", desc_qualityCuts);
628 
629  desc.add<double>("minTauPtForNoIso", -99.0);
630  desc.add<double>("maxAbsPhotonSumPt_outsideSignalCone", 1000000000.0);
631  desc.add<edm::InputTag>("vertexSrc", edm::InputTag("offlinePrimaryVertices"));
632  desc.add<bool>("applySumPtCut", false);
633  desc.add<double>("rhoConeSize", 0.5);
634  desc.add<bool>("ApplyDiscriminationByTrackerIsolation", true);
635  desc.add<bool>("storeRawPhotonSumPt_outsideSignalCone", false);
636  desc.add<edm::InputTag>("rhoProducer", edm::InputTag("fixedGridRhoFastjetAll"));
637  desc.add<bool>("enableHGCalWorkaround", false);
638 
639  {
641  vpsd1.add<std::string>("selection");
642  vpsd1.add<std::string>("offset");
643  desc.addVPSet("footprintCorrections", vpsd1, {});
644  }
645 
646  desc.add<std::string>("deltaBetaFactor", "0.38");
647  desc.add<bool>("applyFootprintCorrection", false);
648  desc.add<bool>("UseAllPFCandsForWeights", false);
649  desc.add<double>("relativeSumPtCut", 0.0);
650  {
651  edm::ParameterSetDescription pset_Prediscriminants;
652  pset_Prediscriminants.add<std::string>("BooleanOperator", "and");
653  {
655  psd1.add<double>("cut");
656  psd1.add<edm::InputTag>("Producer");
657  pset_Prediscriminants.addOptional<edm::ParameterSetDescription>("leadTrack", psd1);
658  }
659  {
660  // encountered this at
661  // RecoTauTag/Configuration/python/HPSPFTaus_cff.py
662  // Prediscriminants = requireDecayMode.clone(),
663  // requireDecayMode = cms.PSet(
664  // BooleanOperator = cms.string("and"),
665  // decayMode = cms.PSet(
666  // Producer = cms.InputTag('hpsPFTauDiscriminationByDecayModeFindingNewDMs'),
667  // cut = cms.double(0.5)
668  // )
669  // )
671  psd1.add<double>("cut");
672  psd1.add<edm::InputTag>("Producer");
673  pset_Prediscriminants.addOptional<edm::ParameterSetDescription>("decayMode", psd1);
674  }
675  {
676  // encountered this at
677  // RecoTauTag/Configuration/python/HPSPFTaus_cff.py
678  // Prediscriminants = requireDecayMode.clone(),
679  // hpsPFTauDiscriminationByLooseIsolation.Prediscriminants.preIso = cms.PSet(
680  // Producer = cms.InputTag("hpsPFTauDiscriminationByLooseChargedIsolation"),
681  // cut = cms.double(0.5)
682  // )
684  psd1.add<double>("cut");
685  psd1.add<edm::InputTag>("Producer");
686  pset_Prediscriminants.addOptional<edm::ParameterSetDescription>("preIso", psd1);
687  }
688  desc.add<edm::ParameterSetDescription>("Prediscriminants", pset_Prediscriminants);
689  }
690 
691  desc.add<unsigned int>("maximumOccupancy", 0);
692  desc.add<int>("verbosity", 0);
693 
694  desc.add<bool>("applyOccupancyCut", true);
695  desc.add<bool>("applyDeltaBetaCorrection", false);
696  desc.add<bool>("applyRelativeSumPtCut", false);
697  desc.add<bool>("storeRawPUsumPt", false);
698  desc.add<bool>("applyPhotonPtSumOutsideSignalConeCut", false);
699  desc.add<bool>("deltaBetaPUTrackPtCutOverride", false);
700  desc.add<bool>("ApplyDiscriminationByWeightedECALIsolation", false);
701  desc.add<bool>("storeRawSumPt", false);
702  desc.add<bool>("ApplyDiscriminationByECALIsolation", true);
703  desc.add<bool>("applyRhoCorrection", false);
704 
705  desc.add<double>("WeightECALIsolation", 1.0);
706  desc.add<double>("rhoUEOffsetCorrection", 1.0);
707  desc.add<double>("maxRelPhotonSumPt_outsideSignalCone", 0.1);
708  desc.add<double>("deltaBetaPUTrackPtCutOverride_val", -1.5);
709  desc.add<double>("isoConeSizeForDeltaBeta", 0.5);
710  desc.add<double>("relativeSumPtOffset", 0.0);
711  desc.add<double>("customOuterCone", -1.0);
712  desc.add<edm::InputTag>("particleFlowSrc", edm::InputTag("particleFlow"));
713 
714  descriptions.add("pfRecoTauDiscriminationByIsolation", desc);
715 }
716 
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
PFRecoTauDiscriminationByIsolation(const edm::ParameterSet &pset)
std::unique_ptr< tau::RecoTauQualityCuts > pileupQcutsGeneralQCuts_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
static void fillDescriptions(edm::ParameterSetDescription &descriptions)
Declare all parameters read from python config file.
std::vector< ParameterSet > VParameterSet
Definition: ParameterSet.h:34
edm::EDGetTokenT< edm::View< reco::Candidate > > pfCand_token
selection
main part
Definition: corrVsCorr.py:100
ParameterSet const & getParameterSet(std::string const &) const
void beginEvent(const edm::Event &evt, const edm::EventSetup &evtSetup) override
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
const LorentzVector & p4() const final
four-momentum Lorentz vector
#define LogTrace(id)
std::vector< std::unique_ptr< FootprintCorrection > > footprintCorrections_
void push_back(D *&d)
Definition: OwnVector.h:326
FootprintCorrection(const std::string &selection, const std::string &offset)
size_type size() const
Definition: OwnVector.h:300
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
virtual int charge() const =0
electric charge
std::pair< edm::ParameterSet, edm::ParameterSet > factorizePUQCuts(const edm::ParameterSet &inputSet)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
double discriminate(const PFTauRef &pfTau) const override
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
std::vector< reco::CandidatePtr > chargedPFCandidatesInEvent_
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
double weightedSum(const std::vector< CandidatePtr > &inColl_, double eta, double phi) const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
fixed size matrix
HLT enums.
std::unique_ptr< tau::RecoTauQualityCuts > pileupQcutsPUTrackSelection_
void setP4(const LorentzVector &p4) final
set 4-momentum
std::unique_ptr< tau::RecoTauQualityCuts > qcuts_
def move(src, dest)
Definition: eostools.py:511
void reserve(size_t)
Definition: OwnVector.h:320
std::unique_ptr< tau::RecoTauVertexAssociator > vertexAssociator_
Definition: event.py:1
edm::EDGetTokenT< reco::VertexCollection > vertex_token
#define LogDebug(id)