File indexing completed on 2024-04-06 12:19:25
0001 #ifndef STANDALONE
0002 #include <JetMETCorrections/Modules/interface/JetResolution.h>
0003 #include <FWCore/Framework/interface/EventSetup.h>
0004 #include <FWCore/Framework/interface/ESHandle.h>
0005
0006 #include <CondFormats/DataRecord/interface/JetResolutionRcd.h>
0007 #include <CondFormats/DataRecord/interface/JetResolutionScaleFactorRcd.h>
0008 #else
0009 #include "JetResolution.h"
0010 #endif
0011
0012 namespace JME {
0013
0014 JetResolution::JetResolution(const std::string& filename) {
0015 m_object = std::make_shared<JetResolutionObject>(filename);
0016 }
0017
0018 JetResolution::JetResolution(const JetResolutionObject& object) {
0019 m_object = std::make_shared<JetResolutionObject>(object);
0020 }
0021
0022 #ifndef STANDALONE
0023 const JetResolution JetResolution::get(const edm::EventSetup& setup, const Token& token) {
0024 return setup.getData(token);
0025 }
0026 #endif
0027
0028 float JetResolution::getResolution(const JetParameters& parameters) const {
0029 const JetResolutionObject::Record* record = m_object->getRecord(parameters);
0030 if (!record)
0031 return 1;
0032
0033 return m_object->evaluateFormula(*record, parameters);
0034 }
0035
0036 JetResolutionScaleFactor::JetResolutionScaleFactor(const std::string& filename) {
0037 m_object = std::make_shared<JetResolutionObject>(filename);
0038 }
0039
0040 JetResolutionScaleFactor::JetResolutionScaleFactor(const JetResolutionObject& object) {
0041 m_object = std::make_shared<JetResolutionObject>(object);
0042 }
0043
0044 #ifndef STANDALONE
0045 const JetResolutionScaleFactor JetResolutionScaleFactor::get(const edm::EventSetup& setup, const Token& token) {
0046 return setup.getData(token);
0047 }
0048 #endif
0049
0050 float JetResolutionScaleFactor::getScaleFactor(const JetParameters& parameters,
0051 Variation variation ,
0052 std::string uncertaintySource ) const {
0053 const JetResolutionObject::Record* record = m_object->getRecord(parameters);
0054 if (!record)
0055 return 1;
0056
0057 const std::vector<float>& parameters_values = record->getParametersValues();
0058 const std::vector<std::string>& parameter_names = m_object->getDefinition().getParametersName();
0059 size_t parameter = static_cast<size_t>(variation);
0060 if (!uncertaintySource.empty()) {
0061 if (variation == Variation::DOWN)
0062 parameter =
0063 std::distance(parameter_names.begin(),
0064 std::find(parameter_names.begin(), parameter_names.end(), uncertaintySource + "Down"));
0065 else if (variation == Variation::UP)
0066 parameter = std::distance(parameter_names.begin(),
0067 std::find(parameter_names.begin(), parameter_names.end(), uncertaintySource + "Up"));
0068 if (parameter >= parameter_names.size()) {
0069 std::string s;
0070 for (const auto& piece : parameter_names)
0071 s += piece + " ";
0072 throw cms::Exception("InvalidParameter")
0073 << "Invalid value for 'uncertaintySource' parameter. Only " + s + " are supported.\n";
0074 }
0075 }
0076 return parameters_values[parameter];
0077 }
0078
0079 }
0080
0081 #ifndef STANDALONE
0082 #include "FWCore/Utilities/interface/typelookup.h"
0083 TYPELOOKUP_DATA_REG(JME::JetResolution);
0084 TYPELOOKUP_DATA_REG(JME::JetResolutionScaleFactor);
0085 #endif