134 lines
3.0 KiB
C++
134 lines
3.0 KiB
C++
//
|
|
// asci_logger.cpp
|
|
// mc_electron
|
|
//
|
|
// Created by Christian Reiling on 06.05.19.
|
|
// Copyright © 2019 Christian Reiling. All rights reserved.
|
|
//
|
|
|
|
#include "asci_logger.hpp"
|
|
|
|
#include <sstream>
|
|
|
|
#include "katrin_geo.h"
|
|
|
|
#include "error_types.h"
|
|
|
|
using namespace std;
|
|
|
|
|
|
// Redundant Code with h5, but ASCI Logger is kept in code as relict.
|
|
const int ASCI_Logger::numberZBins = load_parameter("LOG_BARS");
|
|
|
|
ASCI_Logger::ASCI_Logger() {
|
|
if (numberZBins == 0) {
|
|
logging = false;
|
|
} else if (numberZBins == -1 || numberZBins > 0) {
|
|
logging = true;
|
|
set_zLogValues();
|
|
print_logInfo();
|
|
|
|
set_outdirName();
|
|
create_outdir();
|
|
set_outStream();
|
|
} else {
|
|
stringstream ss;
|
|
ss<<"H5_Logger::Parameter numberZBins invalid value.\nnumberZBins:\t"<<numberZBins<<"\n";
|
|
throw MyException (ss.str());
|
|
}
|
|
|
|
}
|
|
|
|
void ASCI_Logger::set_zLogValues() {
|
|
zLogValues.clear();
|
|
if (logging) {
|
|
double start_m = z_RW_m;
|
|
double length_m = z_WGTS_end_m - start_m;
|
|
double stepLength_m = length_m/(numberZBins-1);
|
|
double z_m;
|
|
for (int i = 0;i<numberZBins;i++) {
|
|
z_m = z_RW_m + stepLength_m*i;
|
|
zLogValues.push_back(z_m);
|
|
}
|
|
}
|
|
}
|
|
|
|
void ASCI_Logger::print_logInfo() {
|
|
stringstream ss;
|
|
ss<<"Logger\t ";
|
|
if (!logging) {
|
|
ss<<"Logging disabled.\n";
|
|
} else if (numberZBins == -1) {
|
|
ss<<"Logging after every Interaction to one file.\n";
|
|
} else if (numberZBins == 1) {
|
|
ss<<"Only Logging Rearwall Output.\n";
|
|
} else {
|
|
ss<<"Logging at "<<numberZBins<<" z values.\n";
|
|
}
|
|
cout<<ss.str();
|
|
}
|
|
|
|
|
|
void ASCI_Logger::log_Particle(Particle *logPart, blitz::TinyVector<double,3> oldLoc_m) {
|
|
if (!logging) {
|
|
return;
|
|
}
|
|
if (logPart->get_species() != electron) {
|
|
return;
|
|
}
|
|
|
|
// Assumption: no change of sign in v_z
|
|
if (numberZBins == -1) {
|
|
outStream[0]<<*logPart<<endl;
|
|
} else {
|
|
double zold = oldLoc_m[2];
|
|
double znew = logPart->get_x_m()[2];
|
|
double zmin = min(zold,znew);
|
|
double zmax = max(zold,znew);
|
|
|
|
for (int i=0;i<numberZBins;i++) {
|
|
if (zLogValues[i]>=zmin && zLogValues[i]<=zmax) {
|
|
outStream[i]<<*logPart<<endl; // Location wrong, because it s the new Location.
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void ASCI_Logger::set_outdirName() {
|
|
string parname = get_parameter_filenamepath();
|
|
stringstream dirname;
|
|
int i = 1;
|
|
do {
|
|
dirname.str(std::string());
|
|
dirname << parname << "_" << get_time_string() << "_" << i++;
|
|
} while ( is_dir(dirname.str()) );
|
|
outdirName = dirname.str();
|
|
return;
|
|
}
|
|
|
|
void ASCI_Logger::create_outdir() {
|
|
if (mkdir(outdirName.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) {
|
|
stringstream ss;
|
|
ss<<"ASCI_Logger::create_outdir: Could not create output directiory.\n outdirName = "<<outdirName<<endl;
|
|
throw MyException(ss.str());
|
|
}
|
|
return;
|
|
}
|
|
|
|
void ASCI_Logger::set_outStream() {
|
|
if (numberZBins == -1) {
|
|
outStream = new ofstream [1];
|
|
stringstream ss;
|
|
ss <<outdirName << "/all" << ".dat";
|
|
outStream[0].open(ss.str().c_str());
|
|
} else {
|
|
outStream = new ofstream [numberZBins];
|
|
for (int i = 0; i < numberZBins; i++)
|
|
{
|
|
stringstream ss;
|
|
ss << outdirName << "/z=" << zLogValues[i] << ".dat";
|
|
outStream[i].open(ss.str().c_str());
|
|
}
|
|
}
|
|
}
|