TkN 2.5
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 if (!decay_label.empty()) 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 energy_print = *flevelto->get_energy_measure();
128 energy_print.set_type(", E");
129 property_message << &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 }
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 if (!_struc.info.is_empty()) RI->set_info_tag(_struc.info);
172 RI->set_type("RI");
173 add_property("RI", RI);
174}
175
176void tkgammadecay::set_relative_intensity(double _val, double _unc)
177{
178 auto RI = get("RI");
179 if (!RI) {
180 auto new_RI = make_shared<tkmeasure>(_val, "%");
181 new_RI->set(_val, "%");
182 new_RI->set_info(tkproperty::kKnown);
183 if (_unc > 0.) new_RI->set_error(_unc);
184 new_RI->set_type("RI");
185 add_property("RI", new_RI);
186 } else {
187 RI->set(_val);
188 if (_unc > 0.) RI->set_error(_unc);
189 }
190}
191
193{
194 add_property_str("mult", _mul, "");
195}
196
198{
199 shared_ptr<tkmeasure> MR = make_shared<tkmeasure>(_struc.value, _struc.unit);
200 MR->set(_struc.value, _struc.unit);
201 MR->set_info(tkproperty::kKnown);
202 if (_struc.err > 0.)
203 MR->set_error(_struc.err);
204 else if (_struc.err_low > 0. && _struc.err_high > 0.)
205 MR->set_error(_struc.err_low, _struc.err_high);
206 if (!_struc.info.is_empty()) MR->set_info_tag(_struc.info);
207 MR->set_type("mix ratio");
208 add_property("mix ratio", MR);
209}
210
212{
213 shared_ptr<tkmeasure> CC = make_shared<tkmeasure>(_struc.value, _struc.unit);
214 CC->set(_struc.value, _struc.unit);
215 CC->set_info(tkproperty::kKnown);
216 if (_struc.err > 0.) CC->set_error(_struc.err);
217 if (!_struc.info.is_empty()) CC->set_info_tag(_struc.info);
218 CC->set_type("conv");
219 add_property("conv", CC);
220}
221
223{
224 tkstring name = _struc.info;
225 tkstring type = name.tokenize(";").front().remove_all("TYPE=");
226 shared_ptr<tkmeasure> B = make_shared<tkmeasure>(_struc.value, _struc.unit);
227 B->set_info(tkproperty::kKnown);
228 if (_struc.err > 0.)
229 B->set_error(_struc.err);
230 else if (_struc.err_low > 0. && _struc.err_high > 0.)
231 B->set_error(_struc.err_low, _struc.err_high);
232 if (!_struc.info.is_empty()) B->set_info_tag(_struc.info);
233 B->set_type(type);
234 add_property(type, B);
235}
236
245{
246 if (!has_property("RI")) return std::nan("1");
247 return get("RI")->get_value();
248}
249
258{
259 if (!has_property("mix ratio")) return std::nan("1");
260 return get("mix ratio")->get_value();
261}
262
263
269 */
271{
272 if (!has_property("conv")) return std::nan("1");
273 return get("conv")->get_value();
274}
275
279
280 * @param _WU true to retrieve the value in Weisskopf units
281 * @return shared pointer to the tkmeasure, or nullptr if not available.
282 * @details Example:
283 * ```cpp
284 * tknucleus nuc("132Sn");
285 * auto gamma = nuc.get_level_scheme()->get_decay<tkgammadecay>("2+1->0+1");
286 * auto be2 = gamma->get_trans_prob_measure(true, 2, true); // B(E2) in W.u.
287 * if (be2) cout << be2->get_value() << " " << be2->get_unit() << endl;
288 * ```
289 * @see get_trans_prob()
290 */
291shared_ptr<tkmeasure> tkgammadecay::get_trans_prob_measure(bool _elec, int _L, bool _WU)
292{
293 tkstring name = "B";
294 if (_elec)
295 name += "E";
296 else
297 name += "M";
298 name += to_string(_L);
299 if (_WU) name += "W";
300 return get(name);
302
311double tkgammadecay::get_trans_prob(bool _elec, int _L, bool _WU)
312{
313 auto meas = get_trans_prob_measure(_elec, _L, _WU);
314 if (!meas) return std::nan("1");
315 return meas->get_value();
316}
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:181
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:168
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:146
void set_relative_intensity(tkdb_table::measure_data_struct &_struc)
set the relative intensity info
Definition tkdecay.cpp:269
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:415
void set_mixing_ratio(tkdb_table::measure_data_struct &_struc)
set the mixing ratio info
Definition tkdecay.cpp:301
double get_conv_coeff()
returns the gamma conversion coefficient value
Definition tkdecay.cpp:374
double get_mixing_ratio()
returns the gamma mixing ratio value
Definition tkdecay.cpp:361
double get_relative_intensity()
returns the gamma relative intensity (100% corresponds to the most intense gamma-ray)
Definition tkdecay.cpp:348
void set_multipolarity(const tkstring &_mul)
set the relative intensity info
Definition tkdecay.cpp:296
void set_transition_probability(tkdb_table::measure_data_struct &_struc)
set the transition probability
Definition tkdecay.cpp:326
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:395
void set_conv_coeff(tkdb_table::measure_data_struct &_struc)
set the conversion coeff
Definition tkdecay.cpp:315
void set_type(const tkstring &_type)
set the measured data type (energy, lifetime...)
Definition tkmeasure.h:87
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
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:32
static const char * form(const char *_format,...)
Definition tkstring.cpp:452
std::vector< tkstring > tokenize(const tkstring &_delim=" ") const
Create a vector of string separated by at least one delimiter.
Definition tkstring.cpp:275
bool is_empty() const
Definition tkstring.h:141
bool contains(const char *_pat, ECaseCompare _cmp=kExact) const
Definition tkstring.h:175
units_keys
units identifiers
Definition tkunit.h:46
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:37
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:49