Main Page
Namespaces
Classes
Package Documentation
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Pages
src
Utilities
BinningTools
src
ClusterizingHistogram.cc
Go to the documentation of this file.
1
#include "
Utilities/BinningTools/interface/ClusterizingHistogram.h
"
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
}
16
ClusterizingHistogram::~ClusterizingHistogram
(){
delete
[]
bin_entries
;
delete
[]
bin_means
;}
17
18
int
ClusterizingHistogram::bin
(
float
x
)
const
{
19
if
(x <
xmin
)
return
-1;
20
else
if
(x >
xmax
)
return
my_nbins
;
21
else
return
int((x-
xmin
)/
binsiz
);
22
}
23
int
ClusterizingHistogram::bin
(
double
x
)
const
{
24
if
(x <
xmin
)
return
-1;
25
else
if
(x >
xmax
)
return
my_nbins
;
26
else
return
int((x-
xmin
)/
binsiz
);
27
}
28
29
void
ClusterizingHistogram::fill
(
float
x
) {
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
}
41
42
vector<float>
ClusterizingHistogram::clusterize
(
float
resol) {
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
}
69
70
71
void
ClusterizingHistogram::dump
()
const
{
dump
(0,
my_nbins
);}
72
73
void
ClusterizingHistogram::dump
(
int
i1,
int
i2)
const
{
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
}
82
83
void
ClusterizingHistogram::dump
(
float
x1,
float
x2)
const
{
dump
(
bin
(x1),
bin
(x2));}
84
void
ClusterizingHistogram::dump
(
double
x1,
double
x2)
const
{
dump
(
bin
(x1),
bin
(x2));}
85
void
ClusterizingHistogram::dump
(
float
x1,
double
x2)
const
{
dump
(
bin
(x1),
bin
(x2));}
86
void
ClusterizingHistogram::dump
(
double
x1,
float
x2)
const
{
dump
(
bin
(x1),
bin
(x2));}
87
88
void
ClusterizingHistogram::reset
() {
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
}
i
int i
Definition:
DBlmapReader.cc:9
ClusterizingHistogram::my_nbins
int my_nbins
Definition:
ClusterizingHistogram.h:41
ClusterizingHistogram.h
ClusterizingHistogram::dump
void dump() const
Definition:
ClusterizingHistogram.cc:71
ClusterizingHistogram::~ClusterizingHistogram
~ClusterizingHistogram()
Definition:
ClusterizingHistogram.cc:16
min
#define min(a, b)
Definition:
mlp_lapack.h:161
ClusterizingHistogram::bin_entries
int * bin_entries
Definition:
ClusterizingHistogram.h:47
SiStripMonitorClusterAlca_cfi.xmin
tuple xmin
Definition:
SiStripMonitorClusterAlca_cfi.py:34
ClusterizingHistogram::my_overflows
int my_overflows
Definition:
ClusterizingHistogram.h:46
ClusterizingHistogram::clusterize
std::vector< float > clusterize(float resolution)
Definition:
ClusterizingHistogram.cc:42
max
const T & max(const T &a, const T &b)
Definition:
MaterialBudgetTrackerHistos.cc:4
ClusterizingHistogram::bin
int bin(float x) const
Definition:
ClusterizingHistogram.cc:18
ClusterizingHistogram::fill
void fill(float x)
Definition:
ClusterizingHistogram.cc:29
ClusterizingHistogram::bin_pos
float bin_pos(int i) const
Definition:
ClusterizingHistogram.h:25
ClusterizingHistogram::my_entries
int my_entries
Definition:
ClusterizingHistogram.h:44
ClusterizingHistogram::xmax
float xmax
Definition:
ClusterizingHistogram.h:43
SiStripMonitorClusterAlca_cfi.xmax
tuple xmax
Definition:
SiStripMonitorClusterAlca_cfi.py:35
ClusterizingHistogram::my_underflows
int my_underflows
Definition:
ClusterizingHistogram.h:45
ClusterizingHistogram::ClusterizingHistogram
ClusterizingHistogram()
Definition:
ClusterizingHistogram.h:40
gather_cfg.cout
tuple cout
Definition:
gather_cfg.py:121
ClusterizingHistogram::xmin
float xmin
Definition:
ClusterizingHistogram.h:42
ClusterizingHistogram::binsiz
float binsiz
Definition:
ClusterizingHistogram.h:49
x
Definition:
DDAxes.h:10
ClusterizingHistogram::bin_means
float * bin_means
Definition:
ClusterizingHistogram.h:48
ClusterizingHistogram::reset
void reset()
Definition:
ClusterizingHistogram.cc:88
Generated for CMSSW Reference Manual by
1.8.5