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

std::vector< edm::InputTaggetGlobalInputTags () const
 
std::vector< edm::InputTaggetHelperInputTags () const
 
const std::string getName (int index) const
 
const int getNVars () const
 
float getValue (int index, const edm::Ptr< ParticleType > &ptclPtr, const edm::EventBase &iEvent) const
 
int getVarIndex (std::string &name)
 
int init (const std::string &variableDefinitionFileName)
 
 MVAVariableManager ()
 
 MVAVariableManager (const std::string &variableDefinitionFileName)
 

Private Member Functions

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

Private Attributes

std::vector< std::string > formulas_
 
std::vector< StringObjectFunction< ParticleType > > functions_
 
std::vector< edm::InputTagglobalInputTags_
 
std::vector< edm::InputTaghelperInputTags_
 
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 19 of file MVAVariableManager.h.

Constructor & Destructor Documentation

template<class ParticleType>
MVAVariableManager< ParticleType >::MVAVariableManager ( )
inline

Definition at line 22 of file MVAVariableManager.h.

22  {
23  nVars_ = 0;
24  };
template<class ParticleType>
MVAVariableManager< ParticleType >::MVAVariableManager ( const std::string &  variableDefinitionFileName)
inline

Definition at line 26 of file MVAVariableManager.h.

26  {
27  init(variableDefinitionFileName);
28  };
int init(const std::string &variableDefinitionFileName)

Member Function Documentation

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

Definition at line 118 of file MVAVariableManager.h.

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

118  {
119  bool hasLowerClip = lowerClip.find("None") == std::string::npos;
120  bool hasUpperClip = upperClip.find("None") == std::string::npos;
121  bool fromVariableHelper = formula.find("MVAVariableHelper") != std::string::npos ||
122  formula.find("IDValueMapProducer") != std::string::npos ||
123  formula.find("egmPhotonIsolation") != std::string::npos;
124  float lowerClipValue = hasLowerClip ? (float)::atof(lowerClip.c_str()) : 0.;
125  float upperClipValue = hasUpperClip ? (float)::atof(upperClip.c_str()) : 0.;
126 
127  // *Rho* is the only global variable used ever, so its hardcoded...
128  bool isGlobalVariable = formula.find("Rho") != std::string::npos;
129 
130  if ( !(fromVariableHelper || isGlobalVariable) ) {
132  } else {
133  // Push back a dummy function since we won't use the
134  // StringObjectFunction to evaluate a variable form the helper or a
135  // global variable
137  }
138 
139  formulas_.push_back(formula);
140  if (fromVariableHelper) {
142  }
143  if (isGlobalVariable) {
145  }
146  MVAVariableInfo varInfo = {
147  .hasLowerClip = hasLowerClip,
148  .hasUpperClip = hasUpperClip,
149  .lowerClipValue = lowerClipValue,
150  .upperClipValue = upperClipValue,
151  .fromVariableHelper = fromVariableHelper,
152  .isGlobalVariable = isGlobalVariable
153  };
154  variableInfos_.push_back(varInfo);
155  names_.push_back(name);
156  indexMap_[name] = nVars_;
157  nVars_++;
158  };
std::vector< std::string > names_
std::map< std::string, int > indexMap_
std::vector< std::string > formulas_
std::vector< edm::InputTag > helperInputTags_
std::vector< edm::InputTag > globalInputTags_
std::vector< StringObjectFunction< ParticleType > > functions_
std::vector< MVAVariableInfo > variableInfos_
template<class ParticleType>
std::vector<edm::InputTag> MVAVariableManager< ParticleType >::getGlobalInputTags ( ) const
inline
template<class ParticleType>
std::vector<edm::InputTag> MVAVariableManager< ParticleType >::getHelperInputTags ( ) const
inline
template<class ParticleType>
const std::string MVAVariableManager< ParticleType >::getName ( int  index) const
inline
template<class ParticleType>
const int MVAVariableManager< ParticleType >::getNVars ( ) const
inline

