CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Static 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 &)
 
- Public Member Functions inherited from edm::global::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
EDProduceroperator= (const EDProducer &)=delete
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsInputProcessBlocks () const final
 
bool wantsProcessBlocks () 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
 
std::vector< bool > const & recordProvenanceList () 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)
 
TypeLabelList const & typeLabelList () const
 used by the fwk to register the list of products of this module More...
 
 ~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
 
ESResolverIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESResolverIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector (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::array< std::vector< ModuleDescription const *> *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, 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
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProductResolverIndices 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
 

Static Private Member Functions

static auto getMVAEstimators (const edm::VParameterSet &vConfig)
 
static std::vector< std::string > getValueMapNames (const edm::VParameterSet &vConfig, std::string &&suffix)
 

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 edm::EDGetTokenT< edm::View< ParticleType > > srcToken_
 
std::atomic< bool > validated_ = false
 
const MVAVariableHelper variableHelper_
 

Additional Inherited Members

- Public Types inherited from edm::global::EDProducerBase
typedef EDProducerBase ModuleType
 
- Public Types inherited from edm::ProducerBase
template<typename T >
using BranchAliasSetterT = ProductRegistryHelper::BranchAliasSetterT< T >
 
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::ProducerBase
template<Transition Tr = Transition::Event>
auto produces (std::string instanceName) noexcept
 declare what type of product will make and with which optional label More...
 
template<Transition B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<BranchType B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces ()
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces ()
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces ()
 
template<Transition Tr = Transition::Event>
auto produces () noexcept
 
ProducesCollector producesCollector ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< Bconsumes (edm::InputTag tag) noexcept
 
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 ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
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)
 
void resetItemsToGetFrom (BranchType iType)
 

Detailed Description

template<class ParticleType>
class MVAValueMapProducer< ParticleType >

Definition at line 29 of file MVAValueMapProducer.h.

Constructor & Destructor Documentation

◆ MVAValueMapProducer()

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

Definition at line 108 of file MVAValueMapProducer.h.

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

110  keysForValueMapsToken_(getKeysForValueMapsToken<ParticleType>(
111  iConfig.getParameter<edm::InputTag>("keysForValueMaps"), consumesCollector())),
112  mvaEstimators_(getMVAEstimators(iConfig.getParameterSetVector("mvaConfigurations"))),
113  mvaValueMapNames_(getValueMapNames(iConfig.getParameterSetVector("mvaConfigurations"), "Values")),
114  mvaRawValueMapNames_(getValueMapNames(iConfig.getParameterSetVector("mvaConfigurations"), "RawValues")),
115  mvaCategoriesMapNames_(getValueMapNames(iConfig.getParameterSetVector("mvaConfigurations"), "Categories")),
117  for (auto const& name : mvaValueMapNames_)
118  produces<edm::ValueMap<float>>(name);
119  for (auto const& name : mvaRawValueMapNames_)
120  produces<edm::ValueMap<float>>(name);
121  for (auto const& name : mvaCategoriesMapNames_)
122  produces<edm::ValueMap<int>>(name);
123 }
const edm::EDGetTokenT< edm::View< ParticleType > > keysForValueMapsToken_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
const std::vector< std::string > mvaRawValueMapNames_
const MVAVariableHelper variableHelper_
const std::vector< std::unique_ptr< AnyMVAEstimatorRun2Base > > mvaEstimators_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
const std::vector< std::string > mvaCategoriesMapNames_
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
const std::vector< std::string > mvaValueMapNames_
static std::vector< std::string > getValueMapNames(const edm::VParameterSet &vConfig, std::string &&suffix)
const edm::EDGetTokenT< edm::View< ParticleType > > srcToken_
VParameterSet const & getParameterSetVector(std::string const &name) const
static auto getMVAEstimators(const edm::VParameterSet &vConfig)

Member Function Documentation

◆ fillDescriptions()

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

Definition at line 164 of file MVAValueMapProducer.h.

References edm::ConfigurationDescriptions::addDefault(), submitPVResolutionJobs::desc, and ElectronMVAValueMapProducer_cfi::mvaConfigurations.

164  {
166  desc.add<edm::InputTag>("src", {});
167  desc.add<edm::InputTag>("keysForValueMaps", {});
168  {
169  //The following says we do not know what parameters are allowed so do no validation
170  // Please change this to state exactly what you do use, even if it is no parameters
172  mvaConfigurations.setUnknown();
173  desc.addVPSet("mvaConfigurations", mvaConfigurations);
174  }
175  descriptions.addDefault(desc);
176 }
void addDefault(ParameterSetDescription const &psetDescription)

◆ getMVAEstimators()

template<class ParticleType >
static auto MVAValueMapProducer< ParticleType >::getMVAEstimators ( const edm::VParameterSet vConfig)
inlinestaticprivate

Definition at line 36 of file MVAValueMapProducer.h.

References beamerCreator::create(), Exception, get, and AlCaHLTBitMon_QueryRunRegistry::string.

