CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
PhotonMVAEstimator Class Reference
Inheritance diagram for PhotonMVAEstimator:
AnyMVAEstimatorRun2Base

Public Member Functions

int findCategory (const reco::Candidate *candPtr) const override
 
float mvaValue (const reco::Candidate *candPtr, std::vector< float > const &auxVars, int &iCategory) const override
 
 PhotonMVAEstimator (const edm::ParameterSet &conf)
 
 ~PhotonMVAEstimator () override
 
- Public Member Functions inherited from AnyMVAEstimatorRun2Base
 AnyMVAEstimatorRun2Base (const edm::ParameterSet &conf)
 
 AnyMVAEstimatorRun2Base (const ::std::string &mvaName, const ::std::string &mvaTag, int nCategories, bool debug)
 
const std::string & getName () const
 
int getNCategories () const
 
const std::string & getTag () const
 
bool isDebug () const
 
float mvaValue (const reco::Candidate *candidate, std::vector< float > const &auxVariables) const
 
virtual ~AnyMVAEstimatorRun2Base ()
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 

Private Member Functions

int findCategory (reco::Photon const &photon) const
 

Private Attributes

std::vector< ThreadSafeFunctor
< StringCutObjectSelector
< reco::Photon > > > 
categoryFunctions_
 
std::unique_ptr< EffectiveAreaseffectiveAreas_
 
std::vector< std::unique_ptr
< const GBRForest > > 
gbrForests_
 
MVAVariableManager< reco::PhotonmvaVarMngr_
 
int nCategories_
 
std::vector< int > nVariables_
 
double phoIsoCutoff_
 
std::vector< double > phoIsoPtScalingCoeff_
 
std::vector< std::vector< int > > variables_
 

Detailed Description

Definition at line 15 of file PhotonMVAEstimator.cc.

Constructor & Destructor Documentation

PhotonMVAEstimator::PhotonMVAEstimator ( const edm::ParameterSet conf)

Definition at line 52 of file PhotonMVAEstimator.cc.

References categoryFunctions_, createGBRForest(), GOODCOLL_filter_cfg::cut, effectiveAreas_, Exception, gbrForests_, AnyMVAEstimatorRun2Base::getNCategories(), edm::ParameterSet::getParameter(), AnyMVAEstimatorRun2Base::getTag(), MVAVariableManager< ParticleType >::getVarIndex(), mps_fire::i, dqmiolumiharvest::j, mvaVarMngr_, nVariables_, phoIsoCutoff_, phoIsoPtScalingCoeff_, and variables_.

54  mvaVarMngr_(conf.getParameter<std::string>("variableDefinition"), MVAVariableHelper::indexMap()) {
55  //
56  // Construct the MVA estimators
57  //
58  if (getTag() == "Run2Spring16NonTrigV1") {
60  std::make_unique<EffectiveAreas>((conf.getParameter<edm::FileInPath>("effAreasConfigFile")).fullPath());
61  phoIsoPtScalingCoeff_ = conf.getParameter<std::vector<double>>("phoIsoPtScalingCoeff");
62  phoIsoCutoff_ = conf.getParameter<double>("phoIsoCutoff");
63  }
64 
65  const auto weightFileNames = conf.getParameter<std::vector<std::string>>("weightFileNames");
66  const auto categoryCutStrings = conf.getParameter<std::vector<std::string>>("categoryCuts");
67 
68  if ((int)(categoryCutStrings.size()) != getNCategories())
69  throw cms::Exception("MVA config failure: ")
70  << "wrong number of category cuts in PhotonMVAEstimator" << getTag() << std::endl;
71 
72  for (auto const& cut : categoryCutStrings)
73  categoryFunctions_.emplace_back(cut);
74 
75  // Initialize GBRForests
76  if (static_cast<int>(weightFileNames.size()) != getNCategories())
77  throw cms::Exception("MVA config failure: ")
78  << "wrong number of weightfiles in PhotonMVAEstimator" << getTag() << std::endl;
79 
80  gbrForests_.clear();
81  // Create a TMVA reader object for each category
82  for (int i = 0; i < getNCategories(); i++) {
83  std::vector<int> variablesInCategory;
84 
85  std::vector<std::string> variableNamesInCategory;
86  gbrForests_.push_back(createGBRForest(weightFileNames[i], variableNamesInCategory));
87 
88  nVariables_.push_back(variableNamesInCategory.size());
89 
90  variables_.push_back(variablesInCategory);
91 
92  for (int j = 0; j < nVariables_[i]; ++j) {
93  int index = mvaVarMngr_.getVarIndex(variableNamesInCategory[j]);
94  if (index == -1) {
95  throw cms::Exception("MVA config failure: ")
96  << "Concerning PhotonMVAEstimator" << getTag() << std::endl
97  << "Variable " << variableNamesInCategory[j] << " not found in variable definition file!" << std::endl;
98  }
99  variables_[i].push_back(index);
100  }
101  }
102 }
std::vector< std::unique_ptr< const GBRForest > > gbrForests_
AnyMVAEstimatorRun2Base(const edm::ParameterSet &conf)
MVAVariableManager< reco::Photon > mvaVarMngr_
const std::string & getTag() const
std::vector< ThreadSafeFunctor< StringCutObjectSelector< reco::Photon > > > categoryFunctions_
std::vector< int > nVariables_
std::vector< double > phoIsoPtScalingCoeff_
int getVarIndex(const std::string &name)
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::unique_ptr< EffectiveAreas > effectiveAreas_
std::vector< std::vector< int > > variables_
std::unique_ptr< const GBRForest > createGBRForest(const std::string &weightsFile)
PhotonMVAEstimator::~PhotonMVAEstimator ( )
inlineoverride

