104 lines
2.4 KiB
C++
104 lines
2.4 KiB
C++
//
|
|
// parameter.cpp
|
|
// mc_electron
|
|
//
|
|
// Created by Christian Reiling on 26.02.19.
|
|
// Copyright © 2019 Christian Reiling. All rights reserved.
|
|
//
|
|
|
|
|
|
#include "parameter.hpp"
|
|
|
|
#include "myexeption.h"
|
|
|
|
#include <iostream>
|
|
#include <sstream>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
using namespace std;
|
|
|
|
|
|
Parameter::Parameter() {
|
|
// Simulation Specs
|
|
|
|
seed = (int)getValue("seed");
|
|
numberTotalDecays = (int)getValue("numberTotalDecays");
|
|
dt_s = getValue("dt_s");
|
|
injectionMethod = (int)getValue("injectionMethod");
|
|
deltaKinEnergy_eV = getValue("deltaKinEnergy_eV");
|
|
MBTemp_K = getValue("MBTemp_K");
|
|
elaOn = (int)getValue("elaOn");
|
|
ionOn = (int)getValue("ionOn");
|
|
propagationMethod = (int)getValue("propagationMethod");
|
|
|
|
// Cutoff
|
|
cutoffMode = (int)getValue("cutoffMode");
|
|
cutoffEnergySet_eV = getValue("cutoffEnergySet_eV");
|
|
cutoffFactor = getValue("cutoffFactor");
|
|
maxNumberInteractionsPerElectron = getValue("maxNumberInteractionsPerElectron");
|
|
|
|
// Katrin Specs
|
|
wgtsMagField_T = getValue("wgtsMagField_T");
|
|
wgtsLength_m = getValue("wgtsLength_m");
|
|
wgtsRadius_m = getValue("wgtsRadius_m");
|
|
wgtsT2Density_m3 = getValue("wgtsT2Density_m3");
|
|
wgtsTemp_K = getValue("wgtsTemp_K");
|
|
wgtsT2FlowSpeed_ms = getValue("wgtsT2FlowSpeed_ms");
|
|
|
|
// Output
|
|
numberZBins = getValue ("numberZBins");
|
|
|
|
}
|
|
|
|
|
|
double Parameter::getValue(string varName) {
|
|
char* ext = (char*)("cat");
|
|
char* str = strdup(varName.c_str());
|
|
double temp;
|
|
char dummy[256];
|
|
char fname[256],*parfile;
|
|
FILE *fcat;
|
|
|
|
if (getenv("parpath") == NULL)
|
|
{
|
|
throw MyException("Parameter::value: Environment variable parpath not defined.");
|
|
}
|
|
strcpy(fname, getenv("parpath"));
|
|
parfile = getenv("parfile");
|
|
if (parfile == NULL)
|
|
{
|
|
throw MyException("Parameter::value: Environment variable parfile not defined.");
|
|
}
|
|
if (!ext)
|
|
{
|
|
ext = (char*)("cat");
|
|
}
|
|
sprintf(fname,"%s/%s.%s",getenv("parpath"),getenv("parfile"), ext);
|
|
if (!(fcat = fopen(fname, "r")))
|
|
{
|
|
stringstream ss;
|
|
ss<<"Parameter::value: Can not open file " <<fname<<".";
|
|
throw MyException(ss.str());
|
|
}
|
|
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);
|
|
|
|
stringstream ss;
|
|
ss<<"Parameter::value: Variable "<<str<<" not found.";
|
|
throw MyException(ss.str());
|
|
return 0;
|
|
}
|
|
|