Definition at line 72 of file MVAVariableManager.h.

Referenced by ElectronMVANtuplizer::ElectronMVANtuplizer().

72  {
73  return nVars_;
74  }
template<class ParticleType>
float MVAVariableManager< ParticleType >::getValue ( int  index,
const edm::Ptr< ParticleType > &  ptclPtr,
const edm::EventBase iEvent 
) const
inline

Definition at line 84 of file MVAVariableManager.h.

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

84  {
85  float value;
86  MVAVariableInfo varInfo = variableInfos_[index];
87  if (varInfo.fromVariableHelper) {
89  iEvent.getByLabel(edm::InputTag(formulas_[index]), vMap);
90  value = (*vMap)[ptclPtr];
91  } else if (varInfo.isGlobalVariable) {
92  edm::Handle<double> valueHandle;
93  iEvent.getByLabel(edm::InputTag(formulas_[index]), valueHandle);
94  value = *valueHandle;
95  } else {
96  value = functions_[index](*ptclPtr);
97  }
98  if (varInfo.hasLowerClip && value < varInfo.lowerClipValue) {
99  value = varInfo.lowerClipValue;
100  }
101  if (varInfo.hasUpperClip && value > varInfo.upperClipValue) {
102  value = varInfo.upperClipValue;
103  }
104  return value;
105  }
std::vector< std::string > formulas_
std::vector< StringObjectFunction< ParticleType > > functions_
bool getByLabel(InputTag const &, Handle< T > &) const
Definition: EventBase.h:94
std::vector< MVAVariableInfo > variableInfos_
template<class ParticleType>
int MVAVariableManager< ParticleType >::getVarIndex ( std::string &  name)
inline

Definition at line 59 of file MVAVariableManager.h.

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

59  {
60  std::map<std::string,int>::iterator it = indexMap_.find(name);
61  if (it == indexMap_.end()) {
62  return -1;
63  } else {
64  return it->second;
65  }
66  }
std::map< std::string, int > indexMap_
template<class ParticleType>
int MVAVariableManager< ParticleType >::init ( const std::string &  variableDefinitionFileName)
inline

Definition at line 30 of file MVAVariableManager.h.

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

30  {
31  nVars_ = 0;
32 
33  variableInfos_.clear();
34  functions_.clear();
35  formulas_.clear();
36  names_.clear();
37  helperInputTags_.clear();
38  globalInputTags_.clear();
39 
40  edm::FileInPath variableDefinitionFileEdm(variableDefinitionFileName);
41  std::ifstream file(variableDefinitionFileEdm.fullPath());
42 
43  std::string name, formula, upper, lower;
44  while( true ) {
45  file >> name;
46  if (name.find("#") != std::string::npos) {
48  continue;
49  }
50  file >> formula >> lower >> upper;
51  if (file.eof()) {
52  break;
53  }
54  addVariable(name, formula, lower, upper);
55  }
56  return nVars_;
57  };
void addVariable(std::string &name, std::string &formula, std::string &lowerClip, std::string &upperClip)
std::vector< std::string > names_
std::vector< std::string > formulas_
std::vector< edm::InputTag > helperInputTags_
std::vector< edm::InputTag > globalInputTags_
std::vector< StringObjectFunction< ParticleType > > functions_
std::vector< MVAVariableInfo > variableInfos_

Member Data Documentation

template<class ParticleType>
std::vector<std::string> MVAVariableManager< ParticleType >::formulas_
private
template<class ParticleType>
std::vector<StringObjectFunction<ParticleType> > MVAVariableManager< ParticleType >::functions_
private
template<class ParticleType>
std::vector<edm::InputTag> MVAVariableManager< ParticleType >::globalInputTags_
private
template<class ParticleType>
std::vector<edm::InputTag> MVAVariableManager< ParticleType >::helperInputTags_
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