OPAL (Object Oriented Parallel Accelerator Library)  2024.1
OPAL
PartData.cpp
Go to the documentation of this file.
1 //
2 // Class PartData
3 // PartData represents a set of reference values for use in algorithms.
4 //
5 // Copyright (c) 200x - 2023, Paul Scherrer Institut, Villigen PSI, Switzerland
6 // All rights reserved
7 //
8 // This file is part of OPAL.
9 //
10 // OPAL is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
17 //
18 #include "Algorithms/PartData.h"
19 
20 #include "Utilities/LogicalError.h"
21 
22 #include <cmath>
23 
24 
25 PartData::PartData(double q, double m, double momentum) {
26  charge_m = q;
27  mass_m = m;
28  setP(momentum);
29 }
30 
31 
33  charge_m = 1.0;
34  mass_m = 0.0;
35  beta_m = 1.0;
36  gamma_m = 1.0e10;
37 }
38 
39 
40 void PartData::setP(double p) {
41  if (mass_m == 0.0) {
42  throw LogicalError("PartData::setP()",
43  "Particle mass must not be zero.");
44  }
45 
46  if (p == 0.0) {
47  throw LogicalError("PartData::setP()",
48  "Particle momentum must not be zero.");
49  }
50 
51  double e = std::sqrt(p * p + mass_m * mass_m);
52  beta_m = p / e;
53  gamma_m = e / mass_m;
54 }
55 
56 
57 void PartData::setE(double energy) {
58  if (energy <= mass_m) {
59  throw LogicalError("PartData::setE()", "Energy should be > mass.");
60  }
61 
62  gamma_m = energy / mass_m;
63  //beta = std::sqrt(energy*energy - mass*mass) / energy;
64  double ginv = 1.0 / gamma_m;
65  beta_m = std::sqrt((1.0 - ginv) * (1.0 + ginv));
66 }
67 
68 
69 void PartData::setBeta(double v) {
70  if (v >= 1.0) {
71  throw LogicalError("PartData::setBeta()", "Beta should be < 1.");
72  }
73 
74  beta_m = v;
75  gamma_m = 1.0 / std::sqrt(1.0 - beta_m * beta_m);
76 }
77 
78 
79 void PartData::setGamma(double v) {
80  if (v <= 1.0) {
81  throw LogicalError("PartData::setGamma()", "Gamma should be > 1.");
82  }
83 
84  gamma_m = v;
85  beta_m = std::sqrt(gamma_m * gamma_m - 1.0) / gamma_m;
86 }
87 
88 void PartData::setMomentumTolerance(double tolerance) {
89  momentumTolerance_m = tolerance;
90 }
void setMomentumTolerance(double tolerance)
Set the momentum tolerance.
Definition: PartData.cpp:88
double beta_m
Definition: PartData.h:102
Tps< T > sqrt(const Tps< T > &x)
Square root.
Definition: TpsMath.h:91
void setBeta(double beta)
Set beta.
Definition: PartData.cpp:69
void setP(double p)
Set reference momentum.
Definition: PartData.cpp:40
double mass_m
Definition: PartData.h:101
PartData()
Definition: PartData.cpp:32
double gamma_m
Definition: PartData.h:103
void setE(double E)
Set reference energy.
Definition: PartData.cpp:57
double momentumTolerance_m
Definition: PartData.h:104
constexpr double e
The value of .
Definition: Physics.h:39
Logical error exception.
Definition: LogicalError.h:33
void setGamma(double gamma)
Set gamma.
Definition: PartData.cpp:79
double charge_m
Definition: PartData.h:100