TkN 2.7.1
Toolkit for Nuclei
Loading...
Searching...
No Matches
tkdecay.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 "tkdecay.h"
15#include "tklevel.h"
16#include "tklog.h"
17#include "tkstring.h"
18
19#include <cctype>
20#include <iomanip>
21#include <sstream>
22#include <string>
23#include <vector>
24
25namespace tkn {
36}
37
38using namespace tkn;
39
40array<tkstring, 6> tkdecay::decay_type_str = {"undefined", "beta", "ec", "alpha", "particle", "gamma"};
41
42tkdecay::tkdecay(int _id, int _from_id, int _to_id, const tkdb_table::measure_data_struct &_struc, decay_type _type) : tkproperty_list("decay"),
43 fdecay_id(_id),
44 fdecay_level_from_id(_from_id),
45 fdecay_level_to_id(_to_id),
46 fdecay_type(_type)
47{
48 shared_ptr<tkmeasure> energy = make_shared<tkmeasure>(_struc.value, _struc.unit);
49 if (_struc.value >= 0.) energy->set_info(tkproperty::kKnown);
50 if (_struc.err > 0.)
51 energy->set_error(_struc.err);
52 else if (_struc.err_low > 0. && _struc.err_high > 0.)
53 energy->set_error(_struc.err_low, _struc.err_high);
54 if (!_struc.info.is_empty()) energy->set_info_tag(_struc.info);
55 energy->set_type(tkstring::form("%s decay energy", decay_type_str.at(fdecay_type).data()));
56 add_property("energy", energy);
57}
58
65{
66 return get("energy")->get_value(_unit);
67}
68
77void tkdecay::print(const tkstring &_option) const
78{
79 // in line printout
80 if (_option.contains("tab")) {
81 std::cout << std::setw(15) << left << fdecay_id << std::setw(15) << left << get_energy_meas()->get_value();
82 if (get_energy_meas()->get_error() > 0.)
83 std::cout << std::setw(15) << left << get_energy_meas()->get_error() << std::endl;
84 else
85 std::cout << " " << std::setw(15) << left << " " << std::endl;
86 } else {
87 if (not _option.contains("quiet")) glog << info;
88 constexpr size_t print_label_width = 14;
89 std::ostringstream decay_message;
90 std::vector<std::string> property_messages;
91
92 std::string decay_label = decay_type_str.at(fdecay_type) + " decay:";
93 decay_label[0] = static_cast<char>(std::toupper(static_cast<unsigned char>(decay_label[0])));
94 decay_message << std::left << std::setw(print_label_width) << decay_label;
95
96 tkmeasure energy_print = *get_energy_meas();
97 energy_print.set_type("energy");
98 std::ostringstream energy_message;
99 energy_message << &energy_print;
100 property_messages.push_back(energy_message.str());
101
102 if (has_property("mult")) {
103 std::ostringstream property_message;
104 property_message << "mult " << get_property("mult");
105 property_messages.push_back(property_message.str());
106 }
107 for (auto &prop : fProperties) {
108 if (prop.first == "energy") continue;
109 if (prop.first == "mult") continue;
110 std::ostringstream property_message;
111 if (prop.second.type == "TEXT") {
112 property_message << prop.second.value;
113 if (!prop.second.unit.is_empty()) property_message << " " << prop.second.unit;
114 } else
115 property_message << get(prop.first).get();
116 property_messages.push_back(property_message.str());
117 }
118 if (is_uncertain()) {
119 std::ostringstream property_message;
120 property_message << "uncertain decay tag: " << funcertain_decay;
121 property_messages.push_back(property_message.str());
122 }
123 if (_option.contains("levto")) {
124 std::ostringstream property_message;
125 property_message << "final level: " << flevelto->get_spin_parity_str();
126
127 tkmeasure final_energy_print = *flevelto->get_energy_measure();
128 final_energy_print.set_type(", E");
129 property_message << &final_energy_print;
130 property_messages.push_back(property_message.str());
131 }
132 const std::string decay_str = decay_message.str();
133 const size_t line_offset = (_option.contains("quiet") ? 16 : 13) + decay_str.length() + 1;
134
135 glog << decay_str;
136 if (!property_messages.empty()) {
137 const std::string property_prefix = "| ";
138 glog << " " << property_messages.front();
139 for (size_t i = 1; i < property_messages.size(); ++i) {
140 glog << "\n"
141 << std::string(line_offset, ' ') << property_prefix;
142 for (char c : property_messages.at(i)) {
143 glog << c;
144 if (c == '\n') glog << std::string(line_offset, ' ') << property_prefix;
145 }
146 }
147 }
148 glog << do_endl;
149 if (has_comment() && _option.contains("com")) {
150 const size_t comment_prefix_size = 13;
151 const size_t property_prefix_size = 2;
152 const size_t comment_start = line_offset + property_prefix_size;
153 const size_t comment_offset = comment_start > comment_prefix_size ? comment_start - comment_prefix_size : 0;
154 const std::string first_indent(comment_offset, ' ');
155 glog << comment << first_indent << wrap_text(get_comment(), comment_start, comment_start) << do_endl;
156 }
157 }
158}
159
160#ifdef HAS_ROOT
162ClassImp(tkdecay);
163#endif
164
166{
167 shared_ptr<tkmeasure> RI = make_shared<tkmeasure>(_struc.value, _struc.unit);
168 RI->set(_struc.value, _struc.unit);
169 RI->set_info(tkproperty::kKnown);
170 if (_struc.err > 0.) RI->set_error(_struc.err);
171 else if (_struc.err_low > 0. || _struc.err_high > 0.)
172 RI->set_error(_struc.err_low, _struc.err_high);
173 if (!_struc.info.is_empty()) RI->set_info_tag(_struc.info);
174 RI->set_type("RI");
175 add_property("RI", RI);
176}
177
178void tkgammadecay::set_relative_intensity(double _val, double _unc)
179{
180 auto RI = get("RI");
181 if (!RI) {
182 auto new_RI = make_shared<tkmeasure>(_val, "%");
183 new_RI->set(_val, "%");
184 new_RI->set_info(tkproperty::kKnown);
185 if (_unc > 0.) new_RI->set_error(_unc);
186 new_RI->set_type("RI");
187 add_property("RI", new_RI);
188 } else {
189 RI->set(_val);
190 if (_unc > 0.) RI->set_error(_unc);
191 }
192}
193
195{
196 add_property_str("mult", _mul, "");
197}
198
200{
201 shared_ptr<tkmeasure> MR = make_shared<tkmeasure>(_struc.value, _struc.unit);
202 MR->set(_struc.value, _struc.unit);
203 MR->set_info(tkproperty::kKnown);
204 if (_struc.err > 0.)
205 MR->set_error(_struc.err);
206 else if (_struc.err_low > 0. && _struc.err_high > 0.)
207 MR->set_error(_struc.err_low, _struc.err_high);
208 if (!_struc.info.is_empty()) MR->set_info_tag(_struc.info);
209 MR->set_type("mix ratio");
210 add_property("mix ratio", MR);
211}
212
214{
215 shared_ptr<tkmeasure> CC = make_shared<tkmeasure>(_struc.value, _struc.unit);
216 CC->set(_struc.value, _struc.unit);
217 CC->set_info(tkproperty::kKnown);
218 if (_struc.err > 0.) CC->set_error(_struc.err);
219 else if (_struc.err_low > 0. || _struc.err_high > 0.)
220 CC->set_error(_struc.err_low, _struc.err_high);
221 if (!_struc.info.is_empty()) CC->set_info_tag(_struc.info);
222 CC->set_type("conv");
223 add_property("conv", CC);
224}
225
227{
228 tkstring name = _struc.info;
229 tkstring type = name.tokenize(";").front().remove_all("TYPE=");
230 shared_ptr<tkmeasure> B = make_shared<tkmeasure>(_struc.value, _struc.unit);
231 B->set_info(tkproperty::kKnown);
232 if (_struc.err > 0.)
233 B->set_error(_struc.err);
234 else if (_struc.err_low > 0. && _struc.err_high > 0.)
235 B->set_error(_struc.err_low, _struc.err_high);
236 if (!_struc.info.is_empty()) B->set_info_tag(_struc.info);
237 B->set_type(type);
238 add_property(type, B);
239}
240
249{
250 if (!has_property("RI")) return std::nan("1");
251 return get("RI")->get_value();
252}
253
262{
263 if (!has_property("mix ratio")) return std::nan("1");
264 return get("mix ratio")->get_value();
265}
266
275{
276 if (!has_property("conv")) return std::nan("1");
277 return get("conv")->get_value();
278}
279
295shared_ptr<tkmeasure> tkgammadecay::get_trans_prob_measure(bool _elec, int _L, bool _WU)
296{
297 tkstring name = "B";
298 if (_elec)
299 name += "E";
300 else
301 name += "M";
302 name += to_string(_L);
303 if (_WU) name += "W";
304 return get(name);
305}
306
315double tkgammadecay::get_trans_prob(bool _elec, int _L, bool _WU)
316{
317 auto meas = get_trans_prob_measure(_elec, _L, _WU);
318 if (!meas) return std::nan("1");
319 return meas->get_value();
320}
Represents a nuclear decay transition between two levels.
Definition tkdecay.h:48
bool is_uncertain() const
check if the decay is uncertain
Definition tkdecay.h:95
const tkstring & get_comment() const
get the level comment string
Definition tkdecay.h:93
void print(const tkstring &_option="") const
print the decay properties
Definition tkdecay.cpp:77
static array< tkstring, 6 > decay_type_str
Definition tkdecay.h:61
bool has_comment() const
check if a comment exists
Definition tkdecay.h:91
double get_energy(const tkunit_manager::units_keys _unit=tkunit_manager::units_keys::keV)
returns the energy in keV by default
Definition tkdecay.cpp:64
shared_ptr< tkmeasure > get_energy_meas() const
returns the energy tkmeasure object
Definition tkdecay.h:83
tkdecay(int _id, int _from_id, int _to_id, const tkdb_table::measure_data_struct &_struc, decay_type _type)
Definition tkdecay.cpp:42
void set_relative_intensity(tkdb_table::measure_data_struct &_struc)
set the relative intensity info
Definition tkdecay.cpp:165
double get_trans_prob(bool _elec, int _L, bool _WU)
returns the gamma transition probability value (ex: BE2 in Weisskopf units, get_trans_prob(1,...
Definition tkdecay.cpp:315
void set_mixing_ratio(tkdb_table::measure_data_struct &_struc)
set the mixing ratio info
Definition tkdecay.cpp:199
double get_conv_coeff()
returns the gamma conversion coefficient value
Definition tkdecay.cpp:274
double get_mixing_ratio()
returns the gamma mixing ratio value
Definition tkdecay.cpp:261
double get_relative_intensity()
returns the gamma relative intensity (100% corresponds to the most intense gamma-ray)
Definition tkdecay.cpp:248
void set_multipolarity(const tkstring &_mul)
set the relative intensity info
Definition tkdecay.cpp:194
void set_transition_probability(tkdb_table::measure_data_struct &_struc)
set the transition probability
Definition tkdecay.cpp:226
shared_ptr< tkmeasure > get_trans_prob_measure(bool _elec, int _L, bool _WU)
returns the gamma transition probability tkmeasure object (ex: BE2 in Weisskopf units,...
Definition tkdecay.cpp:295
void set_conv_coeff(tkdb_table::measure_data_struct &_struc)
set the conversion coeff
Definition tkdecay.cpp:213
Stores a physical measurement with its value, unit, and uncertainty.
Definition tkmeasure.h:56
void set_type(const tkstring &_type)
set the measured data type (energy, lifetime...)
Definition tkmeasure.h:103
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
tkproperty_list(tkstring _name)
tkstring get_property(const tkstring &_property) const
get the property value as a string
std::string with usefull tricks from TString (ROOT) and KVString (KaliVeda) and more....
Definition tkstring.h:33
static const char * form(const char *_format,...)
Definition tkstring.cpp:438
std::vector< tkstring > tokenize(const tkstring &_delim=" ") const
Create a vector of string separated by at least one delimiter.
Definition tkstring.cpp:292
bool is_empty() const
Definition tkstring.h:145
bool contains(const char *_pat, ECaseCompare _cmp=kExact) const
Definition tkstring.h:184
units_keys
units identifiers
Definition tkunit.h:48
Definition tklog.cpp:16
std::string wrap_text(const tkstring &_text, size_t _first_content_col, size_t _continuation_col, size_t _max_line_width=80)
Definition tkstring.cpp:75
tklog & info(tklog &log)
Definition tklog.h:313
tklog & do_endl(tklog &log)
Definition tklog.h:212
tklog & comment(tklog &log)
Definition tklog.h:319
data structure used to fill a tkmeasure object from the sqlite database
Definition tkdb_table.h:51