CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes
reco::tau::RecoTauQualityCuts Class Reference

#include <RecoTauQualityCuts.h>

Public Types

typedef std::function< bool(const Candidate &)> CandQCutFunc
 
typedef std::vector< CandQCutFuncCandQCutFuncCollection
 
typedef std::map< int, CandQCutFuncCollectionCandQCutFuncMap
 
typedef std::function< bool(const TrackBaseRef &)> TrackQCutFunc
 
typedef std::vector< TrackQCutFuncTrackQCutFuncCollection
 

Public Member Functions

bool filterCand (const reco::Candidate &cand) const
 Filter a single Candidate. More...
 
template<typename CandRefType >
bool filterCandRef (const CandRefType &cand) const
 Filter a Candidate held by a smart pointer or Ref. More...
 
template<typename Coll >
Coll filterCandRefs (const Coll &refcoll, bool invert=false) const
 Filter a ref vector of Candidates. More...
 
bool filterChargedCand (const reco::Candidate &cand) const
 or a single charged candidate More...
 
bool filterTrack (const reco::TrackBaseRef &track) const
 Filter a single Track. More...
 
bool filterTrack (const reco::TrackRef &track) const
 
bool filterTrack (const reco::Track &track) const
 
template<typename Coll >
Coll filterTracks (const Coll &coll, bool invert=false) const
 Filter a collection of Tracks. More...
 
 RecoTauQualityCuts (const edm::ParameterSet &qcuts)
 
void setLeadTrack (const reco::Track &leadTrack)
 Update the leading track. More...
 
void setLeadTrack (const reco::Candidate &leadCand)
 
void setLeadTrack (const reco::CandidateRef &leadCand)
 
void setPV (const reco::VertexRef &vtx)
 Update the primary vertex. More...
 

Private Member Functions

bool filterCandByType (const reco::Candidate &cand) const
 
bool filterGammaCand (const reco::Candidate &cand) const
 
bool filterNeutralHadronCand (const reco::Candidate &cand) const
 
bool filterTrack_ (const reco::Track *track) const
 

Private Attributes

bool checkHitPattern_
 
bool checkPV_
 
const reco::TrackleadTrack_
 
double maxDeltaZ_
 
double maxDeltaZToLeadTrack_
 
double maxTrackChi2_
 
double maxTransverseImpactParameter_
 
double minGammaEt_
 
double minNeutralHadronEt_
 
int minTrackHits_
 
int minTrackPixelHits_
 
double minTrackPt_
 
double minTrackVertexWeight_
 
reco::VertexRef pv_
 

Detailed Description

Definition at line 34 of file RecoTauQualityCuts.h.

Member Typedef Documentation

typedef std::function<bool(const Candidate&)> reco::tau::RecoTauQualityCuts::CandQCutFunc

Definition at line 39 of file RecoTauQualityCuts.h.

Definition at line 40 of file RecoTauQualityCuts.h.

Definition at line 41 of file RecoTauQualityCuts.h.

typedef std::function<bool(const TrackBaseRef&)> reco::tau::RecoTauQualityCuts::TrackQCutFunc

Definition at line 37 of file RecoTauQualityCuts.h.

Definition at line 38 of file RecoTauQualityCuts.h.

Constructor & Destructor Documentation

reco::tau::RecoTauQualityCuts::RecoTauQualityCuts ( const edm::ParameterSet qcuts)
explicit

Definition at line 296 of file RecoTauQualityCuts.cc.

References Exception, edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), edm::ParameterSet::getParameterNames(), Skims_PA_cff::name, fileinputsource_cfi::option, and AlCaHLTBitMon_QueryRunRegistry::string.