Definition at line 19 of file PhotonMVAEstimator.cc.

19 {};

Member Function Documentation

static void PhotonMVAEstimator::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static
int PhotonMVAEstimator::findCategory ( const reco::Candidate candPtr) const
overridevirtual

Implements AnyMVAEstimatorRun2Base.

Definition at line 149 of file PhotonMVAEstimator.cc.

References Exception.

Referenced by mvaValue().

149  {
150  const reco::Photon* phoPtr = dynamic_cast<const reco::Photon*>(candPtr);
151  if (phoPtr == nullptr) {
152  throw cms::Exception("MVA failure: ")
153  << " given particle is expected to be reco::Photon or pat::Photon," << std::endl
154  << " but appears to be neither" << std::endl;
155  }
156 
157  return findCategory(*phoPtr);
158 }
int findCategory(const reco::Candidate *candPtr) const override
int PhotonMVAEstimator::findCategory ( reco::Photon const &  photon) const
private

Definition at line 160 of file PhotonMVAEstimator.cc.

References categoryFunctions_, AnyMVAEstimatorRun2Base::getNCategories(), AnyMVAEstimatorRun2Base::getTag(), mps_fire::i, reco::LeafCandidate::pt(), and reco::Photon::superCluster().

160  {
161  for (int i = 0; i < getNCategories(); ++i) {
162  if (categoryFunctions_[i](photon))
163  return i;
164  }
165 
166  edm::LogWarning("MVA warning") << "category not defined for particle with pt " << photon.pt() << " GeV, eta "
167  << photon.superCluster()->eta() << " in PhotonMVAEstimator" << getTag();
168 
169  return -1;
170 }
const std::string & getTag() const
std::vector< ThreadSafeFunctor< StringCutObjectSelector< reco::Photon > > > categoryFunctions_
Log< level::Warning, false > LogWarning
float PhotonMVAEstimator::mvaValue ( const reco::Candidate candPtr,
std::vector< float > const &  auxVars,
int &  iCategory 
) const
overridevirtual

Implements AnyMVAEstimatorRun2Base.

Definition at line 104 of file PhotonMVAEstimator.cc.

References funct::abs(), gather_cfg::cout, effectiveAreas_, Exception, findCategory(), gbrForests_, MVAVariableManager< ParticleType >::getName(), AnyMVAEstimatorRun2Base::getTag(), MVAVariableManager< ParticleType >::getValue(), mps_fire::i, AnyMVAEstimatorRun2Base::isDebug(), SiStripPI::max, mvaVarMngr_, nVariables_, phoIsoCutoff_, phoIsoPtScalingCoeff_, reco::LeafCandidate::pt(), uploadConditions::response, reco::Photon::superCluster(), and variables_.

