CMS 3D CMS Logo

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