CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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

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(), and runTheMatrix::ret.

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 }
tuple 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
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 SplitLinear::begin, dataset::end, mps_fire::i, runTheMatrix::ret, findQualityFiles::size, and createBeamHaloJobs::stepsize.

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 }
tuple ret
prodAgent to be discontinued
string end
Definition: dataset.py:937
long double T
tuple size
Write out results.