CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
ClusterizingHistogram Class Reference

#include <ClusterizingHistogram.h>

Public Member Functions

int bin (float x) const
 
int bin (double x) const
 
float bin_pos (int i) const
 
std::vector< float > clusterize (float resolution)
 
 ClusterizingHistogram (int nb, float xmi, float xma)
 
void dump () const
 
void dump (int i1, int i2) const
 
void dump (float x1, float x2) const
 
void dump (double x1, double x2) const
 
void dump (float x1, double x2) const
 
void dump (double x1, float x2) 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

int * bin_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 
)
ClusterizingHistogram::~ClusterizingHistogram ( )

Definition at line 16 of file ClusterizingHistogram.cc.

References bin_entries, and bin_means.

ClusterizingHistogram::ClusterizingHistogram ( )
inlineprivate

Definition at line 40 of file ClusterizingHistogram.h.

40 {} // Prohibit

Member Function Documentation

int ClusterizingHistogram::bin ( float  x) const

Definition at line 18 of file ClusterizingHistogram.cc.

References binsiz, my_nbins, xmax, and xmin.

Referenced by dump(), and fill().

18  {
19  if (x < xmin) return -1;
20  else if (x > xmax) return my_nbins;
21  else return int((x-xmin)/binsiz);
22 }
int ClusterizingHistogram::bin ( double  x) const

Definition at line 23 of file ClusterizingHistogram.cc.

References binsiz, my_nbins, xmax, and xmin.

23  {
24  if (x < xmin) return -1;
25  else if (x > xmax) return my_nbins;
26  else return int((x-xmin)/binsiz);
27 }
float ClusterizingHistogram::bin_pos ( int  i) const
inline

Definition at line 25 of file ClusterizingHistogram.h.

References bin_entries, bin_means, and i.

Referenced by clusterize(), and dump().

25  {
26  return (bin_entries[i]!=0) ? bin_means[i]/bin_entries[i] : 0;}
int i
Definition: DBlmapReader.cc:9
vector< float > ClusterizingHistogram::clusterize ( float  resolution)

Definition at line 42 of file ClusterizingHistogram.cc.

References bin_entries, bin_means, bin_pos(), i, my_nbins, DeadROCCounter::nclust, and xmin.

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

42  {
43  vector<float> clust;
44  int nclust = 0;
45  bool inclust = false;
46  float last_pos = xmin - 1000.*resol;
47  int sum = 0;
48  float sumx = 0;
49  for (int i=0; i<my_nbins; i++) {
50  if (bin_entries[i] != 0) {
51  if ( fabs(bin_pos(i)-last_pos) > resol) {
52  inclust = false;
53  if (nclust != 0) clust.push_back( sumx/sum); // create cluster
54  }
55  if (!inclust) {
56  nclust++;
57  sumx = 0.;
58  sum = 0;
59  }
60  sum += bin_entries[i];
61  sumx += bin_means[i];
62  last_pos = bin_pos(i);
63  inclust = true;
64  }
65  }
66  if (nclust != 0) clust.push_back( sumx/sum); // create last cluster
67  return clust;
68 }
int i
Definition: DBlmapReader.cc:9
float bin_pos(int i) const
void ClusterizingHistogram::dump ( void  ) const

Definition at line 71 of file ClusterizingHistogram.cc.

References my_nbins.

Referenced by dump().

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

Definition at line 73 of file ClusterizingHistogram.cc.

References bin_entries, bin_pos(), gather_cfg::cout, i, bookConverter::max, min(), my_entries, my_nbins, my_overflows, and my_underflows.

73  {
74  cout << "Dumping ClusterizingHistogram contents:" << endl;
75  for (int i=max(i1,0); i<min(i2,my_nbins); i++) {
76  cout << i << " " << bin_entries[i] << " " << bin_pos(i) << endl;
77  }
78  cout << "Underflows: " << my_underflows << endl;
79  cout << "Overflows: " << my_overflows << endl;
80  cout << "Total number of entries: " << my_entries << endl;
81 }
int i
Definition: DBlmapReader.cc:9
T min(T a, T b)
Definition: MathUtil.h:58
float bin_pos(int i) const
tuple cout
Definition: gather_cfg.py:145
void ClusterizingHistogram::dump ( float  x1,
float  x2 
) const

Definition at line 83 of file ClusterizingHistogram.cc.

References bin(), and dump().

83 { 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().

84 { 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().

85 { dump( bin(x1), bin(x2));}
void ClusterizingHistogram::dump ( double  x1,
float  x2 
) const

Definition at line 86 of file ClusterizingHistogram.cc.

References bin(), and dump().

86 { dump( bin(x1), bin(x2));}
int ClusterizingHistogram::entries ( ) const
inline

Definition at line 22 of file ClusterizingHistogram.h.

References my_entries.

void ClusterizingHistogram::fill ( float  x)

Definition at line 29 of file ClusterizingHistogram.cc.

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

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

29  {
30  if (x < xmin) my_underflows++;
31  else if (x > xmax) my_overflows++;
32  else {
33  int bin = int((x-xmin)/binsiz);
34  if ( bin > my_nbins-1) bin = my_nbins-1;
35  ++bin_entries[bin];
36  bin_means[bin] += x;
37  my_entries++;
38  // may be problematic for negative x; check!
39  }
40 }
float ClusterizingHistogram::max_x ( ) const
inline

Definition at line 21 of file ClusterizingHistogram.h.

References xmax.

21 {return xmax;}
float ClusterizingHistogram::min_x ( ) const
inline

Definition at line 20 of file ClusterizingHistogram.h.

References xmin.

20 {return xmin;}
int ClusterizingHistogram::nbins ( ) const
inline

Definition at line 19 of file ClusterizingHistogram.h.

References my_nbins.

int ClusterizingHistogram::overflows ( ) const
inline

Definition at line 24 of file ClusterizingHistogram.h.

References 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.

88  {
89  my_entries = 0;
90  my_underflows = 0;
91  my_overflows = 0;
92  for (int i=0; i<my_nbins; i++) {
93  bin_entries[i] = 0;
94  bin_means[i] = 0.;
95  }
96 }
int i
Definition: DBlmapReader.cc:9
int ClusterizingHistogram::underflows ( ) const
inline

Definition at line 23 of file ClusterizingHistogram.h.

References my_underflows.

Member Data Documentation

int* ClusterizingHistogram::bin_entries
private
float* ClusterizingHistogram::bin_means
private
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
float ClusterizingHistogram::xmin
private