32 size_t first = line.find (
'{');
33 size_t last = line.find (
'}');
35 if (first != std::string::npos && last != std::string::npos && first < last)
36 return std::string(line, first + 1, last - first - 1);
43 throw edm::Exception(static_cast<edm::errors::ErrorCodes>(code), message);
45 std::stringstream
error;
46 error << message <<
" Error code: " << code;
47 throw std::runtime_error(error.str());
65 set(
i.first,
i.second);
117 set(value.first, value.second);
122 std::vector<float>
values;
123 for (
const auto&
bin: binning) {
128 "' but no value for this parameter has been specified. Please call the appropriate 'set' function of the JME::JetParameters object");
131 values.push_back(it->second);
140 std::vector<std::string> tokens = getTokens(definition);
143 if (tokens.size() < 3) {
147 size_t n_bins = std::stoul(tokens[0]);
149 if (tokens.size() < (n_bins + 2)) {
153 for (
size_t i = 0;
i < n_bins;
i++) {
157 size_t n_variables = std::stoul(tokens[n_bins + 1]);
159 if (tokens.size() < (1 + n_bins + 1 + n_variables + 1)) {
163 for (
size_t i = 0;
i < n_variables;
i++) {
170 std::transform(formula_str_lower.begin(), formula_str_lower.end(), formula_str_lower.begin(), ::tolower);
172 if (formula_str_lower ==
"none")
179 if (m_formula_str.size())
180 m_formula = std::shared_ptr<TFormula>(
new TFormula(
"jet_resolution_formula", m_formula_str.c_str()));
182 for (
const auto&
bin: m_bins_name) {
187 m_bins.push_back(
b->second);
190 for (
const auto&
v: m_variables_name) {
195 m_variables.push_back(
var->second);
201 std::vector<std::string> tokens = getTokens(line);
209 for (
size_t i = 0;
i < def.
nBins();
i++) {
210 Range r(std::stof(tokens[pos]), std::stof(tokens[pos + 1]));
212 m_bins_range.push_back(r);
215 size_t n_parameters = std::stoul(tokens[pos++]);
222 Range r(std::stof(tokens[pos]), std::stof(tokens[pos + 1]));
224 m_variables_range.push_back(r);
228 for (
size_t i = 0;
i < n_parameters;
i++) {
229 m_parameters_values.push_back(std::stof(tokens[pos++]));
236 std::ifstream
f(filename);
243 if ((
line.size() == 0) || (
line[0] ==
'#'))
248 if (definition.size() > 0) {
272 std::cout <<
"Definition: " << std::endl;
287 std::cout << std::endl <<
"Bin contents" << std::endl;
292 for (
const auto&
bin:
record.getBinsRange()) {
299 for (
const auto&
r:
record.getVariablesRange()) {
306 for (
const auto& par:
record.getParametersValues()) {
307 std::cout <<
" Parameter #" << index <<
" = " << par << std::endl;
315 std::ofstream
fout(file);
316 fout.setf(std::ios::right);
333 for (
auto&
r:
record.getBinsRange()) {
334 fout << std::left << std::setw(15) <<
r.min << std::setw(15) <<
r.max << std::setw(15);
338 for (
auto&
r:
record.getVariablesRange()) {
339 fout <<
r.min << std::setw(15) <<
r.max << std::setw(15);
342 for (
auto&
p:
record.getParametersValues()) {
343 fout <<
p << std::setw(15);
346 fout << std::endl << std::setw(0);
360 const Record* good_record =
nullptr;
364 size_t valid_bins = 0;
365 size_t current_bin = 0;
366 for (
const auto&
bin:
record.getBinsRange()) {
367 if (
bin.is_inside(bins[current_bin]))
400 double variables_[4] = {0};
405 return formula.EvalPar(variables_);
const std::vector< Binning > & getVariables() const
const Record * getRecord(const JetParameters &bins) const
JetParameters & setJetEta(float eta)
JetParameters & setRho(float rho)
std::string getFormulaString() const
T clip(const T &n, const T &lower, const T &upper)
const std::vector< Binning > & getBins() const
JetParameters & set(const Binning &bin, float value)
const std::vector< std::string > & getVariablesName() const
const std::vector< Range > & getVariablesRange() const
void saveToFile(const std::string &file) const
std::string getVariableName(size_t variable) const
float evaluateFormula(const Record &record, const JetParameters &variables) const
Container::value_type value_type
size_t nVariables() const
std::vector< std::string > m_variables_name
const std::vector< std::string > & getBinsName() const
std::vector< std::string > m_bins_name
std::string getBinName(size_t bin) const
std::vector< float > createVector(const std::vector< Binning > &binning) const
TFormula const * getFormula() const
std::string getDefinitionLine(const std::string &line)
#define TYPELOOKUP_DATA_REG(_dataclass_)
const std::vector< float > & getParametersValues() const
std::string m_formula_str
JetParameters & setJetE(float e)
JetParameters & setMu(float mu)
unsigned nParameters() const
JetParameters & setJetPt(float pt)
std::vector< Record > m_records
void throwException(uint32_t code, const std::string &message)
JetParameters & setNPV(float npv)
JetParameters & setJetArea(float area)
static const bimap< Binning, std::string > binning_to_string