CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes
GsfEleMVACut Class Reference
Inheritance diagram for GsfEleMVACut:
CutApplicatorWithEventContentBase CutApplicatorBase candidate_functions::CandidateCut

Public Member Functions

CandidateType candidateType () const overridefinal
 
void getEventContent (const edm::EventBase &) overridefinal
 
 GsfEleMVACut (const edm::ParameterSet &c)
 
result_type operator() (const reco::GsfElectronPtr &) const overridefinal
 
void setConsumes (edm::ConsumesCollector &) overridefinal
 
double value (const reco::CandidatePtr &cand) const overridefinal
 
- Public Member Functions inherited from CutApplicatorWithEventContentBase
 CutApplicatorWithEventContentBase (const edm::ParameterSet &c)
 
 CutApplicatorWithEventContentBase (const CutApplicatorWithEventContentBase &)=delete
 
CutApplicatorWithEventContentBaseoperator= (const CutApplicatorWithEventContentBase &)=delete
 
virtual ~CutApplicatorWithEventContentBase ()
 Destructor. More...
 
- Public Member Functions inherited from CutApplicatorBase
virtual result_type asCandidate (const argument_type &) const
 
 CutApplicatorBase (const edm::ParameterSet &c)
 
 CutApplicatorBase (const CutApplicatorBase &)=delete
 
const std::string & name () const
 
virtual result_type operator() (const argument_type &) const 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
 
virtual ~CutApplicatorBase ()
 Destructor. More...
 
- Public Member Functions inherited from candidate_functions::CandidateCut
virtual ~CandidateCut ()
 

Private Attributes

edm::Handle< edm::ValueMap< int > > _mvaCategoriesMap
 
const std::vector< double > _mvaCutValues
 
edm::Handle< edm::ValueMap
< float > > 
_mvaValueMap
 

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::InputTag
contentTags_
 
std::unordered_map
< std::string, edm::EDGetToken
contentTokens_
 

Detailed Description

Definition at line 5 of file GsfEleMVACut.cc.

Constructor & Destructor Documentation

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

Definition at line 35 of file GsfEleMVACut.cc.

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

35  :
37  _mvaCutValues(c.getParameter<std::vector<double> >("mvaCuts"))
38 {
39  edm::InputTag mvaValTag = c.getParameter<edm::InputTag>("mvaValueMapName");
40  contentTags_.emplace("mvaVal",mvaValTag);
41 
42  edm::InputTag mvaCatTag = c.getParameter<edm::InputTag>("mvaCategoriesMapName");
43  contentTags_.emplace("mvaCat",mvaCatTag);
44 
45 }
T getParameter(std::string const &) const
CutApplicatorWithEventContentBase(const edm::ParameterSet &c)
std::unordered_map< std::string, edm::InputTag > contentTags_
const std::vector< double > _mvaCutValues
Definition: GsfEleMVACut.cc:23

Member Function Documentation

CandidateType GsfEleMVACut::candidateType ( ) const
inlinefinaloverridevirtual

Reimplemented from CutApplicatorBase.

Definition at line 16 of file GsfEleMVACut.cc.

References CutApplicatorBase::ELECTRON.

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

Implements CutApplicatorWithEventContentBase.

Definition at line 58 of file GsfEleMVACut.cc.

References _mvaCategoriesMap, _mvaValueMap, CutApplicatorWithEventContentBase::contentTags_, and edm::EventBase::getByLabel().

58  {
59 
60  ev.getByLabel(contentTags_["mvaVal"],_mvaValueMap);
62 }
edm::Handle< edm::ValueMap< float > > _mvaValueMap
Definition: GsfEleMVACut.cc:26
std::unordered_map< std::string, edm::InputTag > contentTags_
edm::Handle< edm::ValueMap< int > > _mvaCategoriesMap
Definition: GsfEleMVACut.cc:27
bool getByLabel(InputTag const &, Handle< T > &) const
Definition: EventBase.h:92
CutApplicatorBase::result_type GsfEleMVACut::operator() ( const reco::GsfElectronPtr cand) const
finaloverridevirtual

Reimplemented from CutApplicatorBase.

Definition at line 66 of file GsfEleMVACut.cc.

References _mvaCategoriesMap, _mvaCutValues, _mvaValueMap, edm::ValueMap< T >::begin(), eostools::cat(), edm::ValueMap< T >::contains(), CutApplicatorWithEventContentBase::contentTags_, edm::hlt::Exception, edm::Ptr< T >::id(), edm::ValueMap< T >::idSize(), edm::HandleBase::isValid(), edm::Ptr< T >::key(), and AlCaHLTBitMon_QueryRunRegistry::string.

