126 lines
2.7 KiB
C++
126 lines
2.7 KiB
C++
//
|
|
// parameter.h
|
|
// mc_electron
|
|
//
|
|
// Created by Christian Reiling on 20.09.18.
|
|
// Copyright © 2018 Christian Reiling. All rights reserved.
|
|
//
|
|
|
|
#ifndef parameter_h
|
|
#define parameter_h
|
|
|
|
#include <iostream>
|
|
#include <fstream>
|
|
|
|
|
|
class Parameter
|
|
{
|
|
public:
|
|
virtual ~Parameter(){};
|
|
|
|
Parameter() {
|
|
// Simulation Specs
|
|
seed = (int)value("seed");
|
|
numTotalParticles = (long int)value("numTotalParticles");
|
|
dt_s = value("dt_s");
|
|
injectionMethod = (int)value("injectionMethod");
|
|
deltaKinEnergy_eV = value("deltaKinEnergy_eV");
|
|
MBKinEnergy_eV = value("MBKinEnergy_eV");
|
|
|
|
// Katrin Specs
|
|
wgtsMagField_T = value("wgtsMagField_T");
|
|
wgtsLength_m = value("wgtsLength_m");
|
|
wgtsRadius_m = value("wgtsRadius_m");
|
|
wgtsTritiumDensity_m3 = value("wgtsTritiumDensity_m3");
|
|
}
|
|
// Natural Constants
|
|
const double pi = 3.1415;
|
|
const double c_nat = 1.;
|
|
const double c_ms = 299792458;
|
|
const double me_eV = 0.511e6;
|
|
const double qe_e = 1;
|
|
const double re_m = 2.817940322719e-15;
|
|
|
|
|
|
private:
|
|
double value(std::string strin, char* ext = (char*)("cat")) {
|
|
char* str = strdup(strin.c_str());
|
|
double temp;
|
|
char dummy[256];
|
|
char fname[256],*pname;
|
|
FILE *fcat;
|
|
|
|
if (getenv("poub") == NULL)
|
|
{
|
|
std::cerr<<"Parameter::value: Environment variable poub not defined.\n";
|
|
exit(1);
|
|
}
|
|
strcpy(fname, getenv("poub"));
|
|
pname = getenv("pname");
|
|
if (pname == NULL)
|
|
{
|
|
std::cerr<<"Parameter::value: Environment variable pname not defined.\n";
|
|
exit(1);
|
|
}
|
|
if (!ext)
|
|
{
|
|
ext = (char*)("cat");
|
|
}
|
|
sprintf(fname,"%s/%s.%s",getenv("poub"),getenv("pname"), ext);
|
|
if (!(fcat = fopen(fname, "r")))
|
|
{
|
|
std::cerr<<"Parameter::value: Can not open file " <<fname<<".\n";
|
|
exit(1);
|
|
}
|
|
while (!feof(fcat))
|
|
{
|
|
// fscanf(fcat, "'%s%*[^']'%F%*[^']",dummy,&temp); 1
|
|
fscanf(fcat, "%s = %lf", dummy, &temp);
|
|
// if (strncmp(dummy, str,strlen(str)) == 0) {
|
|
if (strcmp(dummy, str) == 0)
|
|
{
|
|
fclose(fcat);
|
|
return(temp);
|
|
}
|
|
}
|
|
fclose(fcat);
|
|
|
|
std::cerr<<"Parameter::value: Variable "<<str<<" not found.\n";
|
|
exit(1);
|
|
return 0;
|
|
}
|
|
|
|
protected:
|
|
//Simulation Specs
|
|
int seed;
|
|
long int numTotalParticles;
|
|
double dt_s;
|
|
int injectionMethod;
|
|
double deltaKinEnergy_eV;
|
|
double MBKinEnergy_eV;
|
|
|
|
|
|
//KATRIN Specs
|
|
double wgtsMagField_T;
|
|
double wgtsLength_m;
|
|
double wgtsRadius_m;
|
|
double wgtsTritiumDensity_m3;
|
|
|
|
// Help Functions
|
|
double v_ms(double Ekin_eV) {
|
|
double gamma = 1. + Ekin_eV/me_eV;
|
|
double beta = sqrt(1 - pow(gamma,-2));
|
|
return(beta * c_ms);
|
|
}
|
|
double Ekin_eV(double speedAbs_ms) {
|
|
double beta = speedAbs_ms/c_ms;
|
|
double gamma = pow(1 - pow(beta,2),-0.5);
|
|
return ( (gamma-1) * me_eV * pow(c_nat,2) );
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|