Changes in general code and added class energyhisto for

This commit is contained in:
Christian
2018-09-20 18:43:32 +02:00
parent 7f53fb2bef
commit b3b914f0b4
12 changed files with 473 additions and 245 deletions
+39 -32
View File
@@ -1,8 +1,9 @@
//
// parameter.h
//
// mc_electron
//
// Created by Christian Reiling on 13.09.18.
// Created by Christian Reiling on 20.09.18.
// Copyright © 2018 Christian Reiling. All rights reserved.
//
#ifndef parameter_h
@@ -11,23 +12,24 @@
#include <iostream>
#include <fstream>
using namespace std;
using namespace blitz;
class Parameter
{
public:
virtual ~Parameter(){};
Parameter()
{
Parameter() {
seed = (int)value("seed");
numTotalParticles = (long int)value("numTotalParticles");
dt = value("dt");
numTotalParticles = (long int)value("numTotalParticles");
dt = value("dt");
injectionMethod = (int)value("injectionMethod");
deltaKinEnergy = value("deltaKinEnergy");
MBKinEnergy = value("MBKinEnergy");
numberZBins = (int)value ("numberZBins");
minEBin = value ("minEBin");
maxEBin = value ("maxEBin");
numberEBins = (int)value ("numberEBins");
wgtsMagField = value("wgtsMagField");
wgtsLength = value("wgtsLength");
@@ -40,66 +42,70 @@ public:
constqe = value("constqe");
}
double value(char *str, char* ext = "cat") // Reads Parameter from config file
{
double value(std::string strin, char* ext = (char*)("cat")) {
char* str = strdup(strin.c_str());
double temp;
char dummy[256];
char fname[256],*pname;
char dummy[256];
char fname[256],*pname;
FILE *fcat;
if (getenv("poub") == NULL)
{
fprintf(stderr,"Environment variable %s not defined.\n","poub");
std::cerr<<"Parameter::value: Environment variable poub not defined.\n";
exit(1);
}
strcpy(fname, getenv("poub"));
strcpy(fname, getenv("poub"));
pname = getenv("pname");
if (pname == NULL)
{
fprintf(stderr,"Environment variable %s not defined.\n","pname");
std::cerr<<"Parameter::value: Environment variable pname not defined.\n";
exit(1);
}
if (!ext)
{
ext = "cat";
ext = (char*)("cat");
}
sprintf(fname,"%s/%s.%s",getenv("poub"),getenv("pname"), ext);
if (!(fcat = fopen(fname, "r")))
{
fprintf(stderr,"value: cannot open file %s\n",fname);
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))
{
}
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);
return(temp);
}
}
fclose(fcat);
fprintf(stderr,"variable %s not found\n",str);
exit(1);
return 0;
std::cerr<<"Parameter::value: Variable "<<str<<" not found.\n";
exit(1);
return 0;
}
protected:
string configFilePath;
std::string configFilePath;
//Simulation specs
int seed;
long int numTotalParticles;
double dt;
double dt;
int injectionMethod;
double deltaKinEnergy;
double MBKinEnergy;
int numberZBins;
double minEBin;
double maxEBin;
int numberEBins;
//KATRIN Specs
double wgtsMagField;
double wgtsMagField;
double wgtsLength;
double wgtsDiameter;
@@ -111,4 +117,5 @@ protected:
};
#endif