1 #ifndef __RecoEgamma_EgammaTools_MVAValueMapProducer_H__ 2 #define __RecoEgamma_EgammaTools_MVAValueMapProducer_H__ 21 template <
class ParticleType>
29 static std::unique_ptr<egamma::MVAObjectCache>
31 return std::make_unique<egamma::MVAObjectCache>(conf);
46 const std::vector<T> &
values,
64 template <
class ParticleType>
77 const auto& all_mvas = mva_cache->
allMVAs();
78 for(
auto mvaItr = all_mvas.begin(); mvaItr != all_mvas.end(); ++mvaItr ) {
84 const auto& currentEstimator = mvaItr->second;
85 const std::string full_name = ( currentEstimator->getName() +
86 currentEstimator->getTag() );
87 std::string thisValueMapName = full_name +
"Values";
88 std::string thisRawValueMapName = full_name +
"RawValues";
89 std::string thisCategoriesMapName = full_name +
"Categories";
95 produces<edm::ValueMap<float> >(thisValueMapName);
96 produces<edm::ValueMap<float> >(thisRawValueMapName);
97 produces<edm::ValueMap<int> >(thisCategoriesMapName);
103 template <
class ParticleType>
107 template <
class ParticleType>
122 <<
" failed to find a standard AOD or miniAOD particle collection " << std::endl;
127 const auto& all_mvas = globalCache()->allMVAs();
128 for(
auto mva_itr = all_mvas.begin(); mva_itr != all_mvas.end(); ++mva_itr ){
129 const int iEstimator =
std::distance(all_mvas.begin(),mva_itr);
134 const auto& thisEstimator = mva_itr->second;
136 std::vector<float> mvaValues;
137 std::vector<float> mvaRawValues;
138 std::vector<int> mvaCategories;
141 for (
size_t i = 0;
i < src->size(); ++
i){
142 auto iCand = src->ptrAt(
i);
143 const float response = thisEstimator->mvaValue( iCand, iEvent );
144 mvaRawValues.push_back( response );
145 mvaValues.push_back( 2.0/(1.0+
exp(-2.0*response))-1 );
146 mvaCategories.push_back( thisEstimator->findCategory( iCand ) );
157 template<
class ParticleType>
template<
typename T>
160 const std::vector<T> &
values,
165 auto valMap = std::make_unique<ValueMap<T>>();
167 filler.insert(
handle, values.begin(), values.end());
172 template <
class ParticleType>
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
const std::unordered_map< std::string, MVAPtr > & allMVAs() const
std::vector< std::string > mvaValueMapNames_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
std::vector< std::string > mvaRawValueMapNames_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void addDefault(ParameterSetDescription const &psetDescription)
void produce(edm::Event &, const edm::EventSetup &) override
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
void writeValueMap(edm::Event &iEvent, const edm::Handle< edm::View< ParticleType > > &handle, const std::vector< T > &values, const std::string &label) const
static std::unique_ptr< egamma::MVAObjectCache > initializeGlobalCache(const edm::ParameterSet &conf)
std::vector< std::string > mvaCategoriesMapNames_
~MVAValueMapProducer() override
MVAValueMapProducer(const edm::ParameterSet &, const egamma::MVAObjectCache *)
static void globalEndJob(const egamma::MVAObjectCache *)
edm::EDGetToken srcMiniAOD_