CMS 3D CMS Logo

Public Member Functions | Private Attributes

evf::AsciiHisto Class Reference

#include <AsciiHisto.h>

List of all members.

Public Member Functions

 AsciiHisto (std::string title, unsigned int nbins, float min, float max)
std::string & draw ()
void fill (float x)
void fill (float *cont)
void fillDeque (std::deque< float > &cont)
int maxbin ()

Private Attributes

float binsize_
std::vector< float > cont_
std::string current_
unsigned int nbins_
std::string title_
bool uptodate_
float xmax_
float xmin_
float ymax_
float ymin_

Detailed Description

Definition at line 14 of file AsciiHisto.h.


Constructor & Destructor Documentation

evf::AsciiHisto::AsciiHisto ( std::string  title,
unsigned int  nbins,
float  min,
float  max 
) [inline]

Definition at line 17 of file AsciiHisto.h.

References binsize_, nbins_, xmax_, and xmin_.

                                                                         : 
      uptodate_(false),  
      nbins_(nbins), xmin_(min), xmax_(max), ymax_(-100000.), cont_(nbins_,0), title_(title)
    {
      float span = xmax_-xmin_;
      binsize_ = span/nbins_;
    }

Member Function Documentation

std::string& evf::AsciiHisto::draw ( ) [inline]

Definition at line 56 of file AsciiHisto.h.

References binsize_, cont_, current_, i, j, maxbin(), nbins_, title_, uptodate_, xmin_, and ymax_.

Referenced by evf::AsciiRollingChart::draw().

    {
      if(uptodate_) return current_;
      maxbin();
      float yscale = (ymax_*1.2) /20.;
      std::ostringstream ost;
      ost << "         ^"; 
      ost << std::setw(nbins_-title_.size()) << " ";                
      ost << title_ << std::endl;
      //      std::cout << "         ^" <<  "                " << title_ << std::endl;
      for(int j = 20; j>=0; j--)
        {
          //      std::cout << "--------------> "<< j << std::endl;
          if(j%5==0){
            ost << std::setw(8) << yscale*j << "-|";
            //      std::cout << std::setw(8) << yscale*j << "-|";
          }
          else{
            ost << "         |";
            //      std::cout  << "         |";
          }
          for(unsigned int i = 0; i < nbins_+5; i++)
            {
              if(j==0) {ost << "-"; /*std::cout << "-";*/}
              else
                {
                  if(i<nbins_ && cont_[i] > yscale*j) 
                    {ost << "*"; /*std::cout << "*";*/}
                  else
                    {ost << " "; /*std::cout << " ";*/}
                }
            }
          if(j==0){ost << ">"; /*std::cout << ">";*/}
          ost << std::endl;
          //      std::cout << std::endl;
        }
      ost << "         ";
      //      std::cout  << "         ";

      for(unsigned int i = 0; i < nbins_+5; i++)
        {
          if(i%10==0)
            {ost << "|"; /*std::cout << "|";*/}
          else
            {ost << " "; /*std::cout << " ";*/}
        }
      ost << std::endl;
      //      std::cout << std::endl;
      ost << std::setw(10) << xmin_ ;
      //      std::cout << std::setw(10) << xmin_; 
      for(unsigned int i = 0; i < nbins_+5; i++)
        if((i+3)%10==0){ost << std::setw(10) << xmin_+binsize_*(i+3); 
          //      std::cout << std::setw(10) << xmin_+binsize_*(i+3); 
        }
      ost << std::endl;
      //      std::cout << std::endl;
      
      current_ = ost.str();
      return current_;
    }
void evf::AsciiHisto::fill ( float *  cont) [inline]

Definition at line 31 of file AsciiHisto.h.

References cont_, i, and uptodate_.

    {
      uptodate_ = false;
      for(unsigned int i = 0; i < cont_.size(); i++)
        cont_[i] = cont[i];
    }
void evf::AsciiHisto::fill ( float  x) [inline]

Definition at line 25 of file AsciiHisto.h.

References newFWLiteAna::bin, binsize_, cont_, uptodate_, and xmin_.

    {
      uptodate_ = false;
      int bin = (x-xmin_)/binsize_;
      cont_[bin]++;
    }
void evf::AsciiHisto::fillDeque ( std::deque< float > &  cont) [inline]

Definition at line 38 of file AsciiHisto.h.

References cont_, i, and uptodate_.

Referenced by evf::AsciiRollingChart::flip().

    {
      uptodate_ = false;
      for(unsigned int i = 0; i < cont_.size(); i++)
        cont_[i] = cont.at(i);
    }
int evf::AsciiHisto::maxbin ( ) [inline]

Definition at line 45 of file AsciiHisto.h.

References cont_, i, nbins_, and ymax_.

Referenced by draw().

    {
      int retval = -1;
      ymax_ = -100000.;
      for(unsigned int i = 0; i < nbins_; i++)
        if(ymax_ < cont_[i]){ymax_ = cont_[i]; retval = i;}
/*       std::cout << "max bin " << retval << " has " << ymax_ << std::endl; */
/*       std::cout << "nbins " << nbins_  */
/*              << " binsize " << binsize_ << std::endl; */
      return retval;
    }

Member Data Documentation

float evf::AsciiHisto::binsize_ [private]

Definition at line 120 of file AsciiHisto.h.

Referenced by AsciiHisto(), draw(), and fill().

std::vector<float> evf::AsciiHisto::cont_ [private]

Definition at line 125 of file AsciiHisto.h.

Referenced by draw(), fill(), fillDeque(), and maxbin().

std::string evf::AsciiHisto::current_ [private]

Definition at line 126 of file AsciiHisto.h.

Referenced by draw().

unsigned int evf::AsciiHisto::nbins_ [private]

Definition at line 119 of file AsciiHisto.h.

Referenced by AsciiHisto(), draw(), and maxbin().

std::string evf::AsciiHisto::title_ [private]

Definition at line 127 of file AsciiHisto.h.

Referenced by draw().

Definition at line 118 of file AsciiHisto.h.

Referenced by draw(), fill(), and fillDeque().

float evf::AsciiHisto::xmax_ [private]

Definition at line 122 of file AsciiHisto.h.

Referenced by AsciiHisto().

float evf::AsciiHisto::xmin_ [private]

Definition at line 121 of file AsciiHisto.h.

Referenced by AsciiHisto(), draw(), and fill().

float evf::AsciiHisto::ymax_ [private]

Definition at line 123 of file AsciiHisto.h.

Referenced by draw(), and maxbin().

float evf::AsciiHisto::ymin_ [private]

Definition at line 124 of file AsciiHisto.h.