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 (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 () const
 
void dump (double x1, double x2) const
 
void dump (double x1, float x2) const
 
void dump (float x1, double x2) const
 
void dump (float x1, float x2) const
 
void dump (int i1, int i2) 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 
)

Definition at line 6 of file ClusterizingHistogram.cc.

7  : my_nbins(nb), xmin(xmi), xmax(xma), my_entries(0), my_underflows(0), my_overflows(0) {
8  bin_entries = new int[my_nbins];
9  bin_means = new float[my_nbins];
10  binsiz = (xmax - xmin) / my_nbins;
11  for (int i = 0; i < my_nbins; i++) {
12  bin_entries[i] = 0;
13  bin_means[i] = 0.;
14  }
15 }

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

◆ ~ClusterizingHistogram()

ClusterizingHistogram::~ClusterizingHistogram ( )

Definition at line 16 of file ClusterizingHistogram.cc.

16  {
17  delete[] bin_entries;
18  delete[] bin_means;
19 }

References bin_entries, and bin_means.

◆ 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 ( double  x) const

Definition at line 29 of file ClusterizingHistogram.cc.

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 }

References binsiz, createfilelist::int, my_nbins, x, xmax, and xmin.

◆ bin() [2/2]

int ClusterizingHistogram::bin ( float  x) const

Definition at line 21 of file ClusterizingHistogram.cc.

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 }

References binsiz, createfilelist::int, my_nbins, x, xmax, and xmin.

Referenced by dump(), and fill().

◆ bin_pos()

float ClusterizingHistogram::bin_pos ( int  i) const
inline

Definition at line 25 of file ClusterizingHistogram.h.

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

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.

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 }

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

◆ dump() [1/6]

void ClusterizingHistogram::dump ( void  ) const

Definition at line 84 of file ClusterizingHistogram.cc.

84 { dump(0, my_nbins); }

References my_nbins.

Referenced by dump().

◆ dump() [2/6]

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

◆ dump() [3/6]

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

◆ dump() [4/6]

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

◆ dump() [5/6]

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

◆ dump() [6/6]

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

Definition at line 86 of file ClusterizingHistogram.cc.

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 }

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

◆ entries()

int ClusterizingHistogram::entries ( ) const
inline

Definition at line 22 of file ClusterizingHistogram.h.

22 { return my_entries; }

References my_entries.

◆ fill()

void ClusterizingHistogram::fill ( float  x)

Definition at line 38 of file ClusterizingHistogram.cc.

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 }

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

◆ max_x()

float ClusterizingHistogram::max_x ( ) const
inline

Definition at line 21 of file ClusterizingHistogram.h.

21 { return xmax; }

References xmax.

◆ min_x()

float ClusterizingHistogram::min_x ( ) const
inline

Definition at line 20 of file ClusterizingHistogram.h.

20 { return xmin; }

References xmin.

◆ nbins()

int ClusterizingHistogram::nbins ( ) const
inline

Definition at line 19 of file ClusterizingHistogram.h.

19 { return my_nbins; }

References my_nbins.

◆ overflows()

int ClusterizingHistogram::overflows ( ) const
inline

Definition at line 24 of file ClusterizingHistogram.h.

24 { return my_overflows; }

References my_overflows.

◆ reset()

void ClusterizingHistogram::reset ( void  )

Definition at line 101 of file ClusterizingHistogram.cc.

101  {
102  my_entries = 0;
103  my_underflows = 0;
104  my_overflows = 0;
105  for (int i = 0; i < my_nbins; i++) {
106  bin_entries[i] = 0;
107  bin_means[i] = 0.;
108  }
109 }

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

◆ underflows()

int ClusterizingHistogram::underflows ( ) const
inline

Definition at line 23 of file ClusterizingHistogram.h.

23 { return my_underflows; }

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
ClusterizingHistogram::my_overflows
int my_overflows
Definition: ClusterizingHistogram.h:45
testProducerWithPsetDescEmpty_cfi.i2
i2
Definition: testProducerWithPsetDescEmpty_cfi.py:46
mps_fire.i
i
Definition: mps_fire.py:428
l1ParticleFlow_cff.resol
resol
Definition: l1ParticleFlow_cff.py:17
ClusterizingHistogram::my_underflows
int my_underflows
Definition: ClusterizingHistogram.h:44
min
T min(T a, T b)
Definition: MathUtil.h:58
testProducerWithPsetDescEmpty_cfi.x2
x2
Definition: testProducerWithPsetDescEmpty_cfi.py:28
gather_cfg.cout
cout
Definition: gather_cfg.py:144
testProducerWithPsetDescEmpty_cfi.i1
i1
Definition: testProducerWithPsetDescEmpty_cfi.py:45
ClusterizingHistogram::bin_pos
float bin_pos(int i) const
Definition: ClusterizingHistogram.h:25
ClusterizingHistogram::binsiz
float binsiz
Definition: ClusterizingHistogram.h:48
ClusterizingHistogram::bin_means
float * bin_means
Definition: ClusterizingHistogram.h:47
DDAxes::x
testProducerWithPsetDescEmpty_cfi.x1
x1
Definition: testProducerWithPsetDescEmpty_cfi.py:33
ClusterizingHistogram::bin
int bin(float x) const
Definition: ClusterizingHistogram.cc:21
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
createfilelist.int
int
Definition: createfilelist.py:10
ClusterizingHistogram::bin_entries
int * bin_entries
Definition: ClusterizingHistogram.h:46
ClusterizingHistogram::xmin
float xmin
Definition: ClusterizingHistogram.h:41
ClusterizingHistogram::dump
void dump() const
Definition: ClusterizingHistogram.cc:84
ClusterizingHistogram::xmax
float xmax
Definition: ClusterizingHistogram.h:42
DeadROCCounter.nclust
nclust
Definition: DeadROCCounter.py:66
ClusterizingHistogram::my_nbins
int my_nbins
Definition: ClusterizingHistogram.h:40
ClusterizingHistogram::my_entries
int my_entries
Definition: ClusterizingHistogram.h:43