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
 
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 > mvaRawValueMapNames_
 
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 65 of file MVAValueMapProducer.h.

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

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

104  {
105 }

Member Function Documentation

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

Definition at line 173 of file MVAValueMapProducer.h.

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

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

173  {
174  //The following says we do not know what parameters are allowed so do no validation
175  // Please change this to state exactly what you do use, even if it is no parameters
177  desc.setUnknown();
178  descriptions.addDefault(desc);
179 }
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 108 of file MVAValueMapProducer.h.

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

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

108  {
109 
110  using namespace edm;
111 
113 
114  // Retrieve the collection of particles from the event.
115  // If we fail to retrieve the collection with the standard AOD
116  // name, we next look for the one with the stndard miniAOD name.
117  iEvent.getByToken(src_, src);
118  if( !src.isValid() ){
119  iEvent.getByToken(srcMiniAOD_,src);
120  if( !src.isValid() )
121  throw cms::Exception(" Collection not found: ")
122  << " failed to find a standard AOD or miniAOD particle collection " << std::endl;
123  }
124 
125 
126  // Loop over MVA estimators
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);
130 
131  // Set up all event content, such as ValueMaps produced upstream or other,
132  // original event data pieces, that is needed (if any is implemented in the specific
133  // MVA classes)
134  const auto& thisEstimator = mva_itr->second;
135 
136  std::vector<float> mvaValues;
137  std::vector<float> mvaRawValues;
138  std::vector<int> mvaCategories;
139 
140  // Loop over particles
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 ); // The MVA score
145  mvaValues.push_back( 2.0/(1.0+exp(-2.0*response))-1 ); // MVA output between -1 and 1
146  mvaCategories.push_back( thisEstimator->findCategory( iCand ) );
147  } // end loop over particles
148 
149  writeValueMap(iEvent, src, mvaValues, mvaValueMapNames_[iEstimator] );
150  writeValueMap(iEvent, src, mvaRawValues, mvaRawValueMapNames_[iEstimator] );
151  writeValueMap(iEvent, src, mvaCategories, mvaCategoriesMapNames_[iEstimator] );
152  } // end loop over estimators
153 
154 
155 }
std::vector< std::string > mvaValueMapNames_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:508
std::vector< std::string > mvaRawValueMapNames_
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 158 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().

162 {
163  using namespace edm;
164  using namespace std;
165  auto valMap = std::make_unique<ValueMap<T>>();
166  typename edm::ValueMap<T>::Filler filler(*valMap);
167  filler.insert(handle, values.begin(), values.end());
168  filler.fill();
169  iEvent.put(std::move(valMap), label);
170 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:127
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 >::mvaRawValueMapNames_
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