14#ifndef SCT_SimpleHisto_h
15#define SCT_SimpleHisto_h
22 typedef std::map<float, unsigned int>
S_t;
26 init(
S_t& s,
const float xlo,
const float xhi,
const unsigned int nbins) {
27 if ((xhi <= xlo) or (nbins<2))
return false;
28 float increment{(xhi-xlo)/nbins};
31 for (
unsigned int i{0}; i!=nbins; ++i) {
35 return (s.size()==nbins);
41 S_t::const_iterator start{s.begin()};
42 S_t::const_iterator end{s.end()};
43 unsigned int nbins{
static_cast<unsigned int>(s.size())};
44 if (value * nbins > ((--end)->first - start->first) * (nbins+1))
return 1;
45 S_t::iterator i=s.upper_bound(value);
46 if (i==start)
return -1;
54 std::ostringstream os;
56 for (S_t::const_iterator i{s.begin()}; i!=s.end(); ++i) {
57 os<<
"<b x=\""<<i->first<<
"\">"<<i->second<<
"</b>\n";
64 xmlHeader(
const std::string& version=
"1.0",
const std::string& encoding=
"UTF-8") {
65 return "<?xml version=\""+version+
"\" encoding=\""+encoding+
"\" standalone=\"yes\"?>";
69 return "<?xml-stylesheet type=\"text/xsl\" href=\""+path+
"\"?>";
SCT_SimpleHisto.h C++ projects.
std::string xmlHeader(const std::string &version="1.0", const std::string &encoding="UTF-8")
bool init(S_t &s, const float xlo, const float xhi, const unsigned int nbins)
Initialize a map to be used as a histogram.
std::map< float, unsigned int > S_t
int fill(S_t &s, const float value)
std::string stylesheet(const std::string &path)
std::string asXmlString(const S_t &s)