Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:22:29

0001 #include "L1Trigger/L1CaloTrigger/interface/L1EGammaEECalibrator.h"
0002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0003 #include "FWCore/ParameterSet/interface/FileInPath.h"
0004 #include "boost/property_tree/ptree.hpp"
0005 #include "boost/property_tree/json_parser.hpp"
0006 #include <iterator>
0007 
0008 namespace l1tp2 {
0009   std::vector<float> as_vector(boost::property_tree::ptree const& pt,
0010                                boost::property_tree::ptree::key_type const& key) {
0011     std::vector<float> ret;
0012     for (const auto& item : pt.get_child(key))
0013       ret.push_back(item.second.get_value<float>());
0014     return ret;
0015   }
0016 };  // namespace l1tp2
0017 
0018 L1EGammaEECalibrator::L1EGammaEECalibrator(const edm::ParameterSet& pset) {
0019   //read the JSON file and populate the eta - pt bins and the value container
0020   boost::property_tree::ptree calibration_map;
0021   read_json(pset.getParameter<edm::FileInPath>("calibrationFile").fullPath(), calibration_map);
0022 
0023   auto eta_l = l1tp2::as_vector(calibration_map, "eta_l");
0024   std::copy(eta_l.begin(), eta_l.end(), std::inserter(eta_bins, eta_bins.end()));
0025   auto eta_h = l1tp2::as_vector(calibration_map, "eta_h");
0026   eta_bins.insert(eta_h.back());
0027 
0028   auto pt_l = l1tp2::as_vector(calibration_map, "pt_l");
0029   std::copy(pt_l.begin(), pt_l.end(), std::inserter(pt_bins, pt_bins.end()));
0030   auto pt_h = l1tp2::as_vector(calibration_map, "pt_h");
0031   pt_bins.insert(pt_h.back());
0032 
0033   auto calib_data = l1tp2::as_vector(calibration_map, "calib");
0034   auto n_bins_eta = eta_bins.size();
0035   auto n_bins_pt = pt_bins.size();
0036   calib_factors.reserve(n_bins_eta * n_bins_pt);
0037   for (auto calib_f = calib_data.begin(); calib_f != calib_data.end(); ++calib_f) {
0038     auto index = calib_f - calib_data.begin();
0039     int eta_bin = etaBin(eta_l[index]);
0040     int pt_bin = ptBin(pt_l[index]);
0041     calib_factors[(eta_bin * n_bins_pt) + pt_bin] = *calib_f;
0042   }
0043 }
0044 
0045 int L1EGammaEECalibrator::bin(const std::set<float>& container, float value) const {
0046   auto bin_l = container.upper_bound(value);
0047   if (bin_l == container.end()) {
0048     // value not mapped to any bin
0049     return -1;
0050   }
0051   return std::distance(container.begin(), bin_l) - 1;
0052 }
0053 
0054 float L1EGammaEECalibrator::calibrationFactor(const float& pt, const float& eta) const {
0055   int bin_eta = etaBin(eta);
0056   int bin_pt = ptBin(pt);
0057   if (bin_eta == -1 || bin_pt == -1)
0058     return 1.;
0059   auto n_bins_pt = pt_bins.size();
0060   return calib_factors[(bin_eta * n_bins_pt) + bin_pt];
0061 }