src
CommonTools
Statistics
interface
median.h
Go to the documentation of this file.
1
#ifndef CommonTools_Statistics_median_h
2
#define CommonTools_Statistics_median_h
3
4
#include <vector>
5
#include <algorithm>
6
#include <cmath>
7
//#include "CommonDet/DetUtilities/interface/DetExceptions.h"
8
9
//using namespace std;
10
15
template
<
class
T>
16
T
median
(std::vector<T>
values
) {
17
switch
(
values
.size()) {
18
case
0:
19
// throw LogicError ("Median of empty vector");
20
case
1:
21
return
values
[0];
22
case
2:
23
return
(
values
[0] +
values
[1]) / 2.;
24
};
25
T
ret
;
26
const
int
size
=
values
.size();
27
const
int
half = (
int
)
ceil
(
size
/ 2.);
28
partial_sort(
values
.begin(),
values
.begin() + half + 1,
values
.end());
29
if
(
size
& 1) {
30
ret
=
values
[half - 1];
31
}
else
{
32
ret
= (
values
[half - 1] +
values
[half]) / 2.;
33
};
34
return
ret
;
35
}
36
#endif
findQualityFiles.size
size
Write out results.
Definition:
findQualityFiles.py:443
reco::ceil
constexpr int32_t ceil(float num)
Definition:
constexpr_cmath.h:7
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition:
runTheMatrix.py:760
createfilelist.int
int
Definition:
createfilelist.py:10
contentValuesCheck.values
values
Definition:
contentValuesCheck.py:38
median
T median(std::vector< T > values)
Definition:
median.h:16
T
long double T
Definition:
Basic3DVectorLD.h:48
Generated for CMSSW Reference Manual by
1.8.14