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  std::unique_ptr<FootprintCorrection> footprintCorrection(new 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 
ConfigurationDescriptions.h
PFRecoTauDiscriminationByIsolation::FootprintCorrection
Definition: PFRecoTauDiscriminationByIsolation.cc:224
PFRecoTauDiscriminationByIsolation::discriminate
double discriminate(const PFTauRef &pfTau) const override
Definition: PFRecoTauDiscriminationByIsolation.cc:308
zmumugammaAnalyzer_cfi.pfCandidates
pfCandidates
Definition: zmumugammaAnalyzer_cfi.py:11
PFRecoTauDiscriminationByIsolation::FootprintCorrection::offset_
StringObjectFunction< PFTau > offset_
Definition: PFRecoTauDiscriminationByIsolation.cc:229
mps_fire.i
i
Definition: mps_fire.py:428
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
StringObjectFunction< PFTau >
TauDiscriminationProducerBase.h
PFRecoTauDiscriminationByIsolation::storeRawFootprintCorrection_
bool storeRawFootprintCorrection_
Definition: PFRecoTauDiscriminationByIsolation.cc:237
PFRecoTauDiscriminationByIsolation::deltaBetaCollectionCone_
double deltaBetaCollectionCone_
Definition: PFRecoTauDiscriminationByIsolation.cc:253
PFRecoTauDiscriminationByIsolation::includeGammas_
bool includeGammas_
Definition: PFRecoTauDiscriminationByIsolation.cc:204
min
T min(T a, T b)
Definition: MathUtil.h:58
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
gather_cfg.cout
cout
Definition: gather_cfg.py:144
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
PFRecoTauDiscriminationByIsolation::maximumOccupancy_
uint32_t maximumOccupancy_
Definition: PFRecoTauDiscriminationByIsolation.cc:209
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
PFRecoTauDiscriminationByIsolation::chargedPFCandidatesInEvent_
std::vector< reco::CandidatePtr > chargedPFCandidatesInEvent_
Definition: PFRecoTauDiscriminationByIsolation.cc:251
edm::VParameterSet
std::vector< ParameterSet > VParameterSet
Definition: ParameterSet.h:34
PFRecoTauDiscriminationByIsolation::moduleLabel_
std::string moduleLabel_
Definition: PFRecoTauDiscriminationByIsolation.cc:192
PFRecoTauDiscriminationByIsolation::weightedSum
double weightedSum(const std::vector< CandidatePtr > &inColl_, double eta, double phi) const
Definition: PFRecoTauDiscriminationByIsolation.cc:179
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
ConeTools.h
PFRecoTauDiscriminationByIsolation::useAllPFCands_
bool useAllPFCands_
Definition: PFRecoTauDiscriminationByIsolation.cc:259
edm::Handle
Definition: AssociativeIterator.h:50
edm::ParameterSetDescription::addOptional
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:105
PFRecoTauDiscriminationByIsolation::pileupQcutsPUTrackSelection_
std::unique_ptr< tau::RecoTauQualityCuts > pileupQcutsPUTrackSelection_
Definition: PFRecoTauDiscriminationByIsolation.cc:198
PFRecoTauDiscriminationByIsolation::rhoProducer_
edm::InputTag rhoProducer_
Definition: PFRecoTauDiscriminationByIsolation.cc:260
RecoTauVertexAssociator.h
edm::Ref< PFTauCollection >
PFRecoTauDiscriminationByIsolation::maxAbsPhotonSumPt_outsideSignalCone_
double maxAbsPhotonSumPt_outsideSignalCone_
Definition: PFRecoTauDiscriminationByIsolation.cc:220
PFRecoTauDiscriminationByIsolation::maxRelPhotonSumPt_outsideSignalCone_
double maxRelPhotonSumPt_outsideSignalCone_
Definition: PFRecoTauDiscriminationByIsolation.cc:221
PFRecoTauDiscriminationByIsolation::FootprintCorrection::selection_
StringCutObjectSelector< PFTau > selection_
Definition: PFRecoTauDiscriminationByIsolation.cc:228
PFRecoTauDiscriminationByIsolation::qualityCutsPSet_
edm::ParameterSet qualityCutsPSet_
Definition: PFRecoTauDiscriminationByIsolation.cc:194
PFRecoTauDiscriminationByIsolation::verbosity_
int verbosity_
Definition: PFRecoTauDiscriminationByIsolation.cc:268
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
PFRecoTauDiscriminationByIsolation::rhoThisEvent_
double rhoThisEvent_
Definition: PFRecoTauDiscriminationByIsolation.cc:265
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
reco::Candidate::charge
virtual int charge() const =0
electric charge
PFRecoTauDiscriminationByIsolation::FootprintCorrection::~FootprintCorrection
~FootprintCorrection()
Definition: PFRecoTauDiscriminationByIsolation.cc:227
PFRecoTauDiscriminationByIsolation::storeRawPhotonSumPt_outsideSignalCone_
bool storeRawPhotonSumPt_outsideSignalCone_
Definition: PFRecoTauDiscriminationByIsolation.cc:238
PVValHelper::eta
Definition: PVValidationHelpers.h:69
PFRecoTauDiscriminationByIsolation::vertexAssociator_
std::unique_ptr< tau::RecoTauVertexAssociator > vertexAssociator_
Definition: PFRecoTauDiscriminationByIsolation.cc:201
fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
corrVsCorr.selection
selection
main part
Definition: corrVsCorr.py:100
LeafCandidate.h
TauDiscriminationProducerBase
Definition: TauDiscriminationProducerBase.h:55
HLT_FULL_cff.deltaBetaPUTrackPtCutOverride
deltaBetaPUTrackPtCutOverride
Definition: HLT_FULL_cff.py:32885
ParameterSetDescription.h
ALCARECOTkAlBeamHalo_cff.filter
filter
Definition: ALCARECOTkAlBeamHalo_cff.py:27
PFRecoTauDiscriminationByIsolation::qcuts_
std::unique_ptr< tau::RecoTauQualityCuts > qcuts_
Definition: PFRecoTauDiscriminationByIsolation.cc:195
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
Vertex.h
RecoTauQualityCuts.h
PFRecoTauDiscriminationByIsolation::enableHGCalWorkaround_
bool enableHGCalWorkaround_
Definition: PFRecoTauDiscriminationByIsolation.cc:206
PFRecoTauDiscriminationByIsolation::applyOccupancyCut_
bool applyOccupancyCut_
Definition: PFRecoTauDiscriminationByIsolation.cc:208
edm::OwnVector::reserve
void reserve(size_t)
Definition: OwnVector.h:320
PFRecoTauDiscriminationByIsolation::vertex_token
edm::EDGetTokenT< reco::VertexCollection > vertex_token
Definition: PFRecoTauDiscriminationByIsolation.cc:250
PFRecoTauDiscriminationByIsolation::applyDeltaBeta_
bool applyDeltaBeta_
Definition: PFRecoTauDiscriminationByIsolation.cc:245
PFRecoTauDiscriminationByIsolation::maximumSumPt_
double maximumSumPt_
Definition: PFRecoTauDiscriminationByIsolation.cc:211
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
edm::ParameterSet
Definition: ParameterSet.h:47
PFRecoTauDiscriminationByIsolation::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: PFRecoTauDiscriminationByIsolation.cc:617
reco::tau::cone::DeltaRPtrFilter
Definition: ConeTools.h:33
PFRecoTauDiscriminationByIsolation::rhoConeSize_
double rhoConeSize_
Definition: PFRecoTauDiscriminationByIsolation.cc:262
PFRecoTauDiscriminationByIsolation::storeRawOccupancy_
bool storeRawOccupancy_
Definition: PFRecoTauDiscriminationByIsolation.cc:234
ParameterSet
Definition: Functions.h:16
PFRecoTauDiscriminationByIsolation::PFRecoTauDiscriminationByIsolation
PFRecoTauDiscriminationByIsolation(const edm::ParameterSet &pset)
Definition: PFRecoTauDiscriminationByIsolation.cc:32
PFRecoTauDiscriminationByIsolation::calculateWeights_
bool calculateWeights_
Definition: PFRecoTauDiscriminationByIsolation.cc:205
edm::Ref::isNonnull
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
reco::deltaR2
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
PFRecoTauDiscriminationByIsolation::minPtForNoIso_
double minPtForNoIso_
Definition: PFRecoTauDiscriminationByIsolation.cc:217
reco::tau::cone::DeltaRFilter
Definition: ConeTools.h:15
PFRecoTauDiscriminationByIsolation::applyPhotonPtSumOutsideSignalConeCut_
bool applyPhotonPtSumOutsideSignalConeCut_
Definition: PFRecoTauDiscriminationByIsolation.cc:219
PFRecoTauDiscriminationByIsolation::pileupQcutsGeneralQCuts_
std::unique_ptr< tau::RecoTauQualityCuts > pileupQcutsGeneralQCuts_
Definition: PFRecoTauDiscriminationByIsolation.cc:199
PFRecoTauDiscriminationByIsolation::storeRawSumPt_
bool storeRawSumPt_
Definition: PFRecoTauDiscriminationByIsolation.cc:235
cand
Definition: decayParser.h:32
MetAnalyzer.pv
def pv(vc)
Definition: MetAnalyzer.py:7
PFRecoTauDiscriminationByIsolation::rho_token
edm::EDGetTokenT< double > rho_token
Definition: PFRecoTauDiscriminationByIsolation.cc:261
reco::LeafCandidate::p4
const LorentzVector & p4() const final
four-momentum Lorentz vector
Definition: LeafCandidate.h:114
reco::tau::RecoTauQualityCuts::fillDescriptions
static void fillDescriptions(edm::ParameterSetDescription &descriptions)
Declare all parameters read from python config file.
Definition: RecoTauQualityCuts.cc:346
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::EventSetup
Definition: EventSetup.h:57
reco::tau::factorizePUQCuts
std::pair< edm::ParameterSet, edm::ParameterSet > factorizePUQCuts(const edm::ParameterSet &inputSet)
Definition: RecoTauQualityCuts.cc:167
PFRecoTauDiscriminationByIsolation::storeRawPUsumPt_
bool storeRawPUsumPt_
Definition: PFRecoTauDiscriminationByIsolation.cc:236
PFRecoTauDiscriminationByIsolation
Definition: PFRecoTauDiscriminationByIsolation.cc:30
edm::Ptr< Candidate >
PFRecoTauDiscriminationByIsolation::applySumPtCut_
bool applySumPtCut_
Definition: PFRecoTauDiscriminationByIsolation.cc:210
PFRecoTauDiscriminationByIsolation::vertexSrc_
edm::InputTag vertexSrc_
Definition: PFRecoTauDiscriminationByIsolation.cc:249
PFRecoTauDiscriminationByIsolation::pfCand_token
edm::EDGetTokenT< edm::View< reco::Candidate > > pfCand_token
Definition: PFRecoTauDiscriminationByIsolation.cc:247
PFRecoTauDiscriminationByIsolation::includeTracks_
bool includeTracks_
Definition: PFRecoTauDiscriminationByIsolation.cc:203
PFRecoTauDiscriminationByIsolation::deltaBetaFormula_
std::unique_ptr< TFormula > deltaBetaFormula_
Definition: PFRecoTauDiscriminationByIsolation.cc:254
reco::LeafCandidate::setP4
void setP4(const LorentzVector &p4) final
set 4-momentum
Definition: LeafCandidate.h:158
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
PFRecoTauDiscriminationByIsolation::maximumRelativeSumPt_
double maximumRelativeSumPt_
Definition: PFRecoTauDiscriminationByIsolation.cc:213
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
PFRecoTauDiscriminationByIsolation::beginEvent
void beginEvent(const edm::Event &evt, const edm::EventSetup &evtSetup) override
Definition: PFRecoTauDiscriminationByIsolation.cc:271
StringCutObjectSelector.h
PFRecoTauDiscriminationByIsolation::rhoUEOffsetCorrection_
double rhoUEOffsetCorrection_
Definition: PFRecoTauDiscriminationByIsolation.cc:263
PFRecoTauDiscriminationByIsolation::applyRelativeSumPtCut_
bool applyRelativeSumPtCut_
Definition: PFRecoTauDiscriminationByIsolation.cc:212
PFRecoTauDiscriminationByIsolation::~PFRecoTauDiscriminationByIsolation
~PFRecoTauDiscriminationByIsolation() override
Definition: PFRecoTauDiscriminationByIsolation.cc:174
StringCutObjectSelector< PFTau >
Exception
Definition: hltDiff.cc:246
PFRecoTauDiscriminationByIsolation::deltaBetaFactorThisEvent_
double deltaBetaFactorThisEvent_
Definition: PFRecoTauDiscriminationByIsolation.cc:255
PFRecoTauDiscriminationByIsolation::offsetRelativeSumPt_
double offsetRelativeSumPt_
Definition: PFRecoTauDiscriminationByIsolation.cc:214
PFRecoTauDiscriminationByIsolation::applyFootprintCorrection_
bool applyFootprintCorrection_
Definition: PFRecoTauDiscriminationByIsolation.cc:223
reco::deltaR
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
PFRecoTauDiscriminationByIsolation::footprintCorrections_
std::vector< std::unique_ptr< FootprintCorrection > > footprintCorrections_
Definition: PFRecoTauDiscriminationByIsolation.cc:231
dqm-mbProfile.log
log
Definition: dqm-mbProfile.py:17
edm::OwnVector::push_back
void push_back(D *&d)
Definition: OwnVector.h:326
HLT_FULL_cff.deltaBetaPUTrackPtCutOverride_val
deltaBetaPUTrackPtCutOverride_val
Definition: HLT_FULL_cff.py:32905
PFRecoTauDiscriminationByIsolation::applyRhoCorrection_
bool applyRhoCorrection_
Definition: PFRecoTauDiscriminationByIsolation.cc:258
PFRecoTauDiscriminationByIsolation::weightGammas_
double weightGammas_
Definition: PFRecoTauDiscriminationByIsolation.cc:207
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
reco::LeafCandidate
Definition: LeafCandidate.h:16
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:224
HGC3DClusterGenMatchSelector_cfi.dR
dR
Definition: HGC3DClusterGenMatchSelector_cfi.py:7
PFRecoTauDiscriminationByIsolation::pfCandSrc_
edm::InputTag pfCandSrc_
Definition: PFRecoTauDiscriminationByIsolation.cc:246
PFRecoTauDiscriminationByIsolation::rhoCorrectionThisEvent_
double rhoCorrectionThisEvent_
Definition: PFRecoTauDiscriminationByIsolation.cc:264
event
Definition: event.py:1
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:82
edm::Event
Definition: Event.h:73
StringObjectFunction.h
edm::OwnVector::size
size_type size() const
Definition: OwnVector.h:300
listHistos.trackPt
trackPt
Definition: listHistos.py:120
edm::InputTag
Definition: InputTag.h:15
PFRecoTauDiscriminationByIsolation::FootprintCorrection::FootprintCorrection
FootprintCorrection(const std::string &selection, const std::string &offset)
Definition: PFRecoTauDiscriminationByIsolation.cc:225
edm::ParameterSet::getParameterSet
ParameterSet const & getParameterSet(std::string const &) const
Definition: ParameterSet.cc:2128
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
edm::OwnVector
Definition: OwnVector.h:24
pwdgSkimBPark_cfi.vertices
vertices
Definition: pwdgSkimBPark_cfi.py:7
PFRecoTauDiscriminationByIsolation::customIsoCone_
double customIsoCone_
Definition: PFRecoTauDiscriminationByIsolation.cc:215