Skip to content

Commit

Permalink
Merge branch 'development' into fix-goldstone-reorder
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Athron committed Jun 20, 2014
2 parents d92c2ac + f485213 commit c4cbf9c
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 15 deletions.
9 changes: 6 additions & 3 deletions meta/WriteOut.m
Expand Up @@ -326,9 +326,12 @@
blockNameStr = ToString[blockName];
"{\n" <> IndentText[
"DEFINE_PARAMETER(" <> paramStr <> ");\n" <>
"slha_io.read_block(\"" <> blockNameStr <> "\", " <>
paramStr <> ");\n" <>
"model.set_" <> paramStr <> "(" <> paramStr <> ");"] <> "\n" <>
"const double tmp_scale = slha_io.read_block(\"" <>
blockNameStr <> "\", " <> paramStr <> ");\n" <>
"model.set_" <> paramStr <> "(" <> paramStr <> ");\n" <>
"if (!is_zero(tmp_scale))\n" <>
IndentText["scale = tmp_scale;"] <> "\n"
] <> "\n" <>
"}\n"
];

Expand Down
58 changes: 53 additions & 5 deletions src/slha_io.cpp
Expand Up @@ -41,6 +41,11 @@ void SLHA_io::clear()
modsel.clear();
}

bool SLHA_io::block_exists(const std::string& block_name) const
{
return data.find(block_name) != data.cend();
}

/**
* @brief opens SLHA input file and reads the content
* @param file_name SLHA input file name
Expand Down Expand Up @@ -82,29 +87,46 @@ void SLHA_io::fill(QedQcd& oneset) const
read_block("SMINPUTS", sminputs_processor);
}

void SLHA_io::read_block(const std::string& block_name, const Tuple_processor& processor) const
/**
* Applies processor to each (key, value) pair of a SLHA block.
* Non-data lines are ignored.
*
* @param block_name block name
* @param processor tuple processor to be applied
*
* @return scale (or 0 if no scale is defined)
*/
double SLHA_io::read_block(const std::string& block_name, const Tuple_processor& processor) const
{
if (data.find(block_name) == data.cend())
return;
if (!block_exists(block_name))
return 0.;

double scale = 0.;

for (SLHAea::Block::const_iterator line = data.at(block_name).cbegin(),
end = data.at(block_name).cend(); line != end; ++line) {
if (!line->is_data_line())
if (!line->is_data_line()) {
// read scale from block definition
if (line->size() > 3 && (*line)[2] == "Q=")
scale = convert_to<double>((*line)[3]);
continue;
}

if (line->size() >= 2) {
const int key = convert_to<int>((*line)[0]);
const double value = convert_to<double>((*line)[1]);
processor(key, value);
}
}

return scale;
}

