CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
GsfEleMVAExpoScalingCut Class Reference
Inheritance diagram for GsfEleMVAExpoScalingCut:
CutApplicatorWithEventContentBase CutApplicatorBase candidate_functions::CandidateCut

Public Member Functions

CandidateType candidateType () const final
 
void getEventContent (const edm::EventBase &) final
 
 GsfEleMVAExpoScalingCut (const edm::ParameterSet &c)
 
result_type operator() (const reco::GsfElectronPtr &) const final
 
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 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 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 6 of file GsfEleMVAExpoScalingCut.cc.

Constructor & Destructor Documentation

GsfEleMVAExpoScalingCut::GsfEleMVAExpoScalingCut ( const edm::ParameterSet c)

Definition at line 36 of file GsfEleMVAExpoScalingCut.cc.

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

36  :
38  mvaCutValues(c.getParameter<std::vector<double> >("mvaCuts"))
39 {
40  edm::InputTag mvaValTag = c.getParameter<edm::InputTag>("mvaValueMapName");
41  contentTags_.emplace("mvaVal",mvaValTag);
42 
43  edm::InputTag mvaCatTag = c.getParameter<edm::InputTag>("mvaCategoriesMapName");
44  contentTags_.emplace("mvaCat",mvaCatTag);
45 
46 }
T getParameter(std::string const &) const
std::unordered_map< std::string, edm::InputTag > contentTags_
const std::vector< double > mvaCutValues

Member Function Documentation

CandidateType GsfEleMVAExpoScalingCut::candidateType ( ) const
inlinefinalvirtual

Reimplemented from CutApplicatorBase.

Definition at line 17 of file GsfEleMVAExpoScalingCut.cc.

References CutApplicatorBase::ELECTRON.

17  {
18  return ELECTRON;
19  }
void GsfEleMVAExpoScalingCut::getEventContent ( const edm::EventBase ev)
finalvirtual

Implements CutApplicatorWithEventContentBase.

Definition at line 59 of file GsfEleMVAExpoScalingCut.cc.

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

59  {
60 
61  ev.getByLabel(contentTags_["mvaVal"], mvaValueMap_);
63 }
std::unordered_map< std::string, edm::InputTag > contentTags_
edm::Handle< edm::ValueMap< int > > mvaCategoriesMap_
edm::Handle< edm::ValueMap< float > > mvaValueMap_
bool getByLabel(InputTag const &, Handle< T > &) const
Definition: EventBase.h:94
CutApplicatorBase::result_type GsfEleMVAExpoScalingCut::operator() ( const reco::GsfElectronPtr cand) const
finalvirtual

Reimplemented from CutApplicatorBase.

Definition at line 67 of file GsfEleMVAExpoScalingCut.cc.

References patCaloMETCorrections_cff::A, edm::ValueMap< T >::begin(), EnergyCorrector::c, eostools::cat(), edm::ValueMap< T >::contains(), CutApplicatorWithEventContentBase::contentTags_, Exception, JetChargeProducer_cfi::exp, edm::Ptr< T >::id(), edm::ValueMap< T >::idSize(), edm::HandleBase::isValid(), edm::Ptr< T >::key(), mvaCategoriesMap_, mvaCutValues, mvaValueMap_, reco::LeafCandidate::pt(), AlCaHLTBitMon_QueryRunRegistry::string, metsig::tau, pat::PATObject< ObjectType >::userFloat(), pat::PATObject< ObjectType >::userInt(), and heppy_batch::val.

Referenced by getEventContent().

