#ifndef __HIST_H
#define __HIST_H
#include <vector>
#include <stdlib.h>
#include "meas.h"
#include "bloputils.h"
#include "blopeps.h"
#include "mpps.h"
#include "ignore.h"
#include "function.h"
namespace blop
{
class hist;
class histopt
{
protected:
std::vector<double> min_;
static double default_min_;
static bool default_min_isset_;
std::vector<double> max_;
static double default_max_;
static bool default_max_isset_;
std::vector<int> bins_;
static int default_bins_;
static bool default_bins_isset_;
std::vector<double> binsize_;
static double default_binsize_;
static bool default_binsize_isset_;
std::vector<blop::var> axistitle_;
var rangetitle_;
var legend_;
function x_, y_;
static function default_x_, default_y_;
function condition_;
static function default_condition_;
function x_condition_, y_condition_;
static function default_x_condition_, default_y_condition_;
int maxlines_;
static int default_maxlines_;
public:
histopt();
histopt(const histopt&);
~histopt();
histopt& min(const int axis, const double minvalue);
double min(const int axis) const;
static void default_min(const double minvalue);
histopt& max(const int axis, const double maxvalue);
double max(const int axis) const;
static void default_max(const double maxvalue);
histopt& bins(const int axis, const int nbins);
int bins(const int axis) const;
static void default_bins(const int nbins);
histopt& binsize(const int axis, const double binsize);
double binsize(const int axis);
static void default_binsize(const double binsize);
histopt& axistitle(const int axis, const var &Title);
var axistitle(const int axis);
histopt& rangetitle(const var &Title);
var rangetitle();
histopt& legend(const var &Title);
var legend();
histopt& x(const function &f);
histopt& x(const function &f1, const function &f2);
histopt& x(const function &f1, const function &f2, const function &f3);
const function& x() const { return x_; }
static void default_x(const function &f);
static void default_x(const function &f1, const function &f2);
static void default_x(const function &f1, const function &f2, const function &f3);
histopt& y(const function &f);
const function& y() const { return y_; }
static void default_y(const function &f);
histopt &maxlines(const int i) { maxlines_=i; return *this; }
int maxlines() const { return maxlines_; }
static void default_maxlines(const int i) { default_maxlines_=i; }
histopt &condition(const function &f) { condition_ = f; return *this; }
const function &condition() const { return condition_; }
static void default_condition(const function &f) { default_condition_=f; }
histopt &x_condition(const function &f) { x_condition_ = f; return *this; }
const function &x_condition() const { return x_condition_; }
static void default_x_condition(const function &f) { default_x_condition_=f; }
histopt &y_condition(const function &f) { y_condition_ = f; return *this; }
const function &y_condition() const { return y_condition_; }
static void default_y_condition(const function &f) { default_y_condition_=f; }
histopt &xmin(double x)
{
if(x != unset) x_condition_ = (x<_1);
else x_condition_ = unset;
return *this;
}
histopt &xmax(double x)
{
if(x != unset) x_condition_ = (_1<x);
else x_condition_ = unset;
return *this;
}
histopt &xrange(double x1, double x2)
{
if(x1 == unset && x2 == unset) x_condition_ = unset;
if(x1 != unset && x2 != unset) x_condition_ = (x1<_1) && (_1<x2);
if(x1 == unset && x2 != unset) x_condition_ = (_1<x2);
if(x1 != unset && x2 == unset) x_condition_ = (x1<_1);
return *this;
}
histopt &ymin(double x)
{
if(x != unset) y_condition_ = (x<_1);
else y_condition_ = unset;
return *this;
}
histopt &ymax(double x)
{
if(x != unset) y_condition_ = (_1<x);
else y_condition_ = unset;
return *this;
}
histopt &yrange(double x1, double x2)
{
if(x1 == unset && x2 == unset) y_condition_ = unset;
if(x1 != unset && x2 != unset) y_condition_ = (x1<_1) && (_1<x2);
if(x1 == unset && x2 != unset) y_condition_ = (_1<x2);
if(x1 != unset && x2 == unset) y_condition_ = (x1<_1);
return *this;
}
friend class hist;
};
class mergeopt_side
{
protected:
double min_;
double max_;
int merge_;
public:
mergeopt_side();
mergeopt_side(const double Min, const double Max, const int Merge);
mergeopt_side(const mergeopt_side&);
~mergeopt_side();
bool operator==(const mergeopt_side &m_other) const { return (m_other.min_==min_ && m_other.max_==max_ && m_other.merge_==merge_ ? true : false); }
bool operator>(const mergeopt_side &m_other) const { return false; }
bool operator<(const mergeopt_side &m_other) const { return false; }
friend class hist;
};
class mergeopt : public std::vector<blop::mergeopt_side>
{
public:
mergeopt() : std::vector<blop::mergeopt_side>() { }
mergeopt(const mergeopt &m_other) : std::vector<blop::mergeopt_side>(m_other) { }
mergeopt& side(const double Min, const double Max, const int Merge);
};
class hist : public plottable
{
protected:
static graph_drawer* &default_graph_drawer_1_();
static graph_drawer* &default_graph_drawer_2_();
void set_graph_drawer_();
static point_drawer* default_point_drawer_;
int dim_;
std::vector<double> min_;
std::vector<double> max_;
std::vector<int> bins_;
std::vector<double> binsize_;
std::vector<blop::var> axistitle_;
var rangetitle_;
std::vector<int> mul_;
mutable std::vector<int> ind_;
std::vector<blop::meas> h_;
std::vector<int> m_;
std::vector<unsigned int> sequence_;
std::vector<unsigned int> invsequence_;
mutable datapoint datapoint_;
void reinit_(const int dim,
const std::vector<double> &dbegin, const std::vector<double> &dend,
const std::vector<int> &dbins,
const std::vector<blop::var> &dtitle, const var &rtitle,
const var &hlegend);
public:
static void default_drawstyle_1(const graph_drawer &d);
static void default_drawstyle_2(const graph_drawer &d);
static void default_pointtype(const point_drawer &);
hist();
hist(const histopt&);
hist(const double Min, const double Max, const int Bins,
const var &Title = "",
const var &rTitle="Entries/Bincell",
const var &Legend="");
hist(double min1, double max1, int bins1,
double min2, double max2, int bins2);
hist(const double Min1, const double Max1, const int Bins1, const var &Title1,
const double Min2, const double Max2, const int Bins2, const var &Title2,
const var &rTitle="Entries/Bincell", const var &Legend="");
hist(double min1, double max1, int bins1,
double min2, double max2, int bins2,
double min3, double max3, int bins3);
hist(const double Min1, const double Max1, const int Bins1, const var &Title1,
const double Min2, const double Max2, const int Bins2, const var &Title2,
const double Min3, const double Max3, const int Bins3, const var &Title3,
const var &rTitle="Entries/Bincell", const var &Legend="");
hist(const hist&);
~hist();
void reinit(const histopt&);
void reinit(const double Min, const double Max, const int Bins, const var &Title="",
const var &rTitle="Entries/Bincell", const var &Legend="");
void reinit(const double Min1, const double Max1, const int Bins1, const var &Title1,
const double Min2, const double Max2, const int Bins2, const var &Title2,
const var &rTitle="Entries/Bincell", const var &Legend="");
void reinit(const double Min1, const double Max1, const int Bins1, const var &Title1,
const double Min2, const double Max2, const int Bins2, const var &Title2,
const double Min3, const double Max3, const int Bins3, const var &Title3,
const var &rTitle="Entries/Bincell", const var &Legend="");
void reinit(const hist&);
const hist& operator=(const hist&);
const hist& operator+=(const hist&);
const hist& operator-=(const hist&);
const hist& operator*=(const hist&);
const hist& operator*=(const meas&);
const hist& operator*=(const double);
const hist& operator/=(const hist&);
const hist& operator/=(const meas&);
const hist& operator/=(const double);
hist project_out(const int axis) const;
hist slice(const int axis, const double level) const;
meas integral() const;
void transform(const function&);
static bool isfinite(const hist&);
static bool isinf(const hist&);
static bool isnan(const hist&);
static bool isset(const hist&);
static bool isunset(const hist&);
bool isfinite() const;
bool isinf() const;
bool isnan() const;
bool isset() const;
bool isunset() const;
hist &dup();
void mkfinite(const double newvalue=unset);
void annulate(const var &reset="");
template<class T>
class vector_1based : public std::vector<T>
{
public:
vector_1based() : std::vector<T>() { }
vector_1based(const size_type i) : std::vector<T>(i) { }
vector_1based(const vector_1based &v) : std::vector<T>(v) { }
T& operator[](const size_type i)
{
if ( i>0 && i<=this->size() ) return *(vector<T>::begin()+i-1);
else
{
warning::print("Index out of range! (1-based indices!!!)", "T& hist::vector_1based<T>::operator[](const size_type)");
if ( !(this->size()>0) ) { std::cerr<<"Empty vector! Exiting to avoid a segfault...\n"; exit(1); }
return *(vector<T>::begin());
}
}
const T& operator[](const size_type i) const
{
if ( i>0 && i<=this->size() ) return *(vector<T>::begin()+i-1);
else
{
warning::print("Index out of range! (1-based indices!!!)", "const T& hist::vector_1based<T>::operator[](const size_type) const");
if ( !(this->size()>0) ) { std::cerr<<"Empty vector! Exiting to avoid a segfault...\n"; exit(1); }
return *(vector<T>::begin());
}
}
};
typedef vector_1based<double> point;
typedef vector_1based<blop::meas> cell;
unsigned int bin(const point &pos) const;
unsigned int bin(const datapoint &pos) const;
unsigned int bin(const double x) const;
unsigned int bin(const double x, const double y) const;
unsigned int bin(const double x, const double y, const double z) const;
unsigned int bin(const double x, const double y, const double z, const double t) const;
unsigned int bin(const var &x) const;
unsigned int bin(const var &x, const var &y) const;
unsigned int bin(const var &x, const var &y, const var &z) const;
unsigned int bin(const var &x, const var &y, const var &z, const var &t) const;
cell pos(const unsigned int i) const;
meas pos(const unsigned int i, const int axis) const;
meas& operator[](const unsigned int);
const meas& operator[](const unsigned int) const;
double binsize(int axis) const;
double binwidth(int axis) const { return binsize(axis); }
hist& fill(const point &pos);
hist& fill(const point &pos, const double weight);
hist& remove(const point &pos);
hist& remove(const point &pos, const double weight);
hist& fill(const datapoint &pos);
hist& fill(const datapoint &pos, const var &weight);
hist& remove(const datapoint &pos);
hist& remove(const datapoint &pos, const var &weight);
hist& fill(const double);
hist& fill(const double, const double);
hist& fill(const double, const double, const double);
hist& fill(const double, const double, const double, const double);
hist& remove(const double);
hist& remove(const double, const double);
hist& remove(const double, const double, const double);
hist& remove(const double, const double, const double, const double);
hist& fill(const var&);
hist& fill(const var&, const var&);
hist& fill(const var&, const var&, const var&);
hist& fill(const var&, const var&, const var&, const var&);
hist& remove(const var&);
hist& remove(const var&, const var&);
hist& remove(const var&, const var&, const var&);
hist& remove(const var&, const var&, const var&, const var&);
hist& fill_range(double x1, double x2, double weight);
hist& merge(const mergeopt&);
hist& merge(const double Min, const double Max, const int Merge);
hist& merge(const double Min1, const double Max1, const int Merge1, const double Min2, const double Max2, const int Merge2);
hist& merge(const double Min1, const double Max1, const int Merge1, const double Min2, const double Max2, const int Merge2, const double Min3, const double Max3, const int Merge3);
hist& killbin(const unsigned int i);
hist& killpoint(const point &pos);
hist& killpoint(const datapoint &pos);
hist& killpoint(const double);
hist& killpoint(const double, const double);
hist& killpoint(const double, const double, const double);
hist& killpoint(const var&);
hist& killpoint(const var&, const var&);
hist& killpoint(const var&, const var&, const var&);
hist interpolate(const hist &other_scheme, const std::string &method="linear") const;
int dim() const;
hist& axistitle(const int axis, const var&);
var axistitle(const int axis) const;
hist& rangetitle(const var&);
var rangetitle() const;
hist& legend(const var&);
var legend() const;
int bins(const int axis) const;
class write_many
{
protected:
var dataFileName_;
ostream *output_;
bool isFlushed_;
std::vector<blop::hist*> oHistos_;
public:
write_many();
write_many(ostream &output);
write_many(const var &datafilename);
~write_many();
write_many& reinit(ostream &output);
write_many& reinit(const var &datafilename);
write_many& flush();
write_many& operator<<(hist&);
write_many& put(hist&);
};
hist& write(ostream &output);
hist& write(const var &filename);
hist& fill_from(istream &input, const histopt &hopt);
hist& fill_from(const var &filename, const histopt &hopt);
hist& fill_from(const dgraph &g, const histopt &hopt);
class read_many
{
protected:
var dataFileName_;
istream *input_;
bool isFlushed_;
std::vector< std::pair<blop::hist*, int> > iHistos_;
public:
read_many();
read_many(istream &input);
read_many(const var &datafilename);
~read_many();
read_many& reinit(istream &input);
read_many& reinit(const var &datafilename);
read_many& flush();
read_many& operator>>(hist&);
read_many& operator>>(const int number_of_histo);
read_many& get(hist&, const int number_of_histo=0);
static int dim(istream&);
static int dim(const var&);
static int numhists(istream&);
static int numhists(const var&);
};
hist& read(istream &input, const int number_of_histo=1);
hist& read(const var &datafilename, const int number_of_histo=1);
function x_hint() const;
function dx_hint() const;
function x1_hint() const;
function x2_hint() const;
function y_hint() const;
function dy_hint() const;
function y1_hint() const;
function y2_hint() const;
function z_hint() const;
function dz_hint() const;
function z1_hint() const;
function z2_hint() const;
const datapoint* get(int index) const;
size_type size() const;
double min(int d) const;
double max(int d) const;
var min(const function &f) const;
var max(const function &f) const;
int columns() const;
void prepare_for_draw(axis *,axis *, frame *, int count);
dgraph to_dgraph() const;
class qplot
{
protected:
mpps *blopMpps_;
var blopEpsName_;
var globaltitle_;
std::vector< std::pair<int, double> > min_;
std::vector< std::pair<int, double> > max_;
std::pair<bool, double> rangemin_;
std::pair<bool, double> rangemax_;
std::pair<bool, double> isomin_;
std::pair<bool, double> isomax_;
std::vector< std::pair<int, bool> > log_;
std::pair<bool, bool> rangelog_;
std::pair<bool, bool> isolog_;
public:
class oStuff_t
{
protected:
hist *h;
function f;
var l;
public:
oStuff_t() : h(NULL), f(unset), l("__NULL") { }
oStuff_t(const oStuff_t &other) : h(other.h), f(other.f), l(other.l) { }
oStuff_t(hist *hi, const function &func, const var &leg) : h(hi), f(func), l(leg) { }
bool operator==(const oStuff_t&) const { return false; }
bool operator<(const oStuff_t &) const { return false; }
bool operator>(const oStuff_t &) const { return false; }
friend class hist::qplot;
};
protected:
std::vector<blop::hist::qplot::oStuff_t> oStuff_;
bool doubleplot_;
bool isFlushed_;
public:
qplot(mpps &bm);
qplot(const var &blopepsname);
qplot();
qplot& reinit(mpps &bm);
qplot& reinit(const var &blopepsname);
qplot& reinit();
qplot(mpps &blopmpps, hist &h1, hist &h2);
qplot(const var &blopepsname, hist &h1, hist &h2);
qplot(hist &h1, hist &h2);
qplot(mpps &blopmpps, hist &h, const function &f, const var &legend="__NULL");
qplot(const var &blopepsname, hist &h, const function &f, const var &legend="__NULL");
qplot(hist &h, const function &f, const var &legend="__NULL");
qplot(mpps &blopmpps, const function &f1, const function &f2, const var &legend1="__NULL", const var &legend2="__NULL");
qplot(const var &blopepsname, const function &f1, const function &f2, const var &legend1="__NULL", const var &legend2="__NULL");
qplot(const function &f1, const function &f2, const var &legend1="__NULL", const var &legend2="__NULL");
qplot& reinit(mpps &blopmpps, hist &h1, hist &h2);
qplot& reinit(const var &blopepsname, hist &h1, hist &h2);
qplot& reinit(hist &h1, hist &h2);
qplot& reinit(mpps &blopmpps, hist &h, const function &f, const var &legend="__NULL");
qplot& reinit(const var &blopepsname, hist &h, const function &f, const var &legend="__NULL");
qplot& reinit(hist &h, const function &f, const var &legend="__NULL");
qplot& reinit(mpps &blopmpps, const function &f1, const function &f2, const var &legend1="__NULL", const var &legend2="__NULL");
qplot& reinit(const var &blopepsname, const function &f1, const function &f2, const var &legend1="__NULL", const var &legend2="__NULL");
qplot& reinit(const function &f1, const function &f2, const var &legend1="__NULL", const var &legend2="__NULL");
~qplot();
qplot& title(const var >itle);
qplot& min(const int axis, const double value);
qplot& max(const int axis, const double value);
qplot& rangemin(const double);
qplot& rangemax(const double);
qplot& isomin(const double);
qplot& isomax(const double);
qplot& log(const int axis, const bool flag);
qplot& rangelog(const bool);
qplot& isolog(const bool);
qplot& operator<<(hist &h);
qplot& put(hist &h);
qplot& operator<<(const function &f);
qplot& operator<<(const var &functionlegend);
qplot& put(const function &f, const var &functionlegend="__NULL");
static color color_sequence(const int);
static color color_mapping(double value, double min, double max);
qplot& flush();
};
bool operator==(const hist &h_other) const { return false; }
bool operator>(const hist &h_other) const { return false; }
bool operator<(const hist &h_other) const { return false; }
hist &layer(const var & l) { plottable::layer(l); return *this; }
};
hist apply(const function&, const hist&);
hist operator+(const hist&, const hist&);
hist operator-(const hist&, const hist&);
hist operator-(const hist&);
hist operator*(const hist&, const hist&);
hist operator*(const hist&, const meas&);
hist operator*(const hist&, const double);
hist operator*(const meas&, const hist&);
hist operator*(const double, const hist&);
hist operator/(const hist &, const hist&);
hist operator/(const hist&, const meas&);
hist operator/(const hist&, const double);
hist operator/(const meas&, const hist&);
hist operator/(const double, const hist&);
meas integral(const hist&);
hist& mkhist(istream &input, const histopt &hopt=histopt());
hist& mkhist(const var &filename, const histopt &hopt=histopt());
hist& mkhist(const dgraph &datagraph, const histopt &hopt=histopt());
hist& histplot(istream &input, const histopt &hopt=histopt());
hist& mhistplot(istream &input, const histopt &hopt=histopt());
hist& histplot(const var &filename, const histopt &hopt=histopt());
hist& mhistplot(const var &filename, const histopt &hopt=histopt());
hist& histplot(const dgraph &datagraph, const histopt &hopt=histopt());
hist& mhistplot(const dgraph &datagraph, const histopt &hopt=histopt());
}
#endif