CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Attributes
PileupJetIdAlgo::AlgoGBRForestsAndConstants Class Reference

#include <PileupJetIdAlgo.h>

Public Types

typedef float array_t[3][4][4]
 

Public Member Functions

 AlgoGBRForestsAndConstants (edm::ParameterSet const &, bool runMvas)
 
array_t const & betaStarCut () const
 
bool cutBased () const
 
bool etaBinnedWeights () const
 
std::vector< std::unique_ptr< const GBRForest > > const & etaReader () const
 
std::unique_ptr< const GBRForestgetMVA (std::vector< std::string > const &varList, std::string const &tmvaWeights, std::vector< std::string > const &tmvaSpectators)
 
std::vector< double > const & jEtaMax () const
 
std::vector< double > const & jEtaMin () const
 
std::string const & label () const
 
array_t const & mvacut () const
 
int nEtaBins () const
 
std::unique_ptr< const GBRForest > const & reader () const
 
array_t const & rmsCut () const
 
bool runMvas () const
 
std::vector< std::vector< std::string > > const & tmvaEtaVariables () const
 
std::string const & tmvaMethod () const
 
std::vector< std::string > const & tmvaVariables () const
 

Private Attributes

float betaStarCut_ [3][4][4]
 
bool cutBased_
 
bool etaBinnedWeights_
 
std::vector< std::unique_ptr< const GBRForest > > etaReader_
 
std::vector< double > jEtaMax_
 
std::vector< double > jEtaMin_
 
std::string label_
 
float mvacut_ [3][4][4]
 
int nEtaBins_
 
std::unique_ptr< const GBRForestreader_
 
float rmsCut_ [3][4][4]
 
bool runMvas_
 
std::vector< std::vector< std::string > > tmvaEtaVariables_
 
std::string tmvaMethod_
 
std::map< std::string, std::string > tmvaNames_
 
std::vector< std::string > tmvaVariables_
 

Detailed Description

Definition at line 61 of file PileupJetIdAlgo.h.

Member Typedef Documentation

typedef float PileupJetIdAlgo::AlgoGBRForestsAndConstants::array_t[3][4][4]

Definition at line 79 of file PileupJetIdAlgo.h.

Constructor & Destructor Documentation

PileupJetIdAlgo::AlgoGBRForestsAndConstants::AlgoGBRForestsAndConstants ( edm::ParameterSet const &  ps,
bool  runMvas 
)

Definition at line 22 of file PileupJetIdAlgo.cc.

References betaStarCut_, cutBased_, etaBinnedWeights_, etaReader_, edm::FileInPath::fullPath(), getMVA(), edm::ParameterSet::getParameter(), jEtaMax_, jEtaMin_, PileupJetIdentifier::kLoose, PileupJetIdentifier::kMedium, mvacut_, nEtaBins_, reader_, rmsCut_, runMvas_, AlCaHLTBitMon_QueryRunRegistry::string, tmvaEtaVariables_, tmvaMethod_, hltPUIdAlgo_cff::tmvaSpectators, tmvaVariables_, hltPUIdAlgo_cff::tmvaWeights, PileupJetIDParams_cfi::trainings, PileupJetIdAlgo::USER, findQualityFiles::v, and jets_cff::version.

