TkN 2.1
Toolkit for Nuclei
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 * This software is governed by the CeCILL-B license under French law and *
11 * abiding by the rules of distribution of free software. You can use, *
12 * modify and/ or redistribute the software under the terms of the *
13 * CeCILL-B license as circulated by CEA, CNRS and INRIA at the following *
14 * URL \"http://www.cecill.info\". *
15 * *
16 * As a counterpart to the access to the source code and rights to copy, *
17 * modify and redistribute granted by the license, users are provided *
18 * only with a limited warranty and the software's author, the holder of *
19 * the economic rights, and the successive licensors have only limited *
20 * liability. *
21 * *
22 * In this respect, the user's attention is drawn to the risks associated *
23 * with loading, using, modifying and/or developing or reproducing the *
24 * software by the user in light of its specific status of free software, *
25 * that may mean that it is complicated to manipulate, and that also *
26 * therefore means that it is reserved for developers and experienced *
27 * professionals having in-depth computer knowledge. Users are therefore *
28 * encouraged to load and test the software's suitability as regards *
29 * their requirements in conditions enabling the security of their *
30 * systems and/or data to be ensured and, more generally, to use and *
31 * operate it in the same conditions as regards security. *
32 * *
33 * The fact that you are presently reading this means that you have had *
34 * knowledge of the CeCILL-B license and that you accept its terms. *
35 ********************************************************************************/
36
37#include "tklevel.h"
38#include "tkstring.h"
39#include "tklog.h"
40
41using namespace std;
42
43namespace tkn {
51}
52
53using namespace tkn;
54
55tklevel::tklevel(int _id, const tkdb_table::measure_data_struct &_struc) :
56 tkproperty_list("level"),
57 flevel_id(_id),
58 fspin_parity(make_shared<tkspin_parity>())
59{
60 shared_ptr<tkmeasure> energy = make_shared<tkmeasure>(_struc.value,_struc.unit);
61 if(_struc.value>=0.) energy->set_info(tkproperty::kKnown);
62 if(_struc.err>0.) energy->set_error(_struc.err);
63 else if(_struc.err_low>0. && _struc.err_high>0.) energy->set_error(_struc.err_low,_struc.err_high);
64 if(!_struc.info.is_empty()) energy->set_info_tag(_struc.info);
65 energy->set_type("Level energy");
66 add_property("energy",energy);
67
68 if(energy->get_info_tag().contains(";OFF=")) {
69 int idx = energy->get_info_tag().index(";OFF=");
70 tkstring offset = energy->get_info_tag().substr(idx+5,1);
71 set_energy_offset(offset);
72 }
73}
74
76{
77 shared_ptr<tkmeasure> lifetime = make_shared<tkmeasure>(_struc.value,_struc.unit);
78 lifetime->set_info(tkproperty::kKnown);
79 if(_struc.err>0.) lifetime->set_error(_struc.err);
80 else if(_struc.err_low>0. && _struc.err_high>0.) lifetime->set_error(_struc.err_low,_struc.err_high);
81 if(!_struc.info.is_empty()) lifetime->set_info_tag(_struc.info);
82 if(lifetime->get_info_tag().contains("STABLE")) fis_stable = true;
83 lifetime->set_type("lifetime");
84 add_property("lifetime",lifetime,tkstring::form("%g",lifetime->get_value()));
85
86 if(lifetime->get_info_tag().contains(";ISO=")) {
87 fis_isomer = true;
88 int idx = lifetime->get_info_tag().index(";ISO=");
89 fisomer_level = lifetime->get_info_tag().substr(idx+6,1).atoi(); // ex= ;ISO=M1 => 1
90 if(fisomer_level==0) fisomer_level = 1;
91 }
92}
93
94void tklevel::set_jpi(double _spin, int _parity, const tkstring &_jpi_str)
95{
96 if(_spin>=0) fspin_parity->set_spin(_spin);
97 if(_parity>=0) fspin_parity->set_parity(_parity);
98 fspin_parity->set_from_str(_jpi_str);
99 add_property_str("spin_parity",_jpi_str,"");
100}
101
111double tklevel::get_energy(const tkunit_manager::units_keys _unit, bool _with_offset)
112{
113 if(gunits->get_type(_unit)!=tkunit_manager::units_type::kEnergy){
114 glog << error << gunits->get_name(_unit) << " is not of 'energy' type (returns nan(1))" << do_endl;
115 return std::nan("1");
116 }
117 if(get("energy")->get_unit()=="") {
118 cout << fenergy_offset << endl;
119 cout << fbelongs_to_nucleus << endl;
120 print();
121 }
122 if(is_energy_offset() && !_with_offset) {
123 glog << warning << "Level is only known relatively to an offset, use the _with_offset option to get the relative energy" << do_endl;
124 return std::nan("1");
125 }
126 return get("energy")->get_value(_unit);
127}
128
137{
138 if(!has_property("lifetime")) return std::nan("1");
139 if(gunits->get_type(_unit)!=tkunit_manager::units_type::kTime&&gunits->get_type(_unit)!=tkunit_manager::units_type::kEnergy){
140 glog << error << gunits->get_name(_unit) << " is not of 'time' or 'energy' type (returns nan(1))" << do_endl;
141 return std::nan("1");
142 }
143 return get("lifetime")->get_value(_unit);
144}
145
151{
152 if(!has_property("lifetime")) return "";
153 tkstring lifetime_str;
154
155 if(is_stable())
156 lifetime_str = "STABLE";
157 else {
158 vector<tkunit_manager::units_keys> units{tkunit_manager::y, tkunit_manager::d, tkunit_manager::h, tkunit_manager::min,
162
163 for(auto &unit: units) {
164 double lifetime = get_lifetime(unit);
165 if(lifetime>1.) {
166 lifetime_str = tkstring::Form("%.3g %s",lifetime,std::get<0>(tkunit_manager::funits_properties.at(unit)).data());
167 break;
168 }
169 }
170 }
171
172 return lifetime_str;
173}
174
176
181bool tklevel::is_yrast(bool _with_tentative)
182{
183 if(_with_tentative) return fisYrast_uncertain;
184 else return fisYrast_exact;
185}
186
187
194void tklevel::print(const tkstring &_option)
195{
196 // in line printout
197 if(_option.contains("tab")){
198 std::cout << std::setw(15) << left << flevel_id;
199 if(is_energy_offset()) std::cout << get_offset_bandhead() << "+";
200 std::cout << std::setw(15)<< left << get_energy_measure()->get_value();
201 if(get_energy_measure()->get_error()>0.)
202 std::cout << std::setw(15)<< left << get_energy_measure()->get_error();
203 else
204 std::cout << std::setw(15)<< left << " ";
205 if(fspin_parity)
206 std::cout << std::setw(15)<< left << fspin_parity->get_jpi_str();
207 if(get_lifetime_measure() && get_lifetime_measure()->get_value()>0.) {
208 std::cout << std::setw(15)<< left << get_lifetime_measure()->get_value();
209 if(get_lifetime_measure()->get_error()>0.)
210 std::cout << std::setw(15)<< left << get_lifetime_measure()->get_error();
211 else
212 std::cout << std::setw(15)<< left << " ";
213 std::cout << std::setw(15) << left << get_lifetime_measure()->get_unit();
214 }
215 else {
216 std::cout << std::setw(15)<< left << " "
217 << std::setw(15)<< left << " "
218 << std::setw(15)<< left << " ";
219 }
220 std::cout << std::endl;
221 }
222 else {
223 glog << info << get_energy_measure();
224 if(fspin_parity)
225 glog << " ; Jpi: " << setw(4) << fspin_parity->get_jpi_str();
226 if(get_lifetime_measure() && get_lifetime_measure()->get_value()>0.)
227 glog << " ; " << get_lifetime_measure();
228 if(is_isomer()) {
229 if(get_isomer_level()==1) glog << " [1rst isomer]";
230 else if(get_isomer_level()==2) glog << " [2nd isomer]";
231 else if(get_isomer_level()==3) glog << " [3rd isomer]";
232 else glog << " [" << get_isomer_level() << "th isomer]";
233 }
234 if(is_uncertain()) {
235 glog << " uncertain level tag: " << funcertain_level;
236 }
237 glog << do_endl;
238
239 if(has_comment() && _option.contains("com")) {
240 tkstring _comment = get_comment();
241 _comment.replace_all("\n","\n ");
242 glog << comment << _comment << do_endl;
243 }
244 }
245}
246
247#ifdef HAS_ROOT
249ClassImp(tklevel);
250#endif
Stores information on a nuclear level.
Definition: tklevel.h:54
bool is_isomer()
returns true is the level an isomer
Definition: tklevel.h:116
bool is_stable()
returns true if the level stable
Definition: tklevel.h:114
double get_lifetime(const tkunit_manager::units_keys _unit=tkunit_manager::units_keys::s)
returns the lifetime (in second by default)
Definition: tklevel.cpp:136
shared_ptr< tkmeasure > get_lifetime_measure()
returns the lifetime tkmeasure object
Definition: tklevel.h:97
const tkstring & get_comment()
get the level comment string
Definition: tklevel.h:126
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:111
tkstring get_offset_bandhead()
returns the bandhead string offset value (ex: X)
Definition: tklevel.h:94
shared_ptr< tkmeasure > get_energy_measure()
returns the energy tkmeasure object
Definition: tklevel.h:87
void set_jpi(double _spin, int _parity, const tkstring &_jpi_str)
define the spin parity
Definition: tklevel.cpp:94
tkstring get_lifetime_str()
returns the lifetime in string (using the best adapted unit)
Definition: tklevel.cpp:150
bool is_uncertain()
check if the level is uncertain
Definition: tklevel.h:128
bool is_energy_offset()
to know if the energy is known with an energy offset
Definition: tklevel.h:92
void print(const tkstring &_option="")
print the level properties
Definition: tklevel.cpp:194
int get_isomer_level()
get the isomer level (1 for the 1rst (lowest energy) isomer, 2 for the second, etc....
Definition: tklevel.h:118
bool is_yrast(bool _with_tentative=false)
returns true is the leve is Yrast
Definition: tklevel.cpp:181
void set_energy_offset(tkstring &_offset)
define the energy offset
Definition: tklevel.h:137
void set_lifetime(tkdb_table::measure_data_struct &_struc)
define the level lifetime
Definition: tklevel.cpp:75
bool has_comment()
check if a comment exists
Definition: tklevel.h:124
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:54
static const char * form(const char *_format,...)
Definition: tkstring.cpp:431
static tkstring Form(const char *_format,...)
Definition: tkstring.cpp:345
bool is_empty() const
Definition: tkstring.h:163
tkstring substr(size_type __pos=0, size_type __n=npos) const
Inlines.
Definition: tkstring.h:179
bool contains(const char *_pat, ECaseCompare _cmp=kExact) const
Definition: tkstring.h:197
tkstring & replace_all(const tkstring &_s1, const tkstring &_s2)
Definition: tkstring.h:203
units_keys
units identifiers
Definition: tkunit.h:69
static std::vector< std::tuple< tkstring, units_type, double > > funits_properties
Definition: tkunit.h:75
Definition: tklog.cpp:39
tklog & info(tklog &log)
Definition: tklog.h:336
tklog & error(tklog &log)
Definition: tklog.h:367
tklog & do_endl(tklog &log)
Definition: tklog.h:235
tklog & warning(tklog &log)
Definition: tklog.h:354
tklog & comment(tklog &log)
Definition: tklog.h:342
data structure used to fill a tkmeasure object from the sqlite database
Definition: tkdb_table.h:72