CMS 3D CMS Logo

L1EGammaEECalibrator.cc
Go to the documentation of this file.
4 #include "boost/property_tree/ptree.hpp"
5 #include "boost/property_tree/json_parser.hpp"
6 #include <iterator>
7 
8 namespace l1tp2 {
9  std::vector<float> as_vector(boost::property_tree::ptree const& pt,
10  boost::property_tree::ptree::key_type const& key) {
11  std::vector<float> ret;
12  for (const auto& item : pt.get_child(key))
13  ret.push_back(item.second.get_value<float>());
14  return ret;
15  }
16 }; // namespace l1tp2
17 
19  //read the JSON file and populate the eta - pt bins and the value container
20  boost::property_tree::ptree calibration_map;
21  read_json(pset.getParameter<edm::FileInPath>("calibrationFile").fullPath(), calibration_map);
22 
23  auto eta_l = l1tp2::as_vector(calibration_map, "eta_l");
24  std::copy(eta_l.begin(), eta_l.end(), std::inserter(eta_bins, eta_bins.end()));
25  auto eta_h = l1tp2::as_vector(calibration_map, "eta_h");
26  eta_bins.insert(eta_h.back());
27 
28  auto pt_l = l1tp2::as_vector(calibration_map, "pt_l");
29  std::copy(pt_l.begin(), pt_l.end(), std::inserter(pt_bins, pt_bins.end()));
30  auto pt_h = l1tp2::as_vector(calibration_map, "pt_h");
31  pt_bins.insert(pt_h.back());
32 
33  auto calib_data = l1tp2::as_vector(calibration_map, "calib");
34  auto n_bins_eta = eta_bins.size();
35  auto n_bins_pt = pt_bins.size();
36  calib_factors.reserve(n_bins_eta * n_bins_pt);
37  for (auto calib_f = calib_data.begin(); calib_f != calib_data.end(); ++calib_f) {
38  auto index = calib_f - calib_data.begin();
39  int eta_bin = etaBin(eta_l[index]);
40  int pt_bin = ptBin(pt_l[index]);
41  calib_factors[(eta_bin * n_bins_pt) + pt_bin] = *calib_f;
42  }
43 }
44 
45 int L1EGammaEECalibrator::bin(const std::set<float>& container, float value) const {
46  auto bin_l = container.upper_bound(value);
47  if (bin_l == container.end()) {
48  // value not mapped to any bin
49  return -1;
50  }
51  return std::distance(container.begin(), bin_l) - 1;
52 }
53 
54 float L1EGammaEECalibrator::calibrationFactor(const float& pt, const float& eta) const {
55  int bin_eta = etaBin(eta);
56  int bin_pt = ptBin(pt);
57  if (bin_eta == -1 || bin_pt == -1)
58  return 1.;
59  auto n_bins_pt = pt_bins.size();
60  return calib_factors[(bin_eta * n_bins_pt) + bin_pt];
61 }
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:355
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
HLT_2018_cff.distance
distance
Definition: HLT_2018_cff.py:6417
L1EGammaEECalibrator::eta_bins
std::set< float > eta_bins
Definition: L1EGammaEECalibrator.h:20
FileInPath.h
edm::FileInPath
Definition: FileInPath.h:64
L1EGammaEECalibrator::etaBin
int etaBin(float eta) const
Definition: L1EGammaEECalibrator.h:16
PVValHelper::eta
Definition: PVValidationHelpers.h:69
L1EGammaEECalibrator::ptBin
int ptBin(float pt) const
Definition: L1EGammaEECalibrator.h:17
L1EGammaEECalibrator::L1EGammaEECalibrator
L1EGammaEECalibrator(const edm::ParameterSet &)
Definition: L1EGammaEECalibrator.cc:18
edm::ParameterSet
Definition: ParameterSet.h:36
L1EGammaEECalibrator::calibrationFactor
float calibrationFactor(const float &pt, const float &eta) const
Definition: L1EGammaEECalibrator.cc:54
L1EGammaEECalibrator::bin
int bin(const std::set< float > &container, float value) const
Definition: L1EGammaEECalibrator.cc:45
l1tp2::as_vector
std::vector< float > as_vector(boost::property_tree::ptree const &pt, boost::property_tree::ptree::key_type const &key)
Definition: L1EGammaEECalibrator.cc:9
value
Definition: value.py:1
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
L1EGammaEECalibrator.h
L1EGammaEECalibrator::pt_bins
std::set< float > pt_bins
Definition: L1EGammaEECalibrator.h:21
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
ParameterSet.h
L1EGammaEECalibrator::calib_factors
std::vector< float > calib_factors
Definition: L1EGammaEECalibrator.h:22
crabWrapper.key
key
Definition: crabWrapper.py:19
l1tp2
Definition: CaloCrystalCluster.h:12
edm::FileInPath::fullPath
std::string fullPath() const
Definition: FileInPath.cc:163
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27