22  :
23  cutBased_(ps.getParameter<bool>("cutBased")),
24  etaBinnedWeights_(false),
26  nEtaBins_(0),
27  label_(ps.getParameter<std::string>("label")),
28  mvacut_{},
29  rmsCut_{},
30  betaStarCut_{}
31  {
32 
34  std::vector<std::string> tmvaEtaWeights;
35  std::vector<std::string> tmvaSpectators;
36  int version;
37 
38  if (!cutBased_) {
39  etaBinnedWeights_ = ps.getParameter<bool>("etaBinnedWeights");
40  if (etaBinnedWeights_) {
41  const std::vector<edm::ParameterSet>& trainings = ps.getParameter<std::vector <edm::ParameterSet> >("trainings");
42  nEtaBins_ = ps.getParameter<int>("nEtaBins");
43  for (int v = 0; v < nEtaBins_; v++) {
44  tmvaEtaWeights.push_back( edm::FileInPath(trainings.at(v).getParameter<std::string>("tmvaWeights")).fullPath() );
45  jEtaMin_.push_back( trainings.at(v).getParameter<double>("jEtaMin") );
46  jEtaMax_.push_back( trainings.at(v).getParameter<double>("jEtaMax") );
47  }
48  for (int v = 0; v < nEtaBins_; v++) {
49  tmvaEtaVariables_.push_back( trainings.at(v).getParameter<std::vector<std::string> >("tmvaVariables") );
50  }
51  } else {
52  tmvaWeights = edm::FileInPath(ps.getParameter<std::string>("tmvaWeights")).fullPath();
53  tmvaVariables_ = ps.getParameter<std::vector<std::string> >("tmvaVariables");
54  }
55  tmvaMethod_ = ps.getParameter<std::string>("tmvaMethod");
56  tmvaSpectators = ps.getParameter<std::vector<std::string> >("tmvaSpectators");
57  version = ps.getParameter<int>("version");
58  } else {
59  version = USER;
60  }
61 
62  edm::ParameterSet jetConfig = ps.getParameter<edm::ParameterSet>("JetIdParams");
63  for (int i0 = 0; i0 < 3; i0++) {
64  std::string lCutType = "Tight";
65  if (i0 == PileupJetIdentifier::kMedium) lCutType = "Medium";
66  if (i0 == PileupJetIdentifier::kLoose) lCutType = "Loose";
67  int nCut = 1;
68  if(cutBased_) nCut++;
69  for (int i1 = 0; i1 < nCut; i1++) {
70  std::string lFullCutType = lCutType;
71  if (cutBased_ && i1 == 0) lFullCutType = "BetaStar"+ lCutType;
72  if (cutBased_ && i1 == 1) lFullCutType = "RMS" + lCutType;
73  std::vector<double> pt010 = jetConfig.getParameter<std::vector<double> >(("Pt010_" +lFullCutType).c_str());
74  std::vector<double> pt1020 = jetConfig.getParameter<std::vector<double> >(("Pt1020_"+lFullCutType).c_str());
75  std::vector<double> pt2030 = jetConfig.getParameter<std::vector<double> >(("Pt2030_"+lFullCutType).c_str());
76  std::vector<double> pt3050 = jetConfig.getParameter<std::vector<double> >(("Pt3050_"+lFullCutType).c_str());
77  if (!cutBased_) {
78  for (int i2 = 0; i2 < 4; i2++) mvacut_[i0][0][i2] = pt010 [i2];
79  for (int i2 = 0; i2 < 4; i2++) mvacut_[i0][1][i2] = pt1020[i2];
80  for (int i2 = 0; i2 < 4; i2++) mvacut_[i0][2][i2] = pt2030[i2];
81  for (int i2 = 0; i2 < 4; i2++) mvacut_[i0][3][i2] = pt3050[i2];
82  }
83  if (cutBased_ && i1 == 0) {
84  for (int i2 = 0; i2 < 4; i2++) betaStarCut_[i0][0][i2] = pt010 [i2];
85  for (int i2 = 0; i2 < 4; i2++) betaStarCut_[i0][1][i2] = pt1020[i2];
86  for (int i2 = 0; i2 < 4; i2++) betaStarCut_[i0][2][i2] = pt2030[i2];
87  for (int i2 = 0; i2 < 4; i2++) betaStarCut_[i0][3][i2] = pt3050[i2];
88  }
89  if (cutBased_ && i1 == 1) {
90  for (int i2 = 0; i2 < 4; i2++) rmsCut_[i0][0][i2] = pt010 [i2];
91  for (int i2 = 0; i2 < 4; i2++) rmsCut_[i0][1][i2] = pt1020[i2];
92  for (int i2 = 0; i2 < 4; i2++) rmsCut_[i0][2][i2] = pt2030[i2];
93  for (int i2 = 0; i2 < 4; i2++) rmsCut_[i0][3][i2] = pt3050[i2];
94  }
95  }
96  }
97 
98  if ( ! cutBased_ ) {
99  assert( tmvaMethod_.empty() || ((! tmvaVariables_.empty() || ( !tmvaEtaVariables_.empty() )) && version == USER) );
100  }
101 
102  if (( ! cutBased_ ) && (runMvas_)) {
103  if (etaBinnedWeights_) {
104  for (int v = 0; v < nEtaBins_; v++) {
105  etaReader_.push_back(getMVA(tmvaEtaVariables_.at(v), tmvaEtaWeights.at(v), tmvaSpectators));
106  }
107  } else {
108  reader_ = getMVA(tmvaVariables_, tmvaWeights, tmvaSpectators);
109  }
110  }
111 }
T getParameter(std::string const &) const
std::vector< std::unique_ptr< const GBRForest > > etaReader_
std::vector< std::vector< std::string > > tmvaEtaVariables_
std::unique_ptr< const GBRForest > getMVA(std::vector< std::string > const &varList, std::string const &tmvaWeights, std::vector< std::string > const &tmvaSpectators)
std::string fullPath() const
Definition: FileInPath.cc:197
std::unique_ptr< const GBRForest > reader_

