JHUGen MELA  JHUGen v7.5.6, MELA v2.4.2
Matrix element calculations as used in JHUGen.
MELAAccumulators.h
Go to the documentation of this file.
1 #ifndef MELAAccumulators_h
2 #define MELAAccumulators_h
3 
4 #include <vector>
5 
6 namespace TNumericUtil{
7 
8  template <typename T> class NaiveAccumulator {
9  protected:
10  T sum_;
11  public:
14  NaiveAccumulator(const NaiveAccumulator<T>& other) : sum_(other.sum_){}
15  NaiveAccumulator& operator+=(const T& inc){ sum_ += inc; return *this; }
16  NaiveAccumulator& operator-=(const T& inc){ sum_ -= inc; return *this; }
17  NaiveAccumulator& operator*=(const T& inc){ sum_ *= inc; return *this; }
18  NaiveAccumulator& operator/=(const T& inc){ sum_ /= inc; return *this; }
19  NaiveAccumulator operator+(const T& inc){ NaiveAccumulator<T> tmp(*this); tmp += inc; return tmp; }
20  NaiveAccumulator operator-(const T& inc){ NaiveAccumulator<T> tmp(*this); tmp -= inc; return tmp; }
21  NaiveAccumulator operator*(const T& inc){ NaiveAccumulator<T> tmp(*this); tmp *= inc; return tmp; }
22  NaiveAccumulator operator/(const T& inc){ NaiveAccumulator<T> tmp(*this); tmp /= inc; return tmp; }
23  T sum() const { return sum_; }
24  operator T() const { return sum_; }
25  };
26 
27  template <typename T> class KahanAccumulator {
28  protected:
30  public:
35  T y = inc - compensation_;
36  T sumnew = sum_ + y;
37  T sumerr = (sumnew - sum_);
38  compensation_ = sumerr - y;
39  sum_ = sumnew;
40  return *this;
41  }
42  KahanAccumulator& operator-=(const T& inc){ this->operator+=(-inc); return *this; }
43  KahanAccumulator& operator*=(const T& inc){ sum_ *= inc; compensation_ *= inc; return *this; }
44  KahanAccumulator& operator/=(const T& inc){ sum_ /= inc; compensation_ /= inc; return *this; }
45  KahanAccumulator operator+(const T& inc){ KahanAccumulator<T> tmp(*this); tmp += inc; return tmp; }
46  KahanAccumulator operator-(const T& inc){ KahanAccumulator<T> tmp(*this); tmp -= inc; return tmp; }
47  KahanAccumulator operator*(const T& inc){ KahanAccumulator<T> tmp(*this); tmp *= inc; return tmp; }
48  KahanAccumulator operator/(const T& inc){ KahanAccumulator<T> tmp(*this); tmp /= inc; return tmp; }
49  T sum() const { return sum_; }
50  operator T() const { return sum_; }
51  };
52 
53  template<typename T> using PreciseAccumulator = KahanAccumulator<T>;
54  template<typename T> using FastAccumulator = NaiveAccumulator<T>;
55  template<typename T> using DefaultAccumulator = PreciseAccumulator<T>;
56 
57  template<typename T, class A> inline T sumWith(const std::vector<T>& vals){
58  A ret = 0;
59  for (const T& v : vals) ret += v;
60  return ret;
61  }
62 
63  template<typename T> inline T sumPrecise(const std::vector<T, std::allocator<T>>& vals){
64  T ret = sumWith<T, PreciseAccumulator<T>>(vals);
65  return ret;
66  }
67 
68  template<typename T> inline T sumFast(const std::vector<T, std::allocator<T>>& vals){
69  T ret = sumWith<T, FastAccumulator<T>>(vals);
70  return ret;
71  }
72 
73  template<typename T> inline T sumDefault(const std::vector<T, std::allocator<T>>& vals){
74  T ret = sumWith<T, DefaultAccumulator<T>>(vals);
75  return ret;
76  }
77 
78 }
79 
80 #endif
value
pymela::gHIGGS_KAPPA value("gHIGGS_KAPPA_TILDE", pymela::gHIGGS_KAPPA_TILDE) .value("SIZE_HQQ"
TNumericUtil::KahanAccumulator::operator+
KahanAccumulator operator+(const T &inc)
Definition: MELAAccumulators.h:45
TNumericUtil::NaiveAccumulator::operator-=
NaiveAccumulator & operator-=(const T &inc)
Definition: MELAAccumulators.h:16
TNumericUtil::NaiveAccumulator::operator*=
NaiveAccumulator & operator*=(const T &inc)
Definition: MELAAccumulators.h:17
TNumericUtil::KahanAccumulator
Definition: MELAAccumulators.h:27
TNumericUtil::KahanAccumulator::operator/
KahanAccumulator operator/(const T &inc)
Definition: MELAAccumulators.h:48
TNumericUtil::NaiveAccumulator::operator+
NaiveAccumulator operator+(const T &inc)
Definition: MELAAccumulators.h:19
TNumericUtil::NaiveAccumulator::NaiveAccumulator
NaiveAccumulator(const NaiveAccumulator< T > &other)
Definition: MELAAccumulators.h:14
TNumericUtil::sumPrecise
T sumPrecise(const std::vector< T, std::allocator< T >> &vals)
Definition: MELAAccumulators.h:63
TNumericUtil::NaiveAccumulator::sum
T sum() const
Definition: MELAAccumulators.h:23
TNumericUtil::sumFast
T sumFast(const std::vector< T, std::allocator< T >> &vals)
Definition: MELAAccumulators.h:68
TNumericUtil::KahanAccumulator::operator*=
KahanAccumulator & operator*=(const T &inc)
Definition: MELAAccumulators.h:43
hto_rootw::inc
integer inc
Definition: CALLING_cpHTO.f:246
TNumericUtil::NaiveAccumulator::operator*
NaiveAccumulator operator*(const T &inc)
Definition: MELAAccumulators.h:21
TNumericUtil::KahanAccumulator::operator-
KahanAccumulator operator-(const T &inc)
Definition: MELAAccumulators.h:46
TNumericUtil::KahanAccumulator::sum_
T sum_
Definition: MELAAccumulators.h:29
TNumericUtil::KahanAccumulator::KahanAccumulator
KahanAccumulator(const T &value)
Definition: MELAAccumulators.h:32
TNumericUtil::NaiveAccumulator::NaiveAccumulator
NaiveAccumulator()
Definition: MELAAccumulators.h:12
TNumericUtil
Definition: MELAAccumulators.h:6
TNumericUtil::KahanAccumulator::KahanAccumulator
KahanAccumulator()
Definition: MELAAccumulators.h:31
TNumericUtil::NaiveAccumulator::operator/=
NaiveAccumulator & operator/=(const T &inc)
Definition: MELAAccumulators.h:18
TNumericUtil::KahanAccumulator::KahanAccumulator
KahanAccumulator(const KahanAccumulator< T > &other)
Definition: MELAAccumulators.h:33
TNumericUtil::KahanAccumulator::compensation_
T compensation_
Definition: MELAAccumulators.h:29
TNumericUtil::sumWith
T sumWith(const std::vector< T > &vals)
Definition: MELAAccumulators.h:57
TNumericUtil::NaiveAccumulator::operator/
NaiveAccumulator operator/(const T &inc)
Definition: MELAAccumulators.h:22
TNumericUtil::NaiveAccumulator::operator-
NaiveAccumulator operator-(const T &inc)
Definition: MELAAccumulators.h:20
TNumericUtil::KahanAccumulator::sum
T sum() const
Definition: MELAAccumulators.h:49
TNumericUtil::NaiveAccumulator::sum_
T sum_
Definition: MELAAccumulators.h:10
TNumericUtil::KahanAccumulator::operator-=
KahanAccumulator & operator-=(const T &inc)
Definition: MELAAccumulators.h:42
TNumericUtil::KahanAccumulator::operator+=
KahanAccumulator & operator+=(const T &inc)
Definition: MELAAccumulators.h:34
TNumericUtil::KahanAccumulator::operator*
KahanAccumulator operator*(const T &inc)
Definition: MELAAccumulators.h:47
TNumericUtil::sumDefault
T sumDefault(const std::vector< T, std::allocator< T >> &vals)
Definition: MELAAccumulators.h:73
TNumericUtil::NaiveAccumulator::NaiveAccumulator
NaiveAccumulator(const T &value)
Definition: MELAAccumulators.h:13
TNumericUtil::KahanAccumulator::operator/=
KahanAccumulator & operator/=(const T &inc)
Definition: MELAAccumulators.h:44
TNumericUtil::NaiveAccumulator
Definition: MELAAccumulators.h:8
TNumericUtil::NaiveAccumulator::operator+=
NaiveAccumulator & operator+=(const T &inc)
Definition: MELAAccumulators.h:15