CMS 3D CMS Logo

PhoMVACut.cc
Go to the documentation of this file.
3 
4 
6 public:
8 
9  result_type operator()(const reco::PhotonPtr&) const override final;
10 
11  void setConsumes(edm::ConsumesCollector&) override final;
12  void getEventContent(const edm::EventBase&) override final;
13 
14  double value(const reco::CandidatePtr& cand) const override final;
15 
16  CandidateType candidateType() const override final {
17  return PHOTON;
18  }
19 
20 private:
21 
22  // Cut values
23  const std::vector<double> _mvaCutValues;
24 
25  // Pre-computed MVA value map
28 
29 };
30 
32  PhoMVACut,
33  "PhoMVACut");
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  // Find the cut value
91  const int iCategory = _mvaCategoriesMap.isValid() ? cat : pat->userInt( cat_name );
92  if( iCategory >= (int)(_mvaCutValues.size()) )
93  throw cms::Exception(" Error in MVA categories: ")
94  << " found a particle with a category larger than max configured " << std::endl;
95  const float cutValue = _mvaCutValues[iCategory];
96 
97  // Look up the MVA value for this particle
98  const float mvaValue = _mvaValueMap.isValid() ? val : pat->userFloat( val_name );
99 
100  // Apply the cut and return the result
101  return mvaValue > cutValue;
102 }
103 
105 
106  // in case we are by-value
107  const std::string& val_name =contentTags_.find("mvaVal")->second.instance();
109  float val = 0.0;
110  if( _mvaCategoriesMap.isValid() && _mvaCategoriesMap->contains( cand.id() ) &&
111  _mvaValueMap.isValid() && _mvaValueMap->contains( cand.id() ) ) {
112  val = (*_mvaValueMap)[cand];
113  } else if ( _mvaCategoriesMap.isValid() && _mvaValueMap.isValid() &&
114  _mvaCategoriesMap->idSize() == 1 && _mvaValueMap->idSize() == 1 &&
115  cand.id() == edm::ProductID() ) {
116  // in case we have spoofed a ptr
117  //note this must be a 1:1 valuemap (only one product input)
118  val = _mvaValueMap->begin()[cand.key()];
119  } else if ( _mvaCategoriesMap.isValid() && _mvaValueMap.isValid() ) {
120  val = (*_mvaValueMap)[cand];
121  }
122  const float mvaValue = _mvaValueMap.isValid() ? val : pat->userFloat( val_name );
123  return mvaValue;
124 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
key_type key() const
Definition: Ptr.h:186
PhoMVACut(const edm::ParameterSet &c)
Definition: PhoMVACut.cc:35
std::unordered_map< std::string, edm::EDGetToken > contentTokens_
CandidateType candidateType() const override final
Definition: PhoMVACut.cc:16
result_type operator()(const reco::PhotonPtr &) const override final
Definition: PhoMVACut.cc:66
bool ev
std::unordered_map< std::string, edm::InputTag > contentTags_
edm::Handle< edm::ValueMap< float > > _mvaValueMap
Definition: PhoMVACut.cc:26
float userFloat(const std::string &key) const
Definition: PATObject.h:791
Definition: HeavyIon.h:7
double value(const reco::CandidatePtr &cand) const override final
Definition: PhoMVACut.cc:104
bool contains(ProductID id) const
Definition: ValueMap.h:154
def cat(path)
Definition: eostools.py:400
void getEventContent(const edm::EventBase &) override final
Definition: PhoMVACut.cc:58
bool isValid() const
Definition: HandleBase.h:74
const std::vector< double > _mvaCutValues
Definition: PhoMVACut.cc:23
size_t idSize() const
Definition: ValueMap.h:158
int32_t userInt(const std::string &key) const
Definition: PATObject.h:833
const_iterator begin() const
Definition: ValueMap.h:207
ProductID id() const
Accessor for product ID.
Definition: Ptr.h:181
void setConsumes(edm::ConsumesCollector &) override final
Definition: PhoMVACut.cc:47
bool getByLabel(InputTag const &, Handle< T > &) const
Definition: EventBase.h:94
#define DEFINE_EDM_PLUGIN(factory, type, name)
edm::Handle< edm::ValueMap< int > > _mvaCategoriesMap
Definition: PhoMVACut.cc:27