CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
MVAValueMapProducer< ParticleType > Class Template Reference

#include <MVAValueMapProducer.h>

Inheritance diagram for MVAValueMapProducer< ParticleType >:
edm::stream::EDProducer< edm::GlobalCache< egamma::MVAObjectCache > > edm::stream::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 MVAValueMapProducer (const edm::ParameterSet &, const egamma::MVAObjectCache *)
 
 ~MVAValueMapProducer () override
 
- Public Member Functions inherited from edm::stream::EDProducer< edm::GlobalCache< egamma::MVAObjectCache > >
 EDProducer ()=default
 
- Public Member Functions inherited from edm::stream::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducerBase () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
virtual ~ProducerBase () noexcept(false)
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
static void globalEndJob (const egamma::MVAObjectCache *)
 
static std::unique_ptr< egamma::MVAObjectCacheinitializeGlobalCache (const edm::ParameterSet &conf)
 
- Static Public Member Functions inherited from edm::stream::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Private Member Functions

void produce (edm::Event &, const edm::EventSetup &) override
 
template<typename T >
void writeValueMap (edm::Event &iEvent, const edm::Handle< edm::View< ParticleType > > &handle, const std::vector< T > &values, const std::string &label) const
 

Private Attributes

std::vector< std::string > mvaCategoriesMapNames_
 
std::vector< std::string > mvaValueMapNames_
 
edm::EDGetToken src_
 
edm::EDGetToken srcMiniAOD_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer< edm::GlobalCache< egamma::MVAObjectCache > >
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 
- Public Types inherited from edm::stream::EDProducerBase
typedef EDProducerAdaptorBase ModuleType
 
- Public Types inherited from edm::ProducerBase
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex >>
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

template<class ParticleType>
class MVAValueMapProducer< ParticleType >

Definition at line 22 of file MVAValueMapProducer.h.

Constructor & Destructor Documentation

template<class ParticleType >
MVAValueMapProducer< ParticleType >::MVAValueMapProducer ( const edm::ParameterSet iConfig,
const egamma::MVAObjectCache mva_cache 
)

Definition at line 64 of file MVAValueMapProducer.h.

References egamma::MVAObjectCache::allMVAs(), edm::EDConsumerBase::consumesCollector(), edm::ParameterSet::getParameter(), MVAValueMapProducer< ParticleType >::mvaCategoriesMapNames_, MVAValueMapProducer< ParticleType >::mvaValueMapNames_, MVAValueMapProducer< ParticleType >::src_, MVAValueMapProducer< ParticleType >::srcMiniAOD_, and AlCaHLTBitMon_QueryRunRegistry::string.

66 {
67 
68  //
69  // Declare consummables, handle both AOD and miniAOD case
70  //
71  src_ = mayConsume<edm::View<ParticleType> >(iConfig.getParameter<edm::InputTag>("src"));
72  srcMiniAOD_ = mayConsume<edm::View<ParticleType> >(iConfig.getParameter<edm::InputTag>("srcMiniAOD"));
73 
74  // Loop over the list of MVA configurations passed here from python and
75  // construct all requested MVA esimtators.
76  const auto& all_mvas = mva_cache->allMVAs();
77  for( auto mvaItr = all_mvas.begin(); mvaItr != all_mvas.end(); ++mvaItr ) {
78  // set the consumes
79  mvaItr->second->setConsumes(consumesCollector());
80  //
81  // Compose and save the names of the value maps to be produced
82  //
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 );
90 
91  // Declare the maps to the framework
92  produces<edm::ValueMap<float> >(thisValueMapName);
93  produces<edm::ValueMap<int> >(thisCategoriesMapName);
94  }
95 
96 
97 }
T getParameter(std::string const &) const
const std::unordered_map< std::string, MVAPtr > & allMVAs() const
std::vector< std::string > mvaValueMapNames_
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
std::vector< std::string > mvaCategoriesMapNames_
edm::EDGetToken srcMiniAOD_
template<class ParticleType >
MVAValueMapProducer< ParticleType >::~MVAValueMapProducer ( )
override

Definition at line 100 of file MVAValueMapProducer.h.

100  {
101 }

Member Function Documentation

template<class ParticleType >
void MVAValueMapProducer< ParticleType >::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 165 of file MVAValueMapProducer.h.

References edm::ConfigurationDescriptions::addDefault(), and edm::ParameterSetDescription::setUnknown().

Referenced by MVAValueMapProducer< ParticleType >::globalEndJob().

