00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "PSHist/Axis.h"
00017
00018
00019
00020
00021 #include <iostream>
00022
00023
00024
00025
00026 #include "PSHist/Exceptions.h"
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 namespace PSHist {
00037
00038
00039
00040
00041 Axis::Axis(unsigned nbins, double amin, double amax)
00042 : m_amin(amin)
00043 , m_amax(amax)
00044 , m_nbins(nbins)
00045 , m_edges()
00046 {
00047 if (m_nbins == 0) throw ExceptionBins(ERR_LOC);
00048 if (m_amin >= m_amax) throw ExceptionAxisRange(ERR_LOC, m_amin, m_amax);
00049 }
00050
00051 Axis::Axis(unsigned nbins, const double *edges)
00052 : m_amin()
00053 , m_amax()
00054 , m_nbins(nbins)
00055 , m_edges(edges, edges+nbins+1)
00056 {
00057 if (m_nbins == 0) throw ExceptionBins(ERR_LOC);
00058
00059 for (const double* edge = edges; edge != edges+nbins; ++ edge) {
00060 if (*edge >= *(edge+1)) throw ExceptionAxisEdgeOrder(ERR_LOC);
00061 }
00062 }
00063
00064 const double*
00065 Axis::edges() const
00066 {
00067 if (m_edges.empty()) return 0;
00068 return &m_edges[0];
00069 }
00070
00071
00072 void
00073 Axis::print(std::ostream& out) const
00074 {
00075 out << "=========================================================\n";
00076 if (m_edges.empty()) {
00077 out << "Axis with equal bin sizes\n";
00078 } else {
00079 out << "Axis with variable bin sizes\n";
00080 }
00081 out << "Axis::m_nbins=" << m_nbins << " m_amin=" << m_amin << " m_amax=" << m_amax << '\n';
00082 if (not m_edges.empty()) {
00083 out << "Axis::m_edges[0]=" << m_edges[0] << " m_edges[N]=" << m_edges[m_nbins] << '\n';
00084 }
00085 out << "=========================================================\n";
00086 }
00087
00088 }