CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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.

16  {
17  delete[] bin_entries;
18  delete[] bin_means;
19 }
ClusterizingHistogram::ClusterizingHistogram ( )
inlineprivate

Definition at line 39 of file ClusterizingHistogram.h.

39 {} // Prohibit

Member Function Documentation

int ClusterizingHistogram::bin ( float  x) const

Definition at line 21 of file ClusterizingHistogram.cc.

References binsiz, my_nbins, xmax, and xmin.

Referenced by dump(), and fill().

21  {
22  if (x < xmin)
23  return -1;
24  else if (x > xmax)
25  return my_nbins;
26  else
27  return int((x - xmin) / binsiz);
28 }
int ClusterizingHistogram::bin ( double  x) const

Definition at line 29 of file ClusterizingHistogram.cc.

References binsiz, my_nbins, xmax, and xmin.

29  {
30  if (x < xmin)
31  return -1;
32  else if (x > xmax)
33  return my_nbins;
34  else
35  return int((x - xmin) / binsiz);
36 }
float ClusterizingHistogram::bin_pos ( int  i) const
inline

Definition at line 25 of file ClusterizingHistogram.h.

References bin_entries, bin_means, and mps_fire::i.

Referenced by clusterize(), and dump().

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

Definition at line 54 of file ClusterizingHistogram.cc.

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

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

54  {
55  vector<float> clust;
56  int nclust = 0;
57  bool inclust = false;
58  float last_pos = xmin - 1000. * resol;
59  int sum = 0;
60  float sumx = 0;
61  for (int i = 0; i < my_nbins; i++) {
62  if (bin_entries[i] != 0) {
63  if (fabs(bin_pos(i) - last_pos) > resol) {
64  inclust = false;
65  if (nclust != 0)
66  clust.push_back(sumx / sum); // create cluster
67  }
68  if (!inclust) {
69  nclust++;
70  sumx = 0.;
71  sum = 0;
72  }
73  sum += bin_entries[i];
74  sumx += bin_means[i];
75  last_pos = bin_pos(i);
76  inclust = true;
77  }
78  }
79  if (nclust != 0)
80  clust.push_back(sumx / sum); // create last cluster
81  return clust;
82 }
float bin_pos(int i) const
void ClusterizingHistogram::dump ( void  ) const

Definition at line 84 of file ClusterizingHistogram.cc.

References my_nbins.

Referenced by dump().

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

Definition at line 86 of file ClusterizingHistogram.cc.

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

86  {
87  cout << "Dumping ClusterizingHistogram contents:" << endl;
88  for (int i = max(i1, 0); i < min(i2, my_nbins); i++) {
89  cout << i << " " << bin_entries[i] << " " << bin_pos(i) << endl;
90  }
91  cout << "Underflows: " << my_underflows << endl;
92  cout << "Overflows: " << my_overflows << endl;
93  cout << "Total number of entries: " << my_entries << endl;
94 }
float bin_pos(int i) const
tuple cout
Definition: gather_cfg.py:144
void ClusterizingHistogram::dump ( float  x1,
float  x2 
) const

Definition at line 96 of file ClusterizingHistogram.cc.

References bin(), and dump().

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

Definition at line 97 of file ClusterizingHistogram.cc.

References bin(), and dump().

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

Definition at line 98 of file ClusterizingHistogram.cc.

References bin(), and dump().

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

Definition at line 99 of file ClusterizingHistogram.cc.

References bin(), and dump().

99 { 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 38 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 magneticfield::bRod::bRod(), magneticfield::bSector::bSector(), magneticfield::MagGeoBuilder::build(), MagGeoBuilderFromDDD::build(), and magneticfield::eSector::eSector().

38  {
39  if (x < xmin)
40  my_underflows++;
41  else if (x > xmax)
42  my_overflows++;
43  else {
44  int bin = int((x - xmin) / binsiz);
45  if (bin > my_nbins - 1)
46  bin = my_nbins - 1;
47  ++bin_entries[bin];
48  bin_means[bin] += x;
49  my_entries++;
50  // may be problematic for negative x; check!
51  }
52 }
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  )
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 48 of file ClusterizingHistogram.h.

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

int ClusterizingHistogram::my_entries
private

Definition at line 43 of file ClusterizingHistogram.h.

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

int ClusterizingHistogram::my_nbins
private

Definition at line 40 of file ClusterizingHistogram.h.

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

int ClusterizingHistogram::my_overflows
private

Definition at line 45 of file ClusterizingHistogram.h.

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

int ClusterizingHistogram::my_underflows
private

Definition at line 44 of file ClusterizingHistogram.h.

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

float ClusterizingHistogram::xmax
private
float ClusterizingHistogram::xmin
private