CMS 3D CMS Logo

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)
 
 MVAVariableManager (const std::string &variableDefinitionFileName)
 

Private Member Functions

void addVariable (const std::string &name, const std::string &formula, const std::string &lowerClip, const std::string &upperClip)
 

Private Attributes

std::vector< std::string > formulas_
 
std::vector< ThreadSafeStringCut< StringObjectFunction< ParticleType >, ParticleType > > functions_
 
const MVAVariableIndexMap< ParticleType > indexMap
 
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 14 of file MVAVariableManager.h.

Constructor & Destructor Documentation

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

Definition at line 18 of file MVAVariableManager.h.

19  : nVars_ (0)
20  {
21  edm::FileInPath variableDefinitionFileEdm(variableDefinitionFileName);
22  std::ifstream file(variableDefinitionFileEdm.fullPath());
23 
24  std::string name, formula, upper, lower;
25  while( true ) {
26  file >> name;
27  if(file.eof()) {
28  break;
29  }
30  if (name.find("#") != std::string::npos) {
32  continue;
33  }
34  file >> formula >> lower >> upper;
35  if (file.eof()) {
36  break;
37  }
38  addVariable(name, formula, lower, upper);
39  }
40  }
void addVariable(const std::string &name, const std::string &formula, const std::string &lowerClip, const std::string &upperClip)

Member Function Documentation

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

Definition at line 87 of file MVAVariableManager.h.

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

89  {
90  bool hasLowerClip = lowerClip.find("None") == std::string::npos;
91  bool hasUpperClip = upperClip.find("None") == std::string::npos;
92  bool isAuxiliary = formula.find("MVAVariableHelper") != std::string::npos ||
93  formula.find("IDValueMapProducer") != std::string::npos ||
94  formula.find("egmPhotonIsolation") != std::string::npos ||
95  formula.find("Rho") != std::string::npos;
96  // *Rho* is still hardcoded...
97  float lowerClipValue = hasLowerClip ? (float)::atof(lowerClip.c_str()) : 0.;
98  float upperClipValue = hasUpperClip ? (float)::atof(upperClip.c_str()) : 0.;
99 
100  if ( !isAuxiliary ) functions_.emplace_back(formula);
101  // Else push back a dummy function since we won't use the
102  // StringObjectFunction to evaluate an auxiliary variable
103  else functions_.emplace_back("pt");
104 
105  formulas_.push_back(formula);
106 
107  int auxIndex = isAuxiliary ? indexMap.getIndex(formula) : -1;
108 
109  MVAVariableInfo varInfo {
110  .hasLowerClip = hasLowerClip,
111  .hasUpperClip = hasUpperClip,
112  .lowerClipValue = lowerClipValue,
113  .upperClipValue = upperClipValue,
114  .auxIndex = auxIndex,
115  };
116 
117  variableInfos_.push_back(varInfo);
118  names_.push_back(name);
119  indexMap_[name] = nVars_;
120  nVars_++;
121  };
std::vector< std::string > names_
std::map< std::string, int > indexMap_
std::vector< std::string > formulas_
std::vector< ThreadSafeStringCut< StringObjectFunction< ParticleType >, ParticleType > > functions_
const MVAVariableIndexMap< ParticleType > indexMap
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 56 of file MVAVariableManager.h.

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

Definition at line 60 of file MVAVariableManager.h.

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

60  {
61  float value;
62 
63  MVAVariableInfo varInfo = variableInfos_[index];
64 
65  if (varInfo.auxIndex >= 0) value = auxVariables[varInfo.auxIndex];
66  else value = functions_[index](particle);
67 
68  if (varInfo.hasLowerClip && value < varInfo.lowerClipValue) {
69  value = varInfo.lowerClipValue;
70  }
71  if (varInfo.hasUpperClip && value > varInfo.upperClipValue) {
72  value = varInfo.upperClipValue;
73  }
74  return value;
75  }
std::vector< ThreadSafeStringCut< StringObjectFunction< ParticleType >, ParticleType > > functions_
std::vector< MVAVariableInfo > variableInfos_
template<class ParticleType>
int MVAVariableManager< ParticleType >::getVarIndex ( const std::string &  name)
inline

Definition at line 42 of file MVAVariableManager.h.

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

43  {
44  std::map<std::string,int>::iterator it = indexMap_.find(name);
45  if (it == indexMap_.end()) {
46  return -1;
47  } else {
48  return it->second;
49  }
50  }
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<ThreadSafeStringCut<StringObjectFunction<ParticleType>, ParticleType> > MVAVariableManager< ParticleType >::functions_
private
template<class ParticleType>
const MVAVariableIndexMap<ParticleType> MVAVariableManager< ParticleType >::indexMap
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