Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // HandlerBase.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 ThePEG_HandlerBase_H
0010 #define ThePEG_HandlerBase_H
0011 // This is the declaration of the HandlerBase class.
0012 
0013 #include "ThePEG/Interface/Interfaced.h"
0014 #include "ThePEG/Repository/UseRandom.fh"
0015 #include "ThePEG/Repository/EventGenerator.h"
0016 #include <stdexcept>
0017 
0018 namespace ThePEG {
0019 
0020 template <typename T = UseRandom>
0021 /**
0022  * HandlerBaseT is a dummy abstract templated class used as base class
0023  * to HandlerBase. HandlerBaseT inherits from the Interfaced class
0024  * adding some functionality such as easy acces to the RandomGenerator
0025  * and the StandardModel object of the controlling EventGenerator
0026  * object. The HandlerBaseT should only be used by the HandlerBase as
0027  * a base class. The fact that it is templated allows classes which in
0028  * turn inherits from HandlerBase to not explicitly depend on
0029  * EventGenerator class if the inlined accessor funtions are not
0030  * actually used. The only class which actually works as a template
0031  * argument is UseRandom, which is used to generate random numbers.
0032  *
0033  * @see Interfaced
0034  * @see RandomGenerator
0035  * @see StandardModel
0036  * @see EventGenerator
0037  * 
0038  */
0039 class HandlerBaseT: public Interfaced {
0040 public:
0041 
0042   /** HandlerBase is a friend. */
0043   friend class HandlerBase;
0044 
0045 private:
0046 
0047   /** @name Standard constructors and destructors are private and can
0048    * only be used from the HandlerBase class. */
0049   //@{
0050   /**
0051    * Default constructor.
0052    */
0053   HandlerBaseT() {}
0054 
0055 public:
0056   /**
0057    * Destructor.
0058    */
0059   virtual ~HandlerBaseT() {}
0060   //@}
0061 
0062 public:
0063 
0064   /**
0065    * Return a simple flat random number in the range ]0,1[.
0066    */
0067   double rnd() const {  return T::rnd(); }
0068 
0069   /**
0070    * Return a simple flat random number in the range ]0,\a xu[.
0071    */
0072   double rnd(double xu) const { return T::rnd(xu); }
0073 
0074   /**
0075    * Return a simple flat random number in the range ]\a xl,\a xu[.
0076    */
0077   double rnd(double xl, double xu) const { return T::rnd(xl, xu); }
0078 
0079   /**
0080    * Return true with 50% probability.
0081    */
0082   bool rndbool() const { return T::rndbool(); }
0083 
0084   /**
0085    * Return a true with probability \a p.
0086    */
0087   bool rndbool(double p) const { return T::rndbool(p); }
0088 
0089   /**
0090    * Return a true with probability \a p1/(\a p1+\a p2).
0091    */
0092   bool rndbool(double p1, double p2) const { return T::rndbool(p1, p2); }
0093 
0094   /**
0095    * Return -1, 0, or 1 with relative probabilities \a p1, \a p2, \a p3.
0096    */
0097   int rndsign(double p1, double p2, double p3) const { return T::rndsign(p1, p2, p3); }
0098 
0099   /**
0100    * Return an integer \f$i\f$ with probability p\f$i\f$/(\a p0+\a p1).
0101    */
0102   int rnd2(double p0, double p1) const { return T::rnd2(p0, p1); }
0103 
0104   /**
0105    * Return an integer \f$i\f$ with probability p\f$i\f$/(\a p0+\a
0106    * p1+\a p2).
0107    */
0108   int rnd3(double p0, double p1, double p2) const { return T::rnd3(p0, p1, p2); }
0109 
0110   /**
0111    * Return an integer/ \f$i\f$ with probability p\f$i\f$(\a p0+\a
0112    * p1+\a p2+\a p3).
0113    */
0114   int rnd4(double p0, double p1, double p2, double p3) const { return T::rnd4(p0, p1, p2, p3); }
0115 
0116   /**
0117    * Return a simple flat random integrer number in the range [0,\a xu[.
0118    */
0119   long irnd(long xu = 2) const { return T::irnd(xu); }
0120 
0121   /**
0122    * Return a simple flat random integrer number in the range [\a xl,\a xu[.
0123    */
0124   long irnd(long xl, long xu) const { return T::irnd(xl, xu); }
0125 
0126   /**
0127    * Return a reference to the object containing the standard model
0128    * parameters for this run.
0129    */
0130   const StandardModelBase & SM() const { return *standardModel(); }
0131 
0132   /**
0133    * Return a pointer to the object containing the standard model
0134    * parameters for this run.
0135    */
0136   tSMPtr standardModel() const { return generator()->standardModel(); }
0137 };
0138 
0139 /**
0140  * HandlerBase is an abstract base class derived from the Interfaced
0141  * class via the HandlerBaseT class adding some functionality such as
0142  * easy acces to the RandomGenerator and the StandardModel object of
0143  * the controlling EventGenerator object.
0144  *
0145  * @see Interfaced
0146  * @see RandomGenerator
0147  * @see StandardModel
0148  * @see EventGenerator
0149  * 
0150  */
0151 class HandlerBase: public HandlerBaseT<UseRandom> {
0152 
0153 public:
0154 
0155   /**
0156    * Standard Init function used to initialize the interface.
0157    */
0158   static void Init();
0159 
0160 private:
0161 
0162   /**
0163    * Describe an abstract class without persistent data.
0164    */
0165   static AbstractNoPIOClassDescription<HandlerBase> initHandlerBase;
0166 
0167   /**
0168    *  Private and non-existent assignment operator.
0169    */
0170   HandlerBase & operator=(const HandlerBase &) = delete;
0171 
0172 };
0173 
0174 /** @cond TRAITSPECIALIZATIONS */
0175 
0176 /**
0177  * This template specialization informs ThePEG about the
0178  * base class of HandlerBase.
0179  */
0180 template <>
0181 struct BaseClassTrait<HandlerBase,1>: public ClassTraitsType {
0182   /** Typedef of the base class of HandlerBase. Note that HandlerBaseT
0183    *  is not treated as a base class in this respect. */
0184   typedef Interfaced NthBase;
0185 };
0186 
0187 /**
0188  * This template specialization informs ThePEG about the name of the
0189  * HandlerBase class.
0190  */
0191 template <>
0192 struct ClassTraits<HandlerBase>: public ClassTraitsBase<HandlerBase> {
0193   /** Return the class name. */
0194   static string className() { return "ThePEG::HandlerBase"; }
0195 };
0196 
0197 /** @endcond */
0198 
0199 }
0200 
0201 #endif /* ThePEG_HandlerBase_H */