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) const
 Update the leading track. More...
 
void setLeadTrack (const reco::Candidate &leadCand) const
 
void setLeadTrack (const reco::CandidateRef &leadCand) const
 
void setPV (const reco::VertexRef &vtx) const
 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 33 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 293 of file RecoTauQualityCuts.cc.

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

294 {
295  // Setup all of our predicates
296  CandQCutFuncCollection chargedHadronCuts;
297  CandQCutFuncCollection gammaCuts;
298  CandQCutFuncCollection neutralHadronCuts;
299 
300  // Make sure there are no extra passed options
301  std::set<std::string> passedOptionSet;
302  std::vector<std::string> passedOptions = qcuts.getParameterNames();
303 
304  for(auto const& option : passedOptions) {
305  passedOptionSet.insert(option);
306  }
307 
308  unsigned int nCuts = 0;
309  auto getDouble = [&qcuts, &passedOptionSet, &nCuts](const std::string& name) {
310  if(qcuts.exists(name)) {
311  ++nCuts;
312  passedOptionSet.erase(name);
313  return qcuts.getParameter<double>(name);
314  }
315  return -1.0;
316  };
317  auto getUint = [&qcuts, &passedOptionSet, &nCuts](const std::string& name) -> unsigned int {
318  if(qcuts.exists(name)) {
319  ++nCuts;
320  passedOptionSet.erase(name);
321  return qcuts.getParameter<unsigned int>(name);
322  }
323  return 0;
324  };
325 
326  // Build all the QCuts for tracks
327  minTrackPt_ = getDouble("minTrackPt");
328  maxTrackChi2_ = getDouble("maxTrackChi2");
329  minTrackPixelHits_ = getUint("minTrackPixelHits");
330  minTrackHits_ = getUint("minTrackHits");
331  maxTransverseImpactParameter_ = getDouble("maxTransverseImpactParameter");
332  maxDeltaZ_ = getDouble("maxDeltaZ");
333  maxDeltaZToLeadTrack_ = getDouble("maxDeltaZToLeadTrack");
334  // Require tracks to contribute a minimum weight to the associated vertex.
335  minTrackVertexWeight_ = getDouble("minTrackVertexWeight");
336 
337  // Use bit-wise & to avoid conditional code
340  (maxDeltaZ_ >= 0) ||
341  (maxDeltaZToLeadTrack_ >= 0) ||
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")
360  << "The obsolete exception useTracksInsteadOfPFHadrons "
361  << "is set to true in the quality cut config." << std::endl;
362  }
363  continue;
364  }
365 
366  // If we get to this point, there is a real unknown parameter
367  thereIsABadParameter = true;
368 
369  unParsedOptions += option;
370  unParsedOptions += "\n";
371  }
372  if ( thereIsABadParameter ) {
373  throw cms::Exception("BadQualityCutConfig")
374  << " The PSet passed to the RecoTauQualityCuts class had"
375  << " the following unrecognized options: " << std::endl
376  << unParsedOptions;
377  }
378  }
379 
380  // Make sure there are at least some quality cuts
381  if ( !nCuts ) {
382  throw cms::Exception("BadQualityCutConfig")
383  << " No options were passed to the quality cut class!" << std::endl;
384  }
385 }
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 532 of file RecoTauQualityCuts.cc.

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

Referenced by filterCandRef(), and filterTracks().

533 {
534  auto trackRef = getTrackRef(cand);
535  bool result = true;
536 
537  if (trackRef.isNonnull()) {
538  result = filterTrack(trackRef);
539  }
540  else {
541  auto gsfTrackRef = getGsfTrackRef(cand);
542  if (gsfTrackRef.isNonnull())
543  result = filterTrack(gsfTrackRef);
544  else if (cand.charge() != 0) {
545  result = filterChargedCand(cand);
546  }
547  }
548 
549  if(result)
550  result = filterCandByType(cand);
551 
552  return result;
553 }
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 513 of file RecoTauQualityCuts.cc.

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

Referenced by filterCandRefs().