double SLHA_io::read_entry(const std::string& block_name, int key) const
{
const SLHAea::Coll::const_iterator block = data.find(block_name);

if (block == data.cend()) {
if (!block_exists(block_name)) {
WARNING("block " << block_name << " not found");
return 0.;
}
Expand All @@ -123,6 +145,32 @@ double SLHA_io::read_entry(const std::string& block_name, int key) const
return entry;
}

/**
* Reads scale definition from SLHA block.
*
* @param block_name block name
*
* @return scale (or 0 if no scale is defined)
*/
double SLHA_io::read_scale(const std::string& block_name) const
{
if (!block_exists(block_name))
return 0.;

double scale = 0.;

for (SLHAea::Block::const_iterator line = data.at(block_name).cbegin(),
end = data.at(block_name).cend(); line != end; ++line) {
if (!line->is_data_line()) {
if (line->size() > 3 && (*line)[2] == "Q=")
scale = convert_to<double>((*line)[3]);
break;
}
}

return scale;
}

void SLHA_io::set_block(const std::ostringstream& lines, Position position)
{
SLHAea::Block block;
Expand Down
29 changes: 23 additions & 6 deletions src/slha_io.hpp
Expand Up @@ -134,16 +134,18 @@ class SLHA_io {
void clear();

// reading functions
bool block_exists(const std::string&) const;
void fill(softsusy::QedQcd&) const;
const Extpar& get_extpar() const { return extpar; }
const Modsel& get_modsel() const { return modsel; }
void read_from_file(const std::string&);
void read_block(const std::string&, const Tuple_processor&) const;
double read_block(const std::string&, const Tuple_processor&) const;
template <class Derived>
void read_block(const std::string&, Eigen::MatrixBase<Derived>&) const;
double read_block(const std::string&, Eigen::MatrixBase<Derived>&) const;
double read_entry(const std::string&, int) const;
void read_extpar();
void read_modsel();
double read_scale(const std::string&) const;

// writing functions
void set_data(const SLHAea::Coll& data_) { data = data_; }
Expand Down Expand Up @@ -184,20 +186,33 @@ Scalar SLHA_io::convert_to(const std::string& str)
return value;
}

/**
* Fills a matrix from a SLHA block
*
* @param block_name block name
* @param matrix matrix to be filled
*
* @return scale (or 0 if no scale is defined)
*/
template <class Derived>
void SLHA_io::read_block(const std::string& block_name, Eigen::MatrixBase<Derived>& matrix) const
double SLHA_io::read_block(const std::string& block_name, Eigen::MatrixBase<Derived>& matrix) const
{
if (data.find(block_name) == data.cend()) {
if (!block_exists(block_name)) {
WARNING("block " << block_name << " not found");
return;
return 0.;
}

const int cols = matrix.cols(), rows = matrix.rows();
double scale = 0.;

for (SLHAea::Block::const_iterator line = data.at(block_name).cbegin(),
end = data.at(block_name).cend(); line != end; ++line) {
if (!line->is_data_line())
if (!line->is_data_line()) {
// read scale from block definition
if (line->size() > 3 && (*line)[2] == "Q=")
scale = convert_to<double>((*line)[3]);
continue;
}

if (line->size() >= 3) {
const int i = convert_to<int>((*line)[0]) - 1;
Expand All @@ -208,6 +223,8 @@ void SLHA_io::read_block(const std::string& block_name, Eigen::MatrixBase<Derive
}
}
}

return scale;
}

template<class Scalar, int NRows, int NCols>
Expand Down
5 changes: 5 additions & 0 deletions templates/slha_io.hpp.in
Expand Up @@ -24,6 +24,7 @@
#include "@ModelName@_two_scale_model.hpp"
#include "@ModelName@_info.hpp"
#include "slha_io.hpp"
#include "numerics.hpp"

#include <Eigen/Core>
#include <string>
Expand Down Expand Up @@ -79,7 +80,11 @@ private:
template <class T>
void @ModelName@_slha_io::fill(@ModelName@<T>& model) const
{
double scale = 0.;

@readLesHouchesOutputParameters@

model.set_scale(scale);
}

template <class T>
Expand Down
7 changes: 6 additions & 1 deletion test/test_MSSM_slha_input.cpp
Expand Up @@ -13,6 +13,7 @@ BOOST_AUTO_TEST_CASE( test_MSSM_slha_reading )
{
MSSM<Two_scale> model;

const double scale = 91.0;
const double ALPHASMZ = 0.1176;
const double ALPHAMZ = 1.0 / 127.918;
const double sinthWsq = 0.23122;
Expand Down Expand Up @@ -42,7 +43,7 @@ BOOST_AUTO_TEST_CASE( test_MSSM_slha_reading )
Yd(2,2) = 2.9 * root2 / (vev * cosBeta);
Ye(2,2) = 1.77699 * root2 / (vev * cosBeta);

model.set_scale(91);
model.set_scale(scale);
model.set_loops(2);
model.set_g1(g1);
model.set_g2(g2);
Expand Down Expand Up @@ -74,6 +75,7 @@ BOOST_AUTO_TEST_CASE( test_MSSM_slha_reading )
std::string slha_file("test/test_MSSM_slha_input.out.spc");
slha_io.write_to_file(slha_file);

// clear everything
model.clear();
slha_io.clear();

Expand All @@ -89,9 +91,12 @@ BOOST_AUTO_TEST_CASE( test_MSSM_slha_reading )
}
}

// read from SLHA file
slha_io.read_from_file(slha_file);
slha_io.fill(model);

BOOST_CHECK_EQUAL(model.get_scale(), scale);

BOOST_CHECK_CLOSE_FRACTION(model.get_g1(), g1, 1.0e-8);
BOOST_CHECK_CLOSE_FRACTION(model.get_g2(), g2, 1.0e-8);
BOOST_CHECK_CLOSE_FRACTION(model.get_g3(), g3, 1.0e-8);
Expand Down

0 comments on commit c4cbf9c

Please sign in to comment.