296  {
297  // Setup all of our predicates
298  CandQCutFuncCollection chargedHadronCuts;
299  CandQCutFuncCollection gammaCuts;
300  CandQCutFuncCollection neutralHadronCuts;
301 
302  // Make sure there are no extra passed options
303  std::set<std::string> passedOptionSet;
304  std::vector<std::string> passedOptions = qcuts.getParameterNames();
305 
306  for (auto const& option : passedOptions) {
307  passedOptionSet.insert(option);
308  }
309 
310  unsigned int nCuts = 0;
311  auto getDouble = [&qcuts, &passedOptionSet, &nCuts](const std::string& name) {
312  if (qcuts.exists(name)) {
313  ++nCuts;
314  passedOptionSet.erase(name);
315  return qcuts.getParameter<double>(name);
316  }
317  return -1.0;
318  };
319  auto getUint = [&qcuts, &passedOptionSet, &nCuts](const std::string& name) -> unsigned int {
320  if (qcuts.exists(name)) {
321  ++nCuts;
322  passedOptionSet.erase(name);
323  return qcuts.getParameter<unsigned int>(name);
324  }
325  return 0;
326  };
327 
328  // Build all the QCuts for tracks
329  minTrackPt_ = getDouble("minTrackPt");
330  maxTrackChi2_ = getDouble("maxTrackChi2");
331  minTrackPixelHits_ = getUint("minTrackPixelHits");
332  minTrackHits_ = getUint("minTrackHits");
333  maxTransverseImpactParameter_ = getDouble("maxTransverseImpactParameter");
334  maxDeltaZ_ = getDouble("maxDeltaZ");
335  maxDeltaZToLeadTrack_ = getDouble("maxDeltaZToLeadTrack");
336  // Require tracks to contribute a minimum weight to the associated vertex.
337  minTrackVertexWeight_ = getDouble("minTrackVertexWeight");
338 
339  // Use bit-wise & to avoid conditional code
342  (minTrackVertexWeight_ >= 0);
343 
344  // Build the QCuts for gammas
345  minGammaEt_ = getDouble("minGammaEt");
346 
347  // Build QCuts for netural hadrons
348  minNeutralHadronEt_ = getDouble("minNeutralHadronEt");
349 
350  // Check if there are any remaining unparsed QCuts
351  if (!passedOptionSet.empty()) {
352  std::string unParsedOptions;
353  bool thereIsABadParameter = false;
354  for (auto const& option : passedOptionSet) {
355  // Workaround for HLT - TODO FIXME
356  if (option == "useTracksInsteadOfPFHadrons") {
357  // Crash if true - no one should have this option enabled.
358  if (qcuts.getParameter<bool>("useTracksInsteadOfPFHadrons")) {
359  throw cms::Exception("DontUseTracksInQcuts") << "The obsolete exception useTracksInsteadOfPFHadrons "
360  << "is set to true in the quality cut config." << std::endl;
361  }
362  continue;
363  }
364 
365  // If we get to this point, there is a real unknown parameter
366  thereIsABadParameter = true;
367 
368  unParsedOptions += option;
369  unParsedOptions += "\n";
370  }
371  if (thereIsABadParameter) {
372  throw cms::Exception("BadQualityCutConfig") << " The PSet passed to the RecoTauQualityCuts class had"
373  << " the following unrecognized options: " << std::endl
374  << unParsedOptions;
375  }
376  }
377 
378  // Make sure there are at least some quality cuts
379  if (!nCuts) {
380  throw cms::Exception("BadQualityCutConfig") << " No options were passed to the quality cut class!" << std::endl;
381  }
382  }
T getParameter(std::string const &) const
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::vector< CandQCutFunc > CandQCutFuncCollection
std::vector< std::string > getParameterNames() const

Member Function Documentation

bool reco::tau::RecoTauQualityCuts::filterCand ( const reco::Candidate cand) const

Filter a single Candidate.

Definition at line 529 of file RecoTauQualityCuts.cc.

References reco::Candidate::charge(), and mps_fire::result.

Referenced by filterCandRef(), and filterTracks().

529  {
530  auto trackRef = getTrackRef(cand);
531  bool result = true;
532 
533  if (trackRef.isNonnull()) {
534  result = filterTrack(trackRef);
535  } else {
536  auto gsfTrackRef = getGsfTrackRef(cand);
537  if (gsfTrackRef.isNonnull())
538  result = filterTrack(gsfTrackRef);
539  else if (cand.charge() != 0) {
540  result = filterChargedCand(cand);
541  }
542  }
543 
544  if (result)
545  result = filterCandByType(cand);
546 
547  return result;
548  }
bool filterCandByType(const reco::Candidate &cand) const
bool filterChargedCand(const reco::Candidate &cand) const
or a single charged candidate
virtual int charge() const =0
electric charge
bool filterTrack(const reco::TrackBaseRef &track) const
Filter a single Track.
bool reco::tau::RecoTauQualityCuts::filterCandByType ( const reco::Candidate cand) const
private

Definition at line 510 of file RecoTauQualityCuts.cc.

References funct::abs(), and reco::Candidate::pdgId().

Referenced by filterCandRefs().

