Advanced Computing Platform for Theoretical Physics

Commit c14358a5 authored by Yu-Chen Ding's avatar Yu-Chen Ding
Browse files

parse CR info

parent 838a8da6
......@@ -45,9 +45,11 @@ class CRData {
std::string y_quantity;
std::string y_unit;
bool use_rigidity = false;
bool skewed_error = false;
bool has_bin = true;
bool use_rigidity = false;
bool skewed_error = false;
bool has_bin = true;
bool is_ratio = false;
bool known_species = false;
// prefered features
double scale = 0;
......@@ -62,6 +64,16 @@ class CRData {
std::vector<TimeWindow> time_windows;
// TODO: particle info for automatic extraction
// implemented in <crinfo.cc>
struct particle_number {
static constexpr int any = 999;
std::string str(void) const;
int Z, A = any;
};
std::vector<particle_number> num_list, den_list;
bool has(int Z, int A) const;
bool num_has(int Z, int A) const;
bool den_has(int Z, int A) const;
public:
double x_min(void) const;
......
......@@ -6,6 +6,7 @@
#include <vector>
#include "crutil.hh"
#include "crinfo.hh"
#include <crdb.h>
#define ADS_BASE "https://ui.adsabs.harvard.edu/abs/"
......@@ -29,6 +30,12 @@ std::string parse_link(const std::string& hint) {
}
}
void after_burn(CRData& data) {
data.use_rigidity = _CRUTIL::is_substr_i(data.x_quantity, "r");
get_info(data);
// TODO: time windows
}
}; // namespace _CRDATASET
CRDataset::CRDataset(const std::string& filename) { parse_file(filename); }
......@@ -234,15 +241,13 @@ std::shared_ptr<CRData> _CRDATASET::parse_data_crd(std::istream& is,
}
}
// start with R|r
// data.use_rigidity = !((data.x_quantity[0] - 'R') % 32);
data.use_rigidity = _CRUTIL::is_substr_i(data.x_quantity, "r");
// data.label =
// _CRDATASET::format("%s(%s-%s)", data.experiment.c_str(),
// data.time_begin.c_str(), data.time_end.c_str());
data.label = data.experiment;
_CRDATASET::after_burn(data);
return pdata;
}
......@@ -305,7 +310,7 @@ _CRDATASET::parse_data_usine(std::istream& is, _CRUTIL::StreamParser& fp) {
windows_str += datimes.substr(i + 35, 1);
}
// std::erase(windows_str, '/'); // -std=c++2a
std::remove(windows_str.begin(), windows_str.end(), '/');
(void)std::remove(windows_str.begin(), windows_str.end(), '/');
data.time = windows_str;
// TODO: parse windows
......@@ -359,11 +364,9 @@ _CRDATASET::parse_data_usine(std::istream& is, _CRUTIL::StreamParser& fp) {
dp.ey2 = tb[5];
}
// start with R|r
data.use_rigidity = _CRUTIL::is_substr_i(data.x_quantity, "r");
// TODO: more from x_quantity
// TODO: x_uint, y_unit
_CRDATASET::after_burn(data);
return pdata;
}
......
#include "crinfo.hh"
#include "crdb.h"
std::string CRData::particle_number::str(void) const {
return "(" + (Z == any ? "any" : std::to_string(Z)) + //
"," + (A == any ? "any" : std::to_string(A)) + ")";
}
constexpr auto& any = CRData::particle_number::any;
bool particle_in_list(int Z, int A, //
const std::vector<CRData::particle_number>& lst) {
for (const auto& n : lst) {
if (n.Z == any || n.Z == Z) {
if (n.A == any || n.A == A) {
return true;
}
}
}
return false;
}
bool CRData::num_has(int Z, int A) const {
return particle_in_list(Z, A, num_list);
}
bool CRData::den_has(int Z, int A) const {
return particle_in_list(Z, A, den_list);
}
bool CRData::has(int Z, int A) const {
return num_has(Z, A) || is_ratio && den_has(Z, A);
}
void canonicalize_num_den(std::string& num, std::string& den) {
// "A/B" "" => "A" "B"
size_t pos_slash = num.find('/');
if (pos_slash != num.npos) {
den = num.substr(pos_slash + 1);
num = num.substr(0, pos_slash);
}
}
std::vector<std::string> cr_split(const std::string& s) {
// "A+B+e++C" => {"A", "B", "e+", "C"}
std::vector<std::string> res;
size_t bg = 0, ed = 0;
while (s.npos != (ed = s.find('+', bg))) {
if (bg + 1 == ed && s[bg] == 'e') { // "e+"
++ed;
if (ed == s.size()) {
ed = s.npos;
break;
}
}
if (bg != ed) {
res.push_back(s.substr(bg, ed - bg));
}
bg = ed + 1;
}
if (bg < s.size()) {
res.push_back(s.substr(bg));
}
return res;
}
static std::map<std::string, CRData::particle_number> cr_dict = {
{"All", {any, any}}, {"AllParticles", {any, any}}, //
{"e-", {-1, 0}}, {"electron", {-1, 0}}, //
{"e+", {1, 0}}, {"positron", {1, 0}}, //
{"P", {1, 1}}, {"Proton", {1, 1}}, //
{"H", {1, any}}, {"Hydrogen", {1, any}}, //
{"D", {1, 2}}, {"Deuterium", {1, 2}}, //
{"T", {1, 3}}, {"Tritium", {1, 3}}, //
{"1H", {1, 1}}, {"2H", {1, 2}},
{"3H", {1, 3}}, //
{"He", {2, any}}, {"Helium", {2, any}}, //
{"3He", {2, 3}}, {"4He", {2, 4}}, //
};
CRData::particle_number cr_ident(const std::string& name) {
auto it = cr_dict.find(name);
if (it != cr_dict.end()) {
return it->second;
}
return {0, 0};
// throw std::runtime_error("unrecognized CR name '" + name + "'");
}
bool get_info(CRData& data, const std::string& num, const std::string& den) {
std::string num_str = num.empty() ? data.y_quantity : num;
std::string den_str = den;
canonicalize_num_den(num_str, den_str);
data.is_ratio = !den_str.empty();
data.num_list.clear();
data.den_list.clear();
data.known_species = false;
for (const auto& name : cr_split(num_str)) {
data.num_list.push_back(cr_ident(name));
const auto& n = data.num_list.back();
if (0 == n.A && 0 == n.Z) {
data.num_list.clear();
return false;
}
}
if (data.is_ratio) {
for (const auto& name : cr_split(den_str)) {
data.den_list.push_back(cr_ident(name));
const auto& n = data.den_list.back();
if (0 == n.A && 0 == n.Z) {
data.num_list.clear();
data.den_list.clear();
return false;
}
}
}
data.known_species = true;
return true;
}
#include "crdb.h"
bool get_info(CRData& data, const std::string& num = "", const std::string& den = "");
......@@ -28,6 +28,20 @@ int main(int argc, char* argv[]) {
std::cout << "rig:\t" << d.use_rigidity << std::endl;
std::cout << "phi:\t" << d.phi << std::endl;
std::cout << "dist:\t" << d.solar_dist << std::endl;
if (d.known_species) {
std::cout << "num:";
for (const auto& n : d.num_list) {
std::cout << '\t' + n.str();
}
if (d.is_ratio) {
std::cout << std::endl << "den:";
for (const auto& n : d.den_list) {
std::cout << '\t' + n.str();
}
}
std::cout << std::endl;
}
std::cout << std::scientific;
std::cout << "#x\t\t#y\t\t#ey1\t\t#ey2\t\t#x_lower\t#x_upper" << std::endl;
for (const auto& dp : d) {
......
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