Commit 2774f95e authored by LEFEBVREJP email's avatar LEFEBVREJP email
Browse files

Cleaned up EmitDB implementation. Still need test coverage.

parent 877efeee
Pipeline #152634 passed with stages
in 17 minutes and 50 seconds
......@@ -9,9 +9,9 @@ namespace radix
{
EmitDb::EmitDb()
{
load_mpdkxgam(EmitDb::XGAMDATA4);
// load_mpdkxgam(EmitDb::XGAMDATA4);
// load_mpdkxgam(EmitDb::XGAMDATA3);
load_ensdfbeta(EmitDb::BETADATA);
// load_ensdfbeta(EmitDb::BETADATA);
}
EmitDb::EmitDb(const EmitDb& orig)
......@@ -20,11 +20,11 @@ EmitDb::EmitDb(const EmitDb& orig)
mIsotopeTitle = orig.mIsotopeTitle;
}
void EmitDb::load_mpdkxgam(std::string file)
void XGamDb::load(const std::string& file, EmitDb& database)
{
std::string revStr = radix::split_string(".", file)[1];
int revNum = std::atoi(revStr.substr(revStr.size() - 1, 1).c_str());
int indexThreshold, indexIterator;
int indexThreshold = 70, indexIterator = 20;
int linecount = 0;
if (revNum == 3)
{
......@@ -42,6 +42,7 @@ void EmitDb::load_mpdkxgam(std::string file)
int zaid = -1;
int totalLines = 0;
float totalEnergy = 0.f;
auto& isotopes = database.isotopes();
while (std::getline(xgamFile, line))
{
linecount += 1;
......@@ -51,29 +52,24 @@ void EmitDb::load_mpdkxgam(std::string file)
if (zaid != -1 && energies.size() > 0)
{
EmitDBEntry emitEntry;
emitEntry.z = int(zaid / 10000);
emitEntry.a = int((zaid % 10000) / 10);
emitEntry.m = int(zaid % 10);
emitEntry.nLines = totalLines;
emitEntry.nBetas = 0;
emitEntry.xgamEnergy = totalEnergy;
emitEntry.betaEnergy = 0.0f;
emitEntry.photonEnergies = energies;
emitEntry.betaEnergies = {};
emitEntry.photonIntensities = intensities;
emitEntry.betaIntensities = {};
mIsotope.insert(std::make_pair(zaid, emitEntry));
emitEntry.z = int(zaid / 10000);
emitEntry.a = int((zaid % 10000) / 10);
emitEntry.m = int(zaid % 10);
emitEntry.energy = totalEnergy;
emitEntry.energies = energies;
emitEntry.intensities = intensities;
isotopes.insert(std::make_pair(zaid, emitEntry));
energies.clear();
intensities.clear();
}
zaid = thisZaid;
totalLines = std::atoi(line.substr(9, 12).c_str());
zaid = thisZaid;
// totalLines = std::atoi(line.substr(9, 12).c_str());
totalEnergy = std::atof(line.substr(60, 10).c_str());
}
else
{
int index;
int jumpLength;
int index = 3;
int jumpLength = 10;
if (revNum == 3)
{
index = 10;
......@@ -97,23 +93,18 @@ void EmitDb::load_mpdkxgam(std::string file)
prev = line;
}
EmitDBEntry emitEntry;
emitEntry.z = int(zaid / 10000);
emitEntry.a = int((zaid % 10000) / 10);
emitEntry.m = int(zaid % 10);
emitEntry.nLines = totalLines;
emitEntry.nBetas = 0;
emitEntry.xgamEnergy = totalEnergy;
emitEntry.betaEnergy = 0.0f;
emitEntry.photonEnergies = energies;
emitEntry.betaEnergies = {};
emitEntry.photonIntensities = intensities;
emitEntry.betaIntensities = {};
mIsotope.insert(std::make_pair(zaid, emitEntry));
emitEntry.z = int(zaid / 10000);
emitEntry.a = int((zaid % 10000) / 10);
emitEntry.m = int(zaid % 10);
emitEntry.energy = totalEnergy;
emitEntry.energies = energies;
emitEntry.intensities = intensities;
isotopes.insert(std::make_pair(zaid, emitEntry));
energies.clear();
intensities.clear();
}
void EmitDb::load_ensdfbeta(std::string file)
void EnsdfBetaDb::load(const std::string& file, EmitDb& database)
{
std::ifstream betaFile(file);
std::string line, prev;
......@@ -121,6 +112,7 @@ void EmitDb::load_ensdfbeta(std::string file)
int zaid = -1;
int linecount = 0;
std::vector<float> energies, intensities;
auto& isotopes = database.isotopes();
while (std::getline(betaFile, line))
{
linecount += 1;
......@@ -128,15 +120,12 @@ void EmitDb::load_ensdfbeta(std::string file)
{
if (line.size() > 10)
{
if (zaid == std::atoi(line.substr(2, 6).c_str()))
int zaidl = std::atoi(line.substr(2, 6).c_str());
if (zaid != zaidl)
{
zaidCount++;
}
else
{
zaid = std::atoi(line.substr(2, 6).c_str());
zaidCount++;
zaid = zaidl;
}
zaidCount++;
float intensity = std::atof(line.substr(10, 8).c_str());
float energy = std::atof(line.substr(19, 9).c_str());
energies.push_back(energy);
......@@ -152,25 +141,19 @@ void EmitDb::load_ensdfbeta(std::string file)
totalEnergy += (intensities[i] * energies[i]);
}
EmitDBEntry emitEntry;
emitEntry.z = int(zaid / 10000);
emitEntry.a = int((zaid % 10000) / 10);
emitEntry.m = int(zaid % 10);
emitEntry.nLines = 0;
emitEntry.nBetas = zaidCount;
emitEntry.xgamEnergy = 0.0f;
emitEntry.betaEnergy = totalEnergy;
emitEntry.photonEnergies = {};
emitEntry.betaEnergies = energies;
emitEntry.photonIntensities = {};
emitEntry.betaIntensities = intensities;
emitEntry.z = int(zaid / 10000);
emitEntry.a = int((zaid % 10000) / 10);
emitEntry.m = int(zaid % 10);
emitEntry.energy = totalEnergy;
emitEntry.energies = energies;
emitEntry.intensities = intensities;
const auto& isOutside =
mIsotope.insert(std::make_pair(zaid, emitEntry));
isotopes.insert(std::make_pair(zaid, emitEntry));
if (!isOutside.second)
{
isOutside.first->second.nBetas = zaidCount;
isOutside.first->second.betaEnergy = totalEnergy;
isOutside.first->second.betaEnergies = energies;
isOutside.first->second.betaIntensities = intensities;
isOutside.first->second.energy = totalEnergy;
isOutside.first->second.energies = energies;
isOutside.first->second.intensities = intensities;
}
zaidCount = 0;
energies.clear();
......@@ -188,26 +171,19 @@ void EmitDb::load_ensdfbeta(std::string file)
totalEnergy += (intensities[i] * energies[i]);
}
EmitDBEntry emitEntry;
emitEntry.z = int(zaid / 10000);
emitEntry.a = int((zaid % 10000) / 10);
emitEntry.m = int(zaid % 10);
emitEntry.nLines = 0;
emitEntry.nBetas = zaidCount;
emitEntry.xgamEnergy = 0.0f;
emitEntry.betaEnergy = totalEnergy;
emitEntry.photonEnergies = {};
emitEntry.betaEnergies = energies;
emitEntry.photonIntensities = {};
emitEntry.betaIntensities = intensities;
const auto& isOutside = mIsotope.insert(std::make_pair(zaid, emitEntry));
emitEntry.z = int(zaid / 10000);
emitEntry.a = int((zaid % 10000) / 10);
emitEntry.m = int(zaid % 10);
emitEntry.energy = totalEnergy;
emitEntry.energies = energies;
emitEntry.intensities = intensities;
const auto& isOutside = isotopes.insert(std::make_pair(zaid, emitEntry));
if (!isOutside.second)
{
isOutside.first->second.nBetas = zaidCount;
isOutside.first->second.betaEnergy = totalEnergy;
isOutside.first->second.betaEnergies = energies;
isOutside.first->second.betaIntensities = intensities;
isOutside.first->second.energy = totalEnergy;
isOutside.first->second.energies = energies;
isOutside.first->second.intensities = intensities;
}
zaidCount = 0;
energies.clear();
intensities.clear();
}
......@@ -223,40 +199,16 @@ const std::unordered_map<int, EmitDBEntry>& EmitDb::isotopes() const
return mIsotope;
}
std::unordered_map<int, EmitDBEntry>& EmitDb::isotopes() { return mIsotope; }
const EmitDBEntry& EmitDb::emitter(const int zaid) const
const EmitDBEntry& EmitDb::emitter(int zaid) const
{
const auto& it = mIsotope.find(zaid);
return it->second;
}
const std::vector<std::vector<float>> EmitDb::photons(const int zaid) const
{
const auto& it = mIsotope.find(zaid);
std::vector<float> energies = it->second.photonEnergies;
std::vector<float> intensities = it->second.photonIntensities;
std::vector<std::vector<float>> paired = {energies, intensities};
return paired;
}
std::vector<std::vector<float>> EmitDb::photons(const int zaid)
{
const auto& it = mIsotope.find(zaid);
std::vector<float> energies = it->second.photonEnergies;
std::vector<float> intensities = it->second.photonIntensities;
std::vector<std::vector<float>> paired = {energies, intensities};
return paired;
}
const std::vector<std::vector<float>> EmitDb::betas(const int zaid) const
{
const auto& it = mIsotope.find(zaid);
std::vector<float> energies = it->second.betaEnergies;
std::vector<float> intensities = it->second.betaIntensities;
std::vector<std::vector<float>> paired = {energies, intensities};
return paired;
}
std::vector<std::vector<float>> EmitDb::betas(const int zaid)
std::vector<std::vector<float>> EmitDb::energy_intensities(const int zaid) const
{
const auto& it = mIsotope.find(zaid);
std::vector<float> energies = it->second.betaEnergies;
std::vector<float> intensities = it->second.betaIntensities;
const std::vector<float>& energies = it->second.energies;
const std::vector<float>& intensities = it->second.intensities;
std::vector<std::vector<float>> paired = {energies, intensities};
return paired;
}
......
#ifndef RADIX_RADIXIO_EMITDB_HH_
#define RADIX_RADIXIO_EMITDB_HH_
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#include "radixcore/visibility.hh"
......@@ -24,38 +22,22 @@ struct RADIX_PUBLIC EmitDBEntry
* metastable state
**/
int m;
/**
* The variable nLines, total number of photon lines in dataset
**/
int nLines;
/**
* The variable nBetas, total number of beta lines in dataset
**/
int nBetas;
/**
* The variable xgamEnergy, total energy of photons emitted by isotope
**/
float xgamEnergy;
/**
* The variable betaEnergy, total energy of betas emitted by isotope
**/
float betaEnergy;
/**
* The energies of each photon in dataset
**/
std::vector<float> photonEnergies;
/**
* The intensities of each photon in dataset
* The variable energy, total energy of emission (xgam or beta) emitted by
*isotope
**/
std::vector<float> photonIntensities;
float energy;
/**
* The maximum endpoint energies of each beta transition in dataset
* The energies of each xgam or beta in dataset
**/
std::vector<float> betaEnergies;
std::vector<float> energies;
/**
* The intensities of each beta in dataset
* The intensities of each energy in dataset
**/
std::vector<float> betaIntensities;
std::vector<float> intensities;
int zaid() { return z * 10000 + a * 10 + m; }
bool operator==(const EmitDBEntry& rhs) const
{
......@@ -66,9 +48,9 @@ struct RADIX_PUBLIC EmitDBEntry
class RADIX_PUBLIC EmitDb
{
const std::string XGAMDATA3 = "radixio/examples/origen.rev03.mpdkxgam.data";
const std::string XGAMDATA4 = "radixio/examples/origen.rev04.mpdkxgam.data";
const std::string BETADATA = "radixio/examples/origen.rev00.ensdf95beta.data";
// const std::string XGAMDATA3 = "origen.rev03.mpdkxgam.data";
// const std::string XGAMDATA4 = "origen.rev04.mpdkxgam.data";
// const std::string BETADATA = "origen.rev00.ensdf95beta.data";
public:
std::unordered_map<int, EmitDBEntry> mIsotope;
......@@ -77,35 +59,29 @@ class RADIX_PUBLIC EmitDb
public:
EmitDb();
EmitDb(const EmitDb& orig);
void load_mpdkxgam(std::string file);
void load_ensdfbeta(std::string file);
void operator=(const EmitDb& orig);
const std::string& isotope_title() const;
void set_isotope_title(const std::string& title);
const std::unordered_map<int, EmitDBEntry>& isotopes() const;
std::unordered_map<int, EmitDBEntry>& isotopes();
const EmitDBEntry& emitter(const int zaid) const;
const std::vector<std::vector<float>> photons(const int zaid) const;
std::vector<std::vector<float>> photons(const int zaid);
const std::vector<std::vector<float>> betas(const int zaid) const;
std::vector<std::vector<float>> betas(const int zaid);
void operator=(const EmitDb& orig);
const EmitDBEntry& emitter(int zaid) const;
std::vector<std::vector<float>> energy_intensities(int zaid) const;
}; // class EmitDb
} // namespace radix
namespace std
class RADIX_PUBLIC XGamDb : public EmitDb
{
template <>
struct hash<radix::EmitDBEntry>
public:
static void load(const std::string& file, EmitDb& database);
};
class RADIX_PUBLIC EnsdfBetaDb : public EmitDb
{
std::size_t operator()(const radix::EmitDBEntry& rhs) const
{
using std::hash;
using std::size_t;
using std::string;
return rhs.z + rhs.a + rhs.m + rhs.nLines + rhs.nBetas;
}
}; // struct hash<radix::EmitDBEntry>
} // namespace std
public:
static void load(const std::string& file, EmitDb& database);
};
} // namespace radix
#endif /** RADIX_RADIXIO_EMITDB_HH_ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment