1 #ifndef __RecoEgamma_EgammaTools_MVAValueMapProducer_H__
2 #define __RecoEgamma_EgammaTools_MVAValueMapProducer_H__
27 template <
class ParticleType>
56 template <
typename ValueType,
class HandleType>
59 const std::vector<ValueType>&
values,
61 auto valMap = std::make_unique<edm::ValueMap<ValueType>>();
69 std::vector<std::unique_ptr<AnyMVAEstimatorRun2Base>> mvaEstimators;
73 for (
auto& imva : vConfig) {
77 mvaEstimators.emplace_back(
82 <<
" failed to find proper configuration for one of the MVAs in the main python script " << std::endl;
89 std::vector<std::string>
names;
90 for (
auto& imva : vConfig) {
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>