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::global::EDProducer<> edm::global::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 MVAValueMapProducer (const edm::ParameterSet &)
 
 ~MVAValueMapProducer () override
 
- Public Member Functions inherited from edm::global::EDProducer<>
 EDProducer ()=default
 
bool hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () const final
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsStreamLuminosityBlocks () const final
 
bool wantsStreamRuns () const final
 
- Public Member Functions inherited from edm::global::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)
 
 ~ProducerBase () noexcept(false) override
 
- 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
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
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)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
- Static Public Member Functions inherited from edm::global::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Private Member Functions

void produce (edm::StreamID, edm::Event &, const edm::EventSetup &) const override
 

Private Attributes

const std::vector< std::string > mvaCategoriesMapNames_
 
const std::vector< std::unique_ptr< AnyMVAEstimatorRun2Base > > mvaEstimators_
 
const std::vector< std::string > mvaRawValueMapNames_
 
const std::vector< std::string > mvaValueMapNames_
 
const MultiTokenT< edm::View< ParticleType > > src_
 
const MVAVariableHelper< ParticleType > variableHelper_
 

Additional Inherited Members

- Public Types inherited from edm::global::EDProducerBase
typedef EDProducerBase 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 ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
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 21 of file MVAValueMapProducer.h.

Constructor & Destructor Documentation

template<class ParticleType >
MVAValueMapProducer< ParticleType >::MVAValueMapProducer ( const edm::ParameterSet iConfig)

Definition at line 89 of file MVAValueMapProducer.h.

References MVAValueMapProducer< ParticleType >::mvaCategoriesMapNames_, MVAValueMapProducer< ParticleType >::mvaRawValueMapNames_, MVAValueMapProducer< ParticleType >::mvaValueMapNames_, and dataset::name.

90  : src_(consumesCollector(), iConfig, "src", "srcMiniAOD")
91  , mvaEstimators_(getMVAEstimators(iConfig.getParameterSetVector("mvaConfigurations")))
92  , mvaValueMapNames_ (getValueMapNames(iConfig.getParameterSetVector("mvaConfigurations"), "Values" ))
93  , mvaRawValueMapNames_ (getValueMapNames(iConfig.getParameterSetVector("mvaConfigurations"), "RawValues" ))
94  , mvaCategoriesMapNames_(getValueMapNames(iConfig.getParameterSetVector("mvaConfigurations"), "Categories"))
96 {
97  for( auto const& name : mvaValueMapNames_ ) produces<edm::ValueMap<float>>(name);
98  for( auto const& name : mvaRawValueMapNames_ ) produces<edm::ValueMap<float>>(name);
99  for( auto const& name : mvaCategoriesMapNames_ ) produces<edm::ValueMap<int >>(name);
100 }
VParameterSet const & getParameterSetVector(std::string const &name) const
const std::vector< std::string > mvaRawValueMapNames_
const std::vector< std::unique_ptr< AnyMVAEstimatorRun2Base > > mvaEstimators_
const MultiTokenT< edm::View< ParticleType > > src_
const std::vector< std::string > mvaCategoriesMapNames_
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
const std::vector< std::string > mvaValueMapNames_
const MVAVariableHelper< ParticleType > variableHelper_
template<class ParticleType >
MVAValueMapProducer< ParticleType >::~MVAValueMapProducer ( )
inlineoverride

Member Function Documentation

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

Definition at line 136 of file MVAValueMapProducer.h.

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

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

136  {
137  //The following says we do not know what parameters are allowed so do no validation
138  // Please change this to state exactly what you do use, even if it is no parameters
140  desc.setUnknown();
141  descriptions.addDefault(desc);
142 }
void addDefault(ParameterSetDescription const &psetDescription)
template<class ParticleType >
void MVAValueMapProducer< ParticleType >::produce ( edm::StreamID  ,
edm::Event iEvent,
const edm::EventSetup iSetup 
) const
overrideprivate

Definition at line 103 of file MVAValueMapProducer.h.

References eostools::cat(), JetChargeProducer_cfi::exp, MultiTokenT< T >::getValidHandle(), MVAValueMapProducer< ParticleType >::mvaCategoriesMapNames_, MVAValueMapProducer< ParticleType >::mvaEstimators_, MVAValueMapProducer< ParticleType >::mvaRawValueMapNames_, MVAValueMapProducer< ParticleType >::mvaValueMapNames_, TrackRefitter_38T_cff::src, MVAValueMapProducer< ParticleType >::src_, MVAValueMapProducer< ParticleType >::variableHelper_, and writeValueMap().

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

104 {
105 
107 
108  // Loop over MVA estimators
109  for( unsigned iEstimator = 0; iEstimator < mvaEstimators_.size(); iEstimator++ ){
110 
111  std::vector<float> mvaValues;
112  std::vector<float> mvaRawValues;
113  std::vector<int> mvaCategories;
114 
115  // Loop over particles
116  for (auto const& cand : src->ptrs())
117  {
118  std::vector<float> auxVariables = variableHelper_.getAuxVariables(cand, iEvent);
119 
120  int cat = -1; // Passed by reference to the mvaValue function to store the category
121  const float response = mvaEstimators_[iEstimator]->mvaValue( cand.get(), auxVariables, cat );
122  mvaRawValues.push_back( response ); // The MVA score
123  mvaValues.push_back( 2.0/(1.0+exp(-2.0*response))-1 ); // MVA output between -1 and 1
124  mvaCategories.push_back( cat );
125  } // end loop over particles
126 
127  writeValueMap(iEvent, src, mvaValues , mvaValueMapNames_ [iEstimator] );
128  writeValueMap(iEvent, src, mvaRawValues , mvaRawValueMapNames_ [iEstimator] );
129  writeValueMap(iEvent, src, mvaCategories, mvaCategoriesMapNames_[iEstimator] );
130 
131  } // end loop over estimators
132 
133 }
const std::vector< std::string > mvaRawValueMapNames_
const std::vector< std::unique_ptr< AnyMVAEstimatorRun2Base > > mvaEstimators_
void writeValueMap(edm::Event &iEvent, const edm::Handle< HandleType > &handle, const std::vector< ValueType > &values, const std::string &label)
Definition: Utils.h:13
def cat(path)
Definition: eostools.py:401
const MultiTokenT< edm::View< ParticleType > > src_
const std::vector< std::string > mvaCategoriesMapNames_
const std::vector< std::string > mvaValueMapNames_
edm::Handle< T > getValidHandle(const edm::Event &iEvent) const
Definition: MultiToken.h:95
const MVAVariableHelper< ParticleType > variableHelper_

Member Data Documentation

template<class ParticleType >
const std::vector<std::string> MVAValueMapProducer< ParticleType >::mvaCategoriesMapNames_
private
template<class ParticleType >
const std::vector<std::unique_ptr<AnyMVAEstimatorRun2Base> > MVAValueMapProducer< ParticleType >::mvaEstimators_
private

Definition at line 38 of file MVAValueMapProducer.h.

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

template<class ParticleType >
const std::vector<std::string> MVAValueMapProducer< ParticleType >::mvaRawValueMapNames_
private
template<class ParticleType >
const std::vector<std::string> MVAValueMapProducer< ParticleType >::mvaValueMapNames_
private
template<class ParticleType >
const MultiTokenT<edm::View<ParticleType> > MVAValueMapProducer< ParticleType >::src_
private

Definition at line 35 of file MVAValueMapProducer.h.

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

template<class ParticleType >
const MVAVariableHelper<ParticleType> MVAValueMapProducer< ParticleType >::variableHelper_
private

Definition at line 46 of file MVAValueMapProducer.h.

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