// // terminator_base.h // mc_electron // // Created by Christian Reiling on 19.05.19. // Copyright © 2019 Christian Reiling. All rights reserved. // #ifndef terminator_base_h #define terminator_base_h #include "process_base.h" #include "particle.hpp" struct Termination_Stats { int n_total = 0; int n_rw = 0; int n_dipole = 0; int n_radial = 0; int n_max = 0; int n_energy = 0; int n_reaction = 0; void reset () { n_total = 0; n_rw = 0; n_dipole = 0; n_radial = 0; n_max = 0; n_energy = 0; n_reaction = 0; } void to_array(int *array) { // Ugly workarounds maybe move to casting with reinterpret cast array [0] = n_total; array [1] = n_rw; array [2] = n_dipole; array [3] = n_radial; array [4] = n_max; array [5] = n_energy; array [6] = n_reaction; } void from_array(int *array) { // Ugly workarounds maybe move to casting with reinterpret cast n_total = array [0]; n_rw = array [1]; n_dipole = array [2]; n_radial = array [3]; n_max = array [4]; n_energy = array [5]; n_reaction = array [6]; } }; class Terminator_Base : public Process_Base { protected: Termination_Stats stats; private: long int cur_Id_total = -1; // For counting num_tot long int cur_Id_max = -1; // For max interactions int max_interactions; int interaction_counter = 0; double cut_off_energy_eV; public: Terminator_Base(species this_species, int max_interactions, double cut_off_energy_eV) : Process_Base(this_species) { this->max_interactions = max_interactions; this->cut_off_energy_eV = cut_off_energy_eV; }; bool check_terminlization(const Particle &movePart); Termination_Stats get_stats() { return stats; } void reset_stats() { stats.reset(); } void increase_n_reaction() { stats.n_reaction += 1; } private: void count_total(const long int &Id); bool check_min_energy(const double &E_eV); bool check_max_interactions(const long int &Id); virtual bool check_walls(const Particle &movePart) = 0; }; inline bool Terminator_Base::check_terminlization(const Particle &movePart) { long int Id = movePart.get_Id(); count_total(Id); return check_walls(movePart) || check_min_energy(movePart.get_E_eV()) || check_max_interactions(Id); } inline void Terminator_Base::count_total(const long int &Id) { if (Id != cur_Id_total) { cur_Id_total = Id; stats.n_total += 1; } } inline bool Terminator_Base::check_min_energy(const double &E_eV) { if (E_eV<=cut_off_energy_eV) { stats.n_energy += 1; return true; } else { return false; } } inline bool Terminator_Base::check_max_interactions(const long int &Id) { if (Id != cur_Id_max) { cur_Id_max = Id; interaction_counter = 0; } interaction_counter +=1; if (interaction_counter >= max_interactions) { stats.n_max += 1; return true; } else { return false; } } #endif /* terminator_base_h */