ThePEG  1.8.0
ACDCTraits.h
1 // -*- C++ -*-
2 //
3 // ACDCTraits.h is a part of ThePEG - Toolkit for HEP Event Generation
4 // Copyright (C) 1999-2011 Leif Lonnblad
5 //
6 // ThePEG is licenced under version 2 of the GPL, see COPYING for details.
7 // Please respect the MCnet academic guidelines, see GUIDELINES for details.
8 //
9 #ifndef ACDCTraits_H
10 #define ACDCTraits_H
11 
12 namespace ACDCGenerator {
13 
18 struct ACDCTraitsType {};
19 
27 template <typename FncPtr>
28 struct ACDCFncTraits: public ACDCTraitsType {
29 
34  static inline double value(const FncPtr & f, const DVector & x) {
35  return (*f)(x);
36  }
37 
38 };
39 
46 template <typename Rnd>
48 
52  static inline double rnd(Rnd * r) { return r->flat(); }
53 
57  static inline double rnd(Rnd * r, double xl, double xu) {
58  return xl + (xu - xl)*rnd(r);
59  }
60 
72  template <typename InputIterator, typename OutputIterator>
73  static inline void rnd(Rnd * r, InputIterator l, InputIterator lend,
74  InputIterator u, OutputIterator res) {
75  for ( ; l != lend; ++l ) *res++ = *l + (*u++ - *l)*rnd(r);
76  }
77 
82  template <typename OutputIterator>
83  static inline void rnd(Rnd * r, int D, OutputIterator res) {
84  for ( int d = 0; d < D; ++d ) *res++ = rnd(r);
85  }
86 
90  static inline bool rndBool(Rnd * r, double x) { return rnd(r) < x; }
91 
95  static inline bool rndBool(Rnd * r, double x, double y) {
96  return rndBool(r, x/(x + y)); }
97 
101  static inline long rndInt(Rnd * r, long x) {
102  return long(rnd(r, 0.0, double(x)));
103  }
104 
105 };
106 
107 }
108 
109 #endif