Jpp  19.1.0
the software that should make you happy
JEnergy.hh
Go to the documentation of this file.
1 #ifndef __JFIT__JENERGY__
2 #define __JFIT__JENERGY__
3 
4 #include <cmath>
5 #include <limits>
6 
7 #include "JLang/JComparable.hh"
8 #include "JMath/JMath.hh"
9 
10 
11 /**
12  * \author mdejong
13  */
14 
15 namespace JFIT {}
16 namespace JPP { using namespace JFIT; }
17 
18 namespace JFIT {
19 
20  using JMATH::JMath;
21  using JLANG::JComparable;
22 
23 
24  /**
25  * Data structure for fit of energy.
26  * The internal value is equal to the logarithm of the energy.
27  */
28  class JEnergy :
29  public JMath<JEnergy>,
30  public JComparable<JEnergy>
31  {
32  public:
33  /**
34  * Default constructor.
35  */
36  JEnergy() :
37  __X(0.0)
38  {}
39 
40 
41  /**
42  * Constructor.
43  *
44  * \param X x-value [log(E/GeV)]
45  */
46  JEnergy(const double X) :
47  __X(X)
48  {}
49 
50 
51  /**
52  * Get Energy.
53  *
54  * \return Energy
55  */
56  const JEnergy& getEnergy() const
57  {
58  return static_cast<const JEnergy&>(*this);
59  }
60 
61 
62  /**
63  * Set Energy.
64  *
65  * \param energy Energy
66  */
67  void setEnergy(const JEnergy& energy)
68  {
69  static_cast<JEnergy&>(*this) = energy;
70  }
71 
72 
73  /**
74  * Less than method.
75  *
76  * \param X Energy [log(E/GeV)]
77  * \return true if this energy less than given energy; else false
78  */
79  bool less(const JEnergy& X) const
80  {
81  return __X < X.__X;
82  }
83 
84 
85  /**
86  * Prefix unary minus.
87  *
88  * \return Energy
89  */
91  {
92  __X = -__X;
93 
94  return *this;
95  }
96 
97 
98  /**
99  * Addition operator.
100  *
101  * \param value Energy
102  * \return Energy
103  */
104  JEnergy& add(const JEnergy& value)
105  {
106  __X += value.__X;
107 
108  return *this;
109  }
110 
111 
112  /**
113  * Subtraction operator.
114  *
115  * \param value Energy
116  * \return Energy
117  */
118  JEnergy& sub(const JEnergy& value)
119  {
120  __X -= value.__X;
121 
122  return *this;
123  }
124 
125 
126  /**
127  * Multiplication operator.
128  *
129  * \param value multiplication factor
130  * \return Energy
131  */
132  JEnergy& mul(const double value)
133  {
134  __X *= value;
135 
136  return *this;
137  }
138 
139 
140  /**
141  * Division operator.
142  *
143  * \param value multiplication factor
144  * \return Energy
145  */
146  JEnergy& div(const double value)
147  {
148  __X /= value;
149 
150  return *this;
151  }
152 
153 
154  /**
155  * Get energy.
156  *
157  * \return Energy [log(E/GeV)]
158  */
159  double getlog10E() const
160  {
161  return __X;
162  }
163 
164 
165  /**
166  * Get energy.
167  *
168  * \return Energy [GeV]
169  */
170  double getE() const
171  {
172  return pow(10.0, __X);
173  }
174 
175 
176  /**
177  * Put energy.
178  *
179  * \param E Energy [GeV]
180  */
181  void putE(const double E)
182  {
183  __X = log10(E);
184  }
185 
186 
187  /**
188  * Get derivative of energy.
189  *
190  * \return dE/dx [GeV]
191  */
192  double getDE() const
193  {
194  return getE() * log(10.0);
195  }
196 
197 
198  /**
199  * Get absolute value.
200  *
201  * \param energy energy
202  */
203  friend inline double fabs(const JEnergy& energy)
204  {
205  return std::fabs(energy.__X);
206  }
207 
208 
209  /**
210  * Get minimum possible value.
211  *
212  * \return minimum possible value
213  */
214  static JEnergy min()
215  {
216  return JEnergy(std::numeric_limits<double>::lowest());
217  }
218 
219 
220  /**
221  * Get maximum possible value.
222  *
223  * \return maximum possible value
224  */
225  static JEnergy max()
226  {
227  return JEnergy(std::numeric_limits<double>::max());
228  }
229 
230 
231  /**
232  * Read object from input.
233  *
234  * \param in input stream
235  * \param object object
236  * \return input stream
237  */
238  friend inline std::istream& operator>>(std::istream& in, JEnergy& object)
239  {
240  in >> object.__X;
241 
242  return in;
243  }
244 
245 
246  /**
247  * Write object to output.
248  *
249  * \param out output stream
250  * \param object object
251  * \return output stream
252  */
253  friend inline std::ostream& operator<<(std::ostream& out, const JEnergy& object)
254  {
255  out << object.__X;
256 
257  return out;
258  }
259 
260 
261  typedef double JEnergy::*parameter_type;
262 
263  static parameter_type pE() { return &JEnergy::__X; }
264 
265  protected:
266  double __X;
267  };
268 }
269 
270 #endif
Base class for data structures with artithmetic capabilities.
Data structure for fit of energy.
Definition: JEnergy.hh:31
const JEnergy & getEnergy() const
Get Energy.
Definition: JEnergy.hh:56
JEnergy & add(const JEnergy &value)
Addition operator.
Definition: JEnergy.hh:104
friend std::ostream & operator<<(std::ostream &out, const JEnergy &object)
Write object to output.
Definition: JEnergy.hh:253
double getE() const
Get energy.
Definition: JEnergy.hh:170
bool less(const JEnergy &X) const
Less than method.
Definition: JEnergy.hh:79
JEnergy(const double X)
Constructor.
Definition: JEnergy.hh:46
friend double fabs(const JEnergy &energy)
Get absolute value.
Definition: JEnergy.hh:203
JEnergy()
Default constructor.
Definition: JEnergy.hh:36
friend std::istream & operator>>(std::istream &in, JEnergy &object)
Read object from input.
Definition: JEnergy.hh:238
void putE(const double E)
Put energy.
Definition: JEnergy.hh:181
JEnergy & mul(const double value)
Multiplication operator.
Definition: JEnergy.hh:132
void setEnergy(const JEnergy &energy)
Set Energy.
Definition: JEnergy.hh:67
JEnergy & negate()
Prefix unary minus.
Definition: JEnergy.hh:90
double JEnergy::* parameter_type
Definition: JEnergy.hh:261
double getDE() const
Get derivative of energy.
Definition: JEnergy.hh:192
JEnergy & sub(const JEnergy &value)
Subtraction operator.
Definition: JEnergy.hh:118
double __X
Definition: JEnergy.hh:266
static JEnergy max()
Get maximum possible value.
Definition: JEnergy.hh:225
double getlog10E() const
Get energy.
Definition: JEnergy.hh:159
JEnergy & div(const double value)
Division operator.
Definition: JEnergy.hh:146
static JEnergy min()
Get minimum possible value.
Definition: JEnergy.hh:214
static parameter_type pE()
Definition: JEnergy.hh:263
Auxiliary classes and methods for linear and iterative data regression.
Definition: JEnergy.hh:15
T pow(const T &x, const double y)
Power .
Definition: JMath.hh:97
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Template definition of auxiliary base class for comparison of data structures.
Definition: JComparable.hh:139
Auxiliary base class for aritmetic operations of derived class types.
Definition: JMath.hh:347