66  {
67 
68  // in case we are by-value
69  const std::string& val_name = contentTags_.find("mvaVal")->second.instance();
70  const std::string& cat_name = contentTags_.find("mvaCat")->second.instance();
71  edm::Ptr<pat::Electron> pat(cand);
72  float val = -1.0;
73  int cat = -1;
75  _mvaValueMap.isValid() && _mvaValueMap->contains( cand.id() ) ) {
76  cat = (*_mvaCategoriesMap)[cand];
77  val = (*_mvaValueMap)[cand];
78  } else if ( _mvaCategoriesMap.isValid() && _mvaValueMap.isValid() &&
79  _mvaCategoriesMap->idSize() == 1 && _mvaValueMap->idSize() == 1 &&
80  cand.id() == edm::ProductID() ) {
81  // in case we have spoofed a ptr
82  //note this must be a 1:1 valuemap (only one product input)
83  cat = _mvaCategoriesMap->begin()[cand.key()];
84  val = _mvaValueMap->begin()[cand.key()];
85  } else if ( _mvaCategoriesMap.isValid() && _mvaValueMap.isValid() ){ // throw an exception
86  cat = (*_mvaCategoriesMap)[cand];
87  val = (*_mvaValueMap)[cand];
88  }
89 
90 
91  // Find the cut value
92  const int iCategory = _mvaCategoriesMap.isValid() ? cat : pat->userInt( cat_name );
93  if( iCategory >= (int)(_mvaCutValues.size()) )
94  throw cms::Exception(" Error in MVA categories: ")
95  << " found a particle with a category larger than max configured " << std::endl;
96  const float cutValue = _mvaCutValues[iCategory];
97 
98  // Look up the MVA value for this particle
99  const float mvaValue = _mvaValueMap.isValid() ? val : pat->userFloat( val_name );
100 
101  // Apply the cut and return the result
102  return mvaValue > cutValue;
103 }
key_type key() const
Definition: Ptr.h:169
edm::Handle< edm::ValueMap< float > > _mvaValueMap
Definition: GsfEleMVACut.cc:26
std::unordered_map< std::string, edm::InputTag > contentTags_
bool contains(ProductID id) const
Definition: ValueMap.h:154
def cat
Definition: eostools.py:398
edm::Handle< edm::ValueMap< int > > _mvaCategoriesMap
Definition: GsfEleMVACut.cc:27
bool isValid() const
Definition: HandleBase.h:75
size_t idSize() const
Definition: ValueMap.h:158
const_iterator begin() const
Definition: ValueMap.h:209
ProductID id() const
Accessor for product ID.
Definition: Ptr.h:164
const std::vector< double > _mvaCutValues
Definition: GsfEleMVACut.cc:23
void GsfEleMVACut::setConsumes ( edm::ConsumesCollector cc)
finaloverridevirtual

Implements CutApplicatorWithEventContentBase.

Definition at line 47 of file GsfEleMVACut.cc.

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

47  {
48 
49  auto mvaVal =
51  contentTokens_.emplace("mvaVal",mvaVal);
52 
53  auto mvaCat =
55  contentTokens_.emplace("mvaCat",mvaCat);
56 }
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
finaloverridevirtual

Implements candidate_functions::CandidateCut.

Definition at line 105 of file GsfEleMVACut.cc.

References _mvaCategoriesMap, _mvaValueMap, 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(), and AlCaHLTBitMon_QueryRunRegistry::string.

105  {
106 
107  // in case we are by-value
108  const std::string& val_name =contentTags_.find("mvaVal")->second.instance();
109  edm::Ptr<pat::Electron> pat(cand);
110  float val = 0.0;
111  if( _mvaCategoriesMap.isValid() && _mvaCategoriesMap->contains( cand.id() ) &&
112  _mvaValueMap.isValid() && _mvaValueMap->contains( cand.id() ) ) {
113  val = (*_mvaValueMap)[cand];
114  } else if ( _mvaCategoriesMap.isValid() && _mvaValueMap.isValid() &&
115  _mvaCategoriesMap->idSize() == 1 && _mvaValueMap->idSize() == 1 &&
116  cand.id() == edm::ProductID() ) {
117  // in case we have spoofed a ptr
118  //note this must be a 1:1 valuemap (only one product input)
119  val = _mvaValueMap->begin()[cand.key()];
120  } else if ( _mvaCategoriesMap.isValid() && _mvaValueMap.isValid() ){ // throw an exception
121  val = (*_mvaValueMap)[cand];
122  }
123 
124  const float mvaValue = _mvaValueMap.isValid() ? val : pat->userFloat( val_name );
125  return mvaValue;
126 }
key_type key() const
Definition: Ptr.h:169
edm::Handle< edm::ValueMap< float > > _mvaValueMap
Definition: GsfEleMVACut.cc:26
std::unordered_map< std::string, edm::InputTag > contentTags_
bool contains(ProductID id) const
Definition: ValueMap.h:154
edm::Handle< edm::ValueMap< int > > _mvaCategoriesMap
Definition: GsfEleMVACut.cc:27
bool isValid() const
Definition: HandleBase.h:75
size_t idSize() const
Definition: ValueMap.h:158
const_iterator begin() const
Definition: ValueMap.h:209
ProductID id() const
Accessor for product ID.
Definition: Ptr.h:164

Member Data Documentation

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

Definition at line 27 of file GsfEleMVACut.cc.

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

const std::vector<double> GsfEleMVACut::_mvaCutValues
private

Definition at line 23 of file GsfEleMVACut.cc.

Referenced by operator()().

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

Definition at line 26 of file GsfEleMVACut.cc.

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