CMS 3D CMS Logo

PhotonXGBoostEstimator.cc
Go to the documentation of this file.
2 #include <sstream>
3 
5  XGBoosterCreate(NULL, 0, &booster_);
6  // Set number of threads to 1, to avoid spawning hundreds of OpenMP threads
7  // See https://github.com/cms-sw/cmssw/issues/44923 for details
8  XGBoosterSetParam(booster_, "nthread", "1");
9  XGBoosterLoadModel(booster_, weightsFile.fullPath().c_str());
10  best_ntree_limit_ = best_ntree_limit;
11 
12  std::stringstream config;
13  config << "{\"training\": false, \"type\": 0, \"iteration_begin\": 0, \"iteration_end\": " << best_ntree_limit_
14  << ", \"strict_shape\": false}";
15  config_ = config.str();
16 }
17 
19 
20 namespace {
21  enum inputIndexes {
22  rawEnergy = 0, // 0
23  r9 = 1, // 1
24  sigmaIEtaIEta = 2, // 2
25  etaWidth = 3, // 3
26  phiWidth = 4, // 4
27  s4 = 5, // 5
28  eta = 6, // 6
29  hOvrE = 7, // 7
30  ecalPFIso = 8, // 8
31  };
32 } // namespace
33 
34 float PhotonXGBoostEstimator::computeMva(float rawEnergyIn,
35  float r9In,
36  float sigmaIEtaIEtaIn,
37  float etaWidthIn,
38  float phiWidthIn,
39  float s4In,
40  float etaIn,
41  float hOvrEIn,
42  float ecalPFIsoIn) const {
43  float var[9];
44  var[rawEnergy] = rawEnergyIn;
45  var[r9] = r9In;
46  var[sigmaIEtaIEta] = sigmaIEtaIEtaIn;
47  var[etaWidth] = etaWidthIn;
48  var[phiWidth] = phiWidthIn;
49  var[s4] = s4In;
50  var[eta] = etaIn;
51  var[hOvrE] = hOvrEIn;
52  var[ecalPFIso] = ecalPFIsoIn;
53 
54  DMatrixHandle dmat;
55  XGDMatrixCreateFromMat(var, 1, 9, -999.9f, &dmat);
56  uint64_t const* out_shape;
57  uint64_t out_dim;
58  const float* out_result = NULL;
59  XGBoosterPredictFromDMatrix(booster_, dmat, config_.c_str(), &out_shape, &out_dim, &out_result);
60  float ret = out_result[0];
61  XGDMatrixFree(dmat);
62  return ret;
63 }
ret
prodAgent to be discontinued
#define NULL
Definition: scimark2.h:8
Definition: config.py:1
float computeMva(float rawEnergyIn, float r9In, float sigmaIEtaIEtaIn, float etaWidthIn, float phiWidthIn, float s4In, float etaIn, float hOvrEIn, float ecalPFIsoIn) const
double f[11][100]
unsigned long long uint64_t
Definition: Time.h:13
dictionary config
Read in AllInOne config in JSON format.
Definition: DiMuonV_cfg.py:30
PhotonXGBoostEstimator(const edm::FileInPath &weightsFile, int best_ntree_limit)