Minior Changes on new structure, exported elastic cross section to seperate file.

Please enter the commit message for your changes. Lines starting
This commit is contained in:
Christian
2019-05-02 13:29:21 +02:00
parent e07c03c888
commit 649c278084
33 changed files with 631 additions and 595 deletions
+128
View File
@@ -0,0 +1,128 @@
//
// 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 "constants.h"
#include "error_types.h"
#include <blitz/tinyvec2.h>
#include <sstream>
typedef blitz::TinyVector<double,3> vec3;
inline double vec3Abs(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_Ekin_eV_from_speed(const double &speed_ms, const double &mass_eV) {
double beta = speed_ms/c_ms;
if (beta>=1) {
std::stringstream ss;
ss<<"calc_Ekin_eV_from_speed(): Input speed v="<<speed_ms<<" m/s equal or exeeds speed of light.";
throw MyException(ss.str());
} else if (beta<0) {
std::stringstream ss;
ss<<"calc_Ekin_eV_from_speed(): Input speed v="<<speed_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) * mass_eV );
}
inline double calc_Ekin_eV_from_speed(const vec3 &speed_ms, const double &mass_eV) {
return (calc_Ekin_eV_from_speed(vec3Abs(speed_ms), mass_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_Ekin_eV(const double &Ekin_eV, const double &mass_eV) {
if (Ekin_eV<0) {
std::stringstream ss;
ss<<"calc_gamma_from_Ekin_eV(): Input Ekin_eV ="<<Ekin_eV<<" negative.";
throw MyException(ss.str());
}
return (1. + Ekin_eV/mass_eV);
}
inline double calc_beta_from_Ekin_eV(const double &Ekin_eV, const double &mass_eV) {
return ( calc_beta_from_gamma(calc_gamma_from_Ekin_eV(Ekin_eV, mass_eV)) );
}
inline double calc_Speed_from_Ekin_eV(const double &Ekin_eV, const double &mass_eV) {
if (Ekin_eV<0) {
std::stringstream ss;
ss<<"calc_Speed_from_Ekin_eV(): Input Ekin_eV ="<<Ekin_eV<<" negative.";
throw MyException(ss.str());
}
double gamma = calc_gamma_from_Ekin_eV(Ekin_eV, mass_eV);
double beta = calc_beta_from_gamma(gamma);
return(beta * c_ms);
}
inline vec3 calc_newDirection(const vec3 &direction_old, const double &theta_change, const double &phi_change) {
// Transformation of direction following Plante and Cucinotta
double theta_old = acos(direction_old[2]/vec3Abs(direction_old));
double phi_old = atan2(direction_old[1],direction_old[0]);
double A3 = sin(theta_change)*cos(phi_change);
double A4 = A3*cos(theta_old) + cos(theta_change)*sin(theta_old);
double A5 = sin(theta_change)*sin(phi_change);
double A11 = A4*cos(phi_old) - A5*sin(phi_old);
double A21 = A4*sin(phi_old) + A5*cos(phi_old);
double theta_new = acos( cos(theta_old)*cos(theta_change)-A3*sin(theta_old) );
// Get right phi1, maybe more elegant way later. Problem comes from reverse functions only being on range of pi. So combine both statements to get proper phi over 2pi.
int digits = 6;
double fac = pow(10,digits);
double phi_new = -1;
double phi_new_candidates [4];
phi_new_candidates[0] = acos( roundf ( A11/sin(theta_new) *fac)/fac );
phi_new_candidates[1] = 2*pi - phi_new_candidates[0];
phi_new_candidates[2] = asin ( roundf ( A21/sin(theta_new) *fac)/fac );
phi_new_candidates[3] = pi - phi_new_candidates[2];
phi_new_candidates[2] = (phi_new_candidates[2] > 0) ? phi_new_candidates[2] : 2*pi + phi_new_candidates[2];
for (int i=0;i<3;i++) {
for (int j=i+1;j<4;j++) {
if (phi_new_candidates[i]-phi_new_candidates[j] < 0.0001) {
phi_new = phi_new_candidates[i];
}
}
}
if (phi_new == -1) {
throw MyException("Interaction::getElaNewDir: phi1 not found.");
}
return(vec3(sin(theta_new)*cos(phi_new) , sin(theta_new)*sin(phi_new) , cos(theta_new)));
}
#endif /* kinematics_h */