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 edm::EDGetTokenT< edm::View< ParticleType > > keysForValueMapsToken_
 
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_
 
std::atomic< bool > validated_ = false
 
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 26 of file MVAValueMapProducer.h.

Constructor & Destructor Documentation

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

Definition at line 103 of file MVAValueMapProducer.h.

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

104  : src_(consumesCollector(), iConfig, "src", "srcMiniAOD")
105  , keysForValueMapsToken_(getKeysForValueMapsToken<ParticleType>(
106  iConfig.getParameter<edm::InputTag>("keysForValueMaps"), consumesCollector()))
107  , mvaEstimators_(getMVAEstimators(iConfig.getParameterSetVector("mvaConfigurations")))
108  , mvaValueMapNames_ (getValueMapNames(iConfig.getParameterSetVector("mvaConfigurations"), "Values" ))
109  , mvaRawValueMapNames_ (getValueMapNames(iConfig.getParameterSetVector("mvaConfigurations"), "RawValues" ))
110  , mvaCategoriesMapNames_(getValueMapNames(iConfig.getParameterSetVector("mvaConfigurations"), "Categories"))
112 {
113  for( auto const& name : mvaValueMapNames_ ) produces<edm::ValueMap<float>>(name);
114  for( auto const& name : mvaRawValueMapNames_ ) produces<edm::ValueMap<float>>(name);
115  for( auto const& name : mvaCategoriesMapNames_ ) produces<edm::ValueMap<int >>(name);
116 }
const edm::EDGetTokenT< edm::View< ParticleType > > keysForValueMapsToken_
T getParameter(std::string const &) const
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 160 of file MVAValueMapProducer.h.

References edm::ParameterSetDescription::add(), edm::ConfigurationDescriptions::addDefault(), edm::ParameterSetDescription::addVPSet(), ElectronMVAValueMapProducer_cfi::mvaConfigurations, and edm::ParameterSetDescription::setUnknown().

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

160  {
162  desc.add<edm::InputTag>("src", {});
163  desc.add<edm::InputTag>("srcMiniAOD", {});
164  desc.add<edm::InputTag>("keysForValueMaps", {});
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  mvaConfigurations.setUnknown();
170  desc.addVPSet("mvaConfigurations", mvaConfigurations);
171  }
172  descriptions.addDefault(desc);
173 }
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
void addDefault(ParameterSetDescription const &psetDescription)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
template<class ParticleType >
void MVAValueMapProducer< ParticleType >::produce ( edm::StreamID  ,
edm::Event iEvent,
const edm::EventSetup iSetup 
) const
overrideprivate

Definition at line 119 of file MVAValueMapProducer.h.

References eostools::cat(), JetChargeProducer_cfi::exp, edm::Event::getHandle(), MultiTokenT< T >::getValidHandle(), edm::EDGetTokenT< T >::isUninitialized(), MVAValueMapProducer< ParticleType >::keysForValueMapsToken_, MVAValueMapProducer< ParticleType >::mvaCategoriesMapNames_, MVAValueMapProducer< ParticleType >::mvaEstimators_, MVAValueMapProducer< ParticleType >::mvaRawValueMapNames_, MVAValueMapProducer< ParticleType >::mvaValueMapNames_, MVAValueMapProducer< ParticleType >::src_, MVAValueMapProducer< ParticleType >::validated_, egammaTools::validateEgammaCandidate(), MVAValueMapProducer< ParticleType >::variableHelper_, and writeValueMap().

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

120 {
121 
123  auto keysForValueMapsHandle =
125 
126  // check if nothing is wrong with the data format of the candidates
127  if (!validated_ && !srcHandle->empty()) {
128  egammaTools::validateEgammaCandidate((*srcHandle)[0]);
129  validated_ = true;
130  }
131 
132  // Loop over MVA estimators
133  for( unsigned iEstimator = 0; iEstimator < mvaEstimators_.size(); iEstimator++ ){
134 
135  std::vector<float> mvaValues;
136  std::vector<float> mvaRawValues;
137  std::vector<int> mvaCategories;
138 
139  // Loop over particles
140  for (auto const& cand : srcHandle->ptrs())
141  {
142  std::vector<float> auxVariables = variableHelper_.getAuxVariables(cand, iEvent);
143 
144  int cat = -1; // Passed by reference to the mvaValue function to store the category
145  const float response = mvaEstimators_[iEstimator]->mvaValue( cand.get(), auxVariables, cat );
146  mvaRawValues.push_back( response ); // The MVA score
147  mvaValues.push_back( 2.0/(1.0+exp(-2.0*response))-1 ); // MVA output between -1 and 1
148  mvaCategories.push_back( cat );
149  } // end loop over particles
150 
151  writeValueMap(iEvent, keysForValueMapsHandle, mvaValues, mvaValueMapNames_[iEstimator]);
152  writeValueMap(iEvent, keysForValueMapsHandle, mvaRawValues, mvaRawValueMapNames_[iEstimator]);
153  writeValueMap(iEvent, keysForValueMapsHandle, mvaCategories, mvaCategoriesMapNames_[iEstimator]);
154 
155  } // end loop over estimators
156 
157 }
const edm::EDGetTokenT< edm::View< ParticleType > > keysForValueMapsToken_
const std::vector< std::string > mvaRawValueMapNames_
void validateEgammaCandidate(Candidate const &candidate)
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
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
Definition: Event.h:539
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
std::atomic< bool > validated_
const MVAVariableHelper< ParticleType > variableHelper_
bool isUninitialized() const
Definition: EDGetToken.h:70

Member Data Documentation

template<class ParticleType >
const edm::EDGetTokenT<edm::View<ParticleType> > MVAValueMapProducer< ParticleType >::keysForValueMapsToken_
private

Definition at line 41 of file MVAValueMapProducer.h.

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

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 44 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 40 of file MVAValueMapProducer.h.

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

template<class ParticleType >
std::atomic<bool> MVAValueMapProducer< ParticleType >::validated_ = false
mutableprivate

Definition at line 54 of file MVAValueMapProducer.h.

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

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

Definition at line 52 of file MVAValueMapProducer.h.

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