510  {
511  switch (std::abs(cand.pdgId())) {
512  case 22:
513  return filterGammaCand(cand);
514  case 130:
515  return filterNeutralHadronCand(cand);
516  // We use the same qcuts for muons/electrons and charged hadrons.
517  case 211:
518  case 11:
519  case 13:
520  // no cuts ATM (track cuts applied in filterCand)
521  return true;
522  // Return false if we dont' know how to deal with this particle type
523  default:
524  return false;
525  };
526  return false;
527  }
virtual int pdgId() const =0
PDG identifier.
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool filterNeutralHadronCand(const reco::Candidate &cand) const
bool filterGammaCand(const reco::Candidate &cand) const
template<typename CandRefType >
bool reco::tau::RecoTauQualityCuts::filterCandRef ( const CandRefType &  cand) const
inline

Filter a Candidate held by a smart pointer or Ref.

Definition at line 79 of file RecoTauQualityCuts.h.

References filterCand().

Referenced by filterCandRefs().

79  {
80  return filterCand(*cand);
81  }
bool filterCand(const reco::Candidate &cand) const
Filter a single Candidate.
template<typename Coll >
Coll reco::tau::RecoTauQualityCuts::filterCandRefs ( const Coll &  refcoll,
bool  invert = false 
) const
inline
bool reco::tau::RecoTauQualityCuts::filterChargedCand ( const reco::Candidate cand) const

or a single charged candidate

Definition at line 454 of file RecoTauQualityCuts.cc.

References reco::Candidate::charge(), pat::PackedCandidate::dxy(), pat::PackedCandidate::dz(), getTrack(), reco::tau::qcuts::minPackedCandVertexWeight(), pat::PackedCandidate::pt(), and HLT_2018_cff::track.

Referenced by reco::tau::PFRecoTauChargedHadronFromGenericTrackPlugin< TrackClass >::filterTrack(), and setPV().

454  {
455  if (cand.charge() == 0)
456  return true;
457  const pat::PackedCandidate* pCand = dynamic_cast<const pat::PackedCandidate*>(&cand);
458  if (pCand == nullptr)
459  return true;
460 
461  //Get track, it should be present for cands with pT(charged)>0.5GeV
462  //and check track quality critera other than vertex weight
463  auto track = getTrack(cand);
464  if (track != nullptr) {
465  if (!filterTrack(*track))
466  return false;
467  } else { //Candidates without track (pT(charged)<0.5GeV): Can still check pT and calculate dxy and dz
468  if (minTrackPt_ >= 0 && !(pCand->pt() > minTrackPt_))
469  return false;
470  if (checkPV_ && pv_.isNull()) {
471  edm::LogError("QCutsNoPrimaryVertex") << "Primary vertex Ref in "
472  << "RecoTauQualityCuts is invalid. - filterChargedCand";
473  return false;
474  }
475 
477  !(std::fabs(pCand->dxy(pv_->position())) <= maxTransverseImpactParameter_))
478  return false;
479  if (maxDeltaZ_ >= 0 && !(std::fabs(pCand->dz(pv_->position())) <= maxDeltaZ_))
480  return false;
481  if (maxDeltaZToLeadTrack_ >= 0) {
482  if (leadTrack_ == nullptr) {
483  edm::LogError("QCutsNoValidLeadTrack") << "Lead track Ref in "
484  << "RecoTauQualityCuts is invalid. - filterChargedCand";
485  return false;
486  }
487 
488  if (!(std::fabs(pCand->dz(pv_->position()) - leadTrack_->dz(pv_->position())) <= maxDeltaZToLeadTrack_))
489  return false;
490  }
491  }
493  return false;
494 
495  return true;
496  }
virtual float dz(size_t ipv=0) const
dz with respect to the PV[ipv]
double pt() const override
transverse momentum
bool isNull() const
Checks for null.
Definition: Ref.h:235
double dz() const
dz parameter (= dsz/cos(lambda)). This is the track z0 w.r.t (0,0,0) only if the refPoint is close to...
Definition: TrackBase.h:596
static const TrackGhostTrackState * getTrack(const BasicGhostTrackState *basic)
virtual int charge() const =0
electric charge
virtual float dxy() const
dxy with respect to the PV ref
bool minPackedCandVertexWeight(const pat::PackedCandidate &pCand, const reco::VertexRef *pv, double cut)
bool filterTrack(const reco::TrackBaseRef &track) const
Filter a single Track.
bool reco::tau::RecoTauQualityCuts::filterGammaCand ( const reco::Candidate cand) const
private

Definition at line 498 of file RecoTauQualityCuts.cc.

References reco::Candidate::et().

Referenced by filterCandRefs().

