Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-06 09:38:17

0001 // -*- C++ -*-
0002 //
0003 // ACDCTraits.h is a part of ThePEG - Toolkit for HEP Event Generation
0004 // Copyright (C) 1999-2019 Leif Lonnblad
0005 //
0006 // ThePEG is licenced under version 3 of the GPL, see COPYING for details.
0007 // Please respect the MCnet academic guidelines, see GUIDELINES for details.
0008 //
0009 #ifndef ACDCTraits_H
0010 #define ACDCTraits_H
0011 
0012 namespace ACDCGenerator {
0013 
0014 /**
0015  * ACDCTraitsType is an empty non-polymorphic base class for all
0016  * traits classes in ACDCGenerator.
0017  */
0018 struct ACDCTraitsType {};
0019 
0020 /**
0021  * ACDCFncTraits defines the interface to functions to be sampled by
0022  * ACDCGen. It only defines one function which defines how the
0023  * functions are called. If the default implementation is not
0024  * suitable, ACDCFncTraits may be specialized for a function class
0025  * implementing a function with the same signature.
0026  */
0027 template <typename FncPtr>
0028 struct ACDCFncTraits: public ACDCTraitsType {
0029 
0030   /**
0031    * Call a function to be sampled by ACDCGen.
0032    * @return <code>(*f)(x)</code>.
0033    */
0034   static inline double value(const FncPtr & f, const DVector & x) {
0035     return (*f)(x);
0036   }
0037 
0038 };
0039 
0040 /**
0041  * ACDCRandomTraits defines the interface to random number generator
0042  * objects to be used by ACDCGen. If this default implementation is
0043  * not suitable, ACDCRandomTraits may be specialized for any class as
0044  * long as functions with the same signature are present.
0045  */
0046 template <typename Rnd>
0047 struct ACDCRandomTraits: public ACDCTraitsType {
0048 
0049   /**
0050    * Return a flat random number in the interval ]0,1[.
0051    */
0052   static inline double rnd(Rnd * r) { return r->flat(); }
0053 
0054   /**
0055    * Return a flat random number in the interval ]\a xl,\a xu[.
0056    */
0057   static inline double rnd(Rnd * r, double xl, double xu) {
0058     return xl + (xu - xl)*rnd(r);
0059   }
0060 
0061   /**
0062    * Generate a set of random numbers.
0063    * @param r the random generator.
0064    * @param l an input iterator giving the lower limit of the interval
0065    * of the first requested random number.
0066    * @param lend an input iterator marking the end of the range of
0067    * requested random numbers.
0068    * @param u an input iterator giving the upper limit of the interval
0069    * of the first requested random number.
0070    * @param res the ouput iterator used to output the random numbers.
0071    */
0072   template <typename InputIterator, typename OutputIterator>
0073   static inline void rnd(Rnd * r, InputIterator l, InputIterator lend,
0074                InputIterator u, OutputIterator res) {
0075     for ( ; l != lend; ++l ) *res++ = *l + (*u++ - *l)*rnd(r);
0076   }
0077 
0078   /**
0079    * Generate \a D random numbers. The numbers are put into the
0080    * OutputIterator \a res.
0081    */
0082   template <typename OutputIterator>
0083   static inline void rnd(Rnd * r, int D, OutputIterator res) {
0084     for ( int d = 0; d < D; ++d ) *res++ = rnd(r);
0085   }
0086 
0087   /**
0088    * Return true with probability \a x.
0089    */
0090   static inline bool rndBool(Rnd * r, double x) { return rnd(r) < x; }
0091 
0092   /**
0093    * Return true with probability \a x(\a x + \a y).
0094    */
0095   static inline bool rndBool(Rnd * r, double x, double y) {
0096     return rndBool(r, x/(x + y)); }
0097 
0098   /**
0099    * Return a random integer in the interval [0,\a x[.
0100    */
0101   static inline long rndInt(Rnd * r, long x) {
0102     return long(rnd(r, 0.0, double(x)));
0103   }
0104 
0105 };
0106 
0107 }
0108 
0109 #endif