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 &&)=default
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESProxyIndex > 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
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, 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::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
 

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
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<class ProductType >
BranchAliasSetterT< ProductType > produces ()
 declare what type of product will make and with which optional label More...
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces ()
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces ()
 
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)
 
template<Transition B>
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 (std::string instanceName)
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
ProducesCollector producesCollector ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< B > consumes (edm::InputTag tag) noexcept
 
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<Transition Tr = Transition::Event>
constexpr auto esConsumes () noexcept
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag) noexcept
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 

Detailed Description

template<class ParticleType>
class MVAValueMapProducer< ParticleType >

Definition at line 28 of file MVAValueMapProducer.h.

Constructor & Destructor Documentation

◆ MVAValueMapProducer()

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

Definition at line 107 of file MVAValueMapProducer.h.

109  keysForValueMapsToken_(getKeysForValueMapsToken<ParticleType>(
110  iConfig.getParameter<edm::InputTag>("keysForValueMaps"), consumesCollector())),
111  mvaEstimators_(getMVAEstimators(iConfig.getParameterSetVector("mvaConfigurations"))),
112  mvaValueMapNames_(getValueMapNames(iConfig.getParameterSetVector("mvaConfigurations"), "Values")),
113  mvaRawValueMapNames_(getValueMapNames(iConfig.getParameterSetVector("mvaConfigurations"), "RawValues")),
114  mvaCategoriesMapNames_(getValueMapNames(iConfig.getParameterSetVector("mvaConfigurations"), "Categories")),
116  for (auto const& name : mvaValueMapNames_)
117  produces<edm::ValueMap<float>>(name);
118  for (auto const& name : mvaRawValueMapNames_)
119  produces<edm::ValueMap<float>>(name);
120  for (auto const& name : mvaCategoriesMapNames_)
121  produces<edm::ValueMap<int>>(name);
122 }

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

Member Function Documentation

◆ fillDescriptions()

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

Definition at line 163 of file MVAValueMapProducer.h.

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

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

◆ getMVAEstimators()

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

Definition at line 35 of file MVAValueMapProducer.h.

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

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

◆ getValueMapNames()

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

Definition at line 55 of file MVAValueMapProducer.h.

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

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

◆ 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 125 of file MVAValueMapProducer.h.

127  {
128  std::vector<float> auxVariables = variableHelper_.getAuxVariables(iEvent);
129 
130  auto srcHandle = iEvent.getHandle(srcToken_);
131  auto keysForValueMapsHandle =
133 
134  // check if nothing is wrong with the data format of the candidates
135  if (!validated_ && !srcHandle->empty()) {
136  egammaTools::validateEgammaCandidate((*srcHandle)[0]);
137  validated_ = true;
138  }
139 
140  // Loop over MVA estimators
141  for (unsigned iEstimator = 0; iEstimator < mvaEstimators_.size(); iEstimator++) {
142  std::vector<float> mvaValues;
143  std::vector<float> mvaRawValues;
144  std::vector<int> mvaCategories;
145 
146  // Loop over particles
147  for (auto const& cand : *srcHandle) {
148  int cat = -1; // Passed by reference to the mvaValue function to store the category
149  const float response = mvaEstimators_[iEstimator]->mvaValue(&cand, auxVariables, cat);
150  mvaRawValues.push_back(response); // The MVA score
151  mvaValues.push_back(2.0 / (1.0 + exp(-2.0 * response)) - 1); // MVA output between -1 and 1
152  mvaCategories.push_back(cat);
153  } // end loop over particles
154 
155  writeValueMap(iEvent, keysForValueMapsHandle, mvaValues, mvaValueMapNames_[iEstimator]);
156  writeValueMap(iEvent, keysForValueMapsHandle, mvaRawValues, mvaRawValueMapNames_[iEstimator]);
157  writeValueMap(iEvent, keysForValueMapsHandle, mvaCategories, mvaCategoriesMapNames_[iEstimator]);
158 
159  } // end loop over estimators
160 }

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

Member Data Documentation

◆ keysForValueMapsToken_

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

Definition at line 67 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 70 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 66 of file MVAValueMapProducer.h.

◆ validated_

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

Definition at line 80 of file MVAValueMapProducer.h.

◆ variableHelper_

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

Definition at line 78 of file MVAValueMapProducer.h.

MVAValueMapProducer::getValueMapNames
static std::vector< std::string > getValueMapNames(const edm::VParameterSet &vConfig, std::string &&suffix)
Definition: MVAValueMapProducer.h:55
MVAValueMapProducer::srcToken_
const edm::EDGetTokenT< edm::View< ParticleType > > srcToken_
Definition: MVAValueMapProducer.h:66
eostools.cat
def cat(path)
Definition: eostools.py:401
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
edm::EDGetTokenT::isUninitialized
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:99
edm::EDConsumerBase::consumesCollector
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
Definition: EDConsumerBase.cc:47
beamerCreator.create
def create(alignables, pedeDump, additionalData, outputFile, config)
Definition: beamerCreator.py:44
MVAValueMapProducer::validated_
std::atomic< bool > validated_
Definition: MVAValueMapProducer.h:80
createPayload.suffix
suffix
Definition: createPayload.py:281
names
const std::string names[nVars_]
Definition: PhotonIDValueMapProducer.cc:124
ElectronMVAValueMapProducer_cfi.mvaConfigurations
mvaConfigurations
Definition: ElectronMVAValueMapProducer_cfi.py:46
MVAValueMapProducer::mvaValueMapNames_
const std::vector< std::string > mvaValueMapNames_
Definition: MVAValueMapProducer.h:73
MVAValueMapProducer::getMVAEstimators
static auto getMVAEstimators(const edm::VParameterSet &vConfig)
Definition: MVAValueMapProducer.h:35
egammaTools::validateEgammaCandidate
void validateEgammaCandidate(Candidate const &candidate)
Definition: validateEgammaCandidate.h:11
MVAValueMapProducer::mvaCategoriesMapNames_
const std::vector< std::string > mvaCategoriesMapNames_
Definition: MVAValueMapProducer.h:75
edm::View
Definition: CaloClusterFwd.h:14
MVAValueMapProducer::mvaRawValueMapNames_
const std::vector< std::string > mvaRawValueMapNames_
Definition: MVAValueMapProducer.h:74
cand
Definition: decayParser.h:32
iEvent
int iEvent
Definition: GenABIO.cc:224
get
#define get
MVAVariableHelper::getAuxVariables
const std::vector< float > getAuxVariables(const edm::Event &iEvent) const
Definition: MVAVariableHelper.h:18
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
MVAValueMapProducer::mvaEstimators_
const std::vector< std::unique_ptr< AnyMVAEstimatorRun2Base > > mvaEstimators_
Definition: MVAValueMapProducer.h:70
Exception
Definition: hltDiff.cc:245
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
MVAValueMapProducer::keysForValueMapsToken_
const edm::EDGetTokenT< edm::View< ParticleType > > keysForValueMapsToken_
Definition: MVAValueMapProducer.h:67
edm::ParameterSet::getParameterSetVector
VParameterSet const & getParameterSetVector(std::string const &name) const
Definition: ParameterSet.cc:2160
edm::EDConsumerBase::consumes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: EDConsumerBase.h:159
JetChargeProducer_cfi.exp
exp
Definition: JetChargeProducer_cfi.py:6
MVAValueMapProducer::variableHelper_
const MVAVariableHelper variableHelper_
Definition: MVAValueMapProducer.h:78
edm::ConfigurationDescriptions::addDefault
void addDefault(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:99
edm::InputTag
Definition: InputTag.h:15