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<>

Public Member Functions

 MVAValueMapProducer (const edm::ParameterSet &)
 
 ~MVAValueMapProducer () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
bool hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () const final
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 

Private Member Functions

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

Private Attributes

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

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, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 

Detailed Description

template<class ParticleType>
class MVAValueMapProducer< ParticleType >

Definition at line 25 of file MVAValueMapProducer.h.

Constructor & Destructor Documentation

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

Definition at line 52 of file MVAValueMapProducer.h.

References beamerCreator::create(), Exception, reco::get(), edm::ParameterSet::getParameterSetVector(), MVAValueMapProducer< ParticleType >::mvaCategoriesMapNames_, MVAValueMapProducer< ParticleType >::mvaEstimators_, MVAValueMapProducer< ParticleType >::mvaRawValueMapNames_, MVAValueMapProducer< ParticleType >::mvaValueMapNames_, and AlCaHLTBitMon_QueryRunRegistry::string.

53  : src_(consumesCollector(), iConfig, "src", "srcMiniAOD")
54 
55 {
56  // Loop over the list of MVA configurations passed here from python and
57  // construct all requested MVA estimators.
58  const std::vector<edm::ParameterSet>& mvaEstimatorConfigs
59  = iConfig.getParameterSetVector("mvaConfigurations");
60 
61  for( auto &imva : mvaEstimatorConfigs ){
62 
63  // The factory below constructs the MVA of the appropriate type based
64  // on the "mvaName" which is the name of the derived MVA class (plugin)
65  if( !imva.empty() ) {
66 
68  imva.getParameter<std::string>("mvaName"), imva));
69 
70  } else
71  throw cms::Exception(" MVA configuration not found: ")
72  << " failed to find proper configuration for one of the MVAs in the main python script " << std::endl;
73 
74  mvaEstimators_.back()->setConsumes( consumesCollector() );
75 
76  //
77  // Compose and save the names of the value maps to be produced
78  //
79 
80  const std::string fullName = ( mvaEstimators_.back()->getName() +
81  mvaEstimators_.back()->getTag() );
82 
83  const std::string thisValueMapName = fullName + "Values";
84  const std::string thisRawValueMapName = fullName + "RawValues";
85  const std::string thisCategoriesMapName = fullName + "Categories";
86 
87  mvaValueMapNames_ .push_back( thisValueMapName );
88  mvaRawValueMapNames_ .push_back( thisRawValueMapName );
89  mvaCategoriesMapNames_.push_back( thisCategoriesMapName );
90 
91  // Declare the maps to the framework
92  produces<edm::ValueMap<float>>(thisValueMapName );
93  produces<edm::ValueMap<float>>(thisRawValueMapName );
94  produces<edm::ValueMap<int>> (thisCategoriesMapName);
95 
96  }
97 
98 }
VParameterSet const & getParameterSetVector(std::string const &name) const
def create(alignables, pedeDump, additionalData, outputFile, config)
std::vector< std::string > mvaValueMapNames_
std::vector< std::string > mvaRawValueMapNames_
std::vector< std::unique_ptr< AnyMVAEstimatorRun2Base > > mvaEstimators_
std::vector< std::string > mvaCategoriesMapNames_
MultiTokenT< edm::View< ParticleType > > src_
T get(const Candidate &c)
Definition: component.h:55
template<class ParticleType >
MVAValueMapProducer< ParticleType >::~MVAValueMapProducer ( )
override

Definition at line 101 of file MVAValueMapProducer.h.

101  {
102 }

Member Function Documentation

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

Definition at line 135 of file MVAValueMapProducer.h.

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

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

Definition at line 105 of file MVAValueMapProducer.h.

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

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

Member Data Documentation

template<class ParticleType >
std::vector<std::string> MVAValueMapProducer< ParticleType >::mvaCategoriesMapNames_
private
template<class ParticleType >
std::vector<std::unique_ptr<AnyMVAEstimatorRun2Base> > MVAValueMapProducer< ParticleType >::mvaEstimators_
private
template<class ParticleType >
std::vector<std::string> MVAValueMapProducer< ParticleType >::mvaRawValueMapNames_
private
template<class ParticleType >
std::vector<std::string> MVAValueMapProducer< ParticleType >::mvaValueMapNames_
private
template<class ParticleType >
MultiTokenT<edm::View<ParticleType> > MVAValueMapProducer< ParticleType >::src_
private

Definition at line 39 of file MVAValueMapProducer.h.

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