thepeg is hosted by Hepforge, IPPP Durham
ThePEG  2.2.1
ACDCTraits.h
1 // -*- C++ -*-
2 //
3 // ACDCTraits.h is a part of ThePEG - Toolkit for HEP Event Generation
4 // Copyright (C) 1999-2019 Leif Lonnblad
5 //
6 // ThePEG is licenced under version 3 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
static void rnd(Rnd *r, InputIterator l, InputIterator lend, InputIterator u, OutputIterator res)
Generate a set of random numbers.
Definition: ACDCTraits.h:73
ACDCFncTraits defines the interface to functions to be sampled by ACDCGen.
Definition: ACDCTraits.h:28
static void rnd(Rnd *r, int D, OutputIterator res)
Generate D random numbers.
Definition: ACDCTraits.h:83
ACDCTraitsType is an empty non-polymorphic base class for all traits classes in ACDCGenerator.
Definition: ACDCTraits.h:18
static double rnd(Rnd *r, double xl, double xu)
Return a flat random number in the interval ]xl,xu[.
Definition: ACDCTraits.h:57
static bool rndBool(Rnd *r, double x)
Return true with probability x.
Definition: ACDCTraits.h:90
static long rndInt(Rnd *r, long x)
Return a random integer in the interval [0,x[.
Definition: ACDCTraits.h:101
static double rnd(Rnd *r)
Return a flat random number in the interval ]0,1[.
Definition: ACDCTraits.h:52
vector< double > DVector
A vector of doubles.
Definition: ACDCGenConfig.h:58
static double value(const FncPtr &f, const DVector &x)
Call a function to be sampled by ACDCGen.
Definition: ACDCTraits.h:34
The namespace in which all ACDCGen classes are defined.
Definition: ACDCGen.h:18
static bool rndBool(Rnd *r, double x, double y)
Return true with probability x(x + y).
Definition: ACDCTraits.h:95
ACDCRandomTraits defines the interface to random number generator objects to be used by ACDCGen...
Definition: ACDCTraits.h:47