CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 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 final
 
virtual result_type operator() (const reco::GsfElectronPtr &) const
 
virtual result_type operator() (const pat::ElectronPtr &) const
 
virtual result_type operator() (const reco::MuonPtr &) const
 
virtual result_type operator() (const pat::MuonPtr &) 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
}
 
- Public Types inherited from candidate_functions::CandidateCut
using argument_type = reco::CandidatePtr
 
using result_type = bool
 
- 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 4 of file PhoMVACut.cc.

Constructor & Destructor Documentation

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

Definition at line 28 of file PhoMVACut.cc.

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

29  : CutApplicatorWithEventContentBase(c), _mvaCutValues(c.getParameter<std::vector<double> >("mvaCuts")) {
30  edm::InputTag mvaValTag = c.getParameter<edm::InputTag>("mvaValueMapName");
31  contentTags_.emplace("mvaVal", mvaValTag);
32 
33  edm::InputTag mvaCatTag = c.getParameter<edm::InputTag>("mvaCategoriesMapName");
34  contentTags_.emplace("mvaCat", mvaCatTag);
35 }
std::unordered_map< std::string, edm::InputTag > contentTags_
const std::vector< double > _mvaCutValues
Definition: PhoMVACut.cc:19
T getParameter(std::string const &) const
Definition: ParameterSet.h:303

Member Function Documentation

CandidateType PhoMVACut::candidateType ( ) const
inlinefinalvirtual

Reimplemented from CutApplicatorBase.

Definition at line 15 of file PhoMVACut.cc.

References CutApplicatorBase::PHOTON.

void PhoMVACut::getEventContent ( const edm::EventBase ev)
finalvirtual

Implements CutApplicatorWithEventContentBase.

Definition at line 45 of file PhoMVACut.cc.

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

45  {
46  ev.getByLabel(contentTags_["mvaVal"], _mvaValueMap);
48 }
std::unordered_map< std::string, edm::InputTag > contentTags_
edm::Handle< edm::ValueMap< float > > _mvaValueMap
Definition: PhoMVACut.cc:22
bool getByLabel(InputTag const &, Handle< T > &) const
Definition: EventBase.h:92
edm::Handle< edm::ValueMap< int > > _mvaCategoriesMap
Definition: PhoMVACut.cc:23
CutApplicatorBase::result_type PhoMVACut::operator() ( const reco::PhotonPtr cand) const
finalvirtual

Reimplemented from CutApplicatorBase.

Definition at line 50 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, and hgcalPerformanceValidation::val.

50  {
51  // in case we are by-value
52  const std::string& val_name = contentTags_.find("mvaVal")->second.instance();
53  const std::string& cat_name = contentTags_.find("mvaCat")->second.instance();
54  edm::Ptr<pat::Photon> pat(cand);
55  float val = -1.0;
56  int cat = -1;
58  _mvaValueMap->contains(cand.id())) {
59  cat = (*_mvaCategoriesMap)[cand];
60  val = (*_mvaValueMap)[cand];
62  _mvaValueMap->idSize() == 1 && cand.id() == edm::ProductID()) {
63  // in case we have spoofed a ptr
64  //note this must be a 1:1 valuemap (only one product input)
65  cat = _mvaCategoriesMap->begin()[cand.key()];
66  val = _mvaValueMap->begin()[cand.key()];
67  } else if (_mvaCategoriesMap.isValid() && _mvaValueMap.isValid()) { // throw an exception
68  cat = (*_mvaCategoriesMap)[cand];
69  val = (*_mvaValueMap)[cand];
70  }
71 
72  // Find the cut value
73  const int iCategory = _mvaCategoriesMap.isValid() ? cat : pat->userInt(cat_name);
74  if (iCategory >= (int)(_mvaCutValues.size()))
75  throw cms::Exception(" Error in MVA categories: ")
76  << " found a particle with a category larger than max configured " << std::endl;
77  const float cutValue = _mvaCutValues[iCategory];
78 
79  // Look up the MVA value for this particle
80  const float mvaValue = _mvaValueMap.isValid() ? val : pat->userFloat(val_name);
81 
82  // Apply the cut and return the result
83  return mvaValue > cutValue;
84 }
std::unordered_map< std::string, edm::InputTag > contentTags_
key_type key() const
Definition: Ptr.h:163
edm::Handle< edm::ValueMap< float > > _mvaValueMap
Definition: PhoMVACut.cc:22
bool contains(ProductID id) const
Definition: ValueMap.h:155
def cat
Definition: eostools.py:401
bool isValid() const
Definition: HandleBase.h:70
const std::vector< double > _mvaCutValues
Definition: PhoMVACut.cc:19
size_t idSize() const
Definition: ValueMap.h:157
const_iterator begin() const
Definition: ValueMap.h:229
ProductID id() const
Accessor for product ID.
Definition: Ptr.h:158
edm::Handle< edm::ValueMap< int > > _mvaCategoriesMap
Definition: PhoMVACut.cc:23
void PhoMVACut::setConsumes ( edm::ConsumesCollector cc)
finalvirtual

