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 Member Functions | Private Attributes
GsfEleMVACut Class Reference
Inheritance diagram for GsfEleMVACut:
CutApplicatorWithEventContentBase CutApplicatorBase candidate_functions::CandidateCut

Public Member Functions

CandidateType candidateType () const final
 
void getEventContent (const edm::EventBase &) final
 
 GsfEleMVACut (const edm::ParameterSet &c)
 
result_type operator() (const reco::GsfElectronPtr &) const final
 
void setConsumes (edm::ConsumesCollector &) 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 pat::ElectronPtr &) const
 
virtual result_type operator() (const reco::PhotonPtr &) 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 Member Functions

double value (const reco::CandidatePtr &cand) const final
 

Private Attributes

std::vector
< StringObjectFunction
< reco::GsfElectron > > 
cutFormula_
 
edm::Handle< edm::ValueMap< int > > mvaCategoriesMap_
 
const std::vector< std::string > mvaCutStrings_
 
edm::Handle< edm::ValueMap
< float > > 
mvaValueMap_
 
const int nCuts_
 

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 5 of file GsfEleMVACut.cc.

Constructor & Destructor Documentation

GsfEleMVACut::GsfEleMVACut ( const edm::ParameterSet c)

Definition at line 32 of file GsfEleMVACut.cc.

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

34  mvaCutStrings_(c.getParameter<std::vector<std::string>>("mvaCuts")),
35  nCuts_(mvaCutStrings_.size()) {
36  edm::InputTag mvaValTag = c.getParameter<edm::InputTag>("mvaValueMapName");
37  contentTags_.emplace("mvaVal", mvaValTag);
38 
39  edm::InputTag mvaCatTag = c.getParameter<edm::InputTag>("mvaCategoriesMapName");
40  contentTags_.emplace("mvaCat", mvaCatTag);
41 
42  for (auto& cutString : mvaCutStrings_) {
44  }
45 }
std::unordered_map< std::string, edm::InputTag > contentTags_
const int nCuts_
Definition: GsfEleMVACut.cc:23
std::vector< StringObjectFunction< reco::GsfElectron > > cutFormula_
Definition: GsfEleMVACut.cc:21
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
const std::vector< std::string > mvaCutStrings_
Definition: GsfEleMVACut.cc:20

Member Function Documentation

CandidateType GsfEleMVACut::candidateType ( ) const
inlinefinalvirtual

Reimplemented from CutApplicatorBase.

Definition at line 14 of file GsfEleMVACut.cc.

References CutApplicatorBase::ELECTRON.

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

Implements CutApplicatorWithEventContentBase.

Definition at line 55 of file GsfEleMVACut.cc.

References CutApplicatorWithEventContentBase::contentTags_, edm::EventBase::getByLabel(), mvaCategoriesMap_, and mvaValueMap_.

55  {
56  ev.getByLabel(contentTags_["mvaVal"], mvaValueMap_);
58 }
edm::Handle< edm::ValueMap< int > > mvaCategoriesMap_
Definition: GsfEleMVACut.cc:27
std::unordered_map< std::string, edm::InputTag > contentTags_
bool getByLabel(InputTag const &, Handle< T > &) const
Definition: EventBase.h:92
edm::Handle< edm::ValueMap< float > > mvaValueMap_
Definition: GsfEleMVACut.cc:26
CutApplicatorBase::result_type GsfEleMVACut::operator() ( const reco::GsfElectronPtr cand) const
finalvirtual

Reimplemented from CutApplicatorBase.

Definition at line 60 of file GsfEleMVACut.cc.

References edm::ValueMap< T >::begin(), eostools::cat(), edm::ValueMap< T >::contains(), CutApplicatorWithEventContentBase::contentTags_, cutFormula_, Exception, edm::Ptr< T >::id(), edm::ValueMap< T >::idSize(), edm::HandleBase::isValid(), edm::Ptr< T >::key(), mvaCategoriesMap_, mvaValueMap_, nCuts_, AlCaHLTBitMon_QueryRunRegistry::string, and hgcalPerformanceValidation::val.

