CMS 3D CMS Logo

PhoMVACut.cc
Go to the documentation of this file.
3 
5 public:
7 
8  result_type operator()(const reco::PhotonPtr&) const final;
9 
11  void getEventContent(const edm::EventBase&) final;
12 
13  double value(const reco::CandidatePtr& cand) const final;
14 
16 
17 private:
18  // Cut values
19  const std::vector<double> _mvaCutValues;
20 
21  // Pre-computed MVA value map
24 };
25 
27 
29  : CutApplicatorWithEventContentBase(c), _mvaCutValues(c.getParameter<std::vector<double> >("mvaCuts")) {
30  edm::InputTag mvaValTag = c.getParameter<edm::InputTag>("mvaValueMapName");
31  contentTags_.emplace("mvaVal", mvaValTag);
32 
33  edm::InputTag mvaCatTag = c.getParameter<edm::InputTag>("mvaCategoriesMapName");
34  contentTags_.emplace("mvaCat", mvaCatTag);
35 }
36 
38  auto mvaVal = cc.consumes<edm::ValueMap<float> >(contentTags_["mvaVal"]);
39  contentTokens_.emplace("mvaVal", mvaVal);
40 
41  auto mvaCat = cc.consumes<edm::ValueMap<int> >(contentTags_["mvaCat"]);
42  contentTokens_.emplace("mvaCat", mvaCat);
43 }
44 
46  ev.getByLabel(contentTags_["mvaVal"], _mvaValueMap);
47  ev.getByLabel(contentTags_["mvaCat"], _mvaCategoriesMap);
48 }
49 
51  // in case we are by-value
52  const std::string& val_name = contentTags_.find("mvaVal")->second.instance();
53  const std::string& cat_name = contentTags_.find("mvaCat")->second.instance();
55  float val = -1.0;
56  int cat = -1;
58  _mvaValueMap->contains(cand.id())) {
59  cat = (*_mvaCategoriesMap)[cand];
60  val = (*_mvaValueMap)[cand];
62  _mvaValueMap->idSize() == 1 && cand.id() == edm::ProductID()) {
63  // in case we have spoofed a ptr
64  //note this must be a 1:1 valuemap (only one product input)
65  cat = _mvaCategoriesMap->begin()[cand.key()];
66  val = _mvaValueMap->begin()[cand.key()];
67  } else if (_mvaCategoriesMap.isValid() && _mvaValueMap.isValid()) { // throw an exception
68  cat = (*_mvaCategoriesMap)[cand];
69  val = (*_mvaValueMap)[cand];
70  }
71 
72  // Find the cut value
73  const int iCategory = _mvaCategoriesMap.isValid() ? cat : pat->userInt(cat_name);
74  if (iCategory >= (int)(_mvaCutValues.size()))
75  throw cms::Exception(" Error in MVA categories: ")
76  << " found a particle with a category larger than max configured " << std::endl;
77  const float cutValue = _mvaCutValues[iCategory];
78 
79  // Look up the MVA value for this particle
80  const float mvaValue = _mvaValueMap.isValid() ? val : pat->userFloat(val_name);
81 
82  // Apply the cut and return the result
83  return mvaValue > cutValue;
84 }
85 
87  // in case we are by-value
88  const std::string& val_name = contentTags_.find("mvaVal")->second.instance();
90  float val = 0.0;
92  _mvaValueMap->contains(cand.id())) {
93  val = (*_mvaValueMap)[cand];
95  _mvaValueMap->idSize() == 1 && cand.id() == edm::ProductID()) {
96  // in case we have spoofed a ptr
97  //note this must be a 1:1 valuemap (only one product input)
98  val = _mvaValueMap->begin()[cand.key()];
99  } else if (_mvaCategoriesMap.isValid() && _mvaValueMap.isValid()) {
100  val = (*_mvaValueMap)[cand];
101  }
102  const float mvaValue = _mvaValueMap.isValid() ? val : pat->userFloat(val_name);
103  return mvaValue;
104 }
CutApplicatorBase::PHOTON
Definition: CutApplicatorBase.h:47
PhoMVACut::PhoMVACut
PhoMVACut(const edm::ParameterSet &c)
Definition: PhoMVACut.cc:28
eostools.cat
def cat(path)
Definition: eostools.py:401
watchdog.const
const
Definition: watchdog.py:83
edm::Handle
Definition: AssociativeIterator.h:50
CutApplicatorWithEventContentBase::contentTags_
std::unordered_map< std::string, edm::InputTag > contentTags_
Definition: CutApplicatorWithEventContentBase.h:35
candidate_functions::CandidateCut::result_type
bool result_type
Definition: CandidateCut.h:11
Photon.h
CutApplicatorWithEventContentBase.h
PhoMVACut::_mvaValueMap
edm::Handle< edm::ValueMap< float > > _mvaValueMap
Definition: PhoMVACut.cc:22
DEFINE_EDM_PLUGIN
#define DEFINE_EDM_PLUGIN(factory, type, name)
Definition: PluginFactory.h:124
PhoMVACut::value
double value(const reco::CandidatePtr &cand) const final
Definition: PhoMVACut.cc:86
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet
Definition: ParameterSet.h:47
CutApplicatorBase::CandidateType
CandidateType
Definition: CutApplicatorBase.h:47
edmplugin::PluginFactory
Definition: PluginFactory.h:34
edm::ValueMap::begin
const_iterator begin() const
Definition: ValueMap.h:229
cand
Definition: decayParser.h:32
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
PhoMVACut::getEventContent
void getEventContent(const edm::EventBase &) final
Definition: PhoMVACut.cc:45
pat
Definition: HeavyIon.h:7
cc
edm::Ptr
Definition: AssociationVector.h:31
PhoMVACut::_mvaCategoriesMap
edm::Handle< edm::ValueMap< int > > _mvaCategoriesMap
Definition: PhoMVACut.cc:23
PhoMVACut::operator()
result_type operator()(const reco::PhotonPtr &) const final
Definition: PhoMVACut.cc:50
heppy_batch.val
val
Definition: heppy_batch.py:351
std
Definition: JetResolutionObject.h:76
PhoMVACut::_mvaCutValues
const std::vector< double > _mvaCutValues
Definition: PhoMVACut.cc:19
edm::ValueMap::idSize
size_t idSize() const
Definition: ValueMap.h:157
PhoMVACut::setConsumes
void setConsumes(edm::ConsumesCollector &) final
Definition: PhoMVACut.cc:37
PhoMVACut
Definition: PhoMVACut.cc:4
edm::ValueMap< float >
ev
bool ev
Definition: Hydjet2Hadronizer.cc:95
CutApplicatorWithEventContentBase::contentTokens_
std::unordered_map< std::string, edm::EDGetToken > contentTokens_
Definition: CutApplicatorWithEventContentBase.h:40
edm::EventBase
Definition: EventBase.h:46
Exception
Definition: hltDiff.cc:245
edm::ValueMap::contains
bool contains(ProductID id) const
Definition: ValueMap.h:155
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::InputTag
Definition: InputTag.h:15
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
edm::ProductID
Definition: ProductID.h:27
CutApplicatorWithEventContentBase
Definition: CutApplicatorWithEventContentBase.h:19
PhoMVACut::candidateType
CandidateType candidateType() const final
Definition: PhoMVACut.cc:15