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 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::InputTagcontentTags_
 
std::unordered_map< std::string, edm::EDGetTokencontentTokens_
 

Detailed Description

Definition at line 4 of file PhoMVACut.cc.

Constructor & Destructor Documentation

◆ PhoMVACut()

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

Definition at line 28 of file PhoMVACut.cc.

References DummyCfis::c, and CutApplicatorWithEventContentBase::contentTags_.

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

Member Function Documentation

◆ candidateType()

CandidateType PhoMVACut::candidateType ( ) const
inlinefinalvirtual

Reimplemented from CutApplicatorBase.

Definition at line 15 of file PhoMVACut.cc.

References CutApplicatorBase::PHOTON.

◆ getEventContent()

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

Implements CutApplicatorWithEventContentBase.

Definition at line 45 of file PhoMVACut.cc.

References _mvaCategoriesMap, _mvaValueMap, CutApplicatorWithEventContentBase::contentTags_, and makeMEIFBenchmarkPlots::ev.

45  {
46  ev.getByLabel(contentTags_["mvaVal"], _mvaValueMap);
47  ev.getByLabel(contentTags_["mvaCat"], _mvaCategoriesMap);
48 }
std::unordered_map< std::string, edm::InputTag > contentTags_
edm::Handle< edm::ValueMap< float > > _mvaValueMap
Definition: PhoMVACut.cc:22
edm::Handle< edm::ValueMap< int > > _mvaCategoriesMap
Definition: PhoMVACut.cc:23

◆ operator()()

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::ValueMap< T >::idSize(), edm::HandleBase::isValid(), AlCaHLTBitMon_QueryRunRegistry::string, and heppy_batch::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();
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_
size_t idSize() const
Definition: ValueMap.h:151
edm::Handle< edm::ValueMap< float > > _mvaValueMap
Definition: PhoMVACut.cc:22
Definition: HeavyIon.h:7
def cat(path)
Definition: eostools.py:401
const_iterator begin() const
Definition: ValueMap.h:223
const std::vector< double > _mvaCutValues
Definition: PhoMVACut.cc:19
bool isValid() const
Definition: HandleBase.h:70
edm::Handle< edm::ValueMap< int > > _mvaCategoriesMap
Definition: PhoMVACut.cc:23
bool contains(ProductID id) const
Definition: ValueMap.h:149

◆ setConsumes()

void PhoMVACut::setConsumes ( edm::ConsumesCollector cc)
finalvirtual

Implements CutApplicatorWithEventContentBase.

Definition at line 37 of file PhoMVACut.cc.

References gpuPixelDoublets::cc, 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 }
std::unordered_map< std::string, edm::InputTag > contentTags_
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
std::unordered_map< std::string, edm::EDGetToken > contentTokens_

◆ value()

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::ValueMap< T >::idSize(), edm::HandleBase::isValid(), AlCaHLTBitMon_QueryRunRegistry::string, and heppy_batch::val.

86  {
87  // in case we are by-value
88  const std::string& val_name = contentTags_.find("mvaVal")->second.instance();
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_
size_t idSize() const
Definition: ValueMap.h:151
edm::Handle< edm::ValueMap< float > > _mvaValueMap
Definition: PhoMVACut.cc:22
Definition: HeavyIon.h:7
const_iterator begin() const
Definition: ValueMap.h:223
bool isValid() const
Definition: HandleBase.h:70
edm::Handle< edm::ValueMap< int > > _mvaCategoriesMap
Definition: PhoMVACut.cc:23
bool contains(ProductID id) const
Definition: ValueMap.h:149

Member Data Documentation

◆ _mvaCategoriesMap

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

Definition at line 23 of file PhoMVACut.cc.

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

◆ _mvaCutValues

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

Definition at line 19 of file PhoMVACut.cc.

Referenced by operator()().

◆ _mvaValueMap

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

Definition at line 22 of file PhoMVACut.cc.

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