CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
GsfEleMVACut Class Reference
Inheritance diagram for GsfEleMVACut:
CutApplicatorWithEventContentBase CutApplicatorBase candidate_functions::CandidateCut

Public Member Functions

CandidateType candidateType () const final
 
void getEventContent (const edm::EventBase &) final
 
 GsfEleMVACut (const edm::ParameterSet &c)
 
result_type operator() (const reco::GsfElectronPtr &) const final
 
void setConsumes (edm::ConsumesCollector &) final
 
- Public Member Functions inherited from CutApplicatorWithEventContentBase
 CutApplicatorWithEventContentBase ()
 
 CutApplicatorWithEventContentBase (const edm::ParameterSet &c)
 
 CutApplicatorWithEventContentBase (const CutApplicatorWithEventContentBase &)=delete
 
CutApplicatorWithEventContentBaseoperator= (const CutApplicatorWithEventContentBase &)=delete
 
 ~CutApplicatorWithEventContentBase () override
 Destructor. More...
 
- Public Member Functions inherited from CutApplicatorBase
virtual result_type asCandidate (const argument_type &) const
 
 CutApplicatorBase ()
 
 CutApplicatorBase (const edm::ParameterSet &c)
 
 CutApplicatorBase (const CutApplicatorBase &)=delete
 
const std::string & name () const override
 
result_type operator() (const argument_type &) const override final
 
virtual result_type operator() (const pat::ElectronPtr &) const
 
virtual result_type operator() (const reco::PhotonPtr &) const
 
virtual result_type operator() (const pat::PhotonPtr &) const
 
virtual result_type operator() (const reco::MuonPtr &) const
 
virtual result_type operator() (const pat::MuonPtr &) const
 
virtual result_type operator() (const reco::PFTauPtr &) const
 
virtual result_type operator() (const pat::TauPtr &) const
 
CutApplicatorBaseoperator= (const CutApplicatorBase &)=delete
 
 ~CutApplicatorBase () override
 Destructor. More...
 
- Public Member Functions inherited from candidate_functions::CandidateCut
 CandidateCut ()
 
virtual ~CandidateCut ()
 

Private Member Functions

double value (const reco::CandidatePtr &cand) const final
 

Private Attributes

std::vector< StringObjectFunction< reco::GsfElectron > > cutFormula_
 
edm::Handle< edm::ValueMap< int > > mvaCategoriesMap_
 
const std::vector< std::string > mvaCutStrings_
 
edm::Handle< edm::ValueMap< float > > mvaValueMap_
 
const int nCuts_
 

Additional Inherited Members

- Public Types inherited from CutApplicatorBase
enum  CandidateType {
  NONE, ELECTRON, MUON, PHOTON,
  TAU, PATELECTRON, PATMUON, PATPHOTON,
  PATTAU
}
 
- Protected Attributes inherited from CutApplicatorWithEventContentBase
std::unordered_map< std::string, edm::InputTagcontentTags_
 
std::unordered_map< std::string, edm::EDGetTokencontentTokens_
 

Detailed Description

Definition at line 6 of file GsfEleMVACut.cc.

Constructor & Destructor Documentation

GsfEleMVACut::GsfEleMVACut ( const edm::ParameterSet c)

Definition at line 39 of file GsfEleMVACut.cc.

References CutApplicatorWithEventContentBase::contentTags_, cutFormula_, edm::ParameterSet::getParameter(), and mvaCutStrings_.

39  :
41  mvaCutStrings_(c.getParameter<std::vector<std::string> >("mvaCuts")),
42  nCuts_(mvaCutStrings_.size())
43 {
44  edm::InputTag mvaValTag = c.getParameter<edm::InputTag>("mvaValueMapName");
45  contentTags_.emplace("mvaVal",mvaValTag);
46 
47  edm::InputTag mvaCatTag = c.getParameter<edm::InputTag>("mvaCategoriesMapName");
48  contentTags_.emplace("mvaCat",mvaCatTag);
49 
50  for (auto &cutString : mvaCutStrings_) {
52  }
53 }
T getParameter(std::string const &) const
const int nCuts_
Definition: GsfEleMVACut.cc:27
std::vector< StringObjectFunction< reco::GsfElectron > > cutFormula_
Definition: GsfEleMVACut.cc:25
std::unordered_map< std::string, edm::InputTag > contentTags_
const std::vector< std::string > mvaCutStrings_
Definition: GsfEleMVACut.cc:24

Member Function Documentation

CandidateType GsfEleMVACut::candidateType ( ) const
inlinefinalvirtual

