OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
PartData.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: PartData.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.1.1.1.2.1 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: PartData
10 // PartData represents a set of reference values for use in algorithms.
11 //
12 // ------------------------------------------------------------------------
13 // Class category: Algorithms
14 // ------------------------------------------------------------------------
15 //
16 // $Date: 2003/12/02 23:04:59 $
17 // $Author: dbruhwil $
18 //
19 // ------------------------------------------------------------------------
20 
21 #include "Algorithms/PartData.h"
22 #include "Utilities/LogicalError.h"
23 #include <cmath>
24 
25 
26 // Class PartData
27 // ------------------------------------------------------------------------
28 
29 PartData::PartData(double q, double m, double momentum) {
30  charge = q;
31  mass = m;
32  setP(momentum);
33 }
34 
35 
37  charge = 1.0;
38  mass = 0.0;
39  beta = 1.0;
40  gamma = 1.0e10;
41 }
42 
43 
44 void PartData::setP(double p) {
45  if(mass == 0.0) {
46  throw LogicalError("PartData::setP()",
47  "Particle mass must not be zero.");
48  }
49 
50  if(p == 0.0) {
51  throw LogicalError("PartData::setP()",
52  "Particle momentum must not be zero.");
53  }
54 
55  double e = sqrt(p * p + mass * mass);
56  beta = p / e;
57  gamma = e / mass;
58 }
59 
60 
61 void PartData::setE(double energy) {
62  if(energy <= mass) {
63  throw LogicalError("PartData::setE()", "Energy should be > mass.");
64  }
65 
66  gamma = energy / mass;
67  //beta = sqrt(energy*energy - mass*mass) / energy;
68  double ginv = 1.0 / gamma;
69  beta = sqrt((1.0 - ginv) * (1.0 + ginv));
70 }
71 
72 
73 void PartData::setBeta(double v) {
74  if(v >= 1.0) {
75  throw LogicalError("PartData::setBeta()", "Beta should be < 1.");
76  }
77 
78  beta = v;
79  gamma = 1.0 / sqrt(1.0 - beta * beta);
80 }
81 
82 
83 void PartData::setGamma(double v) {
84  if(v <= 1.0) {
85  throw LogicalError("PartData::setGamma()", "Gamma should be > 1.");
86  }
87 
88  gamma = v;
89  beta = sqrt(gamma * gamma - 1.0) / gamma;
90 }
void setBeta(double beta)
Set beta.
Definition: PartData.cpp:73
constexpr double e
The value of .
Definition: Physics.h:40
double charge
Definition: PartData.h:97
void setP(double p)
Set reference momentum.
Definition: PartData.cpp:44
PartData()
Definition: PartData.cpp:36
void setE(double E)
Set reference energy.
Definition: PartData.cpp:61
Tps< T > sqrt(const Tps< T > &x)
Square root.
Definition: TpsMath.h:91
double beta
Definition: PartData.h:99
double mass
Definition: PartData.h:98
void setGamma(double gamma)
Set gamma.
Definition: PartData.cpp:83
Logical error exception.
Definition: LogicalError.h:33
double gamma
Definition: PartData.h:100