CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Classes | Public Member Functions | Private Member Functions | Private Attributes
MVAVariableManager< ParticleType > Class Template Reference

#include <MVAVariableManager.h>

Classes

struct  MVAVariableInfo
 

Public Member Functions

const std::string & getName (int index) const
 
int getNVars () const
 
float getValue (int index, const ParticleType &particle, const std::vector< float > &auxVariables) const
 
int getVarIndex (const std::string &name)
 
template<class IndexMap >
 MVAVariableManager (const std::string &variableDefinitionFileName, IndexMap const &indexMap)
 

Private Member Functions

template<class IndexMap >
void addVariable (const std::string &name, const std::string &formula, const std::string &lowerClip, const std::string &upperClip, IndexMap const &indexMap)
 

Private Attributes

std::vector< std::string > formulas_
 
std::vector< ThreadSafeFunctor
< StringObjectFunction
< ParticleType > > > 
functions_
 
std::map< std::string, int > indexMap_
 
std::vector< std::string > names_
 
int nVars_
 
std::vector< MVAVariableInfovariableInfos_
 

Detailed Description

template<class ParticleType>
class MVAVariableManager< ParticleType >

Definition at line 12 of file MVAVariableManager.h.

Constructor & Destructor Documentation

template<class ParticleType>
template<class IndexMap >
MVAVariableManager< ParticleType >::MVAVariableManager ( const std::string &  variableDefinitionFileName,
IndexMap const &  indexMap 
)
inline

Definition at line 15 of file MVAVariableManager.h.

15  : nVars_(0) {
16  edm::FileInPath variableDefinitionFileEdm(variableDefinitionFileName);
17  std::ifstream file(variableDefinitionFileEdm.fullPath());
18 
19  std::string name, formula, upper, lower;
20  while (true) {
21  file >> name;
22  if (file.eof()) {
23  break;
24  }
25  if (name.find('#') != std::string::npos) {
27  continue;
28  }
29  file >> formula >> lower >> upper;
30  if (file.eof()) {
31  break;
32  }
33  addVariable(name, formula, lower, upper, indexMap);
34  }
35  }
void addVariable(const std::string &name, const std::string &formula, const std::string &lowerClip, const std::string &upperClip, IndexMap const &indexMap)

Member Function Documentation

template<class ParticleType>
template<class IndexMap >
void MVAVariableManager< ParticleType >::addVariable ( const std::string &  name,
const std::string &  formula,
const std::string &  lowerClip,
const std::string &  upperClip,
IndexMap const &  indexMap 
)
inlineprivate

Definition at line 79 of file MVAVariableManager.h.

Referenced by MVAVariableManager< reco::GsfElectron >::MVAVariableManager().

83  {
84  bool hasLowerClip = lowerClip.find("None") == std::string::npos;
85  bool hasUpperClip = upperClip.find("None") == std::string::npos;
86  bool isAuxiliary = formula.find("Rho") != std::string::npos; // *Rho* is still hardcoded...
87  float lowerClipValue = hasLowerClip ? (float)::atof(lowerClip.c_str()) : 0.;
88  float upperClipValue = hasUpperClip ? (float)::atof(upperClip.c_str()) : 0.;
89 
90  if (!isAuxiliary)
91  functions_.emplace_back(formula);
92  // Else push back a dummy function since we won't use the
93  // StringObjectFunction to evaluate an auxiliary variable
94  else
95  functions_.emplace_back("pt");
96 
97  formulas_.push_back(formula);
98 
99  int auxIndex = isAuxiliary ? indexMap.at(formula) : -1;
100 
101  MVAVariableInfo varInfo{
102  .hasLowerClip = hasLowerClip,
103  .hasUpperClip = hasUpperClip,
104  .lowerClipValue = lowerClipValue,
105  .upperClipValue = upperClipValue,
106  .auxIndex = auxIndex,
107  };
108 
109  variableInfos_.push_back(varInfo);
110  names_.push_back(name);
111  indexMap_[name] = nVars_;
112  nVars_++;
113  };
std::vector< ThreadSafeFunctor< StringObjectFunction< ParticleType > > > functions_
std::vector< std::string > names_
std::map< std::string, int > indexMap_
std::vector< std::string > formulas_
std::vector< MVAVariableInfo > variableInfos_
template<class ParticleType>
const std::string& MVAVariableManager< ParticleType >::getName ( int  index) const
inline
template<class ParticleType>
int MVAVariableManager< ParticleType >::getNVars ( ) const
inline

Definition at line 48 of file MVAVariableManager.h.

48 { return nVars_; }
template<class ParticleType>
float MVAVariableManager< ParticleType >::getValue ( int  index,
const ParticleType &  particle,
const std::vector< float > &  auxVariables 
) const
inline

Definition at line 50 of file MVAVariableManager.h.

Referenced by PhotonMVANtuplizer::analyze(), ElectronMVANtuplizer::analyze(), PhotonMVAEstimator::mvaValue(), and ElectronMVAEstimatorRun2::mvaValue().

50  {
51  float value;
52 
53  MVAVariableInfo varInfo = variableInfos_[index];
54 
55  if (varInfo.auxIndex >= 0)
56  value = auxVariables[varInfo.auxIndex];
57  else
58  value = functions_[index](particle);
59 
60  if (varInfo.hasLowerClip && value < varInfo.lowerClipValue) {
61  value = varInfo.lowerClipValue;
62  }
63  if (varInfo.hasUpperClip && value > varInfo.upperClipValue) {
64  value = varInfo.upperClipValue;
65  }
66  return value;
67  }
std::vector< ThreadSafeFunctor< StringObjectFunction< ParticleType > > > functions_
std::vector< MVAVariableInfo > variableInfos_
template<class ParticleType>
int MVAVariableManager< ParticleType >::getVarIndex ( const std::string &  name)
inline

Definition at line 37 of file MVAVariableManager.h.

Referenced by ElectronMVAEstimatorRun2::init(), and PhotonMVAEstimator::PhotonMVAEstimator().

37  {
38  std::map<std::string, int>::iterator it = indexMap_.find(name);
39  if (it == indexMap_.end()) {
40  return -1;
41  } else {
42  return it->second;
43  }
44  }
std::map< std::string, int > indexMap_

Member Data Documentation

template<class ParticleType>
std::vector<std::string> MVAVariableManager< ParticleType >::formulas_
private
template<class ParticleType>
std::vector<ThreadSafeFunctor<StringObjectFunction<ParticleType> > > MVAVariableManager< ParticleType >::functions_
private
template<class ParticleType>
std::map<std::string, int> MVAVariableManager< ParticleType >::indexMap_
private
template<class ParticleType>
std::vector<std::string> MVAVariableManager< ParticleType >::names_
private
template<class ParticleType>
int MVAVariableManager< ParticleType >::nVars_
private
template<class ParticleType>
std::vector<MVAVariableInfo> MVAVariableManager< ParticleType >::variableInfos_
private