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 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 16 of file MVAVariableManager.h.

16  : nVars_(0) {
17  edm::FileInPath variableDefinitionFileEdm(variableDefinitionFileName);
18  std::ifstream file(variableDefinitionFileEdm.fullPath());
19 
20  std::string name, formula, upper, lower;
21  while (true) {
22  file >> name;
23  if (file.eof()) {
24  break;
25  }
26  if (name.find("#") != std::string::npos) {
28  continue;
29  }
30  file >> formula >> lower >> upper;
31  if (file.eof()) {
32  break;
33  }
34  addVariable(name, formula, lower, upper);
35  }
36  }
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 79 of file MVAVariableManager.h.

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

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

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

Definition at line 51 of file MVAVariableManager.h.

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

51  {
52  float value;
53 
54  MVAVariableInfo varInfo = variableInfos_[index];
55 
56  if (varInfo.auxIndex >= 0)
57  value = auxVariables[varInfo.auxIndex];
58  else
59  value = functions_[index](particle);
60 
61  if (varInfo.hasLowerClip && value < varInfo.lowerClipValue) {
62  value = varInfo.lowerClipValue;
63  }
64  if (varInfo.hasUpperClip && value > varInfo.upperClipValue) {
65  value = varInfo.upperClipValue;
66  }
67  return value;
68  }
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 38 of file MVAVariableManager.h.

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

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