CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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::stream::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 MVAValueMapProducer (const edm::ParameterSet &)
 
 ~MVAValueMapProducer ()
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
- Public Member Functions inherited from edm::stream::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducerBase ()
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (const std::string &iProcessName, std::vector< const char * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
- 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

virtual 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::unique_ptr
< AnyMVAEstimatorRun2Base > > 
mvaEstimators_
 
std::vector< std::string > mvaValueMapNames_
 
edm::EDGetToken src_
 
edm::EDGetToken srcMiniAOD_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
typedef CacheContexts< T...> CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T...> HasAbility
 
typedef
CacheTypes::LuminosityBlockCache 
LuminosityBlockCache
 
typedef
LuminosityBlockContextT
< LuminosityBlockCache,
RunCache, GlobalCache
LuminosityBlockContext
 
typedef
CacheTypes::LuminosityBlockSummaryCache 
LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache,
GlobalCache
RunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 
- Public Types inherited from edm::stream::EDProducerBase
typedef EDProducerAdaptorBase ModuleType
 
- Public Types inherited from edm::ProducerBase
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 18 of file MVAValueMapProducer.h.

Constructor & Destructor Documentation

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

Definition at line 53 of file MVAValueMapProducer.h.

References HLT_25ns14e33_v1_cff::estimator, edm::hlt::Exception, reco::get(), edm::ParameterSet::getParameter(), edm::ParameterSet::getParameterSetVector(), NULL, and AlCaHLTBitMon_QueryRunRegistry::string.

54 {
55 
56  //
57  // Declare consummables, handle both AOD and miniAOD case
58  //
59  src_ = mayConsume<edm::View<ParticleType> >(iConfig.getParameter<edm::InputTag>("src"));
60  srcMiniAOD_ = mayConsume<edm::View<ParticleType> >(iConfig.getParameter<edm::InputTag>("srcMiniAOD"));
61 
62  // Loop over the list of MVA configurations passed here from python and
63  // construct all requested MVA esimtators.
64  const std::vector<edm::ParameterSet>& mvaEstimatorConfigs
65  = iConfig.getParameterSetVector("mvaConfigurations");
66  for( auto &imva : mvaEstimatorConfigs ){
67 
68  std::unique_ptr<AnyMVAEstimatorRun2Base> thisEstimator;
69  thisEstimator.reset(NULL);
70  if( !imva.empty() ) {
71  const std::string& pName = imva.getParameter<std::string>("mvaName");
72  // The factory below constructs the MVA of the appropriate type based
73  // on the "mvaName" which is the name of the derived MVA class (plugin)
75  // Declare all event content, such as ValueMaps produced upstream or other,
76  // original event data pieces, that is needed (if any is implemented in the specific
77  // MVA classes)
78  //edm::ConsumesCollector &cc = consumesCollector();
79  estimator->setConsumes( consumesCollector() );
80 
81  thisEstimator.reset(estimator);
82 
83  } else
84  throw cms::Exception(" MVA configuration not found: ")
85  << " failed to find proper configuration for one of the MVAs in the main python script " << std::endl;
86 
87  // The unique pointer control is passed to the vector in the line below.
88  // Don't use thisEstimator pointer beyond the next line.
89  mvaEstimators_.emplace_back( thisEstimator.release() );
90 
91  //
92  // Compose and save the names of the value maps to be produced
93  //
94  const auto& currentEstimator = mvaEstimators_.back();
95  std::string thisValueMapName = currentEstimator->getName() + "Values";
96  std::string thisCategoriesMapName = currentEstimator->getName() + "Categories";
97  mvaValueMapNames_.push_back( thisValueMapName );
98  mvaCategoriesMapNames_.push_back( thisCategoriesMapName );
99 
100  // Declare the maps to the framework
101  produces<edm::ValueMap<float> >(thisValueMapName);
102  produces<edm::ValueMap<int> >(thisCategoriesMapName);
103 
104  }
105 
106 
107 }
T getParameter(std::string const &) const
VParameterSet const & getParameterSetVector(std::string const &name) const
std::vector< std::string > mvaValueMapNames_
#define NULL
Definition: scimark2.h:8
std::vector< std::unique_ptr< AnyMVAEstimatorRun2Base > > mvaEstimators_
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
std::vector< std::string > mvaCategoriesMapNames_
edm::EDGetToken srcMiniAOD_
T get(const Candidate &c)
Definition: component.h:55
template<class ParticleType >
MVAValueMapProducer< ParticleType >::~MVAValueMapProducer ( )

Definition at line 110 of file MVAValueMapProducer.h.

110  {
111 }

Member Function Documentation

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

Definition at line 175 of file MVAValueMapProducer.h.

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

175  {
176  //The following says we do not know what parameters are allowed so do no validation
177  // Please change this to state exactly what you do use, even if it is no parameters
179  desc.setUnknown();
180  descriptions.addDefault(desc);
181 }
void addDefault(ParameterSetDescription const &psetDescription)
template<class ParticleType >
void MVAValueMapProducer< ParticleType >::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivatevirtual

Implements edm::stream::EDProducerBase.

Definition at line 114 of file MVAValueMapProducer.h.

References edm::Event::getByToken(), i, and alcazmumu_cfi::src.

114  {
115 
116  using namespace edm;
117 
119 
120  // Retrieve the collection of particles from the event.
121  // If we fail to retrieve the collection with the standard AOD
122  // name, we next look for the one with the stndard miniAOD name.
123  iEvent.getByToken(src_, src);
124  if( !src.isValid() ){
125  iEvent.getByToken(srcMiniAOD_,src);
126  if( !src.isValid() )
127  throw cms::Exception(" Collection not found: ")
128  << " failed to find a standard AOD or miniAOD particle collection " << std::endl;
129  }
130 
131 
132  // Loop over MVA estimators
133  for( unsigned iEstimator = 0; iEstimator < mvaEstimators_.size(); iEstimator++ ){
134 
135  // Set up all event content, such as ValueMaps produced upstream or other,
136  // original event data pieces, that is needed (if any is implemented in the specific
137  // MVA classes)
138  mvaEstimators_[iEstimator]->getEventContent( iEvent );
139 
140  std::vector<float> mvaValues;
141  std::vector<int> mvaCategories;
142 
143  // Loop over particles
144  for (size_t i = 0; i < src->size(); ++i){
145  auto iCand = src->ptrAt(i);
146 
147  mvaValues.push_back( mvaEstimators_[iEstimator]->mvaValue( iCand ) );
148  mvaCategories.push_back( mvaEstimators_[iEstimator]->findCategory( iCand ) );
149  } // end loop over particles
150 
151  writeValueMap(iEvent, src, mvaValues, mvaValueMapNames_[iEstimator] );
152  writeValueMap(iEvent, src, mvaCategories, mvaCategoriesMapNames_[iEstimator] );
153 
154  } // end loop over estimators
155 
156 
157 }
int i
Definition: DBlmapReader.cc:9
std::vector< std::string > mvaValueMapNames_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
std::vector< std::unique_ptr< AnyMVAEstimatorRun2Base > > mvaEstimators_
void writeValueMap(edm::Event &iEvent, const edm::Handle< edm::View< ParticleType > > &handle, const std::vector< T > &values, const std::string &label) const
std::vector< std::string > mvaCategoriesMapNames_
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 160 of file MVAValueMapProducer.h.

References edm::helper::Filler< Map >::fill(), patZpeak::handle, edm::helper::Filler< Map >::insert(), and edm::Event::put().

164 {
165  using namespace edm;
166  using namespace std;
167  auto_ptr<ValueMap<T> > valMap(new ValueMap<T>());
168  typename edm::ValueMap<T>::Filler filler(*valMap);
169  filler.insert(handle, values.begin(), values.end());
170  filler.fill();
171  iEvent.put(valMap, label);
172 }
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:115

Member Data Documentation

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

Definition at line 48 of file MVAValueMapProducer.h.

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

Definition at line 44 of file MVAValueMapProducer.h.

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

Definition at line 47 of file MVAValueMapProducer.h.

template<class ParticleType >
edm::EDGetToken MVAValueMapProducer< ParticleType >::src_
private

Definition at line 38 of file MVAValueMapProducer.h.

template<class ParticleType >
edm::EDGetToken MVAValueMapProducer< ParticleType >::srcMiniAOD_
private

Definition at line 41 of file MVAValueMapProducer.h.