File indexing completed on 2024-04-06 12:04:59
0001 #include "DataFormats/PatCandidates/interface/TauJetCorrFactors.h"
0002
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 #include "FWCore/Utilities/interface/EDMException.h"
0005
0006 #include <iomanip>
0007 #include <iostream>
0008 #include <sstream>
0009
0010 using namespace pat;
0011
0012 TauJetCorrFactors::TauJetCorrFactors(const std::string& label, const std::vector<CorrectionFactor>& jec)
0013 : label_(label), jec_(jec) {}
0014
0015 int TauJetCorrFactors::jecLevel(const std::string& level) const {
0016 for (std::vector<CorrectionFactor>::const_iterator corrFactor = jec_.begin(); corrFactor != jec_.end();
0017 ++corrFactor) {
0018 if (corrFactor->first == level)
0019 return (corrFactor - jec_.begin());
0020 }
0021 return -1;
0022 }
0023
0024 float TauJetCorrFactors::correction(unsigned int level) const {
0025 if (!(level < jec_.size())) {
0026 throw cms::Exception("InvalidRequest") << "You try to call a jet energy correction level wich does not exist. \n"
0027 << "Available jet energy correction levels are: \n"
0028 << correctionLabelString();
0029 }
0030 return jec_.at(level).second;
0031 }
0032
0033 std::string TauJetCorrFactors::correctionLabelString() const {
0034 std::string labels;
0035 for (std::vector<CorrectionFactor>::const_iterator corrFactor = jec_.begin(); corrFactor != jec_.end();
0036 ++corrFactor) {
0037 std::stringstream idx;
0038 idx << (corrFactor - jec_.begin());
0039 labels.append(idx.str()).append(" ").append(corrFactor->first).append("\n");
0040 }
0041 return labels;
0042 }
0043
0044 std::vector<std::string> TauJetCorrFactors::correctionLabels() const {
0045 std::vector<std::string> labels;
0046 for (std::vector<CorrectionFactor>::const_iterator corrFactor = jec_.begin(); corrFactor != jec_.end();
0047 ++corrFactor) {
0048 labels.push_back(corrFactor->first);
0049 }
0050 return labels;
0051 }
0052
0053 void TauJetCorrFactors::print() const {
0054 edm::LogInfo message("JetCorrFactors");
0055 for (std::vector<CorrectionFactor>::const_iterator corrFactor = jec_.begin(); corrFactor != jec_.end();
0056 ++corrFactor) {
0057 unsigned int corrFactorIdx = corrFactor - jec_.begin();
0058 message << std::setw(3) << corrFactorIdx << " " << corrFactor->first;
0059 message << std::setw(10) << correction(corrFactor - jec_.begin());
0060 message << "\n";
0061 }
0062 }