CMS 3D CMS Logo

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() [1/2]

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

◆ ~ClusterizingHistogram()

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() [2/2]

ClusterizingHistogram::ClusterizingHistogram ( )
inlineprivate

Definition at line 39 of file ClusterizingHistogram.h.

39 {} // Prohibit

Member Function Documentation

◆ bin() [1/2]

int ClusterizingHistogram::bin ( float  x) const

Definition at line 21 of file ClusterizingHistogram.cc.

References binsiz, createfilelist::int, my_nbins, x, 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 }

◆ bin() [2/2]

int ClusterizingHistogram::bin ( double  x) const

Definition at line 29 of file ClusterizingHistogram.cc.

References binsiz, createfilelist::int, my_nbins, x, 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 }

◆ bin_pos()

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

◆ clusterize()

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, l1tPFClustersFromCombinedCalo_cfi::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

◆ dump() [1/6]

void ClusterizingHistogram::dump ( void  ) const

Definition at line 84 of file ClusterizingHistogram.cc.

References my_nbins.

Referenced by dump().

◆ dump() [2/6]

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, testProducerWithPsetDescEmpty_cfi::i1, testProducerWithPsetDescEmpty_cfi::i2, 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

◆ dump() [3/6]

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

◆ dump() [4/6]

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

◆ dump() [5/6]

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

◆ dump() [6/6]

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

◆ entries()

int ClusterizingHistogram::entries ( ) const
inline

Definition at line 22 of file ClusterizingHistogram.h.

References my_entries.

◆ fill()

void ClusterizingHistogram::fill ( float  x)

Definition at line 38 of file ClusterizingHistogram.cc.

References bin(), bin_entries, bin_means, binsiz, createfilelist::int, 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 }

◆ max_x()

float ClusterizingHistogram::max_x ( ) const
inline

Definition at line 21 of file ClusterizingHistogram.h.

References xmax.

21 { return xmax; }

◆ min_x()

float ClusterizingHistogram::min_x ( ) const
inline

Definition at line 20 of file ClusterizingHistogram.h.

References xmin.

20 { return xmin; }

◆ nbins()

int ClusterizingHistogram::nbins ( ) const
inline

Definition at line 19 of file ClusterizingHistogram.h.

References my_nbins.

◆ overflows()

int ClusterizingHistogram::overflows ( ) const
inline

Definition at line 24 of file ClusterizingHistogram.h.

References my_overflows.

◆ reset()

void ClusterizingHistogram::reset ( void  )

◆ underflows()

int ClusterizingHistogram::underflows ( ) const
inline

Definition at line 23 of file ClusterizingHistogram.h.

References my_underflows.

Member Data Documentation

◆ bin_entries

int* ClusterizingHistogram::bin_entries
private

◆ bin_means

float* ClusterizingHistogram::bin_means
private

◆ binsiz

float ClusterizingHistogram::binsiz
private

Definition at line 48 of file ClusterizingHistogram.h.

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

◆ my_entries

int ClusterizingHistogram::my_entries
private

Definition at line 43 of file ClusterizingHistogram.h.

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

◆ my_nbins

int ClusterizingHistogram::my_nbins
private

Definition at line 40 of file ClusterizingHistogram.h.

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

◆ my_overflows

int ClusterizingHistogram::my_overflows
private

Definition at line 45 of file ClusterizingHistogram.h.

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

◆ my_underflows

int ClusterizingHistogram::my_underflows
private

Definition at line 44 of file ClusterizingHistogram.h.

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

◆ xmax

float ClusterizingHistogram::xmax
private

◆ xmin

float ClusterizingHistogram::xmin
private