498  {
499  if (minGammaEt_ >= 0 && !(cand.et() > minGammaEt_))
500  return false;
501  return true;
502  }
virtual double et() const =0
transverse energy
bool reco::tau::RecoTauQualityCuts::filterNeutralHadronCand ( const reco::Candidate cand) const
private

Definition at line 504 of file RecoTauQualityCuts.cc.

References reco::Candidate::et().

Referenced by filterCandRefs().

504  {
505  if (minNeutralHadronEt_ >= 0 && !(cand.et() > minNeutralHadronEt_))
506  return false;
507  return true;
508  }
virtual double et() const =0
transverse energy
bool reco::tau::RecoTauQualityCuts::filterTrack ( const reco::TrackBaseRef track) const

Filter a single Track.

Definition at line 399 of file RecoTauQualityCuts.cc.

References edm::RefToBase< T >::get().

Referenced by reco::tau::PFRecoTauChargedHadronFromGenericTrackPlugin< TrackClass >::filterTrack(), filterTracks(), and setPV().

399  {
400  if (!filterTrack_(track.get()))
401  return false;
402  if (minTrackVertexWeight_ >= 0. && !(pv_->trackWeight(convertRef(track)) >= minTrackVertexWeight_))
403  return false;
404  return true;
405  }
value_type const * get() const
Definition: RefToBase.h:209
bool filterTrack_(const reco::Track *track) const
bool reco::tau::RecoTauQualityCuts::filterTrack ( const reco::TrackRef track) const

Definition at line 407 of file RecoTauQualityCuts.cc.

References edm::Ref< C, T, F >::get().

407  {
408  if (!filterTrack_(track.get()))
409  return false;
410  if (minTrackVertexWeight_ >= 0. && !(pv_->trackWeight(convertRef(track)) >= minTrackVertexWeight_))
411  return false;
412  return true;
413  }
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:232
bool filterTrack_(const reco::Track *track) const
bool reco::tau::RecoTauQualityCuts::filterTrack ( const reco::Track track) const

Definition at line 415 of file RecoTauQualityCuts.cc.

415 { return filterTrack_(&track); }
bool filterTrack_(const reco::Track *track) const
bool reco::tau::RecoTauQualityCuts::filterTrack_ ( const reco::Track track) const
private

Definition at line 417 of file RecoTauQualityCuts.cc.

References reco::TrackBase::dxy(), reco::TrackBase::dz(), reco::TrackBase::hitPattern(), reco::TrackBase::normalizedChi2(), reco::HitPattern::numberOfValidHits(), reco::HitPattern::numberOfValidPixelHits(), and reco::TrackBase::pt().

Referenced by filterCandRefs().

