CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
BaseMVAValueMapProducer< T > Class Template Reference

#include <PhysicsTools/PatAlgos/plugins/BaseMVAValueMapProducer.cc>

Inheritance diagram for BaseMVAValueMapProducer< T >:
edm::stream::EDProducer<>

Public Member Functions

 BaseMVAValueMapProducer (const edm::ParameterSet &iConfig)
 
void setValue (const std::string var, float val)
 
 ~BaseMVAValueMapProducer () 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)
 
static edm::ParameterSetDescription getDescription ()
 

Private Member Functions

void beginStream (edm::StreamID) override
 
void endStream () override
 
virtual void fillAdditionalVariables (const T &)
 
void produce (edm::Event &, const edm::EventSetup &) override
 
virtual void readAdditionalCollections (edm::Event &, const edm::EventSetup &)
 to be implemented in derived classes, filling values for additional variables More...
 

Private Attributes

std::vector< std::pair< std::string, StringObjectFunction< T, true > > > funcs_
 
bool isClassifier_
 
std::string name_
 
std::map< std::string, size_t > positions_
 
TMVA::Reader reader_
 
edm::EDGetTokenT< edm::View< T > > src_
 
std::vector< float > values_
 
std::vector< std::string > variablesOrder_
 

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<typename T>
class BaseMVAValueMapProducer< T >

Description: [one line class summary]

Implementation: [Notes on implementation]

Definition at line 50 of file BaseMVAValueMapProducer.h.

Constructor & Destructor Documentation

template<typename T>
BaseMVAValueMapProducer< T >::BaseMVAValueMapProducer ( const edm::ParameterSet iConfig)
inlineexplicit

Definition at line 52 of file BaseMVAValueMapProducer.h.

52  :
53  src_(consumes<edm::View<T>>(iConfig.getParameter<edm::InputTag>("src"))),
54  variablesOrder_(iConfig.getParameter<std::vector<std::string>>("variablesOrder")),
55  name_(iConfig.getParameter<std::string>("name")),
56  isClassifier_(iConfig.getParameter<bool>("isClassifier"))
57  {
58  edm::ParameterSet const & varsPSet = iConfig.getParameter<edm::ParameterSet>("variables");
59  for (const std::string & vname : varsPSet.getParameterNamesForType<std::string>()) {
60  funcs_.emplace_back(std::pair<std::string,StringObjectFunction<T,true>>(vname,varsPSet.getParameter<std::string>(vname)));
61  }
62 
63  values_.resize(variablesOrder_.size());
64  size_t i=0;
65  for(const auto & v : variablesOrder_){
66  positions_[v]=i;
67  reader_.AddVariable(v,(&values_.front())+i);
68  i++;
69  }
70 // reader_.BookMVA(name_,iConfig.getParameter<edm::FileInPath>("weightFile").fullPath() );
72  produces<edm::ValueMap<float>>();
73 
74  }
std::vector< float > values_
T getParameter(std::string const &) const
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:194
std::map< std::string, size_t > positions_
std::vector< std::string > variablesOrder_
edm::EDGetTokenT< edm::View< T > > src_
TMVA::IMethod * loadTMVAWeights(TMVA::Reader *reader, const std::string &method, const std::string &weightFile, bool verbose=false)
std::string fullPath() const
Definition: FileInPath.cc:197
std::vector< std::pair< std::string, StringObjectFunction< T, true > > > funcs_
template<typename T>
BaseMVAValueMapProducer< T >::~BaseMVAValueMapProducer ( )
inlineoverride

Definition at line 75 of file BaseMVAValueMapProducer.h.

75 {}

Member Function Documentation

template<typename T>
void BaseMVAValueMapProducer< T >::beginStream ( edm::StreamID  )
inlineoverrideprivate

Definition at line 85 of file BaseMVAValueMapProducer.h.

85 {};
template<typename T>
void BaseMVAValueMapProducer< T >::endStream ( )
inlineoverrideprivate

Definition at line 87 of file BaseMVAValueMapProducer.h.

87 {};
template<typename T>
virtual void BaseMVAValueMapProducer< T >::fillAdditionalVariables ( const T )
inlineprivatevirtual

Reimplemented in BJetEnergyRegressionMVA.

Definition at line 91 of file BaseMVAValueMapProducer.h.

Referenced by BaseMVAValueMapProducer< T >::produce().

91 {}
template<typename T >
void BaseMVAValueMapProducer< T >::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 147 of file BaseMVAValueMapProducer.h.

