CommonTools
Statistics
interface
lms_1d.h
Go to the documentation of this file.
1
#ifndef CommonTools_Statistics_lms_1d_h
2
#define CommonTools_Statistics_lms_1d_h
3
4
#include "
CommonTools/Statistics/interface/StatisticsException.h
"
5
6
#include <vector>
7
#include <algorithm>
8
#include <cmath>
9
14
template
<
class
T>
15
T
lms_1d
(std::vector<T>
values
) {
16
switch
(
values
.size()) {
17
case
0:
18
throw
StatisticsException
(
"Lms of empty vector undefined"
);
19
case
1:
20
return
(
T
) * (
values
.begin());
21
case
2:
22
return
(
T
)((*(
values
.begin()) + *(
values
.end() - 1)) / 2);
23
};
24
const
int
size
=
values
.size();
25
const
int
half =
size
/ 2;
26
const
int
n_steps = (
size
+ 1) / 2;
27
28
sort
(
values
.begin(),
values
.end());
29
30
T
i_begin = *(
values
.begin());
31
T
i_end = *(
values
.begin() + half);
32
T
div = (
T
)fabs(i_begin - i_end);
33
for
(
typename
std::vector<T>::const_iterator
i
=
values
.begin();
i
!= (
values
.begin() + n_steps); ++
i
) {
34
if
(fabs((*
i
) - (*(
i
+ half))) < div) {
35
i_begin = (*i);
36
i_end = *(
i
+ half);
37
div = (
T
)fabs(i_begin - i_end);
38
}
39
}
40
41
return
(
T
)((i_begin + i_end) / 2);
42
}
43
44
#endif
findQualityFiles.size
size
Write out results.
Definition:
findQualityFiles.py:443
mps_fire.i
i
Definition:
mps_fire.py:429
StatisticsException.h
StatisticsException
Definition:
StatisticsException.h:10
jetsAK4_CHS_cff.sort
sort
Definition:
jetsAK4_CHS_cff.py:39
contentValuesCheck.values
values
Definition:
contentValuesCheck.py:38
lms_1d
T lms_1d(std::vector< T > values)
Definition:
lms_1d.h:15
T
long double T
Definition:
Basic3DVectorLD.h:48
Generated for CMSSW Reference Manual by
1.8.14