38 throw edm::Exception(static_cast<edm::errors::ErrorCodes>(code), message);
40 std::stringstream
error;
41 error << message <<
" Error code: " << code;
42 throw std::runtime_error(
error.str());
59 for (
auto&
i :
init) {
60 set(
i.first,
i.second);
117 std::vector<float>
values;
124 "' but no value for this parameter has been specified. Please call the appropriate 'set' " 125 "function of the JME::JetParameters object");
135 std::vector<float>
values;
137 for (
const auto&
name : binname) {
145 "' but no value for this parameter has been specified. Please call the appropriate 'set' " 146 "function of the JME::JetParameters object");
156 std::vector<std::string> tokens = getTokens(definition);
159 if (tokens.size() < 3) {
161 "Definition line needs at least three tokens. Please check file format.");
164 size_t n_bins = std::stoul(tokens[0]);
166 if (tokens.size() < (n_bins + 2)) {
170 for (
size_t i = 0;
i < n_bins;
i++) {
174 size_t n_variables = std::stoul(tokens[n_bins + 1]);
176 if (tokens.size() < (1 + n_bins + 1 + n_variables + 1)) {
180 for (
size_t i = 0;
i < n_variables;
i++) {
187 std::transform(formula_str_lower.begin(), formula_str_lower.end(), formula_str_lower.begin(), ::tolower);
189 if (formula_str_lower ==
"none") {
192 if ((tokens.size() > n_bins + n_variables + 3) && (std::atoi(tokens[n_bins + n_variables + 3].c_str()))) {
193 size_t n_parameters = std::stoul(tokens[n_bins + n_variables + 3]);
195 if (tokens.size() < (1 + n_bins + 1 + n_variables + 1 + 1 + n_parameters)) {
199 for (
size_t i = 0;
i < n_parameters;
i++) {
209 if (!m_formula_str.empty()) {
210 if (m_formula_str.find(
' ') == std::string::npos)
212 m_formula = std::make_shared<reco::FormulaEvaluator>(m_formula_str);
214 m_formula = std::make_shared<TFormula>(
"jet_resolution_formula", m_formula_str.c_str());
217 m_parameters_name = getTokens(m_formula_str);
219 for (
const auto&
bin : m_bins_name) {
224 m_bins.push_back(
b->second);
227 for (
const auto&
v : m_variables_name) {
232 m_variables.push_back(
var->second);
237 std::vector<std::string> tokens = getTokens(
line);
239 if (tokens.size() < (
def.nBins() * 2 +
def.nVariables() * 2 + 1)) {
245 for (
size_t i = 0;
i <
def.nBins();
i++) {
246 Range r(std::stof(tokens[
pos]), std::stof(tokens[
pos + 1]));
248 m_bins_range.push_back(r);
251 size_t n_parameters = std::stoul(tokens[
pos++]);
253 if (tokens.size() < (
def.nBins() * 2 +
def.nVariables() * 2 + 1 + (n_parameters -
def.nVariables() * 2))) {
257 for (
size_t i = 0;
i <
def.nVariables();
i++) {
258 Range r(std::stof(tokens[
pos]), std::stof(tokens[
pos + 1]));
260 m_variables_range.push_back(r);
264 for (
size_t i = 0;
i < n_parameters;
i++) {
265 m_parameters_values.push_back(std::stof(tokens[
pos++]));
278 if ((
line.empty()) || (
line[0] ==
'#'))
283 if (!definition.empty()) {
306 std::cout <<
"Definition: " << std::endl;
321 std::cout << std::endl <<
"Bin contents" << std::endl;
326 for (
const auto&
bin :
record.getBinsRange()) {
334 for (
const auto& r :
record.getVariablesRange()) {
342 for (
const auto& par :
record.getParametersValues()) {
343 std::cout <<
" Parameter #" <<
index <<
" = " << par << std::endl;
351 fout.setf(std::ios::right);
365 <<
" Resolution}" << std::endl;
369 for (
auto& r :
record.getBinsRange()) {
370 fout << std::left << std::setw(15) << r.min << std::setw(15) << r.max << std::setw(15);
374 for (
auto& r :
record.getVariablesRange()) {
375 fout << r.min << std::setw(15) << r.max << std::setw(15);
378 for (
auto&
p :
record.getParametersValues()) {
379 fout <<
p << std::setw(15);
382 fout << std::endl << std::setw(0);
395 const Record* good_record =
nullptr;
398 size_t valid_bins = 0;
399 size_t current_bin = 0;
400 for (
const auto&
bin :
record.getBinsRange()) {
401 if (
bin.is_inside(
bins[current_bin])) {
434 double variables_[4] = {0};
452 return formula.EvalPar(variables_);
int def(FILE *, FILE *, int)
const reco::FormulaEvaluator * getFormula() const
ErrorCode
Error code: whether the classification was successful or failed.
JetParameters & setJetEta(float eta)
std::vector< float > createVector(const std::vector< Binning > &binning) const
std::string getVariableName(size_t variable) const
JetParameters & setRho(float rho)
T clip(const T &n, const T &lower, const T &upper)
JetParameters & set(const Binning &bin, float value)
const std::vector< std::string > & getVariablesName() const
Container::value_type value_type
const std::vector< std::string > & getBinsName() const
std::vector< std::string > m_variables_name
std::vector< std::string > m_bins_name
Log< level::Warning, true > LogPrint
std::string getDefinitionLine(const std::string &line)
const Record * getRecord(const JetParameters &bins) const
std::string m_formula_str
JetParameters & setJetE(float e)
JetParameters & setMu(float mu)
std::string getFormulaString() const
void saveToFile(const std::string &file) const
#define TYPELOOKUP_DATA_REG(_dataclass_)
JetParameters & setJetPt(float pt)
std::vector< Record > m_records
float evaluateFormula(const Record &record, const JetParameters &variables) const
void throwException(uint32_t code, const std::string &message)
JetParameters & setNPV(float npv)
size_t nVariables() const
std::string getBinName(size_t bin) const
JetParameters & setJetArea(float area)
static const bimap< Binning, std::string > binning_to_string