CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 ()
 
- 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
 
virtual ~EDProducerBase ()
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (std::string const &iProcessName, std::string const &iModuleLabel, bool iPrint, std::vector< char const * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
static void globalEndJob (const egamma::MVAObjectCache *)
 
static std::unique_ptr
< egamma::MVAObjectCache
initializeGlobalCache (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

virtual 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, GlobalCache
LuminosityBlockContext
 
typedef
CacheTypes::LuminosityBlockSummaryCache 
LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache,
GlobalCache
RunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 
- Public Types inherited from edm::stream::EDProducerBase
typedef EDProducerAdaptorBase ModuleType
 
- Public Types inherited from edm::ProducerBase
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::ParameterSet::getParameter(), 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 ( )

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().

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

Definition at line 34 of file MVAValueMapProducer.h.

34  {
35  }
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::unique_ptr<egamma::MVAObjectCache>(new egamma::MVAObjectCache(conf));
32  }
template<class ParticleType >
void MVAValueMapProducer< ParticleType >::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivatevirtual

Implements edm::stream::EDProducerBase.

Definition at line 104 of file MVAValueMapProducer.h.

References HLT_25ns10e33_v2_cff::distance, edm::Event::getByToken(), i, and alcazmumu_cfi::src.

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 }
int i
Definition: DBlmapReader.cc:9
std::vector< std::string > mvaValueMapNames_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
void writeValueMap(edm::Event &iEvent, const edm::Handle< edm::View< ParticleType > > &handle, const std::vector< T > &values, const std::string &label) const
std::vector< std::string > mvaCategoriesMapNames_
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 edm::helper::Filler< Map >::fill(), patZpeak::handle, edm::helper::Filler< Map >::insert(), and edm::Event::put().

154 {
155  using namespace edm;
156  using namespace std;
157  auto_ptr<ValueMap<T> > valMap(new ValueMap<T>());
158  typename edm::ValueMap<T>::Filler filler(*valMap);
159  filler.insert(handle, values.begin(), values.end());
160  filler.fill();
161  iEvent.put(valMap, label);
162 }
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121

Member Data Documentation

template<class ParticleType >
std::vector<std::string> MVAValueMapProducer< ParticleType >::mvaCategoriesMapNames_
private

Definition at line 59 of file MVAValueMapProducer.h.

template<class ParticleType >
std::vector<std::string> MVAValueMapProducer< ParticleType >::mvaValueMapNames_
private

Definition at line 58 of file MVAValueMapProducer.h.

template<class ParticleType >
edm::EDGetToken MVAValueMapProducer< ParticleType >::src_
private

Definition at line 50 of file MVAValueMapProducer.h.

template<class ParticleType >
edm::EDGetToken MVAValueMapProducer< ParticleType >::srcMiniAOD_
private

Definition at line 53 of file MVAValueMapProducer.h.