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
PhoMVACut Class Reference
Inheritance diagram for PhoMVACut:
CutApplicatorWithEventContentBase CutApplicatorBase candidate_functions::CandidateCut

Public Member Functions

CandidateType candidateType () const overridefinal
 
void getEventContent (const edm::EventBase &) overridefinal
 
result_type operator() (const reco::PhotonPtr &) const overridefinal
 
 PhoMVACut (const edm::ParameterSet &c)
 
void setConsumes (edm::ConsumesCollector &) overridefinal
 
double value (const reco::CandidatePtr &cand) const overridefinal
 
- Public Member Functions inherited from CutApplicatorWithEventContentBase
 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 ()
 
 CutApplicatorBase (const edm::ParameterSet &c)
 
 CutApplicatorBase (const CutApplicatorBase &)=delete
 
virtual const std::string & name () const
 
virtual result_type operator() (const argument_type &) const final
 
virtual result_type operator() (const reco::GsfElectronPtr &) const
 
virtual result_type operator() (const pat::ElectronPtr &) 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
 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 PhoMVACut.cc.

Constructor & Destructor Documentation

PhoMVACut::PhoMVACut ( const edm::ParameterSet c)

Definition at line 35 of file PhoMVACut.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
std::unordered_map< std::string, edm::InputTag > contentTags_
const std::vector< double > _mvaCutValues
Definition: PhoMVACut.cc:23

Member Function Documentation

CandidateType PhoMVACut::candidateType ( ) const
inlinefinaloverridevirtual

Reimplemented from CutApplicatorBase.

Definition at line 16 of file PhoMVACut.cc.

References CutApplicatorBase::PHOTON.

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

Implements CutApplicatorWithEventContentBase.

Definition at line 58 of file PhoMVACut.cc.

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

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

Reimplemented from CutApplicatorBase.

Definition at line 66 of file PhoMVACut.cc.

References _mvaCategoriesMap, _mvaCutValues, _mvaValueMap, edm::ValueMap< T >::begin(), edm::ValueMap< T >::contains(), CutApplicatorWithEventContentBase::contentTags_, 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::Photon> 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  // Find the cut value
91  const int iCategory = _mvaCategoriesMap.isValid() ? cat : pat->userInt( cat_name );
92  if( iCategory >= (int)(_mvaCutValues.size()) )
93  throw cms::Exception(" Error in MVA categories: ")
94  << " found a particle with a category larger than max configured " << std::endl;
95  const float cutValue = _mvaCutValues[iCategory];
96 
97  // Look up the MVA value for this particle
98  const float mvaValue = _mvaValueMap.isValid() ? val : pat->userFloat( val_name );
99 
100  // Apply the cut and return the result
101  return mvaValue > cutValue;
102 }
key_type key() const
Definition: Ptr.h:186
std::unordered_map< std::string, edm::InputTag > contentTags_
edm::Handle< edm::ValueMap< float > > _mvaValueMap
Definition: PhoMVACut.cc:26
bool contains(ProductID id) const
Definition: ValueMap.h:154
bool isValid() const
Definition: HandleBase.h:75
const std::vector< double > _mvaCutValues
Definition: PhoMVACut.cc:23
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:181
edm::Handle< edm::ValueMap< int > > _mvaCategoriesMap
Definition: PhoMVACut.cc:27
void PhoMVACut::setConsumes ( edm::ConsumesCollector cc)
finaloverridevirtual

Implements CutApplicatorWithEventContentBase.

Definition at line 47 of file PhoMVACut.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 PhoMVACut::value ( const reco::CandidatePtr cand) const
finaloverridevirtual

Implements candidate_functions::CandidateCut.

Definition at line 104 of file PhoMVACut.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.

104  {
105 
106  // in case we are by-value
107  const std::string& val_name =contentTags_.find("mvaVal")->second.instance();
108  edm::Ptr<pat::Photon> pat(cand);
109  float val = 0.0;
110  if( _mvaCategoriesMap.isValid() && _mvaCategoriesMap->contains( cand.id() ) &&
111  _mvaValueMap.isValid() && _mvaValueMap->contains( cand.id() ) ) {
112  val = (*_mvaValueMap)[cand];
113  } else if ( _mvaCategoriesMap.isValid() && _mvaValueMap.isValid() &&
114  _mvaCategoriesMap->idSize() == 1 && _mvaValueMap->idSize() == 1 &&
115  cand.id() == edm::ProductID() ) {
116  // in case we have spoofed a ptr
117  //note this must be a 1:1 valuemap (only one product input)
118  val = _mvaValueMap->begin()[cand.key()];
119  } else if ( _mvaCategoriesMap.isValid() && _mvaValueMap.isValid() ) {
120  val = (*_mvaValueMap)[cand];
121  }
122  const float mvaValue = _mvaValueMap.isValid() ? val : pat->userFloat( val_name );
123  return mvaValue;
124 }
key_type key() const
Definition: Ptr.h:186
std::unordered_map< std::string, edm::InputTag > contentTags_
edm::Handle< edm::ValueMap< float > > _mvaValueMap
Definition: PhoMVACut.cc:26
bool contains(ProductID id) const
Definition: ValueMap.h:154
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:181
edm::Handle< edm::ValueMap< int > > _mvaCategoriesMap
Definition: PhoMVACut.cc:27

Member Data Documentation

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

Definition at line 27 of file PhoMVACut.cc.

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

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

Definition at line 23 of file PhoMVACut.cc.

Referenced by operator()().

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

Definition at line 26 of file PhoMVACut.cc.

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