Reimplemented from CutApplicatorBase.

Definition at line 15 of file GsfEleMVACut.cc.

References CutApplicatorBase::ELECTRON, and value().

15  {
16  return ELECTRON;
17  }
void GsfEleMVACut::getEventContent ( const edm::EventBase ev)
finalvirtual

Implements CutApplicatorWithEventContentBase.

Definition at line 66 of file GsfEleMVACut.cc.

References CutApplicatorWithEventContentBase::contentTags_, edm::EventBase::getByLabel(), mvaCategoriesMap_, mvaValueMap_, and operator()().

66  {
67 
68  ev.getByLabel(contentTags_["mvaVal"], mvaValueMap_);
70 }
edm::Handle< edm::ValueMap< int > > mvaCategoriesMap_
Definition: GsfEleMVACut.cc:31
std::unordered_map< std::string, edm::InputTag > contentTags_
bool getByLabel(InputTag const &, Handle< T > &) const
Definition: EventBase.h:94
edm::Handle< edm::ValueMap< float > > mvaValueMap_
Definition: GsfEleMVACut.cc:30
CutApplicatorBase::result_type GsfEleMVACut::operator() ( const reco::GsfElectronPtr cand) const
finalvirtual

Reimplemented from CutApplicatorBase.

Definition at line 74 of file GsfEleMVACut.cc.

References edm::ValueMap< T >::begin(), eostools::cat(), edm::ValueMap< T >::contains(), CutApplicatorWithEventContentBase::contentTags_, cutFormula_, Exception, edm::Ptr< T >::id(), edm::ValueMap< T >::idSize(), edm::HandleBase::isValid(), edm::Ptr< T >::key(), mvaCategoriesMap_, mvaValueMap_, nCuts_, AlCaHLTBitMon_QueryRunRegistry::string, pat::PATObject< ObjectType >::userFloat(), pat::PATObject< ObjectType >::userInt(), and heppy_batch::val.

Referenced by getEventContent().

74  {
75 
76  // in case we are by-value
77  const std::string& val_name = contentTags_.find("mvaVal")->second.instance();
78  const std::string& cat_name = contentTags_.find("mvaCat")->second.instance();
80  float val = -1.0;
81  int cat = -1;
83  mvaValueMap_.isValid() && mvaValueMap_->contains( cand.id() ) ) {
84  cat = (*mvaCategoriesMap_)[cand];
85  val = (*mvaValueMap_)[cand];
86  } else if ( mvaCategoriesMap_.isValid() && mvaValueMap_.isValid() &&
87  mvaCategoriesMap_->idSize() == 1 && mvaValueMap_->idSize() == 1 &&
88  cand.id() == edm::ProductID() ) {
89  // in case we have spoofed a ptr
90  //note this must be a 1:1 valuemap (only one product input)
91  cat = mvaCategoriesMap_->begin()[cand.key()];
92  val = mvaValueMap_->begin()[cand.key()];
93  } else if ( mvaCategoriesMap_.isValid() && mvaValueMap_.isValid() ){ // throw an exception
94  cat = (*mvaCategoriesMap_)[cand];
95  val = (*mvaValueMap_)[cand];
96  }
97 
98  // Find the cut formula
99  const int iCategory = mvaCategoriesMap_.isValid() ? cat : pat->userInt( cat_name );
100  if( iCategory >= nCuts_ )
101  throw cms::Exception(" Error in MVA categories: ")
102  << " found a particle with a category larger than max configured " << std::endl;
103 
104  // Look up the MVA value for this particle
105  const float mvaValue = mvaValueMap_.isValid() ? val : pat->userFloat( val_name );
106 
107  // Apply the cut and return the result
108  return mvaValue > cutFormula_[iCategory](*cand);
109 }
edm::Handle< edm::ValueMap< int > > mvaCategoriesMap_
Definition: GsfEleMVACut.cc:31
key_type key() const
Definition: Ptr.h:185
const int nCuts_
Definition: GsfEleMVACut.cc:27
std::vector< StringObjectFunction< reco::GsfElectron > > cutFormula_
Definition: GsfEleMVACut.cc:25
std::unordered_map< std::string, edm::InputTag > contentTags_
Definition: HeavyIon.h:7
bool contains(ProductID id) const
Definition: ValueMap.h:155
def cat(path)
Definition: eostools.py:401
bool isValid() const
Definition: HandleBase.h:74
size_t idSize() const
Definition: ValueMap.h:159
const_iterator begin() const
Definition: ValueMap.h:208
ProductID id() const
Accessor for product ID.
Definition: Ptr.h:180
edm::Handle< edm::ValueMap< float > > mvaValueMap_
Definition: GsfEleMVACut.cc:30
void GsfEleMVACut::setConsumes ( edm::ConsumesCollector cc)
finalvirtual

