96 lines
2.8 KiB
C++
96 lines
2.8 KiB
C++
//
|
|
// energeticPop_container.cpp
|
|
// mc_electron
|
|
//
|
|
// Created by Christian Reiling on 15.05.19.
|
|
// Copyright © 2019 Christian Reiling. All rights reserved.
|
|
//
|
|
|
|
#include "energeticPop_container.hpp"
|
|
|
|
using namespace std;
|
|
|
|
|
|
void EnergeticPop_Container::set_Map() {
|
|
vector<vec3> bins = get_bins();
|
|
double Ex_min = floor(log10(1e-3));
|
|
double Ex_max = ceil(log10(E_max_eV));
|
|
double step = (Ex_max-Ex_min)/Epoints;
|
|
double x, E_eV;
|
|
for (vector<vec3>::iterator itr = bins.begin(); itr!=bins.end(); itr++) {
|
|
for (int i = 1; i<=Epoints; i++) {
|
|
x = Ex_min + step*i;
|
|
E_eV = pow(10,x);
|
|
addPoint(deque<double>{(*itr)[0], (*itr)[1], (*itr)[2], E_eV, 0});
|
|
}
|
|
}
|
|
}
|
|
|
|
double EnergeticPop_Container::getDensity_m3(const vec3 &locXYZ_m, double physTime_s) {
|
|
check_In_Container(locXYZ_m, xyz);
|
|
vec3 zrphiCords = transformTo_zrphiCords(locXYZ_m, xyz);
|
|
double V_m3 = get_V_m3(zrphiCords[1]);
|
|
double cumTime_s = get_cumulated_time_s(zrphiCords);
|
|
return cumTime_s/physTime_s/V_m3;
|
|
}
|
|
|
|
double EnergeticPop_Container::get_cumulated_time_s(vec3 zrphiCords) {
|
|
dim1Map EMap = *getSubMap<dim1Map>(ddeque{zrphiCords[0], zrphiCords[1], zrphiCords[2]}, Lower_bound);
|
|
double cumTime_s = 0;
|
|
for (dim1Map::iterator itr = EMap.begin(); itr != EMap.end(); itr++) {
|
|
cumTime_s +=itr->second;
|
|
}
|
|
return cumTime_s;
|
|
}
|
|
|
|
|
|
void EnergeticPop_Container::upDensity (const Particle &upParticle, const vec3 &oldLocXYZ_m) {
|
|
check_In_Container(oldLocXYZ_m, xyz);
|
|
vec3 zrphiOld_m = transformTo_zrphiCords(oldLocXYZ_m, xyz);
|
|
vec3 zrphiNew_m = upParticle.get_x_m();
|
|
check_In_Container(zrphiNew_m, zrphi);
|
|
// Check r and phi not changing, only valid for drift approximation....
|
|
|
|
double z_min_m = zrphiOld_m[0];
|
|
double z_max_m = zrphiNew_m[0];
|
|
if (z_max_m<z_min_m) {
|
|
swap (z_min_m, z_max_m);
|
|
}
|
|
double r_m = zrphiOld_m[1];
|
|
double phi = zrphiOld_m[2];
|
|
double l_m = get_l_m();
|
|
double vAbs_ms = upParticle.get_vAbs_ms();
|
|
double E_eV = upParticle.get_E_eV();
|
|
|
|
dim4Map::iterator zitr_min = Map.lower_bound(z_min_m);
|
|
dim4Map::iterator zitr_max = Map.lower_bound(z_max_m);
|
|
|
|
for (dim4Map::iterator itr = zitr_min;itr != zitr_max;itr++) {
|
|
itr->second.lower_bound(r_m)->second.lower_bound(phi)->second.lower_bound(E_eV)->second += l_m/vAbs_ms;
|
|
}
|
|
}
|
|
|
|
|
|
double EnergeticPop_Container::roll_Energy_eV(const vec3 &locXYZ_m, UniRNG *rngUni) {
|
|
check_In_Container(locXYZ_m, xyz);
|
|
|
|
vec3 zrphiCords = transformTo_zrphiCords(locXYZ_m, xyz);
|
|
dim1Map EMap = *getSubMap<dim1Map>(ddeque{locXYZ_m[0], locXYZ_m[1], locXYZ_m[2]}, Lower_bound);
|
|
|
|
double targetTime_s = rngUni->random() * get_cumulated_time_s(zrphiCords);
|
|
double summedTime_s = 0;
|
|
dim1Map::iterator itr = EMap.begin();
|
|
do {
|
|
summedTime_s += itr->second;
|
|
itr++;
|
|
} while(summedTime_s < targetTime_s);
|
|
itr--;
|
|
|
|
if (itr == EMap.begin() ) {
|
|
return itr->first;
|
|
} else {
|
|
double E_eV = ( (itr->first) + ((--itr)->first) )/2;
|
|
return E_eV;
|
|
}
|
|
}
|