39 std::function<std::string(
double)> printValueFunc)
41 std::ostringstream result;
42 result << std::setprecision(12);
44 if (
const auto* shape =
dynamic_cast<const Polygon*
>(ishape)) {
45 std::vector<double> xpos, ypos;
46 shape->getPoints(xpos, ypos);
47 result <<
indent <<
"points = [";
48 for (
size_t i = 0; i < xpos.size(); ++i) {
49 result <<
"[" << printValueFunc(xpos[i]) <<
", " << printValueFunc(ypos[i]) <<
"]";
50 if (i != xpos.size() - 1)
54 result <<
indent <<
"simulation.addMask("
57 result <<
indent <<
"simulation.maskAll()\n";
58 else if (
const auto* shape =
dynamic_cast<const Ellipse*
>(ishape)) {
59 result <<
indent <<
"simulation.addMask(";
60 result <<
"ba.Ellipse(" << printValueFunc(shape->getCenterX()) <<
", "
61 << printValueFunc(shape->getCenterY()) <<
", " << printValueFunc(shape->radiusX())
62 <<
", " << printValueFunc(shape->radiusY());
63 if (shape->getTheta() != 0.0)
68 else if (
const auto* shape =
dynamic_cast<const Rectangle*
>(ishape)) {
69 result <<
indent <<
"simulation.addMask(";
70 result <<
"ba.Rectangle(" << printValueFunc(shape->getXlow()) <<
", "
71 << printValueFunc(shape->getYlow()) <<
", " << printValueFunc(shape->getXup())
76 else if (
const auto* shape =
dynamic_cast<const VerticalLine*
>(ishape)) {
77 result <<
indent <<
"simulation.addMask(";
78 result <<
"ba.VerticalLine(" << printValueFunc(shape->getXpos()) <<
"), "
82 else if (
const auto* shape =
dynamic_cast<const HorizontalLine*
>(ishape)) {
83 result <<
indent <<
"simulation.addMask(";
84 result <<
"ba.HorizontalLine(" << printValueFunc(shape->getYpos()) <<
"), "
87 throw std::runtime_error(
"representShape2D(const IShape2D*) -> Error. Unknown shape");
95 std::ostringstream result;
96 if (
const auto* a =
dynamic_cast<const FixedBinAxis*
>(axis); a)
100 else if (
const auto* a =
dynamic_cast<const PointwiseAxis*
>(axis); a) {
101 result <<
"numpy.asarray([";
102 const std::vector<double>& points = a->binCenters();
103 for (
auto iter = points.begin(); iter != points.end() - 1; ++iter)
107 throw std::runtime_error(
"printAxis not implemented for current axis type");
112 const std::string& distVarName,
const std::string& units)
114 std::ostringstream result;
117 << distVarName <<
", " << par_distr.
nDraws() <<
", "
126 std::ostringstream result;
128 result << distr.
name();
Defines and implements namespace BaseUtils::algo with some algorithms.
Defines a few helper functions.
Defines M_PI and some more mathematical constants.
Defines classes representing one-dimensional distributions.
Defines class FixedBinAxis.
Defines class InfinitePlane.
Defines class ParameterDistribution.
Defines class PointwiseAxis.
Defines namespace pyfmt2.
Defines classes representing ranged one-dimensional distributions.
Defines some unit conversion factors and other constants in namespace Units.
An ellipse, for use in detector masks.
Axis with fixed bin size.
An infinite horizontal line.
Abstract base class for one-dimensional axes.
Interface for one-dimensional ranged distributions. All derived distributions allow for generating sa...
double sigmaFactor() const
Returns sigma factor to use during sampling.
virtual std::string name() const =0
Returns distribution name for python-formatted text.
RealLimits limits() const
Returns current limits of the distribution.
size_t nSamples() const
Returns number of samples to generate.
Basic class for all shapes in 2D.
The infinite plane is used for masking the entire detector.
A parametric distribution function, for use with any model parameter.
std::string whichParameterAsPyEnum() const
double sigmaFactor() const
get the sigma factor
size_t nDraws() const
get number of samples for this distribution
RealLimits getLimits() const
Axis containing arbitrary (non-equidistant) coordinate values. Lower boundary of the first bin and up...
A polygon, for use in detector masks.
A rectangle, for use in detector masks.
An infinite vertical line.
Utility functions for writing Python code snippets.
std::string representShape2D(const std::string &indent, const IShape2D *ishape, bool mask_value, std::function< std::string(double)> printValueFunc)
Returns fixed Python code snippet that defines the function "simulate".
std::string printRangedDistribution(const IRangedDistribution &distr)
std::string printParameterDistribution(const ParameterDistribution &par_distr, const std::string &distVarName, const std::string &units)
std::string printAxis(const IAxis *axis, const std::string &unit)
Prints an axis.
std::string printDegrees(double input)
std::string printDouble(double input)
std::string printString(const std::string &value)
std::string printRealLimitsArg(const RealLimits &limits, const std::string &units)
Prints RealLimits in the form of argument (in the context of ParameterDistribution and similar)....
std::string printBool(double value)
std::string indent(size_t width)
Returns a string of blanks with given width. By default the width equals standard offset in python fi...
std::string printValue(double value, const std::string &units)