CMS 3D CMS Logo

Functions
hsm_1d.h File Reference
#include "CommonTools/Statistics/interface/StatisticsException.h"
#include <vector>
#include <cmath>
#include <algorithm>

Go to the source code of this file.

Functions

template<class T >
T hsm_1d (std::vector< T > values)
 
template<class T >
std::pair< typename std::vector< T >::iterator, typename std::vector< T >::iterator > hsm_1d_returning_iterators (std::vector< T > &values)
 

Function Documentation

◆ hsm_1d()

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

stepsize Sample Mode one dimension. T must be sortable, 'addable', and dividable by 2.

Definition at line 53 of file hsm_1d.h.

References hsm_1d_returning_iterators(), runTheMatrix::ret, and contentValuesCheck::values.

Referenced by hsm_3d().

53  {
54  switch (values.size()) {
55  case 0:
56  throw StatisticsException("Hsm of empty vector undefined");
57  case 1:
58  return (T) * (values.begin());
59  case 2:
60  return (T)((*(values.begin()) + *(values.end() - 1)) / 2);
61  };
62  std::pair<typename std::vector<T>::iterator, typename std::vector<T>::iterator> itors =
64  T ret = ((T)(*(itors.first)) + (T)(*(itors.second))) / (T)2.;
65  return ret;
66 }
ret
prodAgent to be discontinued
std::pair< typename std::vector< T >::iterator, typename std::vector< T >::iterator > hsm_1d_returning_iterators(std::vector< T > &values)
Definition: hsm_1d.h:11
long double T

◆ hsm_1d_returning_iterators()

template<class T >
std::pair<typename std::vector<T>::iterator, typename std::vector<T>::iterator> hsm_1d_returning_iterators ( std::vector< T > &  values)

Definition at line 11 of file hsm_1d.h.

References mps_fire::end, mps_fire::i, createfilelist::int, runTheMatrix::ret, findQualityFiles::size, jetsAK4_CHS_cff::sort, createBeamHaloJobs::stepsize, and contentValuesCheck::values.

Referenced by hsm_1d().

12  {
13  sort(values.begin(), values.end());
14 
15  typename std::vector<T>::iterator begin = values.begin();
16  typename std::vector<T>::iterator end = values.end() - 1;
17 
18  while (true) {
19  const int size = (int)(end - begin);
20  // const int stepsize = size / 2;
21  int stepsize = static_cast<int>(floor(.4999999999 + size * .5));
22  if (stepsize == 0)
23  stepsize = 1;
24 
25  end = begin + stepsize;
26  T div = (T)fabs((T)(*end) - (T)(*begin));
27  typename std::vector<T>::iterator new_begin = begin;
28  typename std::vector<T>::iterator new_end = end;
29 
30  for (typename std::vector<T>::iterator i = (begin + 1); i != (begin + size - stepsize + 1); ++i) {
31  if (fabs((*i) - (*(i + stepsize))) < div) {
32  new_begin = i;
33  new_end = i + stepsize;
34  div = (T)((T)(*new_end) - (T)(*new_begin));
35  };
36  };
37  begin = new_begin;
38  end = new_end;
39  if (size < 4)
40  break;
41  };
42 
43  std::pair<typename std::vector<T>::iterator, typename std::vector<T>::iterator> ret(begin, end);
44  return ret;
45 }
size
Write out results.
ret
prodAgent to be discontinued
long double T