CMS 3D CMS Logo

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 16 of file PhotonMVAEstimator.cc.

Constructor & Destructor Documentation

◆ PhotonMVAEstimator()

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

Definition at line 53 of file PhotonMVAEstimator.cc.

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

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

◆ ~PhotonMVAEstimator()

PhotonMVAEstimator::~PhotonMVAEstimator ( )
inlineoverride

Definition at line 20 of file PhotonMVAEstimator.cc.

20 {};

Member Function Documentation

◆ fillDescriptions()

static void PhotonMVAEstimator::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

◆ findCategory() [1/2]

int PhotonMVAEstimator::findCategory ( const reco::Candidate candPtr) const
overridevirtual

Implements AnyMVAEstimatorRun2Base.

Definition at line 150 of file PhotonMVAEstimator.cc.

References Exception.

Referenced by mvaValue().

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

◆ findCategory() [2/2]

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

Definition at line 161 of file PhotonMVAEstimator.cc.

References categoryFunctions_, AnyMVAEstimatorRun2Base::getNCategories(), AnyMVAEstimatorRun2Base::getTag(), mps_fire::i, and displacedMuons_cfi::photon.

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

◆ mvaValue()

float PhotonMVAEstimator::mvaValue ( const reco::Candidate candPtr,
std::vector< float > const &  auxVars,
int &  iCategory 
) const
overridevirtual

Implements AnyMVAEstimatorRun2Base.

Definition at line 105 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(), reco::Photon::superCluster(), and variables_.

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

Member Data Documentation

◆ categoryFunctions_

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

Definition at line 34 of file PhotonMVAEstimator.cc.

Referenced by findCategory(), and PhotonMVAEstimator().

◆ effectiveAreas_

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

Definition at line 48 of file PhotonMVAEstimator.cc.

Referenced by mvaValue(), and PhotonMVAEstimator().

◆ gbrForests_

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

Definition at line 38 of file PhotonMVAEstimator.cc.

Referenced by mvaValue(), and PhotonMVAEstimator().

◆ mvaVarMngr_

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

Definition at line 45 of file PhotonMVAEstimator.cc.

Referenced by mvaValue(), and PhotonMVAEstimator().

◆ nCategories_

int PhotonMVAEstimator::nCategories_
private

Definition at line 33 of file PhotonMVAEstimator.cc.

◆ nVariables_

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

Definition at line 35 of file PhotonMVAEstimator.cc.

Referenced by mvaValue(), and PhotonMVAEstimator().

◆ phoIsoCutoff_

double PhotonMVAEstimator::phoIsoCutoff_
private

Definition at line 50 of file PhotonMVAEstimator.cc.

Referenced by mvaValue(), and PhotonMVAEstimator().

◆ phoIsoPtScalingCoeff_

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

Definition at line 49 of file PhotonMVAEstimator.cc.

Referenced by mvaValue(), and PhotonMVAEstimator().

◆ variables_

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

Definition at line 42 of file PhotonMVAEstimator.cc.

Referenced by mvaValue(), and PhotonMVAEstimator().