Member Function Documentation

array_t const& PileupJetIdAlgo::AlgoGBRForestsAndConstants::betaStarCut ( ) const
inline
bool PileupJetIdAlgo::AlgoGBRForestsAndConstants::cutBased ( ) const
inline

Definition at line 68 of file PileupJetIdAlgo.h.

References cutBased_.

Referenced by PileupJetIdAlgo::runMva().

bool PileupJetIdAlgo::AlgoGBRForestsAndConstants::etaBinnedWeights ( ) const
inline

Definition at line 69 of file PileupJetIdAlgo.h.

References etaBinnedWeights_.

Referenced by PileupJetIdAlgo::runMva().

std::vector<std::unique_ptr<const GBRForest> > const& PileupJetIdAlgo::AlgoGBRForestsAndConstants::etaReader ( ) const
inline

Definition at line 67 of file PileupJetIdAlgo.h.

References etaReader_.

Referenced by PileupJetIdAlgo::runMva().

67 { return etaReader_; }
std::vector< std::unique_ptr< const GBRForest > > etaReader_
std::unique_ptr< const GBRForest > PileupJetIdAlgo::AlgoGBRForestsAndConstants::getMVA ( std::vector< std::string > const &  varList,
std::string const &  tmvaWeights,
std::vector< std::string > const &  tmvaSpectators 
)

Definition at line 114 of file PileupJetIdAlgo.cc.

References patPFMETCorrections_cff::algo, relativeConstraints::empty, PileupJetIdAlgo::getVariables(), reco::details::loadTMVAWeights(), tmvaMethod_, and tmvaNames_.

Referenced by AlgoGBRForestsAndConstants(), and betaStarCut().