513  {
514  switch(std::abs(cand.pdgId())) {
515  case 22:
516  return filterGammaCand(cand);
517  case 130:
518  return filterNeutralHadronCand(cand);
519  // We use the same qcuts for muons/electrons and charged hadrons.
520  case 211:
521  case 11:
522  case 13:
523  // no cuts ATM (track cuts applied in filterCand)
524  return true;
525  // Return false if we dont' know how to deal with this particle type
526  default:
527  return false;
528  };
529  return false;
530 }
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 { return filterCand(*cand); }
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 459 of file RecoTauQualityCuts.cc.

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

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

459  {
460 
461  if (cand.charge() == 0)
462  return true;
463  const pat::PackedCandidate* pCand = dynamic_cast<const pat::PackedCandidate*>(&cand);
464  if (pCand == nullptr)
465  return true;
466 
467  //Get track, it should be present for cands with pT(charged)>0.5GeV
468  //and check track quality critera other than vertex weight
469  auto track = getTrack(cand);
470  if (track != nullptr){
471  if (!filterTrack(*track))
472  return false;
473  } else {//Candidates without track (pT(charged)<0.5GeV): Can still check pT and calculate dxy and dz
474  if(minTrackPt_ >= 0 && !(pCand->pt() > minTrackPt_)) return false;
475  if(checkPV_ && pv_.isNull()) {
476  edm::LogError("QCutsNoPrimaryVertex") << "Primary vertex Ref in " <<
477  "RecoTauQualityCuts is invalid. - filterChargedCand";
478  return false;
479  }
480 
482  !(std::fabs(pCand->dxy(pv_->position())) <= maxTransverseImpactParameter_))
483  return false;
484  if(maxDeltaZ_ >= 0 && !(std::fabs(pCand->dz(pv_->position())) <= maxDeltaZ_)) return false;
485  if(maxDeltaZToLeadTrack_ >= 0) {
486  if ( leadTrack_ == nullptr) {
487  edm::LogError("QCutsNoValidLeadTrack") << "Lead track Ref in " <<
488  "RecoTauQualityCuts is invalid. - filterChargedCand";
489  return false;
490  }
491 
492  if(!(std::fabs(pCand->dz(pv_->position()) - leadTrack_->dz(pv_->position())) <= maxDeltaZToLeadTrack_))
493  return false;
494  }
495  }
496  if(minTrackVertexWeight_ >= 0. &&
498  return false;
499 
500  return true;
501 }
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:248
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:648
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 503 of file RecoTauQualityCuts.cc.

References reco::Candidate::et().

Referenced by filterCandRefs().

503  {
504  if(minGammaEt_ >= 0 && !(cand.et() > minGammaEt_)) return false;
505  return true;
506 }
virtual double et() const =0
transverse energy
bool reco::tau::RecoTauQualityCuts::filterNeutralHadronCand ( const reco::Candidate cand) const
private

Definition at line 508 of file RecoTauQualityCuts.cc.

References reco::Candidate::et().

Referenced by filterCandRefs().

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

Filter a single Track.

Definition at line 405 of file RecoTauQualityCuts.cc.

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

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

406 {
407  if (!filterTrack_(track.get()))
408  return false;
409  if(minTrackVertexWeight_ >= 0. && !(pv_->trackWeight(convertRef(track)) >= minTrackVertexWeight_)) return false;
410  return true;
411 }
value_type const * get() const
Definition: RefToBase.h:234
bool filterTrack_(const reco::Track *track) const
bool reco::tau::RecoTauQualityCuts::filterTrack ( const reco::TrackRef track) const

Definition at line 413 of file RecoTauQualityCuts.cc.

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

414 {
415  if (!filterTrack_(track.get()))
416  return false;
417  if(minTrackVertexWeight_ >= 0. && !(pv_->trackWeight(convertRef(track)) >= minTrackVertexWeight_)) return false;
418  return true;
419 }
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:243
bool filterTrack_(const reco::Track *track) const
bool reco::tau::RecoTauQualityCuts::filterTrack ( const reco::Track track) const

Definition at line 421 of file RecoTauQualityCuts.cc.

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

