81 lines
2.4 KiB
C++
81 lines
2.4 KiB
C++
//
|
|
// injector.cpp
|
|
// mc_electron
|
|
//
|
|
// Created by Christian Reiling on 13.04.19.
|
|
// Copyright © 2019 Christian Reiling. All rights reserved.
|
|
//
|
|
|
|
#include "read_system.h"
|
|
|
|
#include "injector.hpp"
|
|
#include "katrin_geo.h"
|
|
|
|
const int Injector::injectionMethod = load_parameter("INJECTION");
|
|
const double Injector::injectionEnergy_eV = load_parameter("INJ_E");
|
|
|
|
Particle Injector::injectElectron (const int &newId) {
|
|
|
|
double r_m = r_WGTS_m*sqrt(rngUni->random());
|
|
double phi = rngUni->random()*2*pi;
|
|
|
|
double z_WGTSstart_m = z_WGTS_start_m;
|
|
double wgtsLength_m = l_WGTS_m;
|
|
|
|
double z_WGTS_start_to_half_pos_m = sqrt(rngUni->random())*wgtsLength_m/2;
|
|
double z_m = (rngUni->random()<0.5) ? z_WGTS_start_to_half_pos_m : wgtsLength_m - z_WGTS_start_to_half_pos_m;
|
|
z_m += z_WGTSstart_m;
|
|
|
|
vec3 loc_m = vec3 (r_m*cos(phi),r_m*sin(phi),z_m);
|
|
double E_eV;
|
|
switch(injectionMethod) {
|
|
case 0: // Fermi
|
|
E_eV = roll_FermiEnergy_eV();
|
|
break;
|
|
case 1: //Delta
|
|
E_eV = injectionEnergy_eV;
|
|
break;
|
|
case 2: //Maxwell Boltzman
|
|
E_eV = roll_MBEnergy(injectionEnergy_eV/kb_eVK,me_eV, rngNormal);
|
|
break;
|
|
default:
|
|
throw MyException("Katrin::injectElectron: Invalid Injection Method.");
|
|
break;
|
|
}
|
|
vec3 v_ms = roll_uniform_direction(rngUni) * calc_v_ms_from_E_eV(E_eV,me_eV);
|
|
return PartFac.create_e(loc_m, v_ms, newId, newId);
|
|
|
|
//double v_ms = calc_v_ms_from_E_eV(pow(rngUni->random(),1./3.), me_eV);
|
|
//double v_ms = -100;
|
|
//return PartFac.create_e(vec3(0,0,z_WGTS_end_m), vec3(0,0,-v_ms),newId, newId);
|
|
}
|
|
|
|
double Injector::roll_FermiEnergy_eV() {
|
|
double pmax,E_min_eV, E_max_eV, Ecan_eV,eta1,eta2;
|
|
pmax = 1.5e-28; // From Plotting EnergyDistributionBetaDecay
|
|
E_min_eV = scale_start;
|
|
E_max_eV = TritiumDecayEndpoint_eV;
|
|
do {
|
|
eta1 = rngUni->random();
|
|
eta2 = rngUni->random();
|
|
Ecan_eV = E_min_eV + eta1*(E_max_eV - E_min_eV);
|
|
} while(eta2*pmax > get_FermiDecaySpectrumDensity(Ecan_eV));
|
|
return Ecan_eV;
|
|
}
|
|
|
|
double Injector::get_FermiDecaySpectrumDensity(const double &E_eV) {
|
|
if (E_eV>TritiumDecayEndpoint_eV) {
|
|
return 0;
|
|
} else{
|
|
double p_eV = sqrt(E_eV*E_eV + 2 * E_eV * me_eV);
|
|
return BetaDecayConst*get_FermiFunction(2, E_eV)*p_eV*(E_eV+me_eV)*pow(TritiumDecayEndpoint_eV-E_eV,2);
|
|
}
|
|
}
|
|
|
|
double Injector::get_FermiFunction(const double &Z, const double &E_eV) {
|
|
double gamma = 1+ E_eV/me_eV;
|
|
double beta = sqrt(1 - pow(gamma,-2));
|
|
double eta =Z/beta/137.;
|
|
return 2*pi*eta/(1-exp(-2*pi*eta));
|
|
}
|