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 CutApplicatorWithEventContentBase &)=delete
 
 CutApplicatorWithEventContentBase (const edm::ParameterSet &c)
 
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 CutApplicatorBase &)=delete
 
 CutApplicatorBase (const edm::ParameterSet &c)
 
const std::string & name () const override
 
result_type operator() (const argument_type &) const final
 
virtual result_type operator() (const pat::ElectronPtr &) const
 
virtual result_type operator() (const pat::MuonPtr &) const
 
virtual result_type operator() (const reco::GsfElectronPtr &) const
 
virtual result_type operator() (const reco::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.

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 }

References c, and CutApplicatorWithEventContentBase::contentTags_.

Member Function Documentation

◆ candidateType()

CandidateType PhoMVACut::candidateType ( ) const
inlinefinalvirtual

Reimplemented from CutApplicatorBase.

Definition at line 15 of file PhoMVACut.cc.

15 { return PHOTON; }

References CutApplicatorBase::PHOTON.

◆ getEventContent()

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

Implements CutApplicatorWithEventContentBase.

Definition at line 45 of file PhoMVACut.cc.

45  {
46  ev.getByLabel(contentTags_["mvaVal"], _mvaValueMap);
47  ev.getByLabel(contentTags_["mvaCat"], _mvaCategoriesMap);
48 }

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

◆ operator()()

CutApplicatorBase::result_type PhoMVACut::operator() ( const reco::PhotonPtr cand) const
finalvirtual

Reimplemented from CutApplicatorBase.

Definition at line 50 of file PhoMVACut.cc.

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 }

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.

◆ setConsumes()

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

Implements CutApplicatorWithEventContentBase.

Definition at line 37 of file PhoMVACut.cc.

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 }

References CutApplicatorWithEventContentBase::contentTags_, and CutApplicatorWithEventContentBase::contentTokens_.

◆ value()

double PhoMVACut::value ( const reco::CandidatePtr cand) const
finalvirtual

Implements candidate_functions::CandidateCut.

Definition at line 86 of file PhoMVACut.cc.

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 }

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.

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().

CutApplicatorBase::PHOTON
Definition: CutApplicatorBase.h:47
eostools.cat
def cat(path)
Definition: eostools.py:401
CutApplicatorWithEventContentBase::contentTags_
std::unordered_map< std::string, edm::InputTag > contentTags_
Definition: CutApplicatorWithEventContentBase.h:35
PhoMVACut::_mvaValueMap
edm::Handle< edm::ValueMap< float > > _mvaValueMap
Definition: PhoMVACut.cc:22
CutApplicatorWithEventContentBase::CutApplicatorWithEventContentBase
CutApplicatorWithEventContentBase()
Definition: CutApplicatorWithEventContentBase.h:21
edm::ValueMap::begin
const_iterator begin() const
Definition: ValueMap.h:229
cand
Definition: decayParser.h:32
pat
Definition: HeavyIon.h:7
cc
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::Ptr
Definition: AssociationVector.h:31
PhoMVACut::_mvaCategoriesMap
edm::Handle< edm::ValueMap< int > > _mvaCategoriesMap
Definition: PhoMVACut.cc:23
heppy_batch.val
val
Definition: heppy_batch.py:351
PhoMVACut::_mvaCutValues
const std::vector< double > _mvaCutValues
Definition: PhoMVACut.cc:19
edm::ValueMap::idSize
size_t idSize() const
Definition: ValueMap.h:157
edm::ValueMap< float >
ev
bool ev
Definition: Hydjet2Hadronizer.cc:97
CutApplicatorWithEventContentBase::contentTokens_
std::unordered_map< std::string, edm::EDGetToken > contentTokens_
Definition: CutApplicatorWithEventContentBase.h:40
Exception
Definition: hltDiff.cc:245
edm::ValueMap::contains
bool contains(ProductID id) const
Definition: ValueMap.h:155
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:56
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::InputTag
Definition: InputTag.h:15
edm::ProductID
Definition: ProductID.h:27