1 /* 2 * data_bins.h -- ePiX::data_bins class for histogram data 3 * 4 * This file is part of ePiX, a C++ library for creating high-quality 5 * figures in LaTeX 6 * 7 * Version 1.1.19 8 * Last Change: September 17, 2007 9 */ 10 11 /* 12 * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 13 * Andrew D. Hwang <rot 13 nujnat at zngupf dot ubylpebff dot rqh> 14 * Department of Mathematics and Computer Science 15 * College of the Holy Cross 16 * Worcester, MA, 01610-2395, USA 17 */ 18 19 /* 20 * ePiX is free software; you can redistribute it and/or modify it 21 * under the terms of the GNU General Public License as published by 22 * the Free Software Foundation; either version 2 of the License, or 23 * (at your option) any later version. 24 * 25 * ePiX is distributed in the hope that it will be useful, but WITHOUT 26 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 27 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 28 * License for more details. 29 * 30 * You should have received a copy of the GNU General Public License 31 * along with ePiX; if not, write to the Free Software Foundation, Inc., 32 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 33 */ 34 35 /* 36 * This file provides the "data_bins" class. 37 * 38 * An object of type data_bins models a closed interval [lo, hi] 39 * divided into subintervals (not necessarily of equal length). Each 40 * subinterval is a "d_bin", whose endpoints are "cuts". A data_bins 41 * can read and sort numerical data, count how many numbers lie in 42 * each bin, and print the result as a bar chart (rectangle height 43 * proportional to population), histogram (area proportional to 44 * population), or as a spline interpolation. 45 * 46 * Ideally no data lies outside (lo, hi) or on a cut. Data on an end 47 * cut is "out of range", data on an interior cut contributes 1/2 to 48 * the population of each adjacent bin. A summary statistic warning is 49 * printed if any points are out of range or lie on a cut. 50 */ 51 52 #ifndef EPIX_DATA_BINS 53 #define EPIX_DATA_BINS 54 55 #include <vector> 56 #include <list> 57 58 namespace ePiX { 59 60 class d_bin; 61 62 class data_bins { 63 public: 64 data_bins(double lo, double hi, unsigned int n=1); 65 66 data_bins(const data_bins&); 67 data_bins& operator= (const data_bins&); 68 ~data_bins(); 69 70 data_bins& cut(double); // add a cut 71 data_bins& read(const std::vector<double>&); 72 73 unsigned int pop() const; // current population 74 75 // draw rectangles 76 void histogram(double scale=1) const; // area prop to pop 77 void bar_chart(double scale=1) const; // height prop to pop 78 void plot(double scale=1) const; // smooth interpolation 79 80 private: 81 double m_lo_val; 82 double m_hi_val; 83 84 unsigned int m_lo_ct; // population smaller than m_lo_val 85 unsigned int m_hi_ct; // population larger than m_hi_val 86 unsigned int m_pop; // current total population 87 88 unsigned int m_cut_hits; // number of data on a cut 89 bool m_cuts_locked; // true once we read data 90 91 std::list<double> m_cuts; 92 std::list<d_bin*> m_bins; 93 94 // bookkeeping 95 void initialize(); // convert cuts to bins and lock 96 void insert(double); // add data point 97 }; // end of class data_bins 98 99 } // end of namespace 100 101 #endif /* EPIX_DATA_BINS */ 102