Implements CutApplicatorWithEventContentBase.

Definition at line 37 of file PhoMVACut.cc.

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

37  {
38  auto mvaVal = cc.consumes<edm::ValueMap<float> >(contentTags_["mvaVal"]);
39  contentTokens_.emplace("mvaVal", mvaVal);
40 
41  auto mvaCat = cc.consumes<edm::ValueMap<int> >(contentTags_["mvaCat"]);
42  contentTokens_.emplace("mvaCat", mvaCat);
43 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
std::unordered_map< std::string, edm::InputTag > contentTags_
std::unordered_map< std::string, edm::EDGetToken > contentTokens_
double PhoMVACut::value ( const reco::CandidatePtr cand) const
finalvirtual

Implements candidate_functions::CandidateCut.

Definition at line 86 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, and hgcalPerformanceValidation::val.

Referenced by Types.int32::__nonzero__(), Types.uint32::__nonzero__(), Types.int64::__nonzero__(), Types.uint64::__nonzero__(), Types.double::__nonzero__(), Types.bool::__nonzero__(), Types.string::__nonzero__(), Types.string::configValue(), Types.FileInPath::configValue(), Types.int32::insertInto(), Types.uint32::insertInto(), Types.int64::insertInto(), Types.uint64::insertInto(), Types.double::insertInto(), Types.bool::insertInto(), Types.string::insertInto(), Types.FileInPath::insertInto(), Types.vint32::insertInto(), Types.vuint32::insertInto(), Types.vint64::insertInto(), Types.vuint64::insertInto(), Types.vdouble::insertInto(), Types.vbool::insertInto(), and Types.vstring::insertInto().

86  {
87  // in case we are by-value
88  const std::string& val_name = contentTags_.find("mvaVal")->second.instance();
89  edm::Ptr<pat::Photon> pat(cand);
90  float val = 0.0;
92  _mvaValueMap->contains(cand.id())) {
93  val = (*_mvaValueMap)[cand];
95  _mvaValueMap->idSize() == 1 && cand.id() == edm::ProductID()) {
96  // in case we have spoofed a ptr
97  //note this must be a 1:1 valuemap (only one product input)
98  val = _mvaValueMap->begin()[cand.key()];
99  } else if (_mvaCategoriesMap.isValid() && _mvaValueMap.isValid()) {
100  val = (*_mvaValueMap)[cand];
101  }
102  const float mvaValue = _mvaValueMap.isValid() ? val : pat->userFloat(val_name);
103  return mvaValue;
104 }
std::unordered_map< std::string, edm::InputTag > contentTags_
key_type key() const
Definition: Ptr.h:163
edm::Handle< edm::ValueMap< float > > _mvaValueMap
Definition: PhoMVACut.cc:22
bool contains(ProductID id) const
Definition: ValueMap.h:155
bool isValid() const
Definition: HandleBase.h:70
size_t idSize() const
Definition: ValueMap.h:157
const_iterator begin() const
Definition: ValueMap.h:229
ProductID id() const
Accessor for product ID.
Definition: Ptr.h:158
edm::Handle< edm::ValueMap< int > > _mvaCategoriesMap
Definition: PhoMVACut.cc:23

Member Data Documentation

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

Definition at line 23 of file PhoMVACut.cc.

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

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

Definition at line 19 of file PhoMVACut.cc.

Referenced by operator()().

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

Definition at line 22 of file PhoMVACut.cc.

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