36  {
37  std::vector<std::unique_ptr<AnyMVAEstimatorRun2Base>> mvaEstimators;
38 
39  // Loop over the list of MVA configurations passed here from python and
40  // construct all requested MVA estimators.
41  for (auto& imva : vConfig) {
42  // The factory below constructs the MVA of the appropriate type based
43  // on the "mvaName" which is the name of the derived MVA class (plugin)
44  if (!imva.empty()) {
45  mvaEstimators.emplace_back(
46  AnyMVAEstimatorRun2Factory::get()->create(imva.getParameter<std::string>("mvaName"), imva));
47 
48  } else
49  throw cms::Exception(" MVA configuration not found: ")
50  << " failed to find proper configuration for one of the MVAs in the main python script " << std::endl;
51  }
52 
53  return mvaEstimators;
54  }
def create(alignables, pedeDump, additionalData, outputFile, config)
#define get

◆ getValueMapNames()

template<class ParticleType >
static std::vector<std::string> MVAValueMapProducer< ParticleType >::getValueMapNames ( const edm::VParameterSet vConfig,
std::string &&  suffix 
)
inlinestaticprivate

Definition at line 56 of file MVAValueMapProducer.h.

References names, AlCaHLTBitMon_QueryRunRegistry::string, and makePlotsFromDump::suffix.

56  {
57  std::vector<std::string> names;
58  for (auto& imva : vConfig) {
59  names.push_back(imva.getParameter<std::string>("mvaName") + imva.getParameter<std::string>("mvaTag") + suffix);
60  }
61 
62  return names;
63  }
const std::string names[nVars_]

◆ produce()

template<class ParticleType >
void MVAValueMapProducer< ParticleType >::produce ( edm::StreamID  ,
edm::Event iEvent,
const edm::EventSetup iSetup 
) const
overrideprivatevirtual

Implements edm::global::EDProducerBase.

Definition at line 126 of file MVAValueMapProducer.h.

References eostools::cat(), JetChargeProducer_cfi::exp, iEvent, and egammaTools::validateEgammaCandidate().

128  {
129  std::vector<float> auxVariables = variableHelper_.getAuxVariables(iEvent);
130 
131  auto srcHandle = iEvent.getHandle(srcToken_);
132  auto keysForValueMapsHandle =
134 
135  // check if nothing is wrong with the data format of the candidates
136  if (!validated_ && !srcHandle->empty()) {
137  egammaTools::validateEgammaCandidate((*srcHandle)[0]);
138  validated_ = true;
139  }
140 
141  // Loop over MVA estimators
142  for (unsigned iEstimator = 0; iEstimator < mvaEstimators_.size(); iEstimator++) {
143  std::vector<float> mvaValues;
144  std::vector<float> mvaRawValues;
145  std::vector<int> mvaCategories;
146 
147  // Loop over particles
148  for (auto const& cand : *srcHandle) {
149  int cat = -1; // Passed by reference to the mvaValue function to store the category
150  const float response = mvaEstimators_[iEstimator]->mvaValue(&cand, auxVariables, cat);
151  mvaRawValues.push_back(response); // The MVA score
152  mvaValues.push_back(2.0 / (1.0 + exp(-2.0 * response)) - 1); // MVA output between -1 and 1
153  mvaCategories.push_back(cat);
154  } // end loop over particles
155 
156  writeValueMap(iEvent, keysForValueMapsHandle, mvaValues, mvaValueMapNames_[iEstimator]);
157  writeValueMap(iEvent, keysForValueMapsHandle, mvaRawValues, mvaRawValueMapNames_[iEstimator]);
158  writeValueMap(iEvent, keysForValueMapsHandle, mvaCategories, mvaCategoriesMapNames_[iEstimator]);
159 
160  } // end loop over estimators
161 }
const edm::EDGetTokenT< edm::View< ParticleType > > keysForValueMapsToken_
const std::vector< std::string > mvaRawValueMapNames_
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:104
void validateEgammaCandidate(Candidate const &candidate)
const MVAVariableHelper variableHelper_
const std::vector< std::unique_ptr< AnyMVAEstimatorRun2Base > > mvaEstimators_
int iEvent
Definition: GenABIO.cc:224
def cat(path)
Definition: eostools.py:401
const std::vector< std::string > mvaCategoriesMapNames_
const std::vector< std::string > mvaValueMapNames_
std::atomic< bool > validated_
const edm::EDGetTokenT< edm::View< ParticleType > > srcToken_
const std::vector< float > getAuxVariables(const edm::Event &iEvent) const

Member Data Documentation

◆ keysForValueMapsToken_

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

Definition at line 68 of file MVAValueMapProducer.h.

◆ mvaCategoriesMapNames_

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

◆ mvaEstimators_

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

Definition at line 71 of file MVAValueMapProducer.h.

◆ mvaRawValueMapNames_

template<class ParticleType >
const std::vector<std::string> MVAValueMapProducer< ParticleType >::mvaRawValueMapNames_
private

◆ mvaValueMapNames_

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

◆ srcToken_

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

Definition at line 67 of file MVAValueMapProducer.h.

◆ validated_

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

Definition at line 81 of file MVAValueMapProducer.h.

◆ variableHelper_

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

Definition at line 79 of file MVAValueMapProducer.h.