|
|
|||
File indexing completed on 2026-08-06 09:38:32
0001 // -*- C++ -*- 0002 // 0003 // Direction.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_Direction_H 0010 #define ThePEG_Direction_H 0011 // This is the declaration of the Direction class. 0012 0013 #include "ThePEG/Config/ThePEG.h" 0014 #include "Direction.xh" 0015 0016 namespace ThePEG { 0017 0018 template <int I> 0019 /** 0020 * A <code>Direction</code> object can be used to specify that some 0021 * following operations should be assumed to be performed with the 0022 * z-direction of the momenta reversed. As an example, if 0023 * <code>Direction<0>::pos()</code> is true, the method 0024 * <code>Lorentz5Momentum::dirPlus()</code> will return the positive, 0025 * light-cone component, and <code>Lorentz5Momentum::dirMinus()</code> 0026 * the negative, while if <code>Direction<0>::pos()</code> is false 0027 * the behavior of the methods are reversed. 0028 * 0029 * <code>Direction</code> is templated with an integer template argument 0030 * (default = 0), and only one object per class can be instatiated at 0031 * the time. Attempts to instatiate a second object of a 0032 * <code>Direction</code> class will result in an exception being 0033 * thrown. To have several different directions classes with different 0034 * template arguments must be instantiated. <code>Direction<0></code> is 0035 * reserved for <code>Lorentz5Momentum</code>. Attempts to use the 0036 * static methods of a <code>Direction</code> class when no object has 0037 * been instatiated will result in an exception being thrown. 0038 * 0039 * @see Lorentz5Momentum 0040 */ 0041 class Direction { 0042 0043 public: 0044 0045 /** The enum defining the directions. */ 0046 enum Dir { Neg = -1, /**< Reversed direction. */ 0047 Negative = -1, /**< Reversed direction. */ 0048 Undefined = 0, /**< No direction has been defined. */ 0049 Pos = 1, /**< Standard (positive) direction. */ 0050 Positive = 1 /**< Standard (positive) direction. */ 0051 }; 0052 0053 public: 0054 0055 /** 0056 * Create an object with a given direction. 0057 */ 0058 Direction(Dir newDirection) 0059 0060 { 0061 if ( theDirection != Undefined ) throw MultipleDirectionException(I); 0062 if ( newDirection == Positive ) theDirection = Positive; 0063 else if ( newDirection == Negative ) theDirection = Negative; 0064 else throw UndefinedDirectionException(I); 0065 } 0066 0067 /** 0068 * Create an object with a positive direction if rnd > 0.5, 0069 * otherwise set the negative direction. 0070 */ 0071 Direction(double rnd) 0072 { 0073 if ( theDirection != Undefined ) throw MultipleDirectionException(I); 0074 theDirection = rnd > 0 ? Positive : Negative; 0075 } 0076 0077 /** 0078 * Create an object with a positive direction if p is true, 0079 * otherwise set the negative direction. 0080 */ 0081 Direction(bool p) 0082 { 0083 if ( theDirection != Undefined ) throw MultipleDirectionException(I); 0084 theDirection = p ? Positive : Negative; 0085 } 0086 0087 /** 0088 * Destructure makeing the static variable undefined. 0089 */ 0090 ~Direction() { theDirection = Undefined; } 0091 0092 public: 0093 0094 /** 0095 * Set the direction. 0096 */ 0097 static void set(Dir newDirection) { 0098 if ( newDirection == Positive ) theDirection = Positive; 0099 else if ( newDirection == Negative ) theDirection = Negative; 0100 else throw UndefinedDirectionException(I); 0101 } 0102 0103 /** 0104 * Reverse the direction. 0105 */ 0106 static void reverse() { 0107 theDirection = pos() ? Negative : Positive; 0108 } 0109 0110 /** 0111 * Return true if the direction is positive. 0112 */ 0113 static bool pos() { 0114 return dir() == Positive; 0115 } 0116 0117 /** 0118 * Return true if the direction is negative (reversed). 0119 */ 0120 static bool neg() { 0121 return dir() == Negative; 0122 } 0123 0124 /** 0125 * Return the direction. 0126 */ 0127 static Dir dir() { 0128 if ( theDirection == Undefined ) throw UndefinedDirectionException(I); 0129 return theDirection; 0130 } 0131 0132 private: 0133 0134 /** 0135 * The direction. 0136 */ 0137 static Dir theDirection; 0138 0139 private: 0140 0141 /** 0142 * Default ctors and assignment is private and not implemented. 0143 */ 0144 Direction(); 0145 /** 0146 * Default ctors and assignment is private and not implemented. 0147 */ 0148 Direction(const Direction &); 0149 /** 0150 * Default ctors and assignment is private and not implemented. 0151 */ 0152 Direction & operator=(const Direction &) = delete; 0153 0154 }; 0155 0156 template<int I> 0157 typename Direction<I>::Dir Direction<I>::theDirection = Direction<I>::Undefined; 0158 0159 } 0160 0161 #endif /* ThePEG_Direction_H */
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|