CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Functions
median.h File Reference
#include <vector>
#include <algorithm>
#include <cmath>

Go to the source code of this file.

Functions

template<class T >
T median (std::vector< T > values)
 

Function Documentation

template<class T >
T median ( std::vector< T values)

Median in one dimension. T must be sortable, 'addable', and dividable by 2.

Definition at line 16 of file median.h.

References reco::ceil(), runTheMatrix::ret, and findQualityFiles::size.

Referenced by SiStripAPVRestorer::baselineFollower(), BoostedJetONNXJetTagsProducer::BoostedJetONNXJetTagsProducer(), SiStripMonitorDigi::FillApvShotsMap(), PVValHelper::getMAD(), TrackerOfflineValidationSummary::getMedian(), PVValHelper::getMedian(), TrackerOfflineValidation::getMedian(), SiStripHotStripAlgorithmFromClusterOccupancy::iterativeSearch(), SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy::iterativeSearch(), KDTreeLinkerAlgo< DATA, DIM >::medianSearch(), PuppiContainer::puppiWeights(), KDTreeLinkerAlgo< DATA, DIM >::recSearch(), CompareToMedian::runTest(), and SiStripZeroSuppression::storeBaseline().

16  {
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 }
constexpr int32_t ceil(float num)
tuple ret
prodAgent to be discontinued
long double T
tuple size
Write out results.