-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfour_momentum.h
41 lines (33 loc) · 881 Bytes
/
four_momentum.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#ifndef FOUR_MOMENTUM_H_
#define FOUR_MOMENTUM_H_
#include <cmath>
#include <stdexcept>
class Four_momentum
{
private:
double mass, energy, momentum, gamma, beta;
void update_from_gamma()
{
if (gamma < 1.0) {
throw std::range_error("Four_momentum: gamma not >= 1.0");
}
energy = gamma * mass;
beta = sqrt(1.0 - 1.0 / (gamma * gamma));
momentum = gamma * beta * mass;
}
public:
Four_momentum(double mass, double total_energy)
: mass(mass)
{
set_total_energy(total_energy);
}
void set_total_energy(double total_energy)
{
gamma = total_energy / mass;
update_from_gamma();
}
double get_mass() const { return mass; }
double get_momentum() const { return momentum; }
double get_gamma() const { return gamma; }
};
#endif /* FOUR_MOMENTUM_H_ */