CMS 3D CMS Logo

ClusterizingHistogram Class Reference

A very simple 1D equidistant bin histogram that has the ability to clusterize it's contents. More...

#include <Utilities/BinningTools/interface/ClusterizingHistogram.h>

List of all members.

Public Member Functions

int bin (double x) const
int bin (float x) const
float bin_pos (int i) const
std::vector< float > clusterize (float resolution)
 ClusterizingHistogram (int nb, float xmi, float xma)
void dump (double x1, float x2) const
void dump (float x1, double x2) const
void dump (double x1, double x2) const
void dump (float x1, float x2) const
void dump (int i1, int i2) const
void dump () const
int entries () const
void fill (float x)
float max_x () const
float min_x () const
int nbins () const
int overflows () const
void reset ()
int underflows () const
 ~ClusterizingHistogram ()

Private Member Functions

 ClusterizingHistogram ()

Private Attributes

intbin_entries
float * bin_means
float binsiz
int my_entries
int my_nbins
int my_overflows
int my_underflows
float xmax
float xmin


Detailed Description

A very simple 1D equidistant bin histogram that has the ability to clusterize it's contents.

The bin entries are averaged in X, giving more accurate indication of where the bin contents are than the center of the bin.

Definition at line 13 of file ClusterizingHistogram.h.


Constructor & Destructor Documentation

ClusterizingHistogram::ClusterizingHistogram ( int  nb,
float  xmi,
float  xma 
)

Definition at line 6 of file ClusterizingHistogram.cc.

References bin_entries, bin_means, binsiz, i, my_nbins, xmax, and xmin.

00006                                                                          : 
00007   my_nbins(nb), xmin(xmi), xmax(xma), my_entries(0), my_underflows(0), my_overflows(0) {
00008     bin_entries = new int[my_nbins];
00009     bin_means = new float[my_nbins];
00010     binsiz = (xmax-xmin) / my_nbins;
00011     for (int i=0; i<my_nbins; i++) {
00012       bin_entries[i] = 0;
00013       bin_means[i] = 0.;
00014     }
00015 }

ClusterizingHistogram::~ClusterizingHistogram (  ) 

Definition at line 16 of file ClusterizingHistogram.cc.

References bin_entries, and bin_means.

00016 { delete[] bin_entries; delete [] bin_means;}

ClusterizingHistogram::ClusterizingHistogram (  )  [inline, private]

Definition at line 40 of file ClusterizingHistogram.h.

00040 {}  // Prohibit


Member Function Documentation

int ClusterizingHistogram::bin ( double  x  )  const

Definition at line 23 of file ClusterizingHistogram.cc.

References binsiz, int, my_nbins, xmax, and xmin.

00023                                               {
00024   if      (x < xmin) return -1;
00025   else if (x > xmax) return my_nbins;
00026   else return int((x-xmin)/binsiz);
00027 }

int ClusterizingHistogram::bin ( float  x  )  const

Definition at line 18 of file ClusterizingHistogram.cc.

References binsiz, int, my_nbins, xmax, and xmin.

Referenced by dump(), and fill().

00018                                              {
00019   if      (x < xmin) return -1;
00020   else if (x > xmax) return my_nbins;
00021   else return int((x-xmin)/binsiz);
00022 }

float ClusterizingHistogram::bin_pos ( int  i  )  const [inline]

Definition at line 25 of file ClusterizingHistogram.h.

References bin_entries, and bin_means.

Referenced by clusterize(), and dump().

00025                              {
00026     return (bin_entries[i]!=0) ? bin_means[i]/bin_entries[i] : 0;}

vector< float > ClusterizingHistogram::clusterize ( float  resolution  ) 

Definition at line 42 of file ClusterizingHistogram.cc.

References bin_entries, bin_means, bin_pos(), i, my_nbins, sum(), and xmin.

Referenced by MagGeoBuilderFromDDD::bRod::bRod(), MagGeoBuilderFromDDD::bSector::bSector(), MagGeoBuilderFromDDD::build(), and MagGeoBuilderFromDDD::eSector::eSector().

00042                                                             {
00043   vector<float> clust;
00044   int nclust = 0;
00045   bool inclust = false;
00046   float last_pos = xmin - 1000.*resol;
00047   int sum = 0;
00048   float sumx = 0;
00049   for (int i=0; i<my_nbins; i++) {
00050     if (bin_entries[i] != 0) {
00051       if ( fabs(bin_pos(i)-last_pos) > resol) {
00052         inclust = false;
00053         if (nclust != 0) clust.push_back( sumx/sum);  // create cluster
00054       }
00055       if (!inclust) {
00056         nclust++;
00057         sumx = 0.;
00058         sum = 0;
00059       }
00060       sum += bin_entries[i];
00061       sumx += bin_means[i];
00062       last_pos = bin_pos(i);
00063       inclust = true;
00064     }
00065   }
00066   if (nclust != 0) clust.push_back( sumx/sum);  // create last cluster
00067   return clust;
00068 }

void ClusterizingHistogram::dump ( double  x1,
float  x2 
) const

Definition at line 86 of file ClusterizingHistogram.cc.

References bin(), and dump().

00086 { dump( bin(x1), bin(x2));}

void ClusterizingHistogram::dump ( float  x1,
double  x2 
) const

Definition at line 85 of file ClusterizingHistogram.cc.

References bin(), and dump().

00085 { dump( bin(x1), bin(x2));}

void ClusterizingHistogram::dump ( double  x1,
double  x2 
) const

Definition at line 84 of file ClusterizingHistogram.cc.

References bin(), and dump().