165  {
166  //The following says we do not know what parameters are allowed so do no validation
167  // Please change this to state exactly what you do use, even if it is no parameters
169  desc.setUnknown();
170  descriptions.addDefault(desc);
171 }
void addDefault(ParameterSetDescription const &psetDescription)
template<class ParticleType >
static void MVAValueMapProducer< ParticleType >::globalEndJob ( const egamma::MVAObjectCache )
inlinestatic
template<class ParticleType >
static std::unique_ptr<egamma::MVAObjectCache> MVAValueMapProducer< ParticleType >::initializeGlobalCache ( const edm::ParameterSet conf)
inlinestatic

Definition at line 30 of file MVAValueMapProducer.h.

30  {
31  return std::make_unique<egamma::MVAObjectCache>(conf);
32  }
template<class ParticleType >
void MVAValueMapProducer< ParticleType >::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 104 of file MVAValueMapProducer.h.

References SoftLeptonByDistance_cfi::distance, edm::Event::getByToken(), mps_fire::i, edm::HandleBase::isValid(), MVAValueMapProducer< ParticleType >::mvaCategoriesMapNames_, MVAValueMapProducer< ParticleType >::mvaValueMapNames_, TrackRefitter_38T_cff::src, MVAValueMapProducer< ParticleType >::src_, MVAValueMapProducer< ParticleType >::srcMiniAOD_, and MVAValueMapProducer< ParticleType >::writeValueMap().

Referenced by MVAValueMapProducer< ParticleType >::globalEndJob().

104  {
105 
106  using namespace edm;
107 
109 
110  // Retrieve the collection of particles from the event.
111  // If we fail to retrieve the collection with the standard AOD
112  // name, we next look for the one with the stndard miniAOD name.
113  iEvent.getByToken(src_, src);
114  if( !src.isValid() ){
115  iEvent.getByToken(srcMiniAOD_,src);
116  if( !src.isValid() )
117  throw cms::Exception(" Collection not found: ")
118  << " failed to find a standard AOD or miniAOD particle collection " << std::endl;
119  }
120 
121 
122  // Loop over MVA estimators
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);
126 
127  // Set up all event content, such as ValueMaps produced upstream or other,
128  // original event data pieces, that is needed (if any is implemented in the specific
129  // MVA classes)
130  const auto& thisEstimator = mva_itr->second;
131 
132  std::vector<float> mvaValues;
133  std::vector<int> mvaCategories;
134 
135  // Loop over particles
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 ) );
140  } // end loop over particles
141 
142  writeValueMap(iEvent, src, mvaValues, mvaValueMapNames_[iEstimator] );
143  writeValueMap(iEvent, src, mvaCategories, mvaCategoriesMapNames_[iEstimator] );
144  } // end loop over estimators
145 
146 
147 }
std::vector< std::string > mvaValueMapNames_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
void writeValueMap(edm::Event &iEvent, const edm::Handle< edm::View< ParticleType > > &handle, const std::vector< T > &values, const std::string &label) const
bool isValid() const
Definition: HandleBase.h:74
std::vector< std::string > mvaCategoriesMapNames_
HLT enums.
edm::EDGetToken srcMiniAOD_
template<class ParticleType >
template<typename T >
void MVAValueMapProducer< ParticleType >::writeValueMap ( edm::Event iEvent,
const edm::Handle< edm::View< ParticleType > > &  handle,
const std::vector< T > &  values,
const std::string &  label 
) const
private

Definition at line 150 of file MVAValueMapProducer.h.

References objects.autophobj::filler, cmsBatch::handle, eostools::move(), and edm::Event::put().

Referenced by MVAValueMapProducer< ParticleType >::globalEndJob(), and MVAValueMapProducer< ParticleType >::produce().

154 {
155  using namespace edm;
156  using namespace std;
157  auto valMap = std::make_unique<ValueMap<T>>();
158  typename edm::ValueMap<T>::Filler filler(*valMap);
159  filler.insert(handle, values.begin(), values.end());
160  filler.fill();
161  iEvent.put(std::move(valMap), label);
162 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
HLT enums.
def move(src, dest)
Definition: eostools.py:510

Member Data Documentation

template<class ParticleType >
std::vector<std::string> MVAValueMapProducer< ParticleType >::mvaCategoriesMapNames_
private
template<class ParticleType >
std::vector<std::string> MVAValueMapProducer< ParticleType >::mvaValueMapNames_
private
template<class ParticleType >
edm::EDGetToken MVAValueMapProducer< ParticleType >::src_
private
template<class ParticleType >
edm::EDGetToken MVAValueMapProducer< ParticleType >::srcMiniAOD_
private