124 lines
3.6 KiB
C++
124 lines
3.6 KiB
C++
//
|
|
// dcs_ionization_container.cpp
|
|
// mc_electron
|
|
//
|
|
// Created by Christian Reiling on 04.06.19.
|
|
// Copyright © 2019 Christian Reiling. All rights reserved.
|
|
//
|
|
|
|
#include "dcs_ionization_container.hpp"
|
|
|
|
#include <algorithm>
|
|
#include "edge_container.h"
|
|
|
|
DCS_Ionization_Container::DCS_Ionization_Container(double T_min_eV, double T_max_eV, int number_T_bins, int number_W_bins, std::string load_path) {
|
|
T_scale = Log_Scale(T_min_eV, T_max_eV, number_T_bins);
|
|
W_scale = new Log_Scale[number_T_bins];
|
|
double Tmax_eV;
|
|
for (int i = 0; i < number_T_bins; i++) {
|
|
Tmax_eV = (T_scale.get_bin_mid(i) - EionT2_eV)/2;
|
|
W_scale[i] = Log_Scale(scale_start, Tmax_eV, number_W_bins);
|
|
}
|
|
init_data();
|
|
calc_data(load_path);
|
|
}
|
|
|
|
DCS_Ionization_Container::~DCS_Ionization_Container() {
|
|
for (int i=0; i < T_scale.get_number_bins(); i++) {
|
|
delete[] data[i];
|
|
}
|
|
delete[] data;
|
|
delete W_scale;
|
|
};
|
|
|
|
DCS_Ionization_Container::DCS_Ionization_Container(const DCS_Ionization_Container& other) {
|
|
T_scale = other.T_scale;
|
|
int num_T_bins = T_scale.get_number_bins();
|
|
W_scale = new Log_Scale[num_T_bins];
|
|
for (int i = 0; i < num_T_bins; i++) {
|
|
W_scale[i] = other.W_scale[i];
|
|
}
|
|
int num_W_bins = W_scale[0].get_number_bins();
|
|
init_data();
|
|
for (int i = 0; i<num_T_bins; i++) {
|
|
for (int j = 0; j<num_W_bins; j++) {
|
|
data[i][j] = other.data[i][j];
|
|
}
|
|
}
|
|
}
|
|
|
|
DCS_Ionization_Container& DCS_Ionization_Container::operator=(const DCS_Ionization_Container& other) {
|
|
DCS_Ionization_Container tmp(other);
|
|
std::swap(T_scale, tmp.T_scale);
|
|
std::swap(W_scale, tmp.W_scale);
|
|
std::swap(data, tmp.data);
|
|
return *this;
|
|
}
|
|
|
|
void DCS_Ionization_Container::init_data() {
|
|
int num_T_bins = T_scale.get_number_bins();
|
|
int num_W_bins = W_scale[0].get_number_bins();
|
|
data = new double *[num_T_bins];
|
|
for (int i = 0; i<num_T_bins; i++) {
|
|
data[i] = new double [num_W_bins];
|
|
}
|
|
}
|
|
|
|
void DCS_Ionization_Container::calc_data(std::string load_path) {
|
|
Edge_Container<dim2Map> E2D(load_path);
|
|
int num_T_bins = T_scale.get_number_bins();
|
|
int num_W_bins = W_scale[0].get_number_bins();
|
|
double *temp;
|
|
double sum;
|
|
//double E_eV;
|
|
for (int i = 0; i<num_T_bins; i++) {
|
|
//E_eV = T_scale.get_bin_mid(i);
|
|
temp = new double[num_W_bins];
|
|
sum = 0;
|
|
|
|
for (int j = 0; j<num_W_bins; j++) {
|
|
sum += calc_bin_surface(i, j, &E2D);
|
|
temp[j] = sum;
|
|
}
|
|
if (sum == 0) {
|
|
std::stringstream ss;
|
|
ss<<"DCS_Ionization_Container::calc_data: sum=0, lower_bound bad.\n";
|
|
throw MyException(ss.str());
|
|
}
|
|
|
|
for (int j = 0; j < num_W_bins; j++) {
|
|
temp[j] /= sum;
|
|
}
|
|
data[i] = temp;
|
|
}
|
|
}
|
|
|
|
double DCS_Ionization_Container::calc_bin_surface(int T_bin, int W_bin, Edge_Container<dim2Map> *E2D) {
|
|
double T_eV = T_scale.get_bin_mid(T_bin);
|
|
double W_eV = W_scale[T_bin].get_bin_mid(W_bin);
|
|
double width = T_scale.get_upper_bin_bound(T_bin) - T_scale.get_lower_bin_bound(T_bin);
|
|
double height = E2D->interpolate(ddeque{T_eV, W_eV});
|
|
return width*height;
|
|
}
|
|
|
|
double DCS_Ionization_Container::roll_value(const double &T_eV, UniRNG *rngUni) {
|
|
int T_bin = T_scale.calc_index(T_eV);
|
|
double target = rngUni->random();
|
|
for (int j=0; j<W_scale[T_bin].get_number_bins(); j++) {
|
|
if (target < data[T_bin][j]) {
|
|
return roll_in_bin(T_bin, j, rngUni);
|
|
}
|
|
}
|
|
std::stringstream ss;
|
|
ss<<"DCS_Ionization_Container::roll_value: Overflow.\n";
|
|
throw MyException (ss.str());
|
|
}
|
|
|
|
double DCS_Ionization_Container::roll_in_bin(const int &T_bin, const int &W_bin, UniRNG *rngUni) {
|
|
double lower_value = W_scale[T_bin].get_lower_bin_bound(W_bin);
|
|
double upper_value = W_scale[T_bin].get_upper_bin_bound(W_bin);
|
|
double distance = upper_value - lower_value;
|
|
double res = lower_value + rngUni->random() * distance;
|
|
return res;
|
|
}
|