#include #include #include #include "catima/catima.h" #include "catima/constants.h" #include "catima/data_ionisation_potential.h" #include "catima/data_atima.h" #include "catima/integrator.h" #include "catima/storage.h" #include "catima/nucdata.h" #include "catima/calculations.h" namespace catima{ Config default_config; bool operator==(const Config &a, const Config&b){ if(std::memcmp(&a,&b,sizeof(Config)) == 0){ return true; } else return false; } double dedx(Projectile &p, double T, const Material &mat, const Config &c){ double sum = 0; double w=0; if(T<=0)return 0.0; for(int i=0;i100){printf("too many iterations finding Eout");return -1;} } return -1; } double energy_out(Projectile &p, double T, const Material &t, const Config &c){ auto data = _storage.Get(p,t,c); Interpolator range_spline(energy_table.values,data.range.data(),energy_table.num); return energy_out(T,t.thickness(),range_spline); } Result calculate(Projectile &p, const Material &t, const Config &c){ Result res; double T = p.T; auto data = _storage.Get(p,t,c); Interpolator range_spline(energy_table.values,data.range.data(),energy_table.num); res.Ein = T; res.range = range_spline(T); res.dEdxi = p.A/range_spline.derivative(T); res.Eout = energy_out(T,t.thickness(),range_spline); Interpolator range_straggling_spline(energy_table.values,data.range_straggling.data(),energy_table.num); if(res.Eout0){ //auto tofdata = calculate_tof(p,t,c); //Interpolator tof_spline(energy_table.values, tofdata.data(), energy_table.num,interpolation_t::linear); //res.tof = tof_spline(res.Ein) - tof_spline(res.Eout); res.tof = calculate_tof_from_E(p,res.Eout,t); } } res.sigma_r = sqrt(range_straggling_spline(T)); res.Eloss = (res.Ein - res.Eout)*p.A; return res; } MultiResult calculate(Projectile &p, const Layers &layers, const Config &c){ MultiResult res; double e = p.T; res.total_result.Ein = e; res.results.reserve(layers.num()); for(auto&m:layers.get_materials()){ Result r = calculate(p,m,e,c); e = r.Eout; res.total_result.sigma_a += r.sigma_a*r.sigma_a; res.total_result.Eloss += r.Eloss; res.total_result.sigma_E += r.sigma_E*r.sigma_E; res.total_result.tof += r.tof; res.total_result.Eout = r.Eout; res.results.push_back(r); } if(e>Ezero){ res.total_result.sigma_a = sqrt(res.total_result.sigma_a); res.total_result.sigma_E = sqrt(res.total_result.sigma_E); } else{ res.total_result.sigma_a = 0.0; res.total_result.sigma_E = 0.0; } return res; } Result calculate(double pa, int pz, double T, double ta, double tz, double thickness, double density){ Projectile p(pa,pz); Material m(ta,tz,density,thickness); return calculate(p(T),m); } std::vector calculate_range(Projectile p, const Material &t, const Config &c){ double res; std::vectorvalues; values.reserve(max_datapoints); auto fdedx = [&](double x)->double{return 1.0/dedx(p,x,t);}; //calculate 1st point to have i-1 element ready for loop res = integrator.integrate(fdedx,Ezero,energy_table(0)); res = p.A*res; values.push_back(res); for(int i=1;i calculate_range_straggling(Projectile p, const Material &t, const Config &c){ double res; std::vectorvalues; values.reserve(max_datapoints); auto function = [&](double x)->double{return 1.0*domega2dx(p,x,t)/pow(dedx(p,x,t),3);}; //auto function = [&](double x)->double{ //double de = dedx(p,x,t); //return 1.0*domega2dx(p,x,t)/(de*de*de); //}; //calculate 1st point to have i-1 element ready for loop res = integrator.integrate(function,Ezero,energy_table(0)); res = p.A*res; values.push_back(res); for(int i=1;i calculate_da2dx(Projectile p, const Material &t, const Config &c){ double res; std::vectorvalues; values.reserve(max_datapoints); //auto function = [&](double x)->double{return p.A*da2dx(p,x,t)/dedx(p,x,t);}; auto function = [&](double x)->double{return 1.0/dedx(p,x,t);}; res = integrator.integrate(function,Ezero,energy_table(0)); res = p.A*da2dx(p,energy_table(0),t)*res; values.push_back(res); for(int i=1;i calculate_tof(Projectile p, const Material &t, const Config &c){ double res; std::vector values; values.reserve(max_datapoints); auto function = [&](double x)->double{return 1.0/(dedx(p,x,t)*beta_from_T(x));}; res = integrator.integrate(function,Ezero,energy_table(0)); res = res*10.0*p.A/(c_light*t.density()); values.push_back(res); for(int i=1;idouble{ return 1.0/dedx(p,x,t,c); }; auto fomega = [&](double x)->double{ //return 1.0*domega2dx(p,x,t)/pow(dedx(p,x,t),3); return domega2dx(p,x,t,c)/catima::power(dedx(p,x,t,c),3); }; double res; //calculate 1st point to have i-1 element ready for loop //res = integrator.integrate(fdedx,Ezero,energy_table(0)); //res = p.A*res; dp.range[0] = 0.0; //res = da2dx(p,energy_table(0),t)*res; dp.angular_variance[0] = 0.0; //res = integrator.integrate(fomega,Ezero,energy_table(0)); //res = p.A*res; dp.range_straggling[0]=0.0; for(int i=1;idouble{return 1.0/(dedx(p,x,t)*beta_from_T(x));}; res = integrator.integrate(function,Eout,p.T); res = res*10.0*p.A/(c_light*t.density()); return res; } } // end of atima namespace