116  {
117 
118  // A temporary only to access the variables while calling TMVA AddVariable and TMVA AddSpectator.
119  PileupJetIdAlgo algo(nullptr);
120 
121  TMVA::Reader tmpTMVAReader( "!Color:Silent:!Error" );
122  for (auto const& varName : varList) {
123  if ( tmvaNames_[varName].empty() ) tmvaNames_[varName] = varName;
124  tmpTMVAReader.AddVariable( varName, std::get<float *,float>(algo.getVariables().at(tmvaNames_[varName])) );
125  }
126  for (auto const& spectatorName : tmvaSpectators) {
127  if ( tmvaNames_[spectatorName].empty() ) tmvaNames_[spectatorName] = spectatorName;
128  tmpTMVAReader.AddSpectator( spectatorName, std::get<float *,float>(algo.getVariables().at(tmvaNames_[spectatorName])) );
129  }
131  return ( std::make_unique<const GBRForest> ( dynamic_cast<TMVA::MethodBDT*>( tmpTMVAReader.FindMVA(tmvaMethod_.c_str()) ) ) );
132 }
std::map< std::string, std::string > tmvaNames_
TMVA::IMethod * loadTMVAWeights(TMVA::Reader *reader, const std::string &method, const std::string &weightFile, bool verbose=false)
std::vector<double> const& PileupJetIdAlgo::AlgoGBRForestsAndConstants::jEtaMax ( ) const
inline

Definition at line 73 of file PileupJetIdAlgo.h.

References jEtaMax_.

Referenced by PileupJetIdAlgo::runMva().

73 { return jEtaMax_; }
std::vector<double> const& PileupJetIdAlgo::AlgoGBRForestsAndConstants::jEtaMin ( ) const
inline

Definition at line 72 of file PileupJetIdAlgo.h.

References jEtaMin_.

Referenced by PileupJetIdAlgo::runMva().

72 { return jEtaMin_; }
std::string const& PileupJetIdAlgo::AlgoGBRForestsAndConstants::label ( ) const
inline

Definition at line 74 of file PileupJetIdAlgo.h.

References label_.

array_t const& PileupJetIdAlgo::AlgoGBRForestsAndConstants::mvacut ( ) const
inline

Definition at line 80 of file PileupJetIdAlgo.h.

References mvacut_.

Referenced by PileupJetIdAlgo::computeIDflag().

int PileupJetIdAlgo::AlgoGBRForestsAndConstants::nEtaBins ( ) const
inline

Definition at line 71 of file PileupJetIdAlgo.h.

References nEtaBins_.

Referenced by PileupJetIdAlgo::runMva().

std::unique_ptr<const GBRForest> const& PileupJetIdAlgo::AlgoGBRForestsAndConstants::reader ( ) const
inline

Definition at line 66 of file PileupJetIdAlgo.h.

References reader_.

Referenced by PileupJetIdAlgo::runMva().

66 { return reader_; }
std::unique_ptr< const GBRForest > reader_
array_t const& PileupJetIdAlgo::AlgoGBRForestsAndConstants::rmsCut ( ) const
inline

Definition at line 81 of file PileupJetIdAlgo.h.

References rmsCut_.

bool PileupJetIdAlgo::AlgoGBRForestsAndConstants::runMvas ( ) const
inline

Definition at line 70 of file PileupJetIdAlgo.h.

References runMvas_.

Referenced by PileupJetIdAlgo::computeIdVariables().

std::vector<std::vector<std::string> > const& PileupJetIdAlgo::AlgoGBRForestsAndConstants::tmvaEtaVariables ( ) const
inline

Definition at line 77 of file PileupJetIdAlgo.h.

References tmvaEtaVariables_.

Referenced by PileupJetIdAlgo::runMva().

77 { return tmvaEtaVariables_; }
std::vector< std::vector< std::string > > tmvaEtaVariables_
std::string const& PileupJetIdAlgo::AlgoGBRForestsAndConstants::tmvaMethod ( ) const
inline

Definition at line 75 of file PileupJetIdAlgo.h.

References tmvaMethod_.

Referenced by PileupJetIdAlgo::method().

std::vector<std::string> const& PileupJetIdAlgo::AlgoGBRForestsAndConstants::tmvaVariables ( ) const
inline

Definition at line 76 of file PileupJetIdAlgo.h.

References tmvaVariables_.

Referenced by PileupJetIdAlgo::runMva().

76 { return tmvaVariables_; }

Member Data Documentation

