Skip to content

Commit

Permalink
Merge pull request #76 from kjs73/hist_bin_centers
Browse files Browse the repository at this point in the history
add function to get bin centers, add cpp test
  • Loading branch information
smcantab committed Mar 22, 2016
2 parents 2b69457 + f470cd7 commit ba02c6b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
6 changes: 6 additions & 0 deletions cpp_tests/source/test_histogram.cpp
Expand Up @@ -121,4 +121,10 @@ TEST_F(TestHistogram, TestBinning){
EXPECT_NEAR(vecdata_normalized.at(ii), true_i, 2 * error.at(ii));
}
}
// Test ticks function returns bin centers
const std::vector<double> vectics = hist.get_vectics();
size_t i = 0;
for (const double x : vectics) {
EXPECT_DOUBLE_EQ(-42 + (0.5 + i++) * 2, x);
}
}
10 changes: 9 additions & 1 deletion source/histogram.cpp
Expand Up @@ -104,6 +104,15 @@ std::vector<double> Histogram::get_vecdata_normalized() const
return result;
}

std::vector<double> Histogram::get_vectics() const
{
std::vector<double> result(m_hist.size(), 0);
for (size_t i = 0; i < m_hist.size(); ++i) {
result.at(i) = get_position(i);
}
return result;
}

void Histogram::print_terminal() const
{
for(size_t i = 0; i < m_hist.size(); ++i) {
Expand All @@ -112,5 +121,4 @@ void Histogram::print_terminal() const
}
}


}//namespace mcpele
7 changes: 4 additions & 3 deletions source/mcpele/histogram.h
Expand Up @@ -82,10 +82,11 @@ class Histogram{
int get_count() const { return m_niter; }
double get_mean() const { return m_moments.mean(); }
double get_variance() const { return m_moments.variance(); }
std::vector<double>::iterator begin(){return m_hist.begin(); }
std::vector<double>::iterator end(){return m_hist.end(); }
std::vector<double>::iterator begin(){ return m_hist.begin(); }
std::vector<double>::iterator end(){ return m_hist.end(); }
double get_position(const size_t bin_index) const { return m_min + (0.5 + bin_index) * m_bin; }
std::vector<double> get_vecdata() const {return m_hist; }
std::vector<double> get_vectics() const;
std::vector<double> get_vecdata() const { return m_hist; }
double get_entry(const size_t bin_index) const { return m_hist.at(bin_index); }
std::vector<double> get_vecdata_error() const;
std::vector<double> get_vecdata_normalized() const;
Expand Down

0 comments on commit ba02c6b

Please sign in to comment.