CMS 3D CMS Logo

GsfEleMVAExpoScalingCut.cc
Go to the documentation of this file.
3 
4 #include <cmath>
5 
7 public:
9 
10  result_type operator()(const reco::GsfElectronPtr&) const final;
11 
13  void getEventContent(const edm::EventBase&) final;
14 
15  double value(const reco::CandidatePtr& cand) const final;
16 
17  CandidateType candidateType() const final {
18  return ELECTRON;
19  }
20 
21 private:
22 
23  // Cut values
24  const std::vector<double> mvaCutValues;
25 
26  // Pre-computed MVA value map
29 
30 };
31 
34  "GsfEleMVAExpoScalingCut");
35 
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 }
47 
49 
50  auto mvaVal =
52  contentTokens_.emplace("mvaVal",mvaVal);
53 
54  auto mvaCat =
56  contentTokens_.emplace("mvaCat",mvaCat);
57 }
58 
60 
61  ev.getByLabel(contentTags_["mvaVal"], mvaValueMap_);
63 }
64 
65 CutApplicatorBase::result_type
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 }
106 
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 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
double value(const reco::CandidatePtr &cand) const final
key_type key() const
Definition: Ptr.h:185
std::unordered_map< std::string, edm::EDGetToken > contentTokens_
double pt() const final
transverse momentum
bool ev
std::unordered_map< std::string, edm::InputTag > contentTags_
float userFloat(const std::string &key) const
Definition: PATObject.h:791
Definition: HeavyIon.h:7
bool contains(ProductID id) const
Definition: ValueMap.h:155
def cat(path)
Definition: eostools.py:400
CandidateType candidateType() const final
bool isValid() const
Definition: HandleBase.h:74
result_type operator()(const reco::GsfElectronPtr &) const final
size_t idSize() const
Definition: ValueMap.h:159
int32_t userInt(const std::string &key) const
Definition: PATObject.h:833
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
bool getByLabel(InputTag const &, Handle< T > &) const
Definition: EventBase.h:94
GsfEleMVAExpoScalingCut(const edm::ParameterSet &c)
#define DEFINE_EDM_PLUGIN(factory, type, name)
void setConsumes(edm::ConsumesCollector &) final
void getEventContent(const edm::EventBase &) final
const std::vector< double > mvaCutValues