CMS 3D CMS Logo

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

◆ median()

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(), createfilelist::int, runTheMatrix::ret, findQualityFiles::size, and contentValuesCheck::values.

Referenced by SiStripAPVRestorer::baselineFollower(), SiStripAPVRestorer::baselineFollowerRestore(), BoostedJetONNXJetTagsProducer::BoostedJetONNXJetTagsProducer(), SiStripMonitorDigi::FillApvShotsMap(), PVValHelper::getMAD(), TrackerOfflineValidationSummary::getMedian(), PVValHelper::getMedian(), TrackerOfflineValidation::getMedian(), SiStripHotStripAlgorithmFromClusterOccupancy::iterativeSearch(), SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy::iterativeSearch(), KDTreeLinkerAlgo< reco::PFRecHit const *>::medianSearch(), PuppiContainer::puppiWeights(), KDTreeLinkerAlgo< reco::PFRecHit const *>::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 }
size
Write out results.
constexpr int32_t ceil(float num)
ret
prodAgent to be discontinued
long double T