67  {
68 
69  // in case we are by-value
70  const std::string& val_name = contentTags_.find("mvaVal")->second.instance();
71  const std::string& cat_name = contentTags_.find("mvaCat")->second.instance();
73  float val = -1.0;
74  int cat = -1;
76  mvaValueMap_.isValid() && mvaValueMap_->contains( cand.id() ) ) {
77  cat = (*mvaCategoriesMap_)[cand];
78  val = (*mvaValueMap_)[cand];
79  } else if ( mvaCategoriesMap_.isValid() && mvaValueMap_.isValid() &&
80  mvaCategoriesMap_->idSize() == 1 && mvaValueMap_->idSize() == 1 &&
81  cand.id() == edm::ProductID() ) {
82  // in case we have spoofed a ptr
83  //note this must be a 1:1 valuemap (only one product input)
84  cat = mvaCategoriesMap_->begin()[cand.key()];
85  val = mvaValueMap_->begin()[cand.key()];
86  } else if ( mvaCategoriesMap_.isValid() && mvaValueMap_.isValid() ){ // throw an exception
87  cat = (*mvaCategoriesMap_)[cand];
88  val = (*mvaValueMap_)[cand];
89  }
90 
91  // Find the cut value
92  const int iCategory = mvaCategoriesMap_.isValid() ? cat : pat->userInt( cat_name );
93  if( iCategory >= (int)(mvaCutValues.size()) * 3)
94  throw cms::Exception(" Error in MVA categories: ")
95  << " found a particle with a category larger than max configured " << std::endl;
96  const float c = mvaCutValues[3*iCategory];
97  const float tau = mvaCutValues[3*iCategory+1];
98  const float A = mvaCutValues[3*iCategory+2];
99 
100  // Look up the MVA value for this particle
101  const float mvaValue = mvaValueMap_.isValid() ? val : pat->userFloat( val_name );
102 
103  // Apply the cut and return the result
104  return mvaValue > c - exp(- cand->pt() / tau) * A;;
105 }
key_type key() const
Definition: Ptr.h:185
double pt() const final
transverse momentum
std::unordered_map< std::string, edm::InputTag > contentTags_
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
size_t idSize() const
Definition: ValueMap.h:159
const_iterator begin() const
Definition: ValueMap.h:208
edm::Handle< edm::ValueMap< int > > mvaCategoriesMap_
edm::Handle< edm::ValueMap< float > > mvaValueMap_
ProductID id() const
Accessor for product ID.
Definition: Ptr.h:180
const std::vector< double > mvaCutValues
void GsfEleMVAExpoScalingCut::setConsumes ( edm::ConsumesCollector cc)
finalvirtual

Implements CutApplicatorWithEventContentBase.

Definition at line 48 of file GsfEleMVAExpoScalingCut.cc.

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

48  {
49 
50  auto mvaVal =
52  contentTokens_.emplace("mvaVal",mvaVal);
53 
54  auto mvaCat =
56  contentTokens_.emplace("mvaCat",mvaCat);
57 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
std::unordered_map< std::string, edm::EDGetToken > contentTokens_
std::unordered_map< std::string, edm::InputTag > contentTags_
double GsfEleMVAExpoScalingCut::value ( const reco::CandidatePtr cand) const
finalvirtual

Implements candidate_functions::CandidateCut.

Definition at line 107 of file GsfEleMVAExpoScalingCut.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, pat::PATObject< ObjectType >::userFloat(), and heppy_batch::val.

107  {
108 
109  // in case we are by-value
110  const std::string& val_name =contentTags_.find("mvaVal")->second.instance();
112  float val = 0.0;
113  if( mvaCategoriesMap_.isValid() && mvaCategoriesMap_->contains( cand.id() ) &&
114  mvaValueMap_.isValid() && mvaValueMap_->contains( cand.id() ) ) {
115  val = (*mvaValueMap_)[cand];
116  } else if ( mvaCategoriesMap_.isValid() && mvaValueMap_.isValid() &&
117  mvaCategoriesMap_->idSize() == 1 && mvaValueMap_->idSize() == 1 &&
118  cand.id() == edm::ProductID() ) {
119  // in case we have spoofed a ptr
120  //note this must be a 1:1 valuemap (only one product input)
121  val = mvaValueMap_->begin()[cand.key()];
122  } else if ( mvaCategoriesMap_.isValid() && mvaValueMap_.isValid() ){ // throw an exception
123  val = (*mvaValueMap_)[cand];
124  }
125 
126  const float mvaValue = mvaValueMap_.isValid() ? val : pat->userFloat( val_name );
127  return mvaValue;
128 }
key_type key() const
Definition: Ptr.h:185
std::unordered_map< std::string, edm::InputTag > contentTags_
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
edm::Handle< edm::ValueMap< int > > mvaCategoriesMap_
edm::Handle< edm::ValueMap< float > > mvaValueMap_
ProductID id() const
Accessor for product ID.
Definition: Ptr.h:180

Member Data Documentation

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

Definition at line 28 of file GsfEleMVAExpoScalingCut.cc.

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

const std::vector<double> GsfEleMVAExpoScalingCut::mvaCutValues
private

Definition at line 24 of file GsfEleMVAExpoScalingCut.cc.

Referenced by operator()().

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

Definition at line 27 of file GsfEleMVAExpoScalingCut.cc.

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