Implements CutApplicatorWithEventContentBase.

Definition at line 55 of file GsfEleMVACut.cc.

References edm::ConsumesCollector::consumes(), CutApplicatorWithEventContentBase::contentTags_, and CutApplicatorWithEventContentBase::contentTokens_.

55  {
56 
57  auto mvaVal =
59  contentTokens_.emplace("mvaVal",mvaVal);
60 
61  auto mvaCat =
63  contentTokens_.emplace("mvaCat",mvaCat);
64 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
std::unordered_map< std::string, edm::EDGetToken > contentTokens_
std::unordered_map< std::string, edm::InputTag > contentTags_
double GsfEleMVACut::value ( const reco::CandidatePtr cand) const
finalprivatevirtual

Implements candidate_functions::CandidateCut.

Definition at line 111 of file GsfEleMVACut.cc.

References edm::ValueMap< T >::begin(), edm::ValueMap< T >::contains(), CutApplicatorWithEventContentBase::contentTags_, edm::Ptr< T >::id(), edm::ValueMap< T >::idSize(), edm::HandleBase::isValid(), edm::Ptr< T >::key(), mvaCategoriesMap_, mvaValueMap_, AlCaHLTBitMon_QueryRunRegistry::string, pat::PATObject< ObjectType >::userFloat(), and heppy_batch::val.

Referenced by candidateType().

111  {
112 
113  // in case we are by-value
114  const std::string& val_name =contentTags_.find("mvaVal")->second.instance();
116  float val = 0.0;
117  if( mvaCategoriesMap_.isValid() && mvaCategoriesMap_->contains( cand.id() ) &&
118  mvaValueMap_.isValid() && mvaValueMap_->contains( cand.id() ) ) {
119  val = (*mvaValueMap_)[cand];
120  } else if ( mvaCategoriesMap_.isValid() && mvaValueMap_.isValid() &&
121  mvaCategoriesMap_->idSize() == 1 && mvaValueMap_->idSize() == 1 &&
122  cand.id() == edm::ProductID() ) {
123  // in case we have spoofed a ptr
124  //note this must be a 1:1 valuemap (only one product input)
125  val = mvaValueMap_->begin()[cand.key()];
126  } else if ( mvaCategoriesMap_.isValid() && mvaValueMap_.isValid() ){ // throw an exception
127  val = (*mvaValueMap_)[cand];
128  }
129 
130  const float mvaValue = mvaValueMap_.isValid() ? val : pat->userFloat( val_name );
131  return mvaValue;
132 }
edm::Handle< edm::ValueMap< int > > mvaCategoriesMap_
Definition: GsfEleMVACut.cc:31
key_type key() const
Definition: Ptr.h:185
std::unordered_map< std::string, edm::InputTag > contentTags_
Definition: HeavyIon.h:7
bool contains(ProductID id) const
Definition: ValueMap.h:155
bool isValid() const
Definition: HandleBase.h:74
size_t idSize() const
Definition: ValueMap.h:159
const_iterator begin() const
Definition: ValueMap.h:208
ProductID id() const
Accessor for product ID.
Definition: Ptr.h:180
edm::Handle< edm::ValueMap< float > > mvaValueMap_
Definition: GsfEleMVACut.cc:30

Member Data Documentation

std::vector<StringObjectFunction<reco::GsfElectron> > GsfEleMVACut::cutFormula_
private

Definition at line 25 of file GsfEleMVACut.cc.

Referenced by GsfEleMVACut(), and operator()().

edm::Handle<edm::ValueMap<int> > GsfEleMVACut::mvaCategoriesMap_
private

Definition at line 31 of file GsfEleMVACut.cc.

Referenced by getEventContent(), operator()(), and value().

const std::vector<std::string> GsfEleMVACut::mvaCutStrings_
private

Definition at line 24 of file GsfEleMVACut.cc.

Referenced by GsfEleMVACut().

edm::Handle<edm::ValueMap<float> > GsfEleMVACut::mvaValueMap_
private

Definition at line 30 of file GsfEleMVACut.cc.

Referenced by getEventContent(), operator()(), and value().

const int GsfEleMVACut::nCuts_
private

Definition at line 27 of file GsfEleMVACut.cc.

Referenced by operator()().