00084 { dump( bin(x1), bin(x2));}

void ClusterizingHistogram::dump ( float  x1,
float  x2 
) const

Definition at line 83 of file ClusterizingHistogram.cc.

References bin(), and dump().

00083 { dump( bin(x1), bin(x2));}

void ClusterizingHistogram::dump ( int  i1,
int  i2 
) const

Definition at line 73 of file ClusterizingHistogram.cc.

References bin_entries, bin_pos(), GenMuonPlsPt100GeV_cfg::cout, lat::endl(), i, max, min, my_entries, my_nbins, my_overflows, and my_underflows.

00073                                                      {
00074   cout << "Dumping ClusterizingHistogram contents:" << endl;
00075   for (int i=max(i1,0); i<min(i2,my_nbins); i++) {
00076     cout << i << "  " << bin_entries[i] << "   " << bin_pos(i) << endl;
00077   }
00078   cout << "Underflows: " << my_underflows << endl;
00079   cout << "Overflows:  " << my_overflows << endl;
00080   cout << "Total number of entries: " << my_entries << endl;
00081 }

void ClusterizingHistogram::dump ( void   )  const

Definition at line 71 of file ClusterizingHistogram.cc.

References my_nbins.

Referenced by dump().

00071 { dump(0, my_nbins);}

int ClusterizingHistogram::entries (  )  const [inline]

Definition at line 22 of file ClusterizingHistogram.h.

References my_entries.

00022 {return my_entries;}

void ClusterizingHistogram::fill ( float  x  ) 

Definition at line 29 of file ClusterizingHistogram.cc.

References bin(), bin_entries, bin_means, binsiz, int, my_entries, my_nbins, my_overflows, my_underflows, xmax, and xmin.

Referenced by MagGeoBuilderFromDDD::bRod::bRod(), MagGeoBuilderFromDDD::bSector::bSector(), MagGeoBuilderFromDDD::build(), and MagGeoBuilderFromDDD::eSector::eSector().

00029                                          {
00030   if      (x < xmin) my_underflows++;
00031   else if (x > xmax) my_overflows++;
00032   else {
00033     int bin = int((x-xmin)/binsiz);
00034     if ( bin > my_nbins-1) bin = my_nbins-1;
00035     ++bin_entries[bin];
00036     bin_means[bin] += x;
00037     my_entries++;
00038     // may be problematic for negative x; check!
00039   }
00040 }

float ClusterizingHistogram::max_x (  )  const [inline]

Definition at line 21 of file ClusterizingHistogram.h.

References xmax.

00021 {return xmax;}

float ClusterizingHistogram::min_x (  )  const [inline]

Definition at line 20 of file ClusterizingHistogram.h.

References xmin.

00020 {return xmin;}

int ClusterizingHistogram::nbins (  )  const [inline]

Definition at line 19 of file ClusterizingHistogram.h.

References my_nbins.

00019 {return my_nbins;}

int ClusterizingHistogram::overflows (  )  const [inline]

Definition at line 24 of file ClusterizingHistogram.h.

References my_overflows.

00024 {return my_overflows;}

void ClusterizingHistogram::reset ( void   ) 

Definition at line 88 of file ClusterizingHistogram.cc.

References bin_entries, bin_means, i, my_entries, my_nbins, my_overflows, and my_underflows.

00088                                   {
00089   my_entries = 0;
00090   my_underflows = 0;
00091   my_overflows = 0;
00092   for (int i=0; i<my_nbins; i++) {
00093     bin_entries[i] = 0;
00094     bin_means[i] = 0.;
00095   }
00096 }

int ClusterizingHistogram::underflows (  )  const [inline]

Definition at line 23 of file ClusterizingHistogram.h.

References my_underflows.

00023 {return my_underflows;}


Member Data Documentation

int* ClusterizingHistogram::bin_entries [private]

Definition at line 47 of file ClusterizingHistogram.h.

Referenced by bin_pos(), clusterize(), ClusterizingHistogram(), dump(), fill(), reset(), and ~ClusterizingHistogram().

float* ClusterizingHistogram::bin_means [private]

Definition at line 48 of file ClusterizingHistogram.h.

Referenced by bin_pos(), clusterize(), ClusterizingHistogram(), fill(), reset(), and ~ClusterizingHistogram().

float ClusterizingHistogram::binsiz [private]

Definition at line 49 of file ClusterizingHistogram.h.

Referenced by bin(), ClusterizingHistogram(), and fill().

int ClusterizingHistogram::my_entries [private]

Definition at line 44 of file ClusterizingHistogram.h.

Referenced by dump(), entries(), fill(), and reset().

int ClusterizingHistogram::my_nbins [private]

Definition at line 41 of file ClusterizingHistogram.h.

Referenced by bin(), clusterize(), ClusterizingHistogram(), dump(), fill(), nbins(), and reset().

int ClusterizingHistogram::my_overflows [private]

Definition at line 46 of file ClusterizingHistogram.h.

Referenced by dump(), fill(), overflows(), and reset().

int ClusterizingHistogram::my_underflows [private]

Definition at line 45 of file ClusterizingHistogram.h.

Referenced by dump(), fill(), reset(), and underflows().

float ClusterizingHistogram::xmax [private]

Definition at line 43 of file ClusterizingHistogram.h.

Referenced by bin(), ClusterizingHistogram(), fill(), and max_x().

float ClusterizingHistogram::xmin [private]

Definition at line 42 of file ClusterizingHistogram.h.

Referenced by bin(), clusterize(), ClusterizingHistogram(), fill(), and min_x().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:16:21 2009 for CMSSW by  doxygen 1.5.4