417  {
418  if (minTrackPt_ >= 0 && !(track->pt() > minTrackPt_))
419  return false;
420  if (maxTrackChi2_ >= 0 && !(track->normalizedChi2() <= maxTrackChi2_))
421  return false;
422  if (checkHitPattern_) {
423  const reco::HitPattern& hitPattern = track->hitPattern();
424  if (minTrackPixelHits_ > 0 && !(hitPattern.numberOfValidPixelHits() >= minTrackPixelHits_))
425  return false;
426  if (minTrackHits_ > 0 && !(hitPattern.numberOfValidHits() >= minTrackHits_))
427  return false;
428  }
429  if (checkPV_ && pv_.isNull()) {
430  edm::LogError("QCutsNoPrimaryVertex") << "Primary vertex Ref in "
431  << "RecoTauQualityCuts is invalid. - filterTrack";
432  return false;
433  }
434 
436  !(std::fabs(track->dxy(pv_->position())) <= maxTransverseImpactParameter_))
437  return false;
438  if (maxDeltaZ_ >= 0 && !(std::fabs(track->dz(pv_->position())) <= maxDeltaZ_))
439  return false;
440  if (maxDeltaZToLeadTrack_ >= 0) {
441  if (!leadTrack_) {
442  edm::LogError("QCutsNoValidLeadTrack") << "Lead track Ref in "
443  << "RecoTauQualityCuts is invalid. - filterTrack";
444  return false;
445  }
446 
447  if (!(std::fabs(track->dz(pv_->position()) - leadTrack_->dz(pv_->position())) <= maxDeltaZToLeadTrack_))
448  return false;
449  }
450 
451  return true;
452  }
double normalizedChi2() const
chi-squared divided by n.d.o.f. (or chi-squared * 1e6 if n.d.o.f. is zero)
Definition: TrackBase.h:572
int numberOfValidHits() const
Definition: HitPattern.h:787
double pt() const
track transverse momentum
Definition: TrackBase.h:602
bool isNull() const
Checks for null.
Definition: Ref.h:235
double dz() const
dz parameter (= dsz/cos(lambda)). This is the track z0 w.r.t (0,0,0) only if the refPoint is close to...
Definition: TrackBase.h:596
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:483
int numberOfValidPixelHits() const
Definition: HitPattern.h:801
double dxy() const
dxy parameter. (This is the transverse impact parameter w.r.t. to (0,0,0) ONLY if refPoint is close t...
Definition: TrackBase.h:587
template<typename Coll >
Coll reco::tau::RecoTauQualityCuts::filterTracks ( const Coll &  coll,
bool  invert = false 
) const
inline

Filter a collection of Tracks.

Definition at line 65 of file RecoTauQualityCuts.h.

References filterCand(), filterTrack(), l1tstage2_dqm_sourceclient-live_cfg::invert, and convertSQLitetoXML_cfg::output.

65  {
66  Coll output;
67  for (auto const& track : coll) {
68  if (filterTrack(track) ^ invert)
69  output.push_back(track);
70  }
71  return output;
72  }
JetCorrectorParametersCollection coll
Definition: classes.h:10
bool filterTrack(const reco::TrackBaseRef &track) const
Filter a single Track.
void reco::tau::RecoTauQualityCuts::setLeadTrack ( const reco::Track leadTrack)

Update the leading track.

Definition at line 550 of file RecoTauQualityCuts.cc.

References singlePfTauSkim_cff::leadTrack.

Referenced by setPV().

void reco::tau::RecoTauQualityCuts::setLeadTrack ( const reco::Candidate leadCand)

Definition at line 552 of file RecoTauQualityCuts.cc.

References getTrack().

552 { leadTrack_ = getTrack(leadCand); }
static const TrackGhostTrackState * getTrack(const BasicGhostTrackState *basic)
void reco::tau::RecoTauQualityCuts::setLeadTrack ( const reco::CandidateRef leadCand)

Update the leading track (using reference) If null, this will set the lead track ref null.

Definition at line 554 of file RecoTauQualityCuts.cc.

References getTrack(), and edm::Ref< C, T, F >::isNonnull().

554  {
555  if (leadCand.isNonnull()) {
556  leadTrack_ = getTrack(*leadCand);
557  } else {
558  // Set null
559  leadTrack_ = nullptr;
560  }
561  }
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
static const TrackGhostTrackState * getTrack(const BasicGhostTrackState *basic)
void reco::tau::RecoTauQualityCuts::setPV ( const reco::VertexRef vtx)
inline

Member Data Documentation

bool reco::tau::RecoTauQualityCuts::checkHitPattern_
private

Definition at line 115 of file RecoTauQualityCuts.h.

bool reco::tau::RecoTauQualityCuts::checkPV_
private

Definition at line 116 of file RecoTauQualityCuts.h.

const reco::Track* reco::tau::RecoTauQualityCuts::leadTrack_
private

Definition at line 103 of file RecoTauQualityCuts.h.

double reco::tau::RecoTauQualityCuts::maxDeltaZ_
private

Definition at line 110 of file RecoTauQualityCuts.h.

double reco::tau::RecoTauQualityCuts::maxDeltaZToLeadTrack_
private

Definition at line 111 of file RecoTauQualityCuts.h.

double reco::tau::RecoTauQualityCuts::maxTrackChi2_
private

Definition at line 106 of file RecoTauQualityCuts.h.

double reco::tau::RecoTauQualityCuts::maxTransverseImpactParameter_
private

Definition at line 109 of file RecoTauQualityCuts.h.

double reco::tau::RecoTauQualityCuts::minGammaEt_
private

Definition at line 113 of file RecoTauQualityCuts.h.

double reco::tau::RecoTauQualityCuts::minNeutralHadronEt_
private

Definition at line 114 of file RecoTauQualityCuts.h.

int reco::tau::RecoTauQualityCuts::minTrackHits_
private

Definition at line 108 of file RecoTauQualityCuts.h.

int reco::tau::RecoTauQualityCuts::minTrackPixelHits_
private

Definition at line 107 of file RecoTauQualityCuts.h.

double reco::tau::RecoTauQualityCuts::minTrackPt_
private

Definition at line 105 of file RecoTauQualityCuts.h.

double reco::tau::RecoTauQualityCuts::minTrackVertexWeight_
private

Definition at line 112 of file RecoTauQualityCuts.h.

reco::VertexRef reco::tau::RecoTauQualityCuts::pv_
private

Definition at line 101 of file RecoTauQualityCuts.h.

Referenced by setPV().