60  {
61  // in case we are by-value
62  const std::string& val_name = contentTags_.find("mvaVal")->second.instance();
63  const std::string& cat_name = contentTags_.find("mvaCat")->second.instance();
64  edm::Ptr<pat::Electron> pat(cand);
65  float val = -1.0;
66  int cat = -1;
68  mvaValueMap_->contains(cand.id())) {
69  cat = (*mvaCategoriesMap_)[cand];
70  val = (*mvaValueMap_)[cand];
72  mvaValueMap_->idSize() == 1 && cand.id() == edm::ProductID()) {
73  // in case we have spoofed a ptr
74  //note this must be a 1:1 valuemap (only one product input)
75  cat = mvaCategoriesMap_->begin()[cand.key()];
76  val = mvaValueMap_->begin()[cand.key()];
77  } else if (mvaCategoriesMap_.isValid() && mvaValueMap_.isValid()) { // throw an exception
78  cat = (*mvaCategoriesMap_)[cand];
79  val = (*mvaValueMap_)[cand];
80  }
81 
82  // Find the cut formula
83  const int iCategory = mvaCategoriesMap_.isValid() ? cat : pat->userInt(cat_name);
84  if (iCategory >= nCuts_)
85  throw cms::Exception(" Error in MVA categories: ")
86  << " found a particle with a category larger than max configured " << std::endl;
87 
88  // Look up the MVA value for this particle
89  const float mvaValue = mvaValueMap_.isValid() ? val : pat->userFloat(val_name);
90 
91  // Apply the cut and return the result
92  return mvaValue > cutFormula_[iCategory](*cand);
93 }
edm::Handle< edm::ValueMap< int > > mvaCategoriesMap_
Definition: GsfEleMVACut.cc:27
std::unordered_map< std::string, edm::InputTag > contentTags_
key_type key() const
Definition: Ptr.h:163
const int nCuts_
Definition: GsfEleMVACut.cc:23
std::vector< StringObjectFunction< reco::GsfElectron > > cutFormula_
Definition: GsfEleMVACut.cc:21
bool contains(ProductID id) const
Definition: ValueMap.h:155
def cat
Definition: eostools.py:401
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< float > > mvaValueMap_
Definition: GsfEleMVACut.cc:26
void GsfEleMVACut::setConsumes ( edm::ConsumesCollector cc)
finalvirtual

Implements CutApplicatorWithEventContentBase.

Definition at line 47 of file GsfEleMVACut.cc.

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

47  {
48  auto mvaVal = cc.consumes<edm::ValueMap<float>>(contentTags_["mvaVal"]);
49  contentTokens_.emplace("mvaVal", mvaVal);
50 
51  auto mvaCat = cc.consumes<edm::ValueMap<int>>(contentTags_["mvaCat"]);
52  contentTokens_.emplace("mvaCat", mvaCat);
53 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
std::unordered_map< std::string, edm::InputTag > contentTags_
std::unordered_map< std::string, edm::EDGetToken > contentTokens_
double GsfEleMVACut::value ( const reco::CandidatePtr cand) const
finalprivatevirtual

Implements candidate_functions::CandidateCut.

Definition at line 95 of file GsfEleMVACut.cc.

References 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(), mvaCategoriesMap_, mvaValueMap_, 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().

95  {
96  // in case we are by-value
97  const std::string& val_name = contentTags_.find("mvaVal")->second.instance();
98  edm::Ptr<pat::Electron> pat(cand);
99  float val = 0.0;
101  mvaValueMap_->contains(cand.id())) {
102  val = (*mvaValueMap_)[cand];
103  } else if (mvaCategoriesMap_.isValid() && mvaValueMap_.isValid() && mvaCategoriesMap_->idSize() == 1 &&
104  mvaValueMap_->idSize() == 1 && cand.id() == edm::ProductID()) {
105  // in case we have spoofed a ptr
106  //note this must be a 1:1 valuemap (only one product input)
107  val = mvaValueMap_->begin()[cand.key()];
108  } else if (mvaCategoriesMap_.isValid() && mvaValueMap_.isValid()) { // throw an exception
109  val = (*mvaValueMap_)[cand];
110  }
111 
112  const float mvaValue = mvaValueMap_.isValid() ? val : pat->userFloat(val_name);
113  return mvaValue;
114 }
edm::Handle< edm::ValueMap< int > > mvaCategoriesMap_
Definition: GsfEleMVACut.cc:27
std::unordered_map< std::string, edm::InputTag > contentTags_
key_type key() const
Definition: Ptr.h:163
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< float > > mvaValueMap_
Definition: GsfEleMVACut.cc:26

Member Data Documentation

std::vector<StringObjectFunction<reco::GsfElectron> > GsfEleMVACut::cutFormula_
private

Definition at line 21 of file GsfEleMVACut.cc.

Referenced by GsfEleMVACut(), and operator()().

edm::Handle<edm::ValueMap<int> > GsfEleMVACut::mvaCategoriesMap_
private

Definition at line 27 of file GsfEleMVACut.cc.

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

const std::vector<std::string> GsfEleMVACut::mvaCutStrings_
private

Definition at line 20 of file GsfEleMVACut.cc.

Referenced by GsfEleMVACut().

edm::Handle<edm::ValueMap<float> > GsfEleMVACut::mvaValueMap_
private

Definition at line 26 of file GsfEleMVACut.cc.

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

const int GsfEleMVACut::nCuts_
private

Definition at line 23 of file GsfEleMVACut.cc.

Referenced by operator()().