References edm::ConfigurationDescriptions::add(), BaseMVAValueMapProducer< T >::getDescription(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by BaseMVAValueMapProducer< pat::Jet >::setValue().

147  {
149  std::string modname;
150  if (typeid(T) == typeid(pat::Jet)) modname+="Jet";
151  else if (typeid(T) == typeid(pat::Muon)) modname+="Muon";
152  else if (typeid(T) == typeid(pat::Electron)) modname+="Ele";
153  modname+="BaseMVAValueMapProducer";
154  descriptions.add(modname,desc);
155 }
static edm::ParameterSetDescription getDescription()
Analysis-level electron class.
Definition: Electron.h:52
Analysis-level calorimeter jet class.
Definition: Jet.h:80
void add(std::string const &label, ParameterSetDescription const &psetDescription)
long double T
Analysis-level muon class.
Definition: Muon.h:50
template<typename T >
edm::ParameterSetDescription BaseMVAValueMapProducer< T >::getDescription ( )
static

Definition at line 132 of file BaseMVAValueMapProducer.h.

References edm::ParameterSetDescription::add(), edm::ParameterSetDescription::setAllowAnything(), AlCaHLTBitMon_QueryRunRegistry::string, and objects.autophobj::variables.

Referenced by BaseMVAValueMapProducer< T >::fillDescriptions(), BJetEnergyRegressionMVA::fillDescriptions(), and BaseMVAValueMapProducer< pat::Jet >::setValue().

132  {
134  desc.add<edm::InputTag>("src")->setComment("input physics object collection");
135  desc.add<std::vector<std::string>>("variablesOrder")->setComment("ordered list of MVA input variable names");
136  desc.add<std::string>("name")->setComment("output score variable name");
137  desc.add<bool>("isClassifier")->setComment("is a classifier discriminator");
139  variables.setAllowAnything();
140  desc.add<edm::ParameterSetDescription>("variables", variables)->setComment("list of input variable definitions");
141  desc.add<edm::FileInPath>("weightFile")->setComment("xml weight file");
142  return desc;
143 }
void setAllowAnything()
allow any parameter label/value pairs
ParameterDescriptionBase * add(U const &iLabel, T const &value)
template<typename T >
void BaseMVAValueMapProducer< T >::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 107 of file BaseMVAValueMapProducer.h.

References edm::helper::Filler< Map >::fill(), BaseMVAValueMapProducer< T >::fillAdditionalVariables(), objects.autophobj::filler, BaseMVAValueMapProducer< T >::funcs_, edm::Event::getByToken(), edm::helper::Filler< Map >::insert(), BaseMVAValueMapProducer< T >::isClassifier_, eostools::move(), BaseMVAValueMapProducer< T >::name_, connectstrParser::o, AlCaHLTBitMon_ParallelJobs::p, BaseMVAValueMapProducer< T >::positions_, edm::Event::put(), BaseMVAValueMapProducer< T >::readAdditionalCollections(), BaseMVAValueMapProducer< T >::reader_, TrackRefitter_38T_cff::src, BaseMVAValueMapProducer< T >::src_, and BaseMVAValueMapProducer< T >::values_.

Referenced by BaseMVAValueMapProducer< pat::Jet >::beginStream().

108 {
110  iEvent.getByToken(src_, src);
111  readAdditionalCollections(iEvent,iSetup);
112 
113  std::vector<float> mvaOut;
114  mvaOut.reserve(src->size());
115  for(auto const & o: *src) {
116  for(auto const & p : funcs_ ){
117  values_[positions_[p.first]]=p.second(o);
118  }
120  mvaOut.push_back(isClassifier_ ? reader_.EvaluateMVA(name_) : reader_.EvaluateRegression(name_)[0]);
121  }
122  std::unique_ptr<edm::ValueMap<float>> mvaV(new edm::ValueMap<float>());
124  filler.insert(src,mvaOut.begin(),mvaOut.end());
125  filler.fill();
126  iEvent.put(std::move(mvaV));
127 
128 }
std::vector< float > values_
virtual void fillAdditionalVariables(const T &)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
std::map< std::string, size_t > positions_
edm::EDGetTokenT< edm::View< T > > src_
std::vector< std::pair< std::string, StringObjectFunction< T, true > > > funcs_
def move(src, dest)
Definition: eostools.py:510
virtual void readAdditionalCollections(edm::Event &, const edm::EventSetup &)
to be implemented in derived classes, filling values for additional variables
template<typename T>
virtual void BaseMVAValueMapProducer< T >::readAdditionalCollections ( edm::Event ,
const edm::EventSetup  
)
inlineprivatevirtual

to be implemented in derived classes, filling values for additional variables

Reimplemented in BJetEnergyRegressionMVA.

Definition at line 90 of file BaseMVAValueMapProducer.h.

Referenced by BaseMVAValueMapProducer< T >::produce().

90 {}
template<typename T>
void BaseMVAValueMapProducer< T >::setValue ( const std::string  var,
float  val 
)
inline

Member Data Documentation

template<typename T>
std::vector<std::pair<std::string,StringObjectFunction<T,true> > > BaseMVAValueMapProducer< T >::funcs_
private
template<typename T>
bool BaseMVAValueMapProducer< T >::isClassifier_
private

Definition at line 101 of file BaseMVAValueMapProducer.h.

Referenced by BaseMVAValueMapProducer< T >::produce().

template<typename T>
std::string BaseMVAValueMapProducer< T >::name_
private
template<typename T>
std::map<std::string,size_t> BaseMVAValueMapProducer< T >::positions_
private
template<typename T>
TMVA::Reader BaseMVAValueMapProducer< T >::reader_
private
template<typename T>
edm::EDGetTokenT<edm::View<T> > BaseMVAValueMapProducer< T >::src_
private

Definition at line 94 of file BaseMVAValueMapProducer.h.

Referenced by BaseMVAValueMapProducer< T >::produce().

template<typename T>
std::vector<float> BaseMVAValueMapProducer< T >::values_
private
template<typename T>
std::vector<std::string> BaseMVAValueMapProducer< T >::variablesOrder_
private