CMS 3D CMS Logo

ClusterizingHistogram.cc
Go to the documentation of this file.
2 #include <iostream>
3 
4 using namespace std;
5 
6 ClusterizingHistogram::ClusterizingHistogram(int nb, float xmi, float xma)
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 }
17  delete[] bin_entries;
18  delete[] bin_means;
19 }
20 
21 int ClusterizingHistogram::bin(float x) const {
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 }
29 int ClusterizingHistogram::bin(double x) const {
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 }
37 
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 }
53 
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 }
83 
85 
86 void ClusterizingHistogram::dump(int i1, int i2) const {
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 }
95 
96 void ClusterizingHistogram::dump(float x1, float x2) const { dump(bin(x1), bin(x2)); }
97 void ClusterizingHistogram::dump(double x1, double x2) const { dump(bin(x1), bin(x2)); }
98 void ClusterizingHistogram::dump(float x1, double x2) const { dump(bin(x1), bin(x2)); }
99 void ClusterizingHistogram::dump(double x1, float x2) const { dump(bin(x1), bin(x2)); }
100 
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 }
ClusterizingHistogram::my_overflows
int my_overflows
Definition: ClusterizingHistogram.h:45
ClusterizingHistogram::clusterize
std::vector< float > clusterize(float resolution)
Definition: ClusterizingHistogram.cc:54
testProducerWithPsetDescEmpty_cfi.i2
i2
Definition: testProducerWithPsetDescEmpty_cfi.py:46
mps_fire.i
i
Definition: mps_fire.py:355
l1ParticleFlow_cff.resol
resol
Definition: l1ParticleFlow_cff.py:17
ClusterizingHistogram::my_underflows
int my_underflows
Definition: ClusterizingHistogram.h:44
ClusterizingHistogram::~ClusterizingHistogram
~ClusterizingHistogram()
Definition: ClusterizingHistogram.cc:16
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
vertices_cff.x
x
Definition: vertices_cff.py:29
ClusterizingHistogram::bin
int bin(float x) const
Definition: ClusterizingHistogram.cc:21
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
ClusterizingHistogram::ClusterizingHistogram
ClusterizingHistogram()
Definition: ClusterizingHistogram.h:39
createfilelist.int
int
Definition: createfilelist.py:10
ClusterizingHistogram::fill
void fill(float x)
Definition: ClusterizingHistogram.cc:38
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
std
Definition: JetResolutionObject.h:76
TrackerOfflineValidation_Dqm_cff.xmax
xmax
Definition: TrackerOfflineValidation_Dqm_cff.py:11
ClusterizingHistogram.h
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
ClusterizingHistogram::reset
void reset()
Definition: ClusterizingHistogram.cc:101
TrackerOfflineValidation_Dqm_cff.xmin
xmin
Definition: TrackerOfflineValidation_Dqm_cff.py:10