Definition at line 426 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().

427 {
428  if(minTrackPt_ >= 0 && !(track->pt() > minTrackPt_)) return false;
429  if(maxTrackChi2_ >= 0 && !(track->normalizedChi2() <= maxTrackChi2_)) return false;
430  if(checkHitPattern_) {
431  const reco::HitPattern &hitPattern = track->hitPattern();
432  if(minTrackPixelHits_ > 0 && !(hitPattern.numberOfValidPixelHits() >= minTrackPixelHits_)) return false;
433  if(minTrackHits_ > 0 && !(hitPattern.numberOfValidHits() >= minTrackHits_)) return false;
434  }
435  if(checkPV_ && pv_.isNull()) {
436  edm::LogError("QCutsNoPrimaryVertex") << "Primary vertex Ref in " <<
437  "RecoTauQualityCuts is invalid. - filterTrack";
438  return false;
439  }
440 
442  !(std::fabs(track->dxy(pv_->position())) <= maxTransverseImpactParameter_))
443  return false;
444  if(maxDeltaZ_ >= 0 && !(std::fabs(track->dz(pv_->position())) <= maxDeltaZ_)) return false;
445  if(maxDeltaZToLeadTrack_ >= 0) {
446  if ( !leadTrack_) {
447  edm::LogError("QCutsNoValidLeadTrack") << "Lead track Ref in " <<
448  "RecoTauQualityCuts is invalid. - filterTrack";
449  return false;
450  }
451 
452  if(!(std::fabs(track->dz(pv_->position()) - leadTrack_->dz(pv_->position())) <= maxDeltaZToLeadTrack_))
453  return false;
454  }
455 
456  return true;
457 }
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:600
int numberOfValidHits() const
Definition: HitPattern.h:896
double pt() const
track transverse momentum
Definition: TrackBase.h:660
bool isNull() const
Checks for null.
Definition: Ref.h:248
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:648
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:485
int numberOfValidPixelHits() const
Definition: HitPattern.h:916
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:630
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(), TopAnalysis_sequences::invert, and convertSQLitetoXML_cfg::output.

66  {
67  Coll output;
68  for(auto const& track : coll ) {
69  if ( filterTrack(track)^invert ) 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) const

Update the leading track.

Definition at line 555 of file RecoTauQualityCuts.cc.

References TauDiscriminatorTools::leadTrack.

Referenced by setPV().

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

Definition at line 560 of file RecoTauQualityCuts.cc.

References getTrack().

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

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

Definition at line 565 of file RecoTauQualityCuts.cc.

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

566 {
567  if ( leadCand.isNonnull() ) {
568  leadTrack_ = getTrack(*leadCand);
569  } else {
570  // Set null
571  leadTrack_ = nullptr;
572  }
573 }
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:251
static const TrackGhostTrackState * getTrack(const BasicGhostTrackState *basic)
void reco::tau::RecoTauQualityCuts::setPV ( const reco::VertexRef vtx) const
inline

Member Data Documentation

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

Definition at line 113 of file RecoTauQualityCuts.h.

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

Definition at line 114 of file RecoTauQualityCuts.h.

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

Definition at line 101 of file RecoTauQualityCuts.h.

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

Definition at line 108 of file RecoTauQualityCuts.h.

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

Definition at line 109 of file RecoTauQualityCuts.h.

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

Definition at line 104 of file RecoTauQualityCuts.h.

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

Definition at line 107 of file RecoTauQualityCuts.h.

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

Definition at line 111 of file RecoTauQualityCuts.h.

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

Definition at line 112 of file RecoTauQualityCuts.h.

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

Definition at line 106 of file RecoTauQualityCuts.h.

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

Definition at line 105 of file RecoTauQualityCuts.h.

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

Definition at line 103 of file RecoTauQualityCuts.h.

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

Definition at line 110 of file RecoTauQualityCuts.h.

reco::VertexRef reco::tau::RecoTauQualityCuts::pv_
mutableprivate

Definition at line 99 of file RecoTauQualityCuts.h.

Referenced by setPV().