CMS 3D CMS Logo

GsfEleMVACut.cc
Go to the documentation of this file.
3 
4 
6 public:
8 
9  result_type operator()(const reco::GsfElectronPtr&) const final;
10 
12  void getEventContent(const edm::EventBase&) final;
13 
14  double value(const reco::CandidatePtr& cand) const final;
15 
16  CandidateType candidateType() const final {
17  return ELECTRON;
18  }
19 
20 private:
21 
22  // Cut values
23  const std::vector<double> mvaCutValues;
24 
25  // Pre-computed MVA value map
28 
29 };
30 
33  "GsfEleMVACut");
34 
37  mvaCutValues(c.getParameter<std::vector<double> >("mvaCuts"))
38 {
39  edm::InputTag mvaValTag = c.getParameter<edm::InputTag>("mvaValueMapName");
40  contentTags_.emplace("mvaVal",mvaValTag);
41 
42  edm::InputTag mvaCatTag = c.getParameter<edm::InputTag>("mvaCategoriesMapName");
43  contentTags_.emplace("mvaCat",mvaCatTag);
44 
45 }
46 
48 
49  auto mvaVal =
51  contentTokens_.emplace("mvaVal",mvaVal);
52 
53  auto mvaCat =
55  contentTokens_.emplace("mvaCat",mvaCat);
56 }
57 
59 
60  ev.getByLabel(contentTags_["mvaVal"], mvaValueMap_);
62 }
63 
64 CutApplicatorBase::result_type
67 
68  // in case we are by-value
69  const std::string& val_name = contentTags_.find("mvaVal")->second.instance();
70  const std::string& cat_name = contentTags_.find("mvaCat")->second.instance();
72  float val = -1.0;
73  int cat = -1;
75  mvaValueMap_.isValid() && mvaValueMap_->contains( cand.id() ) ) {
76  cat = (*mvaCategoriesMap_)[cand];
77  val = (*mvaValueMap_)[cand];
78  } else if ( mvaCategoriesMap_.isValid() && mvaValueMap_.isValid() &&
79  mvaCategoriesMap_->idSize() == 1 && mvaValueMap_->idSize() == 1 &&
80  cand.id() == edm::ProductID() ) {
81  // in case we have spoofed a ptr
82  //note this must be a 1:1 valuemap (only one product input)
83  cat = mvaCategoriesMap_->begin()[cand.key()];
84  val = mvaValueMap_->begin()[cand.key()];
85  } else if ( mvaCategoriesMap_.isValid() && mvaValueMap_.isValid() ){ // throw an exception
86  cat = (*mvaCategoriesMap_)[cand];
87  val = (*mvaValueMap_)[cand];
88  }
89 
90 
91  // Find the cut value
92  const int iCategory = mvaCategoriesMap_.isValid() ? cat : pat->userInt( cat_name );
93  if( iCategory >= (int)(mvaCutValues.size()) )
94  throw cms::Exception(" Error in MVA categories: ")
95  << " found a particle with a category larger than max configured " << std::endl;
96  const float cutValue = mvaCutValues[iCategory];
97 
98  // Look up the MVA value for this particle
99  const float mvaValue = mvaValueMap_.isValid() ? val : pat->userFloat( val_name );
100 
101  // Apply the cut and return the result
102  return mvaValue > cutValue;
103 }
104 
106 
107  // in case we are by-value
108  const std::string& val_name =contentTags_.find("mvaVal")->second.instance();
110  float val = 0.0;
111  if( mvaCategoriesMap_.isValid() && mvaCategoriesMap_->contains( cand.id() ) &&
112  mvaValueMap_.isValid() && mvaValueMap_->contains( cand.id() ) ) {
113  val = (*mvaValueMap_)[cand];
114  } else if ( mvaCategoriesMap_.isValid() && mvaValueMap_.isValid() &&
115  mvaCategoriesMap_->idSize() == 1 && mvaValueMap_->idSize() == 1 &&
116  cand.id() == edm::ProductID() ) {
117  // in case we have spoofed a ptr
118  //note this must be a 1:1 valuemap (only one product input)
119  val = mvaValueMap_->begin()[cand.key()];
120  } else if ( mvaCategoriesMap_.isValid() && mvaValueMap_.isValid() ){ // throw an exception
121  val = (*mvaValueMap_)[cand];
122  }
123 
124  const float mvaValue = mvaValueMap_.isValid() ? val : pat->userFloat( val_name );
125  return mvaValue;
126 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
result_type operator()(const reco::GsfElectronPtr &) const final
Definition: GsfEleMVACut.cc:66
edm::Handle< edm::ValueMap< int > > mvaCategoriesMap_
Definition: GsfEleMVACut.cc:27
key_type key() const
Definition: Ptr.h:185
double value(const reco::CandidatePtr &cand) const final
std::unordered_map< std::string, edm::EDGetToken > contentTokens_
const std::vector< double > mvaCutValues
Definition: GsfEleMVACut.cc:23
GsfEleMVACut(const edm::ParameterSet &c)
Definition: GsfEleMVACut.cc:35
void setConsumes(edm::ConsumesCollector &) final
Definition: GsfEleMVACut.cc:47
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
void getEventContent(const edm::EventBase &) final
Definition: GsfEleMVACut.cc:58
bool isValid() const
Definition: HandleBase.h:74
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
ProductID id() const
Accessor for product ID.
Definition: Ptr.h:180
bool getByLabel(InputTag const &, Handle< T > &) const
Definition: EventBase.h:94
CandidateType candidateType() const final
Definition: GsfEleMVACut.cc:16
#define DEFINE_EDM_PLUGIN(factory, type, name)
edm::Handle< edm::ValueMap< float > > mvaValueMap_
Definition: GsfEleMVACut.cc:26