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)
 
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

◆ MVAVariableManager()

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  }

Member Function Documentation

◆ addVariable()

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.

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  };

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

◆ getName()

template<class ParticleType>
const std::string& MVAVariableManager< ParticleType >::getName ( int  index) const
inline

◆ getNVars()

template<class ParticleType>
int MVAVariableManager< ParticleType >::getNVars ( ) const
inline

Definition at line 48 of file MVAVariableManager.h.

48 { return nVars_; }

◆ getValue()

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.

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  }

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

◆ getVarIndex()

template<class ParticleType>
int MVAVariableManager< ParticleType >::getVarIndex ( const std::string &  name)
inline

Definition at line 37 of file MVAVariableManager.h.

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  }

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

Member Data Documentation

◆ formulas_

template<class ParticleType>
std::vector<std::string> MVAVariableManager< ParticleType >::formulas_
private

◆ functions_

template<class ParticleType>
std::vector<ThreadSafeFunctor<StringObjectFunction<ParticleType> > > MVAVariableManager< ParticleType >::functions_
private

◆ indexMap_

template<class ParticleType>
std::map<std::string, int> MVAVariableManager< ParticleType >::indexMap_
private

◆ names_

template<class ParticleType>
std::vector<std::string> MVAVariableManager< ParticleType >::names_
private

◆ nVars_

template<class ParticleType>
int MVAVariableManager< ParticleType >::nVars_
private

◆ variableInfos_

template<class ParticleType>
std::vector<MVAVariableInfo> MVAVariableManager< ParticleType >::variableInfos_
private
MVAVariableManager::nVars_
int nVars_
Definition: MVAVariableManager.h:113
MVAVariableManager::names_
std::vector< std::string > names_
Definition: MVAVariableManager.h:120
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
pfMETCorrectionType0_cfi.formula
formula
Definition: pfMETCorrectionType0_cfi.py:46
MVAVariableManager::formulas_
std::vector< std::string > formulas_
Definition: MVAVariableManager.h:119
MVAVariableManager::addVariable
void addVariable(const std::string &name, const std::string &formula, const std::string &lowerClip, const std::string &upperClip, IndexMap const &indexMap)
Definition: MVAVariableManager.h:79
MVAVariableManager::variableInfos_
std::vector< MVAVariableInfo > variableInfos_
Definition: MVAVariableManager.h:117
edm::FileInPath
Definition: FileInPath.h:64
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
FrontierConditions_GlobalTag_cff.file
file
Definition: FrontierConditions_GlobalTag_cff.py:13
value
Definition: value.py:1
MVAVariableManager::indexMap_
std::map< std::string, int > indexMap_
Definition: MVAVariableManager.h:121
relativeConstraints.value
value
Definition: relativeConstraints.py:53
pileupCalc.upper
upper
Definition: pileupCalc.py:214
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
MVAVariableManager::functions_
std::vector< ThreadSafeFunctor< StringObjectFunction< ParticleType > > > functions_
Definition: MVAVariableManager.h:118