131 lines
3.5 KiB
C++
131 lines
3.5 KiB
C++
//
|
|
// kinematics.h
|
|
// mc_electron
|
|
//
|
|
// Created by Christian Reiling on 30.04.19.
|
|
// Copyright © 2019 Christian Reiling. All rights reserved.
|
|
//
|
|
|
|
#ifndef kinematics_h
|
|
#define kinematics_h
|
|
|
|
#include <sstream>
|
|
#include <blitz/array.h>
|
|
#include <blitz/tinyvec2.h>
|
|
|
|
#include "constants.h"
|
|
#include "error_types.h"
|
|
|
|
typedef blitz::TinyVector<double,3> vec3;
|
|
|
|
|
|
inline double calc_vec3_abs(const vec3 &vec) {
|
|
return sqrt( pow(vec[0],2) + pow(vec[1],2) + pow(vec[2],2));
|
|
}
|
|
|
|
inline double calc_gamma_from_beta(const double &beta) {
|
|
if (beta>=1) {
|
|
std::stringstream ss;
|
|
ss<<"calc_gamma_from_beta(): Input beta ="<<beta<<" equal or exeeds 1.";
|
|
throw MyException(ss.str());
|
|
} else if (beta<0) {
|
|
std::stringstream ss;
|
|
ss<<"calc_gamma_from_beta(): Input beta ="<<beta<<" negative.";
|
|
throw MyException(ss.str());
|
|
}
|
|
|
|
return pow(1 - pow(beta,2),-0.5);
|
|
}
|
|
|
|
inline double calc_E_eV_from_v_ms(const double &v_ms, const double &m_eV) {
|
|
double beta = v_ms/c_ms;
|
|
if (beta>=1) {
|
|
std::stringstream ss;
|
|
ss<<"calc_E_eV_from_v_ms(): Input speed v="<<v_ms<<" m/s equal or exeeds speed of light.";
|
|
throw MyException(ss.str());
|
|
} else if (beta<0) {
|
|
std::stringstream ss;
|
|
ss<<"calc_E_eV_from_v_ms(): Input speed v="<<v_ms<<" m/s is expected to be absolute value therfore >0.";
|
|
throw MyException(ss.str());
|
|
}
|
|
double gamma = calc_gamma_from_beta(beta);
|
|
return (gamma-1) * m_eV;
|
|
}
|
|
|
|
inline double calc_E_eV_from_v_ms(const vec3 &v_ms, const double &m_eV) {
|
|
return calc_E_eV_from_v_ms(calc_vec3_abs(v_ms), m_eV);
|
|
}
|
|
|
|
inline double calc_beta_from_gamma(const double &gamma) {
|
|
if (gamma<1) {
|
|
std::stringstream ss;
|
|
ss<<"calc_beta_from_gamma(): Input gamma ="<<gamma<<" smaller 1.";
|
|
throw MyException(ss.str());
|
|
}
|
|
return sqrt(1 - pow(gamma,-2));
|
|
}
|
|
|
|
inline double calc_gamma_from_E_eV(const double &E_eV, const double &m_eV) {
|
|
if (E_eV<0) {
|
|
std::stringstream ss;
|
|
ss<<"calc_gamma_from_E_eV(): Input E_eV ="<<E_eV<<" negative.";
|
|
throw MyException(ss.str());
|
|
}
|
|
return 1 + E_eV/m_eV;
|
|
}
|
|
|
|
inline double calc_beta_from_E_eV(const double &E_eV, const double &m_eV) {
|
|
return calc_beta_from_gamma(calc_gamma_from_E_eV(E_eV, m_eV));
|
|
}
|
|
|
|
inline double calc_v_ms_from_E_eV(const double &E_eV, const double &m_eV) {
|
|
if (E_eV<0) {
|
|
std::stringstream ss;
|
|
ss<<"calc_v_ms_from_E_eV(): Input E_eV ="<<E_eV<<" negative.";
|
|
throw MyException(ss.str());
|
|
}
|
|
|
|
double gamma = calc_gamma_from_E_eV(E_eV, m_eV);
|
|
double beta = calc_beta_from_gamma(gamma);
|
|
return beta*c_ms;
|
|
}
|
|
|
|
inline vec3 calc_n_new(const vec3 &direction_old, const double &theta_change, const double &phi_change) {
|
|
// Alireza Haghighat: Appendix 3 (p.249)
|
|
vec3 nOld = direction_old/calc_vec3_abs(direction_old);
|
|
double u = nOld[0];
|
|
double v = nOld[1];
|
|
double w = nOld[2];
|
|
double s = sqrt(1-w*w);
|
|
double uNew, vNew, wNew;
|
|
if (w!=1) {
|
|
uNew = -(u*w/s*cos(phi_change) - v/s*sin(phi_change))*sin(theta_change) + u*cos(theta_change);
|
|
vNew = -(v*w/s*cos(phi_change) + u/s*sin(phi_change))*sin(theta_change) + v*cos(theta_change);
|
|
wNew = s*(sin(theta_change)*cos(phi_change)) + w*cos(theta_change);
|
|
} else {
|
|
uNew = sin(theta_change)*cos(phi_change);
|
|
vNew = sin(theta_change)*sin(phi_change);
|
|
wNew = cos(theta_change);
|
|
}
|
|
return vec3(uNew, vNew, wNew);
|
|
}
|
|
|
|
inline double calc_z_m(const vec3 &loc_m) {
|
|
return loc_m[2];
|
|
}
|
|
|
|
inline double calc_r_m(const vec3 &loc_m) {
|
|
return sqrt(loc_m[0]*loc_m[0] + loc_m[1]*loc_m[1]);
|
|
}
|
|
|
|
inline double calc_phi(const vec3 &loc_m) {
|
|
if (loc_m[1] >= 0) {
|
|
return acos(loc_m[0]/calc_r_m(loc_m));
|
|
} else {
|
|
return 2*pi - acos(loc_m[0]/calc_r_m(loc_m));
|
|
}
|
|
}
|
|
|
|
|
|
#endif /* kinematics_h */
|