Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

rootHist.cxx

Go to the documentation of this file.
00001 //  class rootHist
00002 //  Author:  Theodore Hierath
00003 //  This class contains a basic histogram function
00004 //  The bins are numbered from 0 to number of bins - 1;
00005 
00006 #include <iostream>
00007 #include "rootHist.h"
00008 
00009 // Specify the number of bins for the histogram
00010 rootHist::rootHist(int bins) : num_bins(bins)
00011 {
00012     if(bins <= 0)
00013     {
00014         std::cerr << "ERROR in constructor for roothist:\n" 
00015             "   The total number of bins must be greater than zero."
00016             << std::endl;
00017         exit(0);
00018     }
00019     
00020     hist = new double[num_bins];
00021     for (int i = 0; i < num_bins; i++) hist[i] = 0;
00022 }
00023 
00024 rootHist::~rootHist(void)
00025 {
00026     delete [] hist;
00027     hist = NULL;
00028 }
00029 
00030 rootHist::rootHist(const rootHist &oldHist) : num_bins(oldHist.num_bins)
00031 {
00032     hist = new double[num_bins];
00033     for (int i = 0; i < num_bins; i++) hist[i] = oldHist.hist[i];
00034 }
00035 
00036 // Update a specific bin by replacing its contents
00037 void rootHist::updateBin(int binNumber, double data)
00038 {
00039     if(binNumber < 0 || binNumber >= num_bins)
00040     {
00041         std::cerr << "Error:  bin number is out of range" << std::endl;
00042         exit(0);
00043     }
00044     hist[binNumber] = data;
00045 }
00046 
00047 // Retrieve the contents of a bin
00048 double rootHist::retrieveBin(int binNumber)
00049 {
00050     if(binNumber < 0 || binNumber >= num_bins)
00051     {
00052         std::cerr << "Error:  bin number is out of range" << std::endl;
00053         exit(0);
00054     }
00055     return hist[binNumber];
00056 }

Generated on Wed Oct 16 14:01:30 2002 by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001