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::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
 
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 > mvaRawValueMapNames_
 
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, 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 22 of file MVAValueMapProducer.h.

Constructor & Destructor Documentation

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

Definition at line 58 of file MVAValueMapProducer.h.

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

59 {
60 
61  //
62  // Declare consummables, handle both AOD and miniAOD case
63  //
64  src_ = mayConsume<edm::View<ParticleType> >(iConfig.getParameter<edm::InputTag>("src"));
65  srcMiniAOD_ = mayConsume<edm::View<ParticleType> >(iConfig.getParameter<edm::InputTag>("srcMiniAOD"));
66 
67  // Loop over the list of MVA configurations passed here from python and
68  // construct all requested MVA estimators.
69  const std::vector<edm::ParameterSet>& mvaEstimatorConfigs
70  = iConfig.getParameterSetVector("mvaConfigurations");
71 
72  for( auto &imva : mvaEstimatorConfigs ){
73 
74  // The factory below constructs the MVA of the appropriate type based
75  // on the "mvaName" which is the name of the derived MVA class (plugin)
76  if( !imva.empty() ) {
77 
79  imva.getParameter<std::string>("mvaName"), imva));
80 
81  } else
82  throw cms::Exception(" MVA configuration not found: ")
83  << " failed to find proper configuration for one of the MVAs in the main python script " << std::endl;
84 
85  mvaEstimators_.back()->setConsumes( consumesCollector() );
86 
87  //
88  // Compose and save the names of the value maps to be produced
89  //
90 
91  const std::string fullName = ( mvaEstimators_.back()->getName() +
92  mvaEstimators_.back()->getTag() );
93 
94  const std::string thisValueMapName = fullName + "Values";
95  const std::string thisRawValueMapName = fullName + "RawValues";
96  const std::string thisCategoriesMapName = fullName + "Categories";
97 
98  mvaValueMapNames_ .push_back( thisValueMapName );
99  mvaRawValueMapNames_ .push_back( thisRawValueMapName );
100  mvaCategoriesMapNames_.push_back( thisCategoriesMapName );
101 
102  // Declare the maps to the framework
103  produces<edm::ValueMap<float>>(thisValueMapName );
104  produces<edm::ValueMap<float>>(thisRawValueMapName );
105  produces<edm::ValueMap<int>> (thisCategoriesMapName);
106 
107  }
108 
109 }
T getParameter(std::string const &) const
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_
edm::EDGetToken srcMiniAOD_
T get(const Candidate &c)
Definition: component.h:55
template<class ParticleType >
MVAValueMapProducer< ParticleType >::~MVAValueMapProducer ( )
override

Definition at line 112 of file MVAValueMapProducer.h.

112  {
113 }

Member Function Documentation

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

Definition at line 170 of file MVAValueMapProducer.h.

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

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

Definition at line 116 of file MVAValueMapProducer.h.

References JetChargeProducer_cfi::exp, edm::Event::getByToken(), mps_fire::i, edm::HandleBase::isValid(), MVAValueMapProducer< ParticleType >::mvaCategoriesMapNames_, MVAValueMapProducer< ParticleType >::mvaEstimators_, MVAValueMapProducer< ParticleType >::mvaRawValueMapNames_, MVAValueMapProducer< ParticleType >::mvaValueMapNames_, TrackRefitter_38T_cff::src, MVAValueMapProducer< ParticleType >::src_, MVAValueMapProducer< ParticleType >::srcMiniAOD_, and MVAValueMapProducer< ParticleType >::writeValueMap().

116  {
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  std::vector<float> mvaValues;
136  std::vector<float> mvaRawValues;
137  std::vector<int> mvaCategories;
138 
139  // Loop over particles
140  for (size_t i = 0; i < src->size(); ++i){
141  auto iCand = src->ptrAt(i);
142  const float response = mvaEstimators_[iEstimator]->mvaValue( iCand, iEvent );
143  mvaRawValues.push_back( response ); // The MVA score
144  mvaValues.push_back( 2.0/(1.0+exp(-2.0*response))-1 ); // MVA output between -1 and 1
145  mvaCategories.push_back( mvaEstimators_[iEstimator]->findCategory( iCand ) );
146  } // end loop over particles
147 
148  writeValueMap(iEvent, src, mvaValues , mvaValueMapNames_ [iEstimator] );
149  writeValueMap(iEvent, src, mvaRawValues , mvaRawValueMapNames_ [iEstimator] );
150  writeValueMap(iEvent, src, mvaCategories, mvaCategoriesMapNames_[iEstimator] );
151 
152  } // end loop over estimators
153 
154 }
std::vector< std::string > mvaValueMapNames_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
std::vector< std::string > mvaRawValueMapNames_
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
bool isValid() const
Definition: HandleBase.h:74
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 157 of file MVAValueMapProducer.h.

References objects.autophobj::filler, cmsBatch::handle, eostools::move(), and edm::Event::put().

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

161 {
162  auto valMap = std::make_unique<edm::ValueMap<T>>();
163  typename edm::ValueMap<T>::Filler filler(*valMap);
164  filler.insert(handle, values.begin(), values.end());
165  filler.fill();
166  iEvent.put(std::move(valMap), label);
167 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
def move(src, dest)
Definition: eostools.py:510

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 >
edm::EDGetToken MVAValueMapProducer< ParticleType >::src_
private
template<class ParticleType >
edm::EDGetToken MVAValueMapProducer< ParticleType >::srcMiniAOD_
private