1 #ifndef __RecoEgamma_EgammaTools_MVAValueMapProducer_H__
2 #define __RecoEgamma_EgammaTools_MVAValueMapProducer_H__
21 template <
class ParticleType>
29 static std::unique_ptr<egamma::MVAObjectCache>
46 const std::vector<T> &
values,
63 template <
class ParticleType>
76 const auto& all_mvas = mva_cache->
allMVAs();
77 for(
auto mvaItr = all_mvas.begin(); mvaItr != all_mvas.end(); ++mvaItr ) {
79 mvaItr->second->setConsumes(consumesCollector());
83 const auto& currentEstimator = mvaItr->second;
84 const std::string full_name = ( currentEstimator->getName() +
85 currentEstimator->getTag() );
86 std::string thisValueMapName = full_name +
"Values";
87 std::string thisCategoriesMapName = full_name +
"Categories";
88 mvaValueMapNames_.push_back( thisValueMapName );
89 mvaCategoriesMapNames_.push_back( thisCategoriesMapName );
92 produces<edm::ValueMap<float> >(thisValueMapName);
93 produces<edm::ValueMap<int> >(thisCategoriesMapName);
99 template <
class ParticleType>
103 template <
class ParticleType>
114 if( !
src.isValid() ){
118 <<
" failed to find a standard AOD or miniAOD particle collection " << std::endl;
123 const auto& all_mvas = globalCache()->allMVAs();
124 for(
auto mva_itr = all_mvas.begin(); mva_itr != all_mvas.end(); ++mva_itr ){
125 const int iEstimator =
std::distance(all_mvas.begin(),mva_itr);
130 const auto& thisEstimator = mva_itr->second;
132 std::vector<float> mvaValues;
133 std::vector<int> mvaCategories;
136 for (
size_t i = 0;
i <
src->size(); ++
i){
137 auto iCand =
src->ptrAt(
i);
138 mvaValues.push_back( thisEstimator->mvaValue( iCand, iEvent ) );
139 mvaCategories.push_back( thisEstimator->findCategory( iCand ) );
142 writeValueMap(iEvent,
src, mvaValues, mvaValueMapNames_[iEstimator] );
143 writeValueMap(iEvent,
src, mvaCategories, mvaCategoriesMapNames_[iEstimator] );
149 template<
class ParticleType>
template<
typename T>
152 const std::vector<T> &
values,
161 iEvent.
put(valMap, label);
164 template <
class ParticleType>
T getParameter(std::string const &) const
const std::unordered_map< std::string, MVAPtr > & allMVAs() const
std::vector< std::string > mvaValueMapNames_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
void insert(const H &h, I begin, I end)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void addDefault(ParameterSetDescription const &psetDescription)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
virtual void produce(edm::Event &, const edm::EventSetup &) override
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(const edm::ParameterSet &, const egamma::MVAObjectCache *)
static void globalEndJob(const egamma::MVAObjectCache *)
edm::EDGetToken srcMiniAOD_