OPAL (Object Oriented Parallel Accelerator Library) 2022.1
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"
23#include <cmath>
24
25
26// Class PartData
27// ------------------------------------------------------------------------
28
29PartData::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
44void 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 = std::sqrt(p * p + mass * mass);
56 beta = p / e;
57 gamma = e / mass;
58}
59
60
61void 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 = std::sqrt(energy*energy - mass*mass) / energy;
68 double ginv = 1.0 / gamma;
69 beta = std::sqrt((1.0 - ginv) * (1.0 + ginv));
70}
71
72
73void 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 / std::sqrt(1.0 - beta * beta);
80}
81
82
83void 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 = std::sqrt(gamma * gamma - 1.0) / gamma;
90}
Tps< T > sqrt(const Tps< T > &x)
Square root.
Definition: TpsMath.h:91
constexpr double e
The value of.
Definition: Physics.h:39
double mass
Definition: PartData.h:95
void setGamma(double gamma)
Set gamma.
Definition: PartData.cpp:83
double charge
Definition: PartData.h:94
double gamma
Definition: PartData.h:97
void setP(double p)
Set reference momentum.
Definition: PartData.cpp:44
void setE(double E)
Set reference energy.
Definition: PartData.cpp:61
PartData()
Definition: PartData.cpp:36
double beta
Definition: PartData.h:96
void setBeta(double beta)
Set beta.
Definition: PartData.cpp:73
Logical error exception.
Definition: LogicalError.h:33