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

◆ MVAVariableManager()

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  }

Member Function Documentation

◆ addVariable()

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.

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

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

49 { 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 51 of file MVAVariableManager.h.

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  }

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

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  }

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<ThreadSafeStringCut<StringObjectFunction<ParticleType>, ParticleType> > MVAVariableManager< ParticleType >::functions_
private

◆ indexMap

template<class ParticleType>
const MVAVariableIndexMap MVAVariableManager< ParticleType >::indexMap
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:112
MVAVariableManager::names_
std::vector< std::string > names_
Definition: MVAVariableManager.h:119
MVAVariableManager::indexMap
const MVAVariableIndexMap indexMap
Definition: MVAVariableManager.h:122
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:118
MVAVariableManager::variableInfos_
std::vector< MVAVariableInfo > variableInfos_
Definition: MVAVariableManager.h:116
edm::FileInPath
Definition: FileInPath.h:64
MVAVariableManager::addVariable
void addVariable(const std::string &name, const std::string &formula, const std::string &lowerClip, const std::string &upperClip)
Definition: MVAVariableManager.h:79
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:120
MVAVariableIndexMap::getIndex
int getIndex(std::string const &name) const
Definition: MVAVariableHelper.h:17
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< ThreadSafeStringCut< StringObjectFunction< ParticleType >, ParticleType > > functions_
Definition: MVAVariableManager.h:117