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 {
30  public:
33  moduleLabel_(pset.getParameter<std::string>("@module_label")),
34  qualityCutsPSet_(pset.getParameter<edm::ParameterSet>("qualityCuts"))
35  {
36  includeTracks_ = pset.getParameter<bool>(
37  "ApplyDiscriminationByTrackerIsolation");
38  includeGammas_ = pset.getParameter<bool>(
39  "ApplyDiscriminationByECALIsolation");
40 
41  calculateWeights_ = pset.getParameter<bool>("ApplyDiscriminationByWeightedECALIsolation");
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")
72  << "A 'store raw' and a 'apply cut' option have been set to true "
73  << "simultaneously. These options are mutually exclusive.";
74  }
75  }
76 
77  // sanity check2 - can't use weighted and unweighted iso at the same time
78  if ( includeGammas_ && calculateWeights_ ) {
79  throw cms::Exception("BasIsoConfig")
80  << "Both 'ApplyDiscriminationByECALIsolation' and 'ApplyDiscriminationByWeightedECALIsolation' "
81  << "have been set to true. These options are mutually exclusive.";
82  }
83 
84  // Can only store one type
85  int numStoreOptions = 0;
86  if ( storeRawSumPt_ ) ++numStoreOptions;
87  if ( storeRawOccupancy_ ) ++numStoreOptions;
88  if ( storeRawPUsumPt_ ) ++numStoreOptions;
89  if ( storeRawFootprintCorrection_ ) ++numStoreOptions;
90  if ( storeRawPhotonSumPt_outsideSignalCone_ ) ++numStoreOptions;
91  if ( numStoreOptions > 1 ) {
92  throw cms::Exception("BadIsoConfig")
93  << "Multiple 'store sum pt' and/or 'store occupancy' options are set."
94  << " These options are mutually exclusive.";
95  }
96 
97  customIsoCone_ = pset.getParameter<double>("customOuterCone");
98 
99  applyPhotonPtSumOutsideSignalConeCut_ = pset.getParameter<bool>("applyPhotonPtSumOutsideSignalConeCut");
100  if ( applyPhotonPtSumOutsideSignalConeCut_ ) {
101  maxAbsPhotonSumPt_outsideSignalCone_ = pset.getParameter<double>("maxAbsPhotonSumPt_outsideSignalCone");
102  maxRelPhotonSumPt_outsideSignalCone_ = pset.getParameter<double>("maxRelPhotonSumPt_outsideSignalCone");
103  }
104 
105  applyFootprintCorrection_ = pset.getParameter<bool>("applyFootprintCorrection");
106  if ( applyFootprintCorrection_ || storeRawFootprintCorrection_ ) {
107  edm::VParameterSet cfgFootprintCorrections = pset.getParameter<edm::VParameterSet>("footprintCorrections");
108  for ( edm::VParameterSet::const_iterator cfgFootprintCorrection = cfgFootprintCorrections.begin();
109  cfgFootprintCorrection != cfgFootprintCorrections.end(); ++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(
119  "isolationQualityCuts");
120 
121  qcuts_.reset(new tau::RecoTauQualityCuts(isolationQCuts));
122 
123  vertexAssociator_.reset(
124  new tau::RecoTauVertexAssociator(qualityCutsPSet_,consumesCollector()));
125 
126  applyDeltaBeta_ = pset.getParameter<bool>("applyDeltaBetaCorrection");
127 
128  if ( applyDeltaBeta_ || calculateWeights_ ) {
129  // Factorize the isolation QCuts into those that are used to
130  // select PU and those that are not.
131  std::pair<edm::ParameterSet, edm::ParameterSet> puFactorizedIsoQCuts =
132  reco::tau::factorizePUQCuts(isolationQCuts);
133 
134  // Determine the pt threshold for the PU tracks
135  // First check if the user specifies explicitly the cut.
136  // For that the user has to provide a >= 0 value for the PtCutOverride.
137  bool deltaBetaPUTrackPtCutOverride = pset.getParameter<bool>("deltaBetaPUTrackPtCutOverride");
138  if ( deltaBetaPUTrackPtCutOverride ) {
139  double deltaBetaPUTrackPtCutOverride_val = pset.getParameter<double>("deltaBetaPUTrackPtCutOverride_val");
140  puFactorizedIsoQCuts.second.addParameter<double>(
141  "minTrackPt",
143  } else {
144  // Secondly take it from the minGammaEt
145  puFactorizedIsoQCuts.second.addParameter<double>(
146  "minTrackPt",
147  isolationQCuts.getParameter<double>("minGammaEt"));
148  }
149 
150  pileupQcutsPUTrackSelection_.reset(new tau::RecoTauQualityCuts(
151  puFactorizedIsoQCuts.first));
152 
153  pileupQcutsGeneralQCuts_.reset(new tau::RecoTauQualityCuts(
154  puFactorizedIsoQCuts.second));
155 
156  pfCandSrc_ = pset.getParameter<edm::InputTag>("particleFlowSrc");
157  pfCand_token = consumes<edm::View<reco::Candidate> >(pfCandSrc_);
158  vertexSrc_ = pset.getParameter<edm::InputTag>("vertexSrc");
159  vertex_token = consumes<reco::VertexCollection>(vertexSrc_);
160  deltaBetaCollectionCone_ = pset.getParameter<double>(
161  "isoConeSizeForDeltaBeta");
162  std::string deltaBetaFactorFormula =
163  pset.getParameter<string>("deltaBetaFactor");
164  deltaBetaFormula_.reset(
165  new TFormula("DB_corr", deltaBetaFactorFormula.c_str()));
166  }
167 
168  applyRhoCorrection_ = pset.getParameter<bool>("applyRhoCorrection");
169  if ( applyRhoCorrection_ ) {
170  rhoProducer_ = pset.getParameter<edm::InputTag>("rhoProducer");
171  rho_token=consumes<double>(rhoProducer_);
172  rhoConeSize_ = pset.getParameter<double>("rhoConeSize");
173  rhoUEOffsetCorrection_ =
174  pset.getParameter<double>("rhoUEOffsetCorrection");
175  }
176  useAllPFCands_ = pset.getParameter<bool>("UseAllPFCandsForWeights");
177 
178  verbosity_ = pset.getParameter<int>("verbosity");
179  }
180 
182  {
183  }
184 
185  void beginEvent(const edm::Event& evt, const edm::EventSetup& evtSetup) override;
186  double discriminate(const PFTauRef& pfTau) const override;
187 
188  inline double weightedSum(const std::vector<CandidatePtr>& inColl_, double eta, double phi) const {
189  double out = 1.0;
190  for (auto const & inObj_ : inColl_){
191  double sum = (inObj_->pt()*inObj_->pt())/(deltaR2(eta,phi,inObj_->eta(),inObj_->phi()));
192  if(sum > 1.0) out *= sum;
193  }
194  return out;
195  }
196 
197  static void fillDescriptions(edm::ConfigurationDescriptions & descriptions);
198 
199  private:
201 
203  std::auto_ptr<tau::RecoTauQualityCuts> qcuts_;
204 
205  // Inverted QCut which selects tracks with bad DZ/trackWeight
206  std::auto_ptr<tau::RecoTauQualityCuts> pileupQcutsPUTrackSelection_;
207  std::auto_ptr<tau::RecoTauQualityCuts> pileupQcutsGeneralQCuts_;
208 
209  std::auto_ptr<tau::RecoTauVertexAssociator> vertexAssociator_;
210 
223  // RIC:
225 
229 
232  {
234  : selection_(selection),
235  offset_(offset)
236  {}
240  };
241  std::vector<std::unique_ptr<FootprintCorrection> > footprintCorrections_;
242 
243  // Options to store the raw value in the discriminator instead of boolean pass/fail flag
249 
250  /* **********************************************************************
251  **** Pileup Subtraction Parameters ***********************************
252  **********************************************************************/
253 
254  // Delta Beta correction
258  // Keep track of how many vertices are in the event
261  std::vector<reco::CandidatePtr> chargedPFCandidatesInEvent_;
262  // Size of cone used to collect PU tracks
264  std::auto_ptr<TFormula> deltaBetaFormula_;
266 
267  // Rho correction
272  double rhoConeSize_;
276 
277  // Flag to enable/disable debug output
279 };
280 
282 {
283  // NB: The use of the PV in this context is necessitated by its use in
284  // applying quality cuts to the different objects in the isolation cone
285  // The vertex associator contains the logic to select the appropriate vertex
286  // We need to pass it the event so it can load the vertices.
287  vertexAssociator_->setEvent(event);
288 
289  // If we are applying the delta beta correction, we need to get the PF
290  // candidates from the event so we can find the PU tracks.
291  if ( applyDeltaBeta_ || calculateWeights_ ) {
292  // Collect all the PF pile up tracks
294  event.getByToken(pfCand_token, pfCandidates);
295  chargedPFCandidatesInEvent_.clear();
296  chargedPFCandidatesInEvent_.reserve(pfCandidates->size());
297  size_t numPFCandidates = pfCandidates->size();
298  for ( size_t i = 0; i < numPFCandidates; ++i ) {
299  reco::CandidatePtr pfCandidate(pfCandidates, i);
300  if ( pfCandidate->charge() != 0 ) {
301  chargedPFCandidatesInEvent_.push_back(pfCandidate);
302  }
303  }
304  // Count all the vertices in the event, to parameterize the DB
305  // correction factor
307  event.getByToken(vertex_token, vertices);
308  size_t nVtxThisEvent = vertices->size();
309  deltaBetaFactorThisEvent_ = deltaBetaFormula_->Eval(nVtxThisEvent);
310  }
311 
312  if ( applyRhoCorrection_ ) {
313  edm::Handle<double> rhoHandle_;
314  event.getByToken(rho_token, rhoHandle_);
315  rhoThisEvent_ = (*rhoHandle_ - rhoUEOffsetCorrection_)*
316  (3.14159)*rhoConeSize_*rhoConeSize_;
317  }
318 }
319 
320 double
322 {
323  LogDebug("discriminate") << " tau: Pt = " << pfTau->pt() << ", eta = " << pfTau->eta() << ", phi = " << pfTau->phi();
324  LogDebug("discriminate") << *pfTau ;
325 
326  // collect the objects we are working with (ie tracks, tracks+gammas, etc)
327  std::vector<CandidatePtr> isoCharged_;
328  std::vector<CandidatePtr> isoNeutral_;
329  std::vector<CandidatePtr> isoPU_;
330  CandidateCollection isoNeutralWeight_;
331  std::vector<CandidatePtr> chPV_;
332  isoCharged_.reserve(pfTau->isolationChargedHadrCands().size());
333  isoNeutral_.reserve(pfTau->isolationGammaCands().size());
334  isoPU_.reserve(std::min(100UL, chargedPFCandidatesInEvent_.size()));
335  isoNeutralWeight_.reserve(pfTau->isolationGammaCands().size());
336 
337  chPV_.reserve(std::min(50UL, chargedPFCandidatesInEvent_.size()));
338 
339  // Get the primary vertex associated to this tau
340  reco::VertexRef pv = vertexAssociator_->associatedVertex(*pfTau);
341  // Let the quality cuts know which the vertex to use when applying selections
342  // on dz, etc.
343  if ( verbosity_ ) {
344  if ( pv.isNonnull() ) {
345  LogTrace("discriminate") << "pv: x = " << pv->position().x() << ", y = " << pv->position().y() << ", z = " << pv->position().z() ;
346  } else {
347  LogTrace("discriminate") << "pv: N/A" ;
348  }
349  if ( pfTau->leadChargedHadrCand().isNonnull() ) {
350  LogTrace("discriminate") << "leadPFChargedHadron:"
351  << " Pt = " << pfTau->leadChargedHadrCand()->pt() << ","
352  << " eta = " << pfTau->leadChargedHadrCand()->eta() << ","
353  << " phi = " << pfTau->leadChargedHadrCand()->phi() ;
354  } else {
355  LogTrace("discriminate") << "leadPFChargedHadron: N/A" ;
356  }
357  }
358 
359  // CV: isolation is not well defined in case primary vertex or leading charged hadron do not exist
360  if ( !(pv.isNonnull() && pfTau->leadChargedHadrCand().isNonnull()) ) return 0.;
361 
362  qcuts_->setPV(pv);
363  qcuts_->setLeadTrack(*pfTau->leadChargedHadrCand());
364 
365  if ( applyDeltaBeta_ || calculateWeights_) {
366  pileupQcutsGeneralQCuts_->setPV(pv);
367  pileupQcutsGeneralQCuts_->setLeadTrack(*pfTau->leadChargedHadrCand());
368  pileupQcutsPUTrackSelection_->setPV(pv);
369  pileupQcutsPUTrackSelection_->setLeadTrack(*pfTau->leadChargedHadrCand());
370  }
371 
372  // Load the tracks if they are being used.
373  if ( includeTracks_ ) {
374  for( auto const & cand : pfTau->isolationChargedHadrCands() ) {
375  if ( qcuts_->filterCandRef(cand) ) {
376  LogTrace("discriminate") << "adding charged iso cand with pt " << cand->pt() ;
377  isoCharged_.push_back(cand);
378  }
379  }
380  }
381  if ( includeGammas_ || calculateWeights_ ) {
382  for( auto const & cand : pfTau->isolationGammaCands() ) {
383  if ( qcuts_->filterCandRef(cand) ) {
384  LogTrace("discriminate") << "adding neutral iso cand with pt " << cand->pt() ;
385  isoNeutral_.push_back(cand);
386  }
387  }
388  }
389 
392 
393  // If desired, get PU tracks.
394  if ( applyDeltaBeta_ || calculateWeights_) {
395  // First select by inverted the DZ/track weight cuts. True = invert
396  if ( verbosity_ ) {
397  std::cout << "Initial PFCands: " << chargedPFCandidatesInEvent_.size() << std::endl;
398  }
399 
400  std::vector<CandidatePtr> allPU =
401  pileupQcutsPUTrackSelection_->filterCandRefs(
402  chargedPFCandidatesInEvent_, true);
403 
404  std::vector<CandidatePtr> allNPU =
405  pileupQcutsPUTrackSelection_->filterCandRefs(
406  chargedPFCandidatesInEvent_);
407  LogTrace("discriminate") << "After track cuts: " << allPU.size() ;
408 
409  // Now apply the rest of the cuts, like pt, and TIP, tracker hits, etc
410  if ( !useAllPFCands_ ) {
411  std::vector<CandidatePtr> cleanPU =
412  pileupQcutsGeneralQCuts_->filterCandRefs(allPU);
413 
414  std::vector<CandidatePtr> cleanNPU =
415  pileupQcutsGeneralQCuts_->filterCandRefs(allNPU);
416 
417  LogTrace("discriminate") << "After cleaning cuts: " << cleanPU.size() ;
418 
419  // Only select PU tracks inside the isolation cone.
420  DRFilter deltaBetaFilter(pfTau->p4(), 0, deltaBetaCollectionCone_);
421  for ( auto const & cand : cleanPU ) {
422  if ( deltaBetaFilter(cand) ) isoPU_.push_back(cand);
423  }
424 
425  for ( auto const & cand : cleanNPU ) {
426  if ( deltaBetaFilter(cand) ) chPV_.push_back(cand);
427  }
428  LogTrace("discriminate") << "After cone cuts: " << isoPU_.size() << " " << chPV_.size() ;
429  } else {
430  isoPU_ = std::move(allPU);
431  chPV_ = std::move(allNPU);
432  }
433  }
434 
435  if ( calculateWeights_ ) {
436  for ( auto const & isoObject : isoNeutral_ ) {
437  if ( isoObject->charge() != 0 ) {
438  // weight only neutral objects
439  isoNeutralWeight_.push_back(*isoObject);
440  continue;
441  }
442 
443  double eta = isoObject->eta();
444  double phi = isoObject->phi();
445  double sumNPU = 0.5*log(weightedSum(chPV_, eta, phi));
446 
447  double sumPU = 0.5*log(weightedSum(isoPU_, eta, phi));
448  LeafCandidate neutral(*isoObject);
449  if ( (sumNPU + sumPU) > 0 ) neutral.setP4(((sumNPU)/(sumNPU + sumPU))*neutral.p4());
450 
451  isoNeutralWeight_.push_back(neutral);
452  }
453  }
454 
455  // Check if we want a custom iso cone
456  if ( customIsoCone_ >= 0. ) {
457  DRFilter filter(pfTau->p4(), 0, customIsoCone_);
458  DRFilter2 filter2(pfTau->p4(), 0, customIsoCone_);
459  std::vector<CandidatePtr> isoCharged_filter;
460  std::vector<CandidatePtr> isoNeutral_filter;
461  CandidateCollection isoNeutralWeight_filter;
462  // Remove all the objects not in our iso cone
463  for( auto const & isoObject : isoCharged_ ) {
464  if ( filter(isoObject) ) isoCharged_filter.push_back(isoObject);
465  }
466  if(!calculateWeights_){
467  for( auto const & isoObject : isoNeutral_ ) {
468  if ( filter(isoObject) ) isoNeutral_filter.push_back(isoObject);
469  }
470  isoNeutral_ = isoNeutral_filter;
471  }else{
472  for( auto const & isoObject : isoNeutralWeight_){
473  if ( filter2(isoObject) ) isoNeutralWeight_filter.push_back(isoObject);
474  }
475  isoNeutralWeight_ = isoNeutralWeight_filter;
476  }
477  isoCharged_ = isoCharged_filter;
478  }
479 
480  bool failsOccupancyCut = false;
481  bool failsSumPtCut = false;
482  bool failsRelativeSumPtCut = false;
483 
484 //--- nObjects requirement
485  int neutrals = isoNeutral_.size();
486 
487  if ( applyDeltaBeta_ ) {
488  neutrals -= TMath::Nint(deltaBetaFactorThisEvent_*isoPU_.size());
489  }
490  if ( neutrals < 0 ) {
491  neutrals = 0;
492  }
493 
494  size_t nOccupants = isoCharged_.size() + neutrals;
495 
496  failsOccupancyCut = ( nOccupants > maximumOccupancy_ );
497 
498  double footprintCorrection_value = 0.;
499  if ( applyFootprintCorrection_ || storeRawFootprintCorrection_ ) {
500  for ( std::vector<std::unique_ptr<FootprintCorrection> >::const_iterator footprintCorrection = footprintCorrections_.begin();
501  footprintCorrection != footprintCorrections_.end(); ++footprintCorrection ) {
502  if ( (*footprintCorrection)->selection_(*pfTau) ) {
503  footprintCorrection_value = (*footprintCorrection)->offset_(*pfTau);
504  }
505  }
506  }
507 
508  double totalPt = 0.;
509  double puPt = 0.;
510 //--- Sum PT requirement
511  if ( applySumPtCut_ || applyRelativeSumPtCut_ || storeRawSumPt_ || storeRawPUsumPt_ ) {
512  double chargedPt = 0.;
513  double neutralPt = 0.;
514  double weightedNeutralPt = 0.;
515  for ( auto const & isoObject : isoCharged_ ) {
516  chargedPt += isoObject->pt();
517  }
518  if ( !calculateWeights_ ) {
519  for ( auto const & isoObject : isoNeutral_ ) {
520  neutralPt += isoObject->pt();
521  }
522  } else {
523  for ( auto const & isoObject : isoNeutralWeight_ ) {
524  weightedNeutralPt += isoObject.pt();
525  }
526  }
527  for ( auto const & isoObject : isoPU_ ) {
528  puPt += isoObject->pt();
529  }
530  LogTrace("discriminate") << "chargedPt = " << chargedPt ;
531  LogTrace("discriminate") << "neutralPt = " << neutralPt ;
532  LogTrace("discriminate") << "weighted neutral Pt = " << weightedNeutralPt ;
533  LogTrace("discriminate") << "puPt = " << puPt << " (delta-beta corr. = " << (deltaBetaFactorThisEvent_*puPt) << ")" ;
534 
535  if ( calculateWeights_ ) {
536  neutralPt = weightedNeutralPt;
537  }
538 
539  if ( applyDeltaBeta_ ) {
540  neutralPt -= (deltaBetaFactorThisEvent_*puPt);
541  }
542 
543  if ( applyFootprintCorrection_ ) {
544  neutralPt -= footprintCorrection_value;
545  }
546 
547  if ( applyRhoCorrection_ ) {
548  neutralPt -= rhoThisEvent_;
549  }
550 
551  if ( neutralPt < 0. ) {
552  neutralPt = 0.;
553  }
554 
555  totalPt = chargedPt + weightGammas_ * neutralPt;
556  LogTrace("discriminate") << "totalPt = " << totalPt << " (cut = " << maximumSumPt_ << ")" ;
557 
558  failsSumPtCut = (totalPt > maximumSumPt_);
559 
560 //--- Relative Sum PT requirement
561  failsRelativeSumPtCut = (totalPt > ((pfTau->pt() - offsetRelativeSumPt_)*maximumRelativeSumPt_));
562  }
563 
564  bool failsPhotonPtSumOutsideSignalConeCut = false;
565  double photonSumPt_outsideSignalCone = 0.;
566  if ( applyPhotonPtSumOutsideSignalConeCut_ || storeRawPhotonSumPt_outsideSignalCone_ ) {
567  const std::vector<reco::CandidatePtr>& signalGammas = pfTau->signalGammaCands();
568  for ( std::vector<reco::CandidatePtr>::const_iterator signalGamma = signalGammas.begin();
569  signalGamma != signalGammas.end(); ++signalGamma ) {
570  double dR = deltaR(pfTau->eta(), pfTau->phi(), (*signalGamma)->eta(), (*signalGamma)->phi());
571  if ( dR > pfTau->signalConeSize() ) photonSumPt_outsideSignalCone += (*signalGamma)->pt();
572  }
573  if ( photonSumPt_outsideSignalCone > maxAbsPhotonSumPt_outsideSignalCone_ || photonSumPt_outsideSignalCone > (maxRelPhotonSumPt_outsideSignalCone_*pfTau->pt()) ) {
574  failsPhotonPtSumOutsideSignalConeCut = true;
575  }
576  }
577 
578  bool fails = (applyOccupancyCut_ && failsOccupancyCut) ||
579  (applySumPtCut_ && failsSumPtCut) ||
580  (applyRelativeSumPtCut_ && failsRelativeSumPtCut) ||
581  (applyPhotonPtSumOutsideSignalConeCut_ && failsPhotonPtSumOutsideSignalConeCut);
582 
583 
584  if (pfTau->pt() > minPtForNoIso_ && minPtForNoIso_ > 0.){
585  return 1.;
586  LogDebug("discriminate") << "tau pt = " << pfTau->pt() << "\t min cutoff pt = " << minPtForNoIso_ ;
587  }
588 
589  // We did error checking in the constructor, so this is safe.
590  if ( storeRawSumPt_ ) {
591  return totalPt;
592  } else if ( storeRawPUsumPt_ ) {
593  if ( applyDeltaBeta_ ) return puPt;
594  else if ( applyRhoCorrection_ ) return rhoThisEvent_;
595  else return 0.;
596  } else if ( storeRawOccupancy_ ) {
597  return nOccupants;
598  } else if ( storeRawFootprintCorrection_ ) {
599  return footprintCorrection_value;
600  } else if ( storeRawPhotonSumPt_outsideSignalCone_ ) {
601  return photonSumPt_outsideSignalCone;
602  } else {
603  return (fails ? 0. : 1.);
604  }
605 }
606 
607 void
609  // pfRecoTauDiscriminationByIsolation
611  desc.add<bool>("storeRawFootprintCorrection", false);
612  desc.add<edm::InputTag>("PFTauProducer", edm::InputTag("pfRecoTauProducer"));
613  desc.add<bool>("storeRawOccupancy", false);
614  desc.add<double>("maximumSumPtCut", 6.0);
615 
616  {
617  edm::ParameterSetDescription pset_signalQualityCuts;
618  pset_signalQualityCuts.add<double>("maxDeltaZ", 0.4);
619  pset_signalQualityCuts.add<double>("minTrackPt", 0.5);
620  pset_signalQualityCuts.add<double>("minTrackVertexWeight", -1.0);
621  pset_signalQualityCuts.add<double>("maxTrackChi2", 100.0);
622  pset_signalQualityCuts.add<unsigned int>("minTrackPixelHits", 0);
623  pset_signalQualityCuts.add<double>("minGammaEt", 1.0);
624  pset_signalQualityCuts.add<unsigned int>("minTrackHits", 3);
625  pset_signalQualityCuts.add<double>("minNeutralHadronEt", 30.0);
626  pset_signalQualityCuts.add<double>("maxTransverseImpactParameter", 0.1);
627  pset_signalQualityCuts.addOptional<bool>("useTracksInsteadOfPFHadrons");
628 
629  edm::ParameterSetDescription pset_vxAssocQualityCuts;
630  pset_vxAssocQualityCuts.add<double>("minTrackPt", 0.5);
631  pset_vxAssocQualityCuts.add<double>("minTrackVertexWeight", -1.0);
632  pset_vxAssocQualityCuts.add<double>("maxTrackChi2", 100.0);
633  pset_vxAssocQualityCuts.add<unsigned int>("minTrackPixelHits", 0);
634  pset_vxAssocQualityCuts.add<double>("minGammaEt", 1.0);
635  pset_vxAssocQualityCuts.add<unsigned int>("minTrackHits", 3);
636  pset_vxAssocQualityCuts.add<double>("maxTransverseImpactParameter", 0.1);
637  pset_vxAssocQualityCuts.addOptional<bool>("useTracksInsteadOfPFHadrons");
638 
639  edm::ParameterSetDescription pset_isolationQualityCuts;
640  pset_isolationQualityCuts.add<double>("maxDeltaZ", 0.2);
641  pset_isolationQualityCuts.add<double>("minTrackPt", 1.0);
642  pset_isolationQualityCuts.add<double>("minTrackVertexWeight", -1.0);
643  pset_isolationQualityCuts.add<double>("maxTrackChi2", 100.0);
644  pset_isolationQualityCuts.add<unsigned int>("minTrackPixelHits", 0);
645  pset_isolationQualityCuts.add<double>("minGammaEt", 1.5);
646  pset_isolationQualityCuts.add<unsigned int>("minTrackHits", 8);
647  pset_isolationQualityCuts.add<double>("maxTransverseImpactParameter", 0.03);
648  pset_isolationQualityCuts.addOptional<bool>("useTracksInsteadOfPFHadrons");
649 
650  edm::ParameterSetDescription pset_qualityCuts;
651  pset_qualityCuts.add<edm::ParameterSetDescription>("signalQualityCuts", pset_signalQualityCuts);
652  pset_qualityCuts.add<edm::ParameterSetDescription>("vxAssocQualityCuts", pset_vxAssocQualityCuts);
653  pset_qualityCuts.add<edm::ParameterSetDescription>("isolationQualityCuts", pset_isolationQualityCuts);
654  pset_qualityCuts.add<std::string>("leadingTrkOrPFCandOption", "leadPFCand");
655  pset_qualityCuts.add<std::string>("pvFindingAlgo", "closestInDeltaZ");
656  pset_qualityCuts.add<edm::InputTag>("primaryVertexSrc", edm::InputTag("offlinePrimaryVertices"));
657  pset_qualityCuts.add<bool>("vertexTrackFiltering", false);
658  pset_qualityCuts.add<bool>("recoverLeadingTrk", false);
659 
660  desc.add<edm::ParameterSetDescription>("qualityCuts", pset_qualityCuts);
661  }
662 
663  desc.add<double>("minTauPtForNoIso", -99.0);
664  desc.add<double>("maxAbsPhotonSumPt_outsideSignalCone", 1000000000.0);
665  desc.add<edm::InputTag>("vertexSrc", edm::InputTag("offlinePrimaryVertices"));
666  desc.add<bool>("applySumPtCut", false);
667  desc.add<double>("rhoConeSize", 0.5);
668  desc.add<bool>("ApplyDiscriminationByTrackerIsolation", true);
669  desc.add<bool>("storeRawPhotonSumPt_outsideSignalCone", false);
670  desc.add<edm::InputTag>("rhoProducer", edm::InputTag("fixedGridRhoFastjetAll"));
671 
672  {
674  vpsd1.add<std::string>("selection");
675  vpsd1.add<std::string>("offset");
676  desc.addVPSet("footprintCorrections", vpsd1);
677  }
678 
679  desc.add<std::string>("deltaBetaFactor", "0.38");
680  desc.add<bool>("applyFootprintCorrection", false);
681  desc.add<bool>("UseAllPFCandsForWeights", false);
682  desc.add<double>("relativeSumPtCut", 0.0);
683  {
684  edm::ParameterSetDescription pset_Prediscriminants;
685  pset_Prediscriminants.add<std::string>("BooleanOperator", "and");
686  {
688  psd1.add<double>("cut");
689  psd1.add<edm::InputTag>("Producer");
690  pset_Prediscriminants.addOptional<edm::ParameterSetDescription>("leadTrack", psd1);
691  }
692  {
693  // encountered this at
694  // RecoTauTag/Configuration/python/HPSPFTaus_cff.py
695  // Prediscriminants = requireDecayMode.clone(),
696  // requireDecayMode = cms.PSet(
697  // BooleanOperator = cms.string("and"),
698  // decayMode = cms.PSet(
699  // Producer = cms.InputTag('hpsPFTauDiscriminationByDecayModeFindingNewDMs'),
700  // cut = cms.double(0.5)
701  // )
702  // )
704  psd1.add<double>("cut");
705  psd1.add<edm::InputTag>("Producer");
706  pset_Prediscriminants.addOptional<edm::ParameterSetDescription>("decayMode", psd1);
707  }
708  {
709  // encountered this at
710  // RecoTauTag/Configuration/python/HPSPFTaus_cff.py
711  // Prediscriminants = requireDecayMode.clone(),
712  // hpsPFTauDiscriminationByLooseIsolation.Prediscriminants.preIso = cms.PSet(
713  // Producer = cms.InputTag("hpsPFTauDiscriminationByLooseChargedIsolation"),
714  // cut = cms.double(0.5)
715  // )
717  psd1.add<double>("cut");
718  psd1.add<edm::InputTag>("Producer");
719  pset_Prediscriminants.addOptional<edm::ParameterSetDescription>("preIso", psd1);
720  }
721  desc.add<edm::ParameterSetDescription>("Prediscriminants", pset_Prediscriminants);
722  }
723 
724  desc.add<unsigned int>("maximumOccupancy", 0);
725  desc.add<int>("verbosity", 0);
726 
727  desc.add<bool>("applyOccupancyCut", true);
728  desc.add<bool>("applyDeltaBetaCorrection", false);
729  desc.add<bool>("applyRelativeSumPtCut", false);
730  desc.add<bool>("storeRawPUsumPt", false);
731  desc.add<bool>("applyPhotonPtSumOutsideSignalConeCut", false);
732  desc.add<bool>("deltaBetaPUTrackPtCutOverride", false);
733  desc.add<bool>("ApplyDiscriminationByWeightedECALIsolation", false);
734  desc.add<bool>("storeRawSumPt", false);
735  desc.add<bool>("ApplyDiscriminationByECALIsolation", true);
736  desc.add<bool>("applyRhoCorrection", false);
737 
738  desc.add<double>("WeightECALIsolation", 1.0);
739  desc.add<double>("rhoUEOffsetCorrection", 1.0);
740  desc.add<double>("maxRelPhotonSumPt_outsideSignalCone", 0.1);
741  desc.add<double>("deltaBetaPUTrackPtCutOverride_val", -1.5);
742  desc.add<double>("isoConeSizeForDeltaBeta", 0.5);
743  desc.add<double>("relativeSumPtOffset", 0.0);
744  desc.add<double>("customOuterCone", -1.0);
745  desc.add<edm::InputTag>("particleFlowSrc", edm::InputTag("particleFlow"));
746 
747  descriptions.add("pfRecoTauDiscriminationByIsolation", desc);
748 }
749 
#define LogDebug(id)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
PFRecoTauDiscriminationByIsolation(const edm::ParameterSet &pset)
T getParameter(std::string const &) const
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:251
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
std::auto_ptr< tau::RecoTauQualityCuts > pileupQcutsGeneralQCuts_
deltaBetaPUTrackPtCutOverride_val
std::vector< ParameterSet > VParameterSet
Definition: ParameterSet.h:33
edm::EDGetTokenT< edm::View< reco::Candidate > > pfCand_token
size_type size() const
Definition: OwnVector.h:264
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:290
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
Definition: LeafCandidate.h:99
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)
std::auto_ptr< tau::RecoTauQualityCuts > qcuts_
std::auto_ptr< tau::RecoTauQualityCuts > pileupQcutsPUTrackSelection_
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:28
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::auto_ptr< tau::RecoTauVertexAssociator > vertexAssociator_
void setP4(const LorentzVector &p4) final
set 4-momentum
def move(src, dest)
Definition: eostools.py:511
void reserve(size_t)
Definition: OwnVector.h:284
Definition: event.py:1
edm::EDGetTokenT< reco::VertexCollection > vertex_token