1 #ifndef __RecoEgamma_EgammaTools_MVAValueMapProducer_H__
2 #define __RecoEgamma_EgammaTools_MVAValueMapProducer_H__
27 template <
class ParticleType>
36 std::vector<std::unique_ptr<AnyMVAEstimatorRun2Base>> mvaEstimators;
40 for (
auto& imva : vConfig) {
44 mvaEstimators.emplace_back(
49 <<
" failed to find proper configuration for one of the MVAs in the main python script " << std::endl;
56 std::vector<std::string>
names;
57 for (
auto& imva : vConfig) {
85 template <
typename ValueType,
class HandleType>
88 const std::vector<ValueType>&
values,
90 auto valMap = std::make_unique<edm::ValueMap<ValueType>>();
97 template <
class ParticleType>
99 const bool tagGiven = !keysForValueMapsTag.
label().empty();
106 template <
class ParticleType>
109 keysForValueMapsToken_(getKeysForValueMapsToken<
ParticleType>(
110 iConfig.getParameter<
edm::
InputTag>(
"keysForValueMaps"), consumesCollector())),
111 mvaEstimators_(getMVAEstimators(iConfig.getParameterSetVector(
"mvaConfigurations"))),
112 mvaValueMapNames_(getValueMapNames(iConfig.getParameterSetVector(
"mvaConfigurations"),
"Values")),
113 mvaRawValueMapNames_(getValueMapNames(iConfig.getParameterSetVector(
"mvaConfigurations"),
"RawValues")),
114 mvaCategoriesMapNames_(getValueMapNames(iConfig.getParameterSetVector(
"mvaConfigurations"),
"Categories")),
115 variableHelper_(consumesCollector()) {
117 produces<edm::ValueMap<float>>(
name);
119 produces<edm::ValueMap<float>>(
name);
121 produces<edm::ValueMap<int>>(
name);
124 template <
class ParticleType>
128 std::vector<float> auxVariables = variableHelper_.getAuxVariables(
iEvent);
130 auto srcHandle =
iEvent.getHandle(srcToken_);
131 auto keysForValueMapsHandle =
132 keysForValueMapsToken_.isUninitialized() ? srcHandle :
iEvent.getHandle(keysForValueMapsToken_);
135 if (!validated_ && !srcHandle->empty()) {
141 for (
unsigned iEstimator = 0; iEstimator < mvaEstimators_.size(); iEstimator++) {
142 std::vector<float> mvaValues;
143 std::vector<float> mvaRawValues;
144 std::vector<int> mvaCategories;
147 for (
auto const&
cand : *srcHandle) {
149 const float response = mvaEstimators_[iEstimator]->mvaValue(&
cand, auxVariables,
cat);
150 mvaRawValues.push_back(response);
151 mvaValues.push_back(2.0 / (1.0 +
exp(-2.0 * response)) - 1);
152 mvaCategories.push_back(
cat);
155 writeValueMap(
iEvent, keysForValueMapsHandle, mvaValues, mvaValueMapNames_[iEstimator]);
156 writeValueMap(
iEvent, keysForValueMapsHandle, mvaRawValues, mvaRawValueMapNames_[iEstimator]);
157 writeValueMap(
iEvent, keysForValueMapsHandle, mvaCategories, mvaCategoriesMapNames_[iEstimator]);
162 template <
class ParticleType>