Reworked Populations Loggers.
Added Save and Load Option for Population Data.
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
//
|
||||
// population4_container.cpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 11.06.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include "population4_container.hpp"
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
Pop4_Container::Pop4_Container(int num_z_bins, int num_r_bins, int num_phi_bins, int num_E_bins) {
|
||||
z_scale = Lin_Scale(Katrin_Geo::get_z_RW_m(), Katrin_Geo::get_z_WGTSend_m(), num_z_bins);
|
||||
r_scale = Lin_Scale(0,Katrin_Geo::get_radius_m(), num_r_bins);
|
||||
phi_scale = Lin_Scale(0, 2*pi, num_phi_bins);
|
||||
E_scale = Log_Scale(zero, 2e4, num_E_bins);
|
||||
|
||||
data = new double ***[num_z_bins];
|
||||
for (int i = 0; i < num_z_bins; i++) {
|
||||
data[i] = new double **[num_r_bins];
|
||||
for(int j = 0; j < num_r_bins; j++) {
|
||||
data[i][j] = new double *[num_phi_bins];
|
||||
for (int k = 0; k < num_phi_bins; k++) {
|
||||
data[i][j][k] = new double [num_E_bins];
|
||||
for (int l = 0; l< num_E_bins; l++) {
|
||||
data[i][j][k][l] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Pop4_Container::~Pop4_Container() {
|
||||
int num_z_bins = z_scale.get_number_bins();
|
||||
int num_r_bins = r_scale.get_number_bins();
|
||||
int num_phi_bins = phi_scale.get_number_bins();
|
||||
for (int i = 0; i < num_z_bins; i++) {
|
||||
for(int j = 0; j < num_r_bins; j++) {
|
||||
for (int k = 0; k < num_phi_bins; k++) {
|
||||
delete[] data[i][j][k];
|
||||
}
|
||||
delete[] data[i][j];
|
||||
}
|
||||
delete[] data[i];
|
||||
}
|
||||
delete[] data;
|
||||
}
|
||||
|
||||
Pop4_Container::Pop4_Container(const Pop4_Container& other) {
|
||||
z_scale = other.z_scale;
|
||||
r_scale = other.r_scale;
|
||||
phi_scale = other.phi_scale;
|
||||
E_scale = other.E_scale;
|
||||
int num_z_bins = z_scale.get_number_bins();
|
||||
int num_r_bins = r_scale.get_number_bins();
|
||||
int num_phi_bins = phi_scale.get_number_bins();
|
||||
int num_E_bins = E_scale.get_number_bins();
|
||||
|
||||
data = new double ***[num_z_bins];
|
||||
for (int i = 0; i < num_z_bins; i++) {
|
||||
data[i] = new double **[num_r_bins];
|
||||
for(int j = 0; j < num_r_bins; j++) {
|
||||
data[i][j] = new double *[num_phi_bins];
|
||||
for (int k = 0; k < num_phi_bins; k++) {
|
||||
data[i][j][k] = new double [num_E_bins];
|
||||
for (int l = 0; l < num_E_bins; l++) {
|
||||
data[i][j][k][l] = other.data[i][j][k][l];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Pop4_Container& Pop4_Container::operator=(const Pop4_Container& other) {
|
||||
Pop4_Container tmp(other);
|
||||
swap(z_scale, tmp.z_scale);
|
||||
swap(r_scale, tmp.r_scale);
|
||||
swap(phi_scale, tmp.phi_scale);
|
||||
swap(E_scale, tmp.E_scale);
|
||||
swap(data, tmp.data);
|
||||
return (*this);
|
||||
}
|
||||
|
||||
void Pop4_Container::increase_value(const double &value, const vec3 &loc_m, const double &E_eV) {
|
||||
int zbin = z_scale.calc_index(get_z_m(loc_m));
|
||||
int rbin = r_scale.calc_index(get_r_m(loc_m));
|
||||
int phibin = phi_scale.calc_index(get_phi(loc_m));
|
||||
int E_bin = E_scale.calc_index(E_eV);
|
||||
|
||||
data[zbin][rbin][phibin][E_bin] += value;
|
||||
}
|
||||
|
||||
void Pop4_Container::increase_value(const double &value, const vec3 &loc1_m, const vec3 &loc2_m, const double &E_eV) {
|
||||
double z_min_m = get_z_m(loc1_m);
|
||||
double z_max_m = get_z_m(loc2_m);
|
||||
if (z_max_m < z_min_m) {
|
||||
swap(z_min_m, z_max_m);
|
||||
}
|
||||
int min_z_index = z_scale.calc_index(z_min_m);
|
||||
int max_z_index = z_scale.calc_index(z_max_m);
|
||||
// No r/phi movement, else need to calculate more exactly
|
||||
double r = get_r_m(loc1_m);
|
||||
int rbin = r_scale.calc_index(get_r_m(r));
|
||||
double phi = get_phi(loc1_m);
|
||||
int phibin = phi_scale.calc_index(phi);
|
||||
int E_bin = E_scale.calc_index(E_eV);
|
||||
|
||||
for (int i = min_z_index; i<=max_z_index; i++) {
|
||||
data[i][rbin][phibin][E_bin] += value;
|
||||
}
|
||||
}
|
||||
|
||||
double Pop4_Container::get_value(const vec3 &loc_m, const double &E_eV) {
|
||||
int zbin = z_scale.calc_index(get_z_m(loc_m));
|
||||
int rbin = r_scale.calc_index(get_r_m(loc_m));
|
||||
int phibin = phi_scale.calc_index(get_phi(loc_m));
|
||||
int E_bin = E_scale.calc_index(E_eV);
|
||||
return (data[zbin][rbin][phibin][E_bin]);
|
||||
}
|
||||
|
||||
double *Pop4_Container::get_E_bins (const vec3 &loc_m) {
|
||||
int z_bin = z_scale.calc_index(loc_m[0]);
|
||||
int r_bin = r_scale.calc_index(loc_m[1]);
|
||||
int phi_bin = phi_scale.calc_index(loc_m[2]);
|
||||
return data[z_bin][r_bin][phi_bin];
|
||||
}
|
||||
Reference in New Issue
Block a user