125 lines
3.5 KiB
C++
125 lines
3.5 KiB
C++
//
|
|
// tests.cpp
|
|
// mc_electron
|
|
//
|
|
// Created by Christian Reiling on 17.10.18.
|
|
// Copyright © 2018 Christian Reiling. All rights reserved.
|
|
//
|
|
|
|
#include "tests.h"
|
|
void runTests() {
|
|
string outputFilePath = "/Users/ChristianReiling/Documents/Masterarbeit/CodeTesting/Data/";
|
|
TestSimulation TEST;
|
|
TEST.injection (100000, outputFilePath + "injection.dat");
|
|
TEST.decaySpectrum(100000, outputFilePath + "decaySpectrum.dat");
|
|
TEST.rejectionBetaDecay(100000, outputFilePath + "rejectionBetaDecay.dat");
|
|
TEST.maxwellBoltzmann(100000, outputFilePath + "maxwellBoltzmann.dat");
|
|
|
|
TEST.SigmaTot_m2(10000, outputFilePath + "sigmaTot_m2.dat", -3, 9);
|
|
TEST.MFP_m(10000, outputFilePath + "MFP_m.dat", -3, 9);
|
|
}
|
|
|
|
void TestSimulation::injection (int numParticles, string outputFilePath) {
|
|
ofstream outFile;
|
|
outFile.open (outputFilePath.c_str());
|
|
for (int i = 0;i<numParticles;i++) {
|
|
outFile << inject() <<endl;
|
|
}
|
|
outFile.close();
|
|
|
|
}
|
|
|
|
void TestSimulation::decaySpectrum (int numPoints,string outputFilePath) {
|
|
ofstream outFile;
|
|
outFile.open (outputFilePath.c_str());
|
|
double x,y;
|
|
for (int i = 0;i<numPoints;i++) {
|
|
x = i * Etridecay_eV/(numPoints-1);
|
|
y = EnergyDistributionBetaDecay(x);
|
|
outFile << x <<";"<<y <<endl;
|
|
}
|
|
outFile.close();
|
|
}
|
|
|
|
void TestSimulation::rejectionBetaDecay(int numDecays, string outputFilePath) {
|
|
ofstream outFile;
|
|
outFile.open (outputFilePath.c_str());
|
|
for (int i = 0;i<numDecays;i++) {
|
|
outFile << getBetaDecayEnergyRejection_eV() <<endl;
|
|
}
|
|
outFile.close();
|
|
}
|
|
|
|
|
|
void TestSimulation::maxwellBoltzmann(int numDecays, string outputFilePath) {
|
|
ofstream outFile;
|
|
outFile.open (outputFilePath.c_str());
|
|
for (int i = 0;i<numDecays;i++) {
|
|
//outFile << getEnergyBoltzmann_eV() <<endl;
|
|
}
|
|
outFile.close();
|
|
}
|
|
|
|
void TestSimulation::SigmaTot_m2(int numPointsPerPower, string outputFilePath, int EminPower, int EmaxPower) {
|
|
if (EminPower >= EmaxPower) {
|
|
cerr<<"TestSimulation::getMFP_m: Power of lower energy bound \">=\" upper energy bound."<<endl;
|
|
exit(1);
|
|
}
|
|
ofstream outFile;
|
|
outFile.open (outputFilePath.c_str());
|
|
|
|
Particle P1 = Particle(me_eV, 1, zeroVec(), electron);
|
|
Particle P2 = Particle(mT2_eV, ZT2, zeroVec(), tritium2);
|
|
|
|
Interaction Inter = Interaction(&P1, &P2);
|
|
|
|
|
|
double distance = 1./double(numPointsPerPower);
|
|
int numPoints = (EmaxPower - EminPower) * numPointsPerPower;
|
|
double power;
|
|
double energy_eV, sigma_m2;
|
|
blitz::TinyVector<double,3> speed;
|
|
for (int i=0;i<=numPoints;i++) {
|
|
power = EminPower + i*distance;
|
|
energy_eV = pow(10,power);
|
|
speed = 0,0, calcV_msFromEkin_eV(energy_eV, me_eV);
|
|
P2.setSpeed_ms(speed);
|
|
sigma_m2 = Inter.getSigmaTot_m2();
|
|
outFile<<energy_eV<<";"<<sigma_m2<<endl;
|
|
}
|
|
outFile.close();
|
|
|
|
}
|
|
|
|
void TestSimulation::MFP_m(int numPointsPerPower, string outputFilePath, int EminPower, int EmaxPower) {
|
|
if (EminPower >= EmaxPower) {
|
|
cerr<<"TestSimulation::getMFP_m: Power of lower energy bound \">=\" upper energy bound."<<endl;
|
|
exit(1);
|
|
}
|
|
ofstream outFile;
|
|
outFile.open (outputFilePath.c_str());
|
|
|
|
Particle P1 = Particle(me_eV, 1, zeroVec(), electron);
|
|
Particle P2 = Particle(mT2_eV, ZT2, zeroVec(), tritium2);
|
|
|
|
|
|
Interaction Inter = Interaction(&P1, &P2);
|
|
|
|
|
|
double distance = 1./double(numPointsPerPower);
|
|
int numPoints = (EmaxPower - EminPower) * numPointsPerPower;
|
|
double power;
|
|
double energy_eV, MFP_m;
|
|
blitz::TinyVector<double,3> speed;
|
|
for (int i=0;i<=numPoints;i++) {
|
|
power = EminPower + i*distance;
|
|
energy_eV = pow(10,power);
|
|
speed = 0,0, calcV_msFromEkin_eV(energy_eV, me_eV);
|
|
P2.setSpeed_ms(speed);
|
|
MFP_m = getMFP_m(Inter);
|
|
outFile<<energy_eV<<";"<<MFP_m<<endl;
|
|
}
|
|
outFile.close();
|
|
}
|
|
|