41#include "tkdb_table.h"
42#include "tklevel_scheme.h"
45#include "tkdatabase.h"
70tklevel_scheme::tklevel_scheme(
const tkstring &_nuc,
int _zz,
int _aa):fnucleus(_nuc), fA(_aa), fZ(_zz)
72 if(fA<0||fZ<0)
return;
95 vector<shared_ptr<tklevel>> res;
96 for(
const auto &lvl :
get_levels())
if(_selection(lvl)) res.push_back(lvl);
116 vector<shared_ptr<tkdecay>> res;
117 for(
const auto &dec :
get_decays())
if(_selection(dec)) res.push_back(dec);
146 glog <<
info <<
" Level scheme of " << fnucleus <<
do_endl;
147 glog <<
info <<
" Options : 'dataset', 'level', 'decay'" <<
do_endl;
150 glog <<
info <<
"Available datasets are : " <<
do_endl;
151 for(
auto &dts : fmap_of_dataset) glog <<
info << dts.second->get_name() <<
" (" << dts.first <<
")" <<
do_endl;
155 fmap_of_dataset[fdatasetid]->print(_data, _option);
158 int _current_data_set = fdatasetid;
159 for(
auto &dataset: fmap_of_dataset) {
160 glog <<
info <<
"dataset : " << dataset.second->get_name() <<
do_endl;
162 dataset.second->print(
"leveldecay");
175 if(fmap_of_dataset_name_id.count(_dataset_name)==0) {
176 glog <<
warning <<
"dataset '" << _dataset_name <<
"' do not exist for " << fnucleus <<
do_endl;
180 fdatasetid = fmap_of_dataset_name_id[_dataset_name];
190 if(fmap_of_dataset.count(_dataset_id)==0) {
191 glog <<
warning <<
"dataset with id '" << _dataset_id <<
"' do not exist for " << fnucleus <<
do_endl;
196 fdatasetid = _dataset_id;
197 fmap_of_dataset[fdatasetid]->load_dataset();
219 const char* sep =
"";
220 if(_name.
contains(
"+")) {sep =
"+";}
221 else if(_name.
contains(
"-")) {sep =
"-";}
224 if(array.size()!=2) {
225 glog <<
error <<
" <nuclear_level_scheme::get_level_energy()> invalid argument '" << _name <<
"'. Syntax: '[spin][parity][rank]'." <<
do_endl;
230 rank = array.at(1).atoi();
233 for(
const auto &lvlp :
get_levels([](
auto lvl) {
return (lvl->get_spin_parity()!=
nullptr);})) {
234 auto jpistr = lvlp->get_spin_parity()->get_jpi_str();
244 else if(jpistr.equal_to(
tkstring::form(
"%s%s",spin.data(),sep))) {
249 if(idx==rank)
return lvlp;
265 shared_ptr<tklevel> clostest_lev;
266 double best_ediff=1e6;
269 if(_offset != lev->get_offset_bandhead())
continue;
271 if(_offset.
is_empty() && !lev->get_offset_bandhead().is_empty())
continue;
272 if(_offset.
contains(
"dec") && lev->get_decays_down().size()==0)
continue;
273 double ediff = abs(lev->get_energy(tkunit_manager::units_keys::keV,
true)-_energy);
274 if(ediff<best_ediff) {
282void tklevel_scheme::init()
284 gdatabase->begin(
"DISTINCT dataset.dataset_id, dataset.dataset_name",
"level INNER JOIN dataset on level.dataset_id=dataset.dataset_id INNER JOIN isotope on level.isotope_id=isotope.isotope_id INNER JOIN element on isotope.element_id=element.element_id",
tkstring::form(
"element.charge=%d AND isotope.mass=%d",fZ,fA),
tkstring::form(
"read_dataset_%s",fnucleus.data()));
286 while(gdatabase->next(
tkstring::form(
"read_dataset_%s",fnucleus.data()))) {
287 tkdb_table& datasets = (*gdatabase)[
"DATASET"];
288 fmap_of_dataset_name_id[datasets[
"dataset_name"].get_value()] = datasets[
"dataset_id"].get_value().atoi();
289 fmap_of_dataset[datasets[
"dataset_id"].get_value().atoi()] = make_shared<tkdataset>(
tkdataset(fnucleus,fZ,fA,datasets[
"dataset_name"].get_value(),datasets[
"dataset_id"].get_value().atoi()));
291 tkstring default_dataset = fnucleus.data();
292 default_dataset +=
" : ADOPTED LEVELS, GAMMAS";
293 gdebug <<
"looking for dataset : " << default_dataset <<
do_endl;
294 bool found = (fmap_of_dataset_name_id.count(default_dataset)>0);
295 gdebug << (found?
"":
"not ") <<
"found " << (found?fmap_of_dataset_name_id[default_dataset.data()]:-1) <<
do_endl;
297 if(found)
select_dataset(fmap_of_dataset_name_id[default_dataset.data()]);
299 for(
const auto &dts : fmap_of_dataset) {
300 glog <<
warning <<
tkstring::form(
"%5s",fnucleus.data()) <<
" -- no 'ADOPTED LEVELS' dataset : '" << dts.second->get_name() <<
"' used instead." <<
do_endl;
305 if(fmap_of_dataset.empty()) {
308 fmap_of_dataset_name_id[datasetname] = fdatasetid;
309 fmap_of_dataset[fdatasetid] = make_shared<tkdataset>(
tkdataset(fnucleus,fZ,fA,datasetname,fdatasetid));
315void tkdataset::check_yrast(shared_ptr<tklevel> _lvl)
318 if(_lvl->get_spin_parity()->get_spin().is_known()) {
319 int TwoJ = (int)(_lvl->get_spin_parity()->get_spin().get_value()*2+0.5);
320 if(!fyrastmap_exact.count(TwoJ)) {
321 fyrastmap_exact[TwoJ] = _lvl;
322 _lvl->fisYrast_exact =
true;
325 if(!fyrastmap_uncertain.count(TwoJ)) {
326 fyrastmap_uncertain[TwoJ] = _lvl;
327 _lvl->fisYrast_uncertain =
true;
331 else if(!_lvl->get_spin_parity_str().is_empty() && !_lvl->get_spin_parity_str().contains(
",")) {
335 else TwoJ = tmp.
atoi()*2;
336 if(!fyrastmap_uncertain.count(TwoJ)) {
337 fyrastmap_uncertain[TwoJ] = _lvl;
338 _lvl->fisYrast_uncertain =
true;
344void tkdataset::load_dataset()
349 auto t_0 = std::chrono::high_resolution_clock::now();
350 gdebug <<
"loading levels for dataset '" << fname <<
"' of " << fnucleus <<
do_endl;
353 gdatabase->begin(
"DISTINCT level.*",
"level",
tkstring::form(
"dataset_id=%d",fid));
355 while(gdatabase->next()) {
360 gmanager->set_max_level_id(
id);
365 shared_ptr<tklevel> lvl = make_shared<tklevel>(
id,energy_struc);
366 lvl->fbelongs_to_nucleus = fnucleus;
372 col = &(*levels)[
"level_spin_parity"];
374 col = &(*levels)[
"level_spin"];
376 col = &(*levels)[
"level_parity"];
379 if(!spin_parity_str.
is_empty()) lvl->set_jpi(spin,parity,spin_parity_str);
383 if(lifetime_struc.
filled) lvl->set_lifetime(lifetime_struc);
385 col = &(*levels)[
"level_comment"];
387 col = &(*levels)[
"level_uncertain"];
390 flevels.push_back(lvl);
394 for(
const auto &lvl: flevels) {
395 fmapoflevels[lvl->get_id()] = lvl;
399 auto t_1 = std::chrono::high_resolution_clock::now();
400 gdebug <<
"loading decays for dataset '" << fname <<
"' of " << fnucleus <<
do_endl;
403 gdatabase->begin(
"DISTINCT decay.*",
"decay INNER JOIN level on decay.level_from_id=level.level_id ",
tkstring::form(
"dataset_id=%d",fid));
405 while(gdatabase->next()) {
407 int level_from = -1.;
414 gmanager->set_max_decay_id(
id);
416 col = &(*decay)[
"decay_type"];
418 col = &(*decay)[
"level_from_id"];
420 col = &(*decay)[
"level_to_id"];
423 shared_ptr<tkdecay> dec =
nullptr;
429 dec = make_shared<tkgammadecay>(
id, level_from, level_to, energy_struc);
430 shared_ptr<tkgammadecay> gamma = dynamic_pointer_cast<tkgammadecay>(dec);
433 decay->
read_measure(relative_intensity_struc,
"decay_relative_intensity");
434 if(relative_intensity_struc.
filled) gamma->set_relative_intensity(relative_intensity_struc);
436 col = &(*decay)[
"decay_multipolarity"];
440 decay->
read_measure(mixing_ratio_struc,
"decay_mixing_ratio");
441 if(mixing_ratio_struc.
filled) gamma->set_mixing_ratio(mixing_ratio_struc);
444 decay->
read_measure(conv_coeff_struc,
"decay_conv_coeff");
445 if(conv_coeff_struc.
filled) gamma->set_conv_coeff(conv_coeff_struc);
450 if(transprob_struc.
filled) gamma->set_transition_probability(transprob_struc);
451 transprob_struc.
clear();
453 if(transprob_struc.
filled) gamma->set_transition_probability(transprob_struc);
454 transprob_struc.
clear();
456 if(transprob_struc.
filled) gamma->set_transition_probability(transprob_struc);
457 transprob_struc.
clear();
459 if(transprob_struc.
filled) gamma->set_transition_probability(transprob_struc);
463 col = &(*decay)[
"decay_comment"];
465 col = &(*decay)[
"decay_uncertain"];
468 fdecays.push_back(dec);
469 fdecays.back()->set_levels(fmapoflevels.at(level_from),fmapoflevels.at(level_to));
471 for(
auto &dec: fdecays) {
472 fmapoflevels.at(dec->get_level_from_id())->add_decay_down(dec);
473 fmapoflevels.at(dec->get_level_to_id())->add_decay_up(dec);
478 auto t_2 = std::chrono::high_resolution_clock::now();
480 auto dt01 = std::chrono::duration<double, std::milli>(t_1-t_0).count() * 0.001;
481 auto dt12 = std::chrono::duration<double, std::milli>(t_2-t_1).count() * 0.001;
483 gdebug << std::fixed << std::setprecision(4) <<
"time level: "
487 gdebug << std::fixed << std::setprecision(4) <<
"time decays: "
502 glog <<
info <<
"dataset '" << fname <<
"' contains " << flevels.size() <<
" levels" <<
do_endl;
503 glog <<
info <<
"dataset '" << fname <<
"' contains " << fdecays.size() <<
" decays" <<
do_endl;
504 for(
auto &lev : flevels) {
505 if(_option.
contains(
"yrastt") && !lev->is_yrast(
true))
continue;
506 else if(_option.
contains(
"yrast") && !_option.
contains(
"yrastt") && !lev->is_yrast())
continue;
508 for(
auto &dec : lev->get_decays_down()) {
509 cout<<setw(13)<<
""<<
"-> ";dec->print(
"quiet;levto");
515 std::cout << std::setw(15) << left <<
"symbol" << std::setw(15) <<
"levelid"
516 << std::setw(15) << left <<
"energy (keV)"
517 << std::setw(15) << left <<
"energy error"
518 << std::setw(15) << left <<
"spin parity"
519 << std::setw(15) << left <<
"t1/2"
520 << std::setw(15) << left <<
"t1/2 error"
521 << std::setw(15) << left <<
"t1/2 unit" << std::endl;}
522 else glog <<
info <<
"dataset '" << fname <<
"' contains " << flevels.size() <<
" levels:" <<
do_endl;
523 for(
auto &lev : flevels) {
524 if(_option.
contains(
"yrastt") && !lev->is_yrast(
true))
continue;
525 else if(_option.
contains(
"yrast") && !_option.
contains(
"yrastt") && !lev->is_yrast())
continue;
526 if(_option.
contains(
"tab")) std::cout << std::setw(15)<< left << fnucleus;
531 if(_option.
contains(
"tab")) std::cout << std::setw(15) << left <<
"symbol" << std::setw(15) << left <<
"decayid" << std::setw(15) << left <<
"energy (keV)" << std::setw(15) << left <<
"energy error (keV)" << std::endl;
532 else glog <<
info <<
"dataset '" << fname <<
"' contains " << fdecays.size() <<
" decays:" <<
do_endl;
533 for(
auto &dec : fdecays) {
534 if(_option.
contains(
"tab")) std::cout << std::setw(15) << left << fnucleus;
544 double spin_val = -1.;
545 int parity_val = -1.;
548 shared_ptr<tklevel> lvl = make_shared<tklevel>(gmanager->get_new_level_id(),lvl_properties);
550 spin.
set(_jpistr);parity.
set(_jpistr);
552 if(parity.
is_known()) parity_val = (parity.
is_parity(tkparity::eparity::kParityMinus));
554 lvl->set_jpi(spin_val,parity_val,_jpistr);
557 lvl->fbelongs_to_nucleus = fnucleus;
560 auto it = std::lower_bound(flevels.begin(), flevels.end(), lvl,
561 [](
const std::shared_ptr<tklevel>& a,
const std::shared_ptr<tklevel>& b) {
562 return a->get_energy() < b->get_energy();
564 flevels.insert(it, lvl);
567 fmapoflevels[lvl->get_id()] = lvl;
574 if(_ener==0.) _ener = _lvlfrom->get_energy() - _lvlto->get_energy();
578 shared_ptr<tkgammadecay> decay = make_shared<tkgammadecay>(gmanager->get_new_decay_id(), _lvlfrom->get_id(), _lvlto->get_id(), energy_struc);
579 decay->set_levels(_lvlfrom,_lvlto);
580 fdecays.push_back(decay);
581 _lvlfrom->add_decay_down(decay);
582 _lvlto->add_decay_up(decay);
Stores information on a specific dataset.
shared_ptr< tklevel > add_level(double _ener, double _unc, tkstring _unit, tkstring _jpistr)
manually add a new level to the dataset
shared_ptr< tkgammadecay > add_gamma_decay(shared_ptr< tklevel > _lvlfrom, shared_ptr< tklevel > _lvlto, double _ener=0., double _unc=0.)
add a new decay between two levels to the dataset
Simple structure to store a table column.
tkstring get_value() const
Representaiton of a sqlite data table.
void read_measure(measure_data_struct &_struct, const tkstring &_col_base_name)
Collection of levels and decay.
void print(const tkstring &_data="", const tkstring &_option="")
print the level scheme information
const std::vector< shared_ptr< tklevel > > & get_levels()
get the vector containing all the levels
bool select_dataset(const tkstring &_dataset_name)
select a dataset using its name
const shared_ptr< tkdataset > & get_dataset()
returns the current dataset
shared_ptr< tklevel > get_level(const tkstring &_name, bool _exact=true)
get the level corresponding to the given name
const std::vector< shared_ptr< tkdecay > > & get_decays()
get the vector containing all the decays
Nuclear excited state parity.
virtual bool is_parity(tkparity::eparity _parity)
test the parity value
virtual void set(const tkstring &_st)
define the parity from a string
bool is_known() const
to get some information about this data
Nuclear excited state spin.
double get_value()
To get the spin as a double.
void set(int n, int d=1)
define the spin value
std::string with usefull tricks from TString (ROOT) and KVString (KaliVeda) and more....
tkstring copy() const
Returns a copy of this string.
static const char * form(const char *_format,...)
std::vector< tkstring > tokenize(const tkstring &_delim=" ") const
Create a vector of string separated by at least one delimiter.
tkstring & remove_all(const tkstring &_s1)
int atoi() const
Converts a string to integer value.
bool contains(const char *_pat, ECaseCompare _cmp=kExact) const
double atof() const
Converts a string to double value.
tklog & error(tklog &log)
tklog & do_endl(tklog &log)
tklog & warning(tklog &log)
tklog & comment(tklog &log)
data structure used to fill a tkmeasure object from the sqlite database