TkN 2.4
Toolkit for Nuclei
Loading...
Searching...
No Matches
tklevel.cpp
1/********************************************************************************
2 * Copyright (c) : Université de Lyon 1, CNRS/IN2P3, UMR5822, *
3 * IP2I, F-69622 Villeurbanne Cedex, France *
4 * Normandie Université, ENSICAEN, UNICAEN, CNRS/IN2P3, *
5 * LPC Caen, F-14000 Caen, France *
6 * Contibutor(s) : *
7 * Jérémie Dudouet jeremie.dudouet@cnrs.fr [2020] *
8 * Diego Gruyer diego.gruyer@cnrs.fr [2020] *
9 * *
10 * Licensed under the MIT License <http://opensource.org/licenses/MIT>. *
11 * SPDX-License-Identifier: MIT *
12 ********************************************************************************/
13
14#include "tklevel.h"
15#include "tkstring.h"
16#include "tklog.h"
17
18using namespace std;
19
20namespace tkn {
28}
29
30using namespace tkn;
31
33 tkproperty_list("level"),
34 flevel_id(_id),
35 fspin_parity(make_shared<tkspin_parity>())
36{
37 shared_ptr<tkmeasure> energy = make_shared<tkmeasure>(_struc.value,_struc.unit);
38 if(_struc.value>=0.) energy->set_info(tkproperty::kKnown);
39 if(_struc.err>0.) energy->set_error(_struc.err);
40 else if(_struc.err_low>0. && _struc.err_high>0.) energy->set_error(_struc.err_low,_struc.err_high);
41 if(!_struc.info.is_empty()) energy->set_info_tag(_struc.info);
42 energy->set_type("Level energy");
43 add_property("energy",energy);
44
45 if(energy->get_info_tag().contains(";OFF=")) {
46 int idx = energy->get_info_tag().index(";OFF=");
47 tkstring offset = energy->get_info_tag().substr(idx+5,1);
48 set_energy_offset(offset);
49 }
50}
51
53{
54 shared_ptr<tkmeasure> lifetime = make_shared<tkmeasure>(_struc.value,_struc.unit);
55 lifetime->set_info(tkproperty::kKnown);
56 if(_struc.err>0.) lifetime->set_error(_struc.err);
57 else if(_struc.err_low>0. && _struc.err_high>0.) lifetime->set_error(_struc.err_low,_struc.err_high);
58 if(!_struc.info.is_empty()) lifetime->set_info_tag(_struc.info);
59 if(lifetime->get_info_tag().contains("STABLE")) fis_stable = true;
60 lifetime->set_type("lifetime");
61 add_property("lifetime",lifetime,tkstring::form("%g",lifetime->get_value()));
62
63 if(lifetime->get_info_tag().contains(";ISO=")) {
64 fis_isomer = true;
65 int idx = lifetime->get_info_tag().index(";ISO=");
66 fisomer_level = lifetime->get_info_tag().substr(idx+6,1).atoi(); // ex= ;ISO=M1 => 1
67 if(fisomer_level==0) fisomer_level = 1;
68 }
69}
70
71void tklevel::set_jpi(double _spin, int _parity, const tkstring &_jpi_str)
72{
73 if(_spin>=0) fspin_parity->set_spin(_spin);
74 if(_parity>=0) fspin_parity->set_parity(_parity);
75 fspin_parity->set_from_str(_jpi_str);
76 add_property_str("spin_parity",_jpi_str,"");
77}
78
88double tklevel::get_energy(const tkunit_manager::units_keys _unit, bool _with_offset)
89{
90 if(gunits->get_type(_unit)!=tkunit_manager::units_type::kEnergy){
91 glog << error << gunits->get_name(_unit) << " is not of 'energy' type (returns nan(1))" << do_endl;
92 return std::nan("1");
93 }
94 if(get("energy")->get_unit()=="") {
95 cout << fenergy_offset << endl;
96 cout << fbelongs_to_nucleus << endl;
97 print();
98 }
99 if(is_energy_offset() && !_with_offset) {
100 glog << warning << "Level is only known relatively to an offset, use the _with_offset option to get the relative energy" << do_endl;
101 return std::nan("1");
102 }
103 return get("energy")->get_value(_unit);
104}
105
114{
115 if(!has_property("lifetime")) return std::nan("1");
116 if(gunits->get_type(_unit)!=tkunit_manager::units_type::kTime&&gunits->get_type(_unit)!=tkunit_manager::units_type::kEnergy){
117 glog << error << gunits->get_name(_unit) << " is not of 'time' or 'energy' type (returns nan(1))" << do_endl;
118 return std::nan("1");
119 }
120 return get("lifetime")->get_value(_unit);
121}
122
128{
129 if(!has_property("lifetime")) return "";
130 tkstring lifetime_str;
131
132 if(is_stable())
133 lifetime_str = "STABLE";
134 else {
139
140 for(auto &unit: units) {
141 double lifetime = get_lifetime(unit);
142 if(lifetime>1.) {
143 lifetime_str = tkstring::Form("%.3g %s",lifetime,std::get<0>(tkunit_manager::funits_properties.at(unit)).data());
144 break;
145 }
146 }
147 }
148
149 return lifetime_str;
150}
151
153
154 * @param _with_tentative if enabled, consider also the tentative spin assignments
155 * @details
156 * This method returns true if the level is Yrast: corresponding to the lowest energy level for a given spin value
157 */
158bool tklevel::is_yrast(bool _with_tentative)
159{
160 if(_with_tentative) return fisYrast_uncertain;
161 else return fisYrast_exact;
162}
163
164
171void tklevel::print(const tkstring &_option)
172{
173 // in line printout
174 if(_option.contains("tab")){
175 std::cout << std::setw(15) << left << flevel_id;
176 if(is_energy_offset()) std::cout << get_offset_bandhead() << "+";
177 std::cout << std::setw(15)<< left << get_energy_measure()->get_value();
178 if(get_energy_measure()->get_error()>0.)
179 std::cout << std::setw(15)<< left << get_energy_measure()->get_error();
180 else
181 std::cout << std::setw(15)<< left << " ";
182 if(fspin_parity)
183 std::cout << std::setw(15)<< left << fspin_parity->get_jpi_str();
184 if(get_lifetime_measure() && get_lifetime_measure()->get_value()>0.) {
185 std::cout << std::setw(15)<< left << get_lifetime_measure()->get_value();
186 if(get_lifetime_measure()->get_error()>0.)
187 std::cout << std::setw(15)<< left << get_lifetime_measure()->get_error();
188 else
189 std::cout << std::setw(15)<< left << " ";
190 std::cout << std::setw(15) << left << get_lifetime_measure()->get_unit();
191 }
192 else {
193 std::cout << std::setw(15)<< left << " "
194 << std::setw(15)<< left << " "
195 << std::setw(15)<< left << " ";
197 std::cout << std::endl;
198 }
199 else {
200 glog << info << get_energy_measure();
201 if(fspin_parity)
202 glog << " ; Jpi: " << setw(4) << fspin_parity->get_jpi_str();
203 if(get_lifetime_measure() && get_lifetime_measure()->get_value()>0.)
204 glog << " ; " << get_lifetime_measure();
205 if(is_isomer()) {
206 if(get_isomer_level()==1) glog << " [1rst isomer]";
207 else if(get_isomer_level()==2) glog << " [2nd isomer]";
208 else if(get_isomer_level()==3) glog << " [3rd isomer]";
209 else glog << " [" << get_isomer_level() << "th isomer]";
211 if(is_uncertain()) {
212 glog << " uncertain level tag: " << funcertain_level;
213 }
214 glog << do_endl;
215
216 if(has_comment() && _option.contains("com")) {
217 tkstring _comment = get_comment();
218 _comment.replace_all("\n","\n ");
219 glog << comment << _comment << do_endl;
220 }
221 }
222}
223
224#ifdef HAS_ROOT
226ClassImp(tklevel);
227#endif
Stores information on a nuclear level.
Definition tklevel.h:31
bool is_isomer()
returns true is the level an isomer
Definition tklevel.h:93
bool is_stable()
returns true if the level stable
Definition tklevel.h:91
double get_lifetime(const tkunit_manager::units_keys _unit=tkunit_manager::units_keys::s)
returns the lifetime (in second by default)
Definition tklevel.cpp:196
shared_ptr< tkmeasure > get_lifetime_measure()
returns the lifetime tkmeasure object
Definition tklevel.h:74
const tkstring & get_comment()
get the level comment string
Definition tklevel.h:103
double get_energy(const tkunit_manager::units_keys _unit=tkunit_manager::units_keys::keV, bool _with_offset=false)
returns the energy in keV by default
Definition tklevel.cpp:171
tkstring get_offset_bandhead()
returns the bandhead string offset value (ex: X)
Definition tklevel.h:71
shared_ptr< tkmeasure > get_energy_measure()
returns the energy tkmeasure object
Definition tklevel.h:64
void set_jpi(double _spin, int _parity, const tkstring &_jpi_str)
define the spin parity
Definition tklevel.cpp:154
tklevel(int _id, const tkdb_table::measure_data_struct &_struc)
Definition tklevel.cpp:115
tkstring get_lifetime_str()
returns the lifetime in string (using the best adapted unit)
Definition tklevel.cpp:210
bool is_uncertain()
check if the level is uncertain
Definition tklevel.h:105
bool is_energy_offset()
to know if the energy is known with an energy offset
Definition tklevel.h:69
void print(const tkstring &_option="")
print the level properties
Definition tklevel.cpp:254
int get_isomer_level()
get the isomer level (1 for the ␌1rst (lowest energy) isomer, 2 for the second, etc....
Definition tklevel.h:95
bool is_yrast(bool _with_tentative=false)
returns true is the leve is Yrast
Definition tklevel.cpp:241
void set_lifetime(tkdb_table::measure_data_struct &_struc)
define the level lifetime
Definition tklevel.cpp:135
bool has_comment()
check if a comment exists
Definition tklevel.h:101
Contains list of properties.
bool has_property(const tkstring &_property) const
to check if the property is available
shared_ptr< tkmeasure > get(const tkstring &_property) const
get the property as tkmeasure
Nuclear excited state spin-parity.
std::string with usefull tricks from TString (ROOT) and KVString (KaliVeda) and more....
Definition tkstring.h:31
static const char * form(const char *_format,...)
Definition tkstring.cpp:408
static tkstring Form(const char *_format,...)
Definition tkstring.cpp:322
bool is_empty() const
Definition tkstring.h:140
tkstring substr(size_type __pos=0, size_type __n=npos) const
Inlines.
Definition tkstring.h:156
bool contains(const char *_pat, ECaseCompare _cmp=kExact) const
Definition tkstring.h:174
tkstring & replace_all(const tkstring &_s1, const tkstring &_s2)
Definition tkstring.h:180
units_keys
units identifiers
Definition tkunit.h:46
static std::vector< std::tuple< tkstring, units_type, double > > funits_properties
Definition tkunit.h:52
Definition tklog.cpp:16
tklog & info(tklog &log)
Definition tklog.h:313
tklog & error(tklog &log)
Definition tklog.h:344
tklog & do_endl(tklog &log)
Definition tklog.h:212
tklog & warning(tklog &log)
Definition tklog.h:331
tklog & comment(tklog &log)
Definition tklog.h:319
data structure used to fill a tkmeasure object from the sqlite database
Definition tkdb_table.h:49