float PileupJetIdAlgo::AlgoGBRForestsAndConstants::betaStarCut_[3][4][4]
private

Definition at line 105 of file PileupJetIdAlgo.h.

Referenced by AlgoGBRForestsAndConstants(), and betaStarCut().

bool PileupJetIdAlgo::AlgoGBRForestsAndConstants::cutBased_
private

Definition at line 92 of file PileupJetIdAlgo.h.

Referenced by AlgoGBRForestsAndConstants(), and cutBased().

bool PileupJetIdAlgo::AlgoGBRForestsAndConstants::etaBinnedWeights_
private

Definition at line 93 of file PileupJetIdAlgo.h.

Referenced by AlgoGBRForestsAndConstants(), and etaBinnedWeights().

std::vector<std::unique_ptr<const GBRForest> > PileupJetIdAlgo::AlgoGBRForestsAndConstants::etaReader_
private

Definition at line 91 of file PileupJetIdAlgo.h.

Referenced by AlgoGBRForestsAndConstants(), and etaReader().

std::vector<double> PileupJetIdAlgo::AlgoGBRForestsAndConstants::jEtaMax_
private

Definition at line 97 of file PileupJetIdAlgo.h.

Referenced by AlgoGBRForestsAndConstants(), and jEtaMax().

std::vector<double> PileupJetIdAlgo::AlgoGBRForestsAndConstants::jEtaMin_
private

Definition at line 96 of file PileupJetIdAlgo.h.

Referenced by AlgoGBRForestsAndConstants(), and jEtaMin().

std::string PileupJetIdAlgo::AlgoGBRForestsAndConstants::label_
private
float PileupJetIdAlgo::AlgoGBRForestsAndConstants::mvacut_[3][4][4]
private

Definition at line 103 of file PileupJetIdAlgo.h.

Referenced by AlgoGBRForestsAndConstants(), and mvacut().

int PileupJetIdAlgo::AlgoGBRForestsAndConstants::nEtaBins_
private

Definition at line 95 of file PileupJetIdAlgo.h.

Referenced by AlgoGBRForestsAndConstants(), and nEtaBins().

std::unique_ptr<const GBRForest> PileupJetIdAlgo::AlgoGBRForestsAndConstants::reader_
private

Definition at line 90 of file PileupJetIdAlgo.h.

Referenced by AlgoGBRForestsAndConstants(), and reader().

float PileupJetIdAlgo::AlgoGBRForestsAndConstants::rmsCut_[3][4][4]
private

Definition at line 104 of file PileupJetIdAlgo.h.

Referenced by AlgoGBRForestsAndConstants(), and rmsCut().

bool PileupJetIdAlgo::AlgoGBRForestsAndConstants::runMvas_
private

Definition at line 94 of file PileupJetIdAlgo.h.

Referenced by AlgoGBRForestsAndConstants(), and runMvas().

std::vector<std::vector<std::string> > PileupJetIdAlgo::AlgoGBRForestsAndConstants::tmvaEtaVariables_
private

Definition at line 101 of file PileupJetIdAlgo.h.

Referenced by AlgoGBRForestsAndConstants(), and tmvaEtaVariables().

std::string PileupJetIdAlgo::AlgoGBRForestsAndConstants::tmvaMethod_
private

Definition at line 99 of file PileupJetIdAlgo.h.

Referenced by AlgoGBRForestsAndConstants(), getMVA(), and tmvaMethod().

std::map<std::string,std::string> PileupJetIdAlgo::AlgoGBRForestsAndConstants::tmvaNames_
private

Definition at line 107 of file PileupJetIdAlgo.h.

Referenced by getMVA().

std::vector<std::string> PileupJetIdAlgo::AlgoGBRForestsAndConstants::tmvaVariables_
private

Definition at line 100 of file PileupJetIdAlgo.h.

Referenced by AlgoGBRForestsAndConstants(), and tmvaVariables().