CMS 3D CMS Logo

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 final
 
void getEventContent (const edm::EventBase &) final
 
result_type operator() (const reco::PhotonPtr &) const final
 
 PhoMVACut (const edm::ParameterSet &c)
 
void setConsumes (edm::ConsumesCollector &) final
 
double value (const reco::CandidatePtr &cand) const 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 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
 
 ~CutApplicatorBase () override
 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::InputTagcontentTags_
 
std::unordered_map< std::string, edm::EDGetTokencontentTokens_
 

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
inlinefinalvirtual

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)
finalvirtual

Implements CutApplicatorWithEventContentBase.

Definition at line 58 of file PhoMVACut.cc.

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

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:94
edm::Handle< edm::ValueMap< int > > _mvaCategoriesMap
Definition: PhoMVACut.cc:27
CutApplicatorBase::result_type PhoMVACut::operator() ( const reco::PhotonPtr cand) const
finalvirtual

Reimplemented from CutApplicatorBase.

Definition at line 66 of file PhoMVACut.cc.

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

Referenced by getEventContent().

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();
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:185
std::unordered_map< std::string, edm::InputTag > contentTags_
edm::Handle< edm::ValueMap< float > > _mvaValueMap
Definition: PhoMVACut.cc:26
Definition: HeavyIon.h:7
bool contains(ProductID id) const
Definition: ValueMap.h:155
def cat(path)
Definition: eostools.py:400
bool isValid() const
Definition: HandleBase.h:74
const std::vector< double > _mvaCutValues
Definition: PhoMVACut.cc:23
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< int > > _mvaCategoriesMap
Definition: PhoMVACut.cc:27
void PhoMVACut::setConsumes ( edm::ConsumesCollector cc)
finalvirtual

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
finalvirtual

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(), AlCaHLTBitMon_QueryRunRegistry::string, pat::PATObject< ObjectType >::userFloat(), and heppy_batch::val.

104  {
105 
106  // in case we are by-value
107  const std::string& val_name =contentTags_.find("mvaVal")->second.instance();
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:185
std::unordered_map< std::string, edm::InputTag > contentTags_
edm::Handle< edm::ValueMap< float > > _mvaValueMap
Definition: PhoMVACut.cc:26
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< 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().