106  {
107  const reco::Photon* phoPtr = dynamic_cast<const reco::Photon*>(candPtr);
108  if (phoPtr == nullptr) {
109  throw cms::Exception("MVA failure: ")
110  << " given particle is expected to be reco::Photon or pat::Photon," << std::endl
111  << " but appears to be neither" << std::endl;
112  }
113 
114  iCategory = findCategory(phoPtr);
115 
116  std::vector<float> vars;
117 
118  vars.reserve(nVariables_[iCategory]);
119  for (int i = 0; i < nVariables_[iCategory]; ++i) {
120  vars.push_back(mvaVarMngr_.getValue(variables_[iCategory][i], *phoPtr, auxVars));
121  }
122 
123  // Special case for Spring16!
124  if (getTag() == "Run2Spring16NonTrigV1" and iCategory == 1) { // Endcap category
125  // Raw value for EB only, because of loss of transparency in EE
126  // for endcap MVA only in 2016
127  double eA = effectiveAreas_->getEffectiveArea(std::abs(phoPtr->superCluster()->eta()));
128  double phoIsoCorr = vars[10] - eA * (double)vars[9] - phoIsoPtScalingCoeff_.at(1) * phoPtr->pt();
129  vars[10] = std::max(phoIsoCorr, phoIsoCutoff_);
130  }
131 
132  if (isDebug()) {
133  std::cout << " *** Inside PhotonMVAEstimator" << getTag() << std::endl;
134  std::cout << " category " << iCategory << std::endl;
135  for (int i = 0; i < nVariables_[iCategory]; ++i) {
136  std::cout << " " << mvaVarMngr_.getName(variables_[iCategory][i]) << " " << vars[i] << std::endl;
137  }
138  }
139 
140  const float response = gbrForests_.at(iCategory)->GetResponse(vars.data());
141 
142  if (isDebug()) {
143  std::cout << " ### MVA " << response << std::endl << std::endl;
144  }
145 
146  return response;
147 }
std::vector< std::unique_ptr< const GBRForest > > gbrForests_
const std::string & getName(int index) const
double pt() const final
transverse momentum
int findCategory(const reco::Candidate *candPtr) const override
MVAVariableManager< reco::Photon > mvaVarMngr_
float getValue(int index, const ParticleType &particle, const std::vector< float > &auxVariables) const
const std::string & getTag() const
reco::SuperClusterRef superCluster() const override
Ref to SuperCluster.
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< int > nVariables_
std::vector< double > phoIsoPtScalingCoeff_
std::unique_ptr< EffectiveAreas > effectiveAreas_
tuple cout
Definition: gather_cfg.py:144
std::vector< std::vector< int > > variables_
vars
Definition: DeepTauId.cc:164

Member Data Documentation

std::vector<ThreadSafeFunctor<StringCutObjectSelector<reco::Photon> > > PhotonMVAEstimator::categoryFunctions_
private

Definition at line 33 of file PhotonMVAEstimator.cc.

Referenced by findCategory(), and PhotonMVAEstimator().

std::unique_ptr<EffectiveAreas> PhotonMVAEstimator::effectiveAreas_
private

Definition at line 47 of file PhotonMVAEstimator.cc.

Referenced by mvaValue(), and PhotonMVAEstimator().

std::vector<std::unique_ptr<const GBRForest> > PhotonMVAEstimator::gbrForests_
private

Definition at line 37 of file PhotonMVAEstimator.cc.

Referenced by mvaValue(), and PhotonMVAEstimator().

MVAVariableManager<reco::Photon> PhotonMVAEstimator::mvaVarMngr_
private

Definition at line 44 of file PhotonMVAEstimator.cc.

Referenced by mvaValue(), and PhotonMVAEstimator().

int PhotonMVAEstimator::nCategories_
private

Definition at line 32 of file PhotonMVAEstimator.cc.

std::vector<int> PhotonMVAEstimator::nVariables_
private

Definition at line 34 of file PhotonMVAEstimator.cc.

Referenced by mvaValue(), and PhotonMVAEstimator().

double PhotonMVAEstimator::phoIsoCutoff_
private

Definition at line 49 of file PhotonMVAEstimator.cc.

Referenced by mvaValue(), and PhotonMVAEstimator().

std::vector<double> PhotonMVAEstimator::phoIsoPtScalingCoeff_
private

Definition at line 48 of file PhotonMVAEstimator.cc.

Referenced by mvaValue(), and PhotonMVAEstimator().

std::vector<std::vector<int> > PhotonMVAEstimator::variables_
private

Definition at line 41 of file PhotonMVAEstimator.cc.

Referenced by mvaValue(), and PhotonMVAEstimator().