TkN 2.7.1
Toolkit for Nuclei
Loading...
Searching...
No Matches
tkensdf_gamma_rec.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 "tkensdf_gamma_rec.h"
15
16#include <cmath>
17
18#include "tklog.h"
19
20namespace tkn {
27}
28
29using namespace tkn;
30using namespace std;
31
36
38{
39 fIs_final_level_set = _gamma_record.fIs_final_level_set;
40 fFinal_level_energy = _gamma_record.fFinal_level_energy;
41}
42
44{
45 frecord = _record;
46 return true;
47}
48
50{
51 // check if the level is uncertain
52 fUncertain_record = frecord.substr(79,1);
53
54 // decode gamma energy
56
57 // decode relative intensity
58 set_relative_intensity(frecord);
59
60 // decode multipolarity
61 set_multipolarity(frecord);
62
63 // decode mixing ratio
64 set_mixing_ratio(frecord);
65
66 // decode conversion coeff
67 set_conv_coeff(frecord);
68
70}
71
72void tkensdf_gamma_rec::set_relative_intensity(const tkstring &_record)
73{
74 auto RI_str = _record.substr(21,8).strip_all_extra_white_space();
75 auto DRI_str = _record.substr(29,2).strip_all_extra_white_space();
76
77 if(RI_str.contains("(")) {
78 frelative_intensity.info += ";VAL=()";
79 RI_str.remove_all("(").remove_all(")");
80 }
81 frelative_intensity.value = RI_str.atof();
82 if(frelative_intensity.value>0) frelative_intensity.filled = true;
83 else return;
84
85 frelative_intensity.unit = "%";
86 if (DRI_str.is_empty()) frelative_intensity.info += ";ERR=?";
87 else if (DRI_str.is_alpha()) frelative_intensity.info += ";ERR=" + DRI_str;
88 else frelative_intensity.err = DRI_str.atof() * tkstring::get_precision(RI_str);
89}
90
91void tkensdf_gamma_rec::set_multipolarity(const tkstring &_record)
92{
93 auto str = _record.substr(31,10);
94 if(!str.is_empty()) fmultipolarity = str.remove_all_extra_white_space();
95}
96
97void tkensdf_gamma_rec::set_mixing_ratio(const tkstring &_record)
98{
99 auto MR_str = _record.substr(41,8).strip_all_extra_white_space();
100 auto DMR_str = _record.substr(49,6).strip_all_extra_white_space();
101
102 fmixing_ratio.value = MR_str.atof();
103 if(fmixing_ratio.value==0) return;
104
105 if(!DMR_str.is_empty()) {
106
107 if(DMR_str.is_alpha()) {
108 fmixing_ratio.info += ";ERR=" + DMR_str;
109 }
110 else {
111 // define precision according to the value string
112 double precision = tkstring::get_precision(MR_str);
113
114 // check if asym errors
115 if(DMR_str.contains("+") && DMR_str.contains("-")) {
116 bool inv = DMR_str.index("-") < DMR_str.index("+");
117 DMR_str.replace_all("+"," ");
118 DMR_str.replace_all("-"," ");
119 auto tokens_lt_err = DMR_str.tokenize(" ");
120 if(tokens_lt_err.size()!=2) {
121 glog << error << " bad asymetric error decoding in record " << frecord << do_endl;
122 return;
123 }
124 tkstring err_low_str = tokens_lt_err.back();
125 tkstring err_high_str = tokens_lt_err.front();
126 if(inv) {
127 err_low_str = tokens_lt_err.front();
128 err_high_str = tokens_lt_err.back();
129 }
130
131 fmixing_ratio.err_low = err_low_str.atof()*precision;
132 fmixing_ratio.err_high = err_high_str.atof()*precision;
133 }
134 else {
135 fmixing_ratio.err = DMR_str.atof()*precision;
136 }
137 }
138 }
139 else
140 fmixing_ratio.info += ";ERR=?";
141
142 fmixing_ratio.filled = true;
143}
144
145void tkensdf_gamma_rec::set_conv_coeff(const tkstring &_record)
146{
147 auto CC_str = _record.substr(55,7).strip_all_extra_white_space();
148 auto DCC_str = _record.substr(62,2).strip_all_extra_white_space();
149
150 fconv_coeff.value = CC_str.atof();
151 if(fconv_coeff.value>0) fconv_coeff.filled = true;
152 else return;
153
154 fconv_coeff.unit = "";
155 if (DCC_str.is_empty()) fconv_coeff.info += ";ERR=?";
156 else if (DCC_str.is_alpha()) fconv_coeff.info += ";ERR=" + DCC_str;
157 else fconv_coeff.err = DCC_str.atof() * tkstring::get_precision(CC_str);
158}
159
160void tkensdf_gamma_rec::set_red_trans_prob(const tkstring &_record)
161{
162 auto tmp_rec = _record;
164
165 tkstring trans_name{};
166
167 bool is_elec=false;
168 bool is_mag=false;
169 if(tmp_rec.begins_with("BM")) {
170 is_mag=true;
171 trans_name += "BM";
172 }
173 if(tmp_rec.begins_with("BE")) {
174 is_elec=true;
175 trans_name += "BE";
176 }
177 if(!(is_elec || is_mag)) return;
178
179 trans_name += tmp_rec[2];
180 int mult = tmp_rec.substr(2,1).atoi();
181
182 bool wu = (tmp_rec.substr(3,1) == "W");
183 if(wu) trans_name += "W";
184
185 tkdb_table::measure_data_struct *the_struct=nullptr;
186 if(is_elec && wu) the_struct = &fBEW;
187 else if(is_elec && !wu) the_struct = &fBE;
188 else if(is_mag && wu) the_struct = &fBMW;
189 else if(is_mag && !wu) the_struct = &fBM;
190 if(!the_struct) return;
191 if(the_struct->filled) return;
192
193 if(!wu) {
194 if(is_elec) {
195 the_struct->value *= pow(100,mult);
196 the_struct->err *= pow(100,mult);
197 the_struct->err_low *= pow(100,mult);
198 the_struct->err_high *= pow(100,mult);
199 the_struct->unit = tkstring::form("e^2 x (fm)^%d",mult*2);
200 }
201 else {
202 the_struct->value *= pow(100,mult-1);
203 the_struct->err *= pow(100,mult-1);
204 the_struct->err_low *= pow(100,mult-1);
205 the_struct->err_high *= pow(100,mult-1);
206 if(mult==1) the_struct->unit = "mu^2";
207 else the_struct->unit = tkstring::form("mu^2 x (fm)^%d",2*(mult-1));
208 }
209 }
210 else the_struct->unit = "Weisskopf";
211
212 the_struct->info += ";TYPE=" + trans_name;
213
214 tmp_rec.remove_all(trans_name);
215 // no info on what are the parenthesis, so we remove it
216 tmp_rec.remove_all("(").remove_all(")");
217
218 // check if the value is known
219 if(tmp_rec.substr(0,1) == "=") {
220 tmp_rec.remove_all("=");
221 auto toks = tmp_rec.tokenize(" ");
222 tkstring val = toks.at(0);
223 tkstring err = "";
224 if(toks.size()>1) err = toks.at(1);
225
226 the_struct->value = val.atof();
227
228 if(!err.is_empty()) {
229 // define precision according to the value string
230 double precision = tkstring::get_precision(val);
231
232 // check if asym errors
233 if(err.contains("+") && err.contains("-")) {
234 bool inv = err.index("-") < err.index("+");
235 err.replace_all("+"," ");
236 err.replace_all("-"," ");
237 auto tokens_lt_err = err.tokenize(" ");
238 if(tokens_lt_err.size()!=2) {
239 glog << error << " bad asymetric error decoding in record " << frecord << do_endl;
240 return;
241 }
242 tkstring err_low_str = tokens_lt_err.back();
243 tkstring err_high_str = tokens_lt_err.front();
244 if(inv) {
245 err_low_str = tokens_lt_err.front();
246 err_high_str = tokens_lt_err.back();
247 }
248
249 the_struct->err_low = err_low_str.atof()*precision;
250 the_struct->err_high = err_high_str.atof()*precision;
251 }
252 else {
253 the_struct->err = err.atof()*precision;
254 }
255 }
256 else
257 the_struct->info += ";ERR=?";
258 }
259 else {
260 tmp_rec.replace_all(">", " GT ").replace_all("<", " LT ");
261
262 auto toks = tmp_rec.tokenize(" ");
263 tkstring lim = toks.at(0);
264 tkstring value = toks.at(1);
265
266 the_struct->value = value.atof();
267 the_struct->info += ";ERR=" + lim;
268 }
269
270 the_struct->filled = true;
271}
272
274{
275 auto tokens = fcontinuation_record.tokenize("$");
276 for(auto &token: tokens) {
277 // check if final level energy is defined
278 if(token.contains("FL=")) {
279 fIs_final_level_set = true;
280 token.remove_all_extra_white_space().remove_all("FL=");
281 const auto final_level_fields = token.tokenize(" ");
282 if(!final_level_fields.empty() && final_level_fields.front().is_float())
283 fFinal_level_energy = final_level_fields.front().atof();
284 else
285 fFinal_level_energy = -1;
286 }
287 if(token.contains("BE") || token.contains("BM")) {
288 set_red_trans_prob(token);
289 }
290 }
291
292 check_red_trans_prob();
293}
294
295void tkensdf_gamma_rec::check_red_trans_prob()
296{
297 if((fBE.filled && !fBEW.filled) || (!fBE.filled && fBEW.filled) || (fBM.filled && !fBMW.filled) || (!fBM.filled && fBMW.filled) ) {
298 double mass = frecord.substr(0,3).atof();
299 if(!fBE.filled && fBEW.filled) {
300 tkstring transname = fBEW.info.tokenize(";").front().remove_all("TYPE=");
301 int mult = transname.substr(2,1).atoi();
302 double conv = weisskopf_conversion(true,mass,mult);
303 fBE.value = fBEW.value*conv;
304 fBE.err = fBEW.err*conv;
305 fBE.err_low = fBEW.err_low*conv;
306 fBE.err_high = fBEW.err_high*conv;
307 fBE.unit = tkstring::form("e^2 x (fm)^%d",2*mult);
308 fBE.info = fBEW.info.copy().replace_all(transname,transname.copy().remove_all("W"));
309 fBE.info += ";ERR=CONV";
310 fBE.filled = true;
311 }
312 if(fBE.filled && !fBEW.filled) {
313 tkstring transname = fBE.info.tokenize(";").front().remove_all("TYPE=");
314 int mult = transname.substr(2,1).atoi();
315 double conv = 1./weisskopf_conversion(true,mass,mult);
316 fBEW.value = fBE.value*conv;
317 fBEW.err = fBE.err*conv;
318 fBEW.err_low = fBE.err_low*conv;
319 fBEW.err_high = fBE.err_high*conv;
320 fBEW.unit = "Weisskopf";
321 fBEW.info = fBE.info.copy().replace_all(transname,transname.copy().append("W"));
322 fBEW.info += ";ERR=CONV";
323 fBEW.filled = true;
324 }
325 if(!fBM.filled && fBMW.filled) {
326 tkstring transname = fBMW.info.tokenize(";").front().remove_all("TYPE=");
327 int mult = transname.substr(2,1).atoi();
328 double conv = weisskopf_conversion(false,mass,mult);
329 fBM.value = fBMW.value*conv;
330 fBM.err = fBMW.err*conv;
331 fBM.err_low = fBMW.err_low*conv;
332 fBM.err_high = fBMW.err_high*conv;
333 if(mult==1) fBM.unit = "mu^2";
334 else fBM.unit = tkstring::form("mu^2 x (fm)^%d",2*(mult-1));
335 fBM.info = fBMW.info.copy().replace_all(transname,transname.copy().remove_all("W"));
336 fBM.info += ";ERR=CONV";
337 fBM.filled = true;
338 }
339 if(fBM.filled && !fBMW.filled) {
340 tkstring transname = fBM.info.tokenize(";").front().remove_all("TYPE=");
341 int mult = transname.substr(2,1).atoi();
342 double conv = 1./weisskopf_conversion(false,mass,mult);
343 fBMW.value = fBM.value*conv;
344 fBMW.err = fBM.err*conv;
345 fBMW.err_low = fBM.err_low*conv;
346 fBMW.err_high = fBM.err_high*conv;
347 fBMW.unit = "Weisskopf";
348 fBMW.info = fBM.info.copy().replace_all(transname,transname.copy().append("W"));
349 fBMW.info += ";ERR=CONV";
350 fBMW.filled = true;
351 }
352 }
353}
354
355double tkensdf_gamma_rec::weisskopf_conversion(bool electric, double mass, double mult)
356{
357 if(electric) return pow(1.2,2.*mult)/(4.*M_PI)*3./(mult+3.)*3./(mult+3.)*pow(mass,2.*mult/3.);
358 return 10./M_PI*pow(1.2,2.*mult-2.)*3./(mult+3.)*3./(mult+3.)*pow(mass,(2.*mult-2.)/3.);
359}
360
362{
364
365 fIs_final_level_set = false;
366 fFinal_level_energy = -1.;
367 frelative_intensity.clear();
368 fmultipolarity.clear();
369 fmixing_ratio.clear();
370 fconv_coeff.clear();
371 fBE.clear();
372 fBEW.clear();
373 fBM.clear();
374 fBMW.clear();
375
376}
377
378void tkensdf_gamma_rec::print(std::ostream &/*out*/) const
379{
380
381}
void print(std::ostream &) const override
void analyse_continuation_record() override
analyse a continuation record
virtual void analyse_record() override
analyse the record content
virtual bool set_record(const tkstring &_record) override
define the record from a string
bool decode_energy(const tkstring &_st)
decode an anergy record
tkstring get_energy_str(const tkstring &_record) const
extract the energy part
std::string with usefull tricks from TString (ROOT) and KVString (KaliVeda) and more....
Definition tkstring.h:33
tkstring strip_all_extra_white_space() const
Definition tkstring.cpp:550
tkstring copy() const
Returns a copy of this string.
Definition tkstring.cpp:377
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
tkstring & remove_all(const tkstring &_s1)
Definition tkstring.h:208
tkstring substr(size_type __pos=0, size_type __n=npos) const
Inlines.
Definition tkstring.h:160
int atoi() const
Converts a string to integer value.
Definition tkstring.cpp:210
size_t index(const char *_s, size_t _pos=0, ECaseCompare _cmp=kExact) const
Returns the index of the substring _s.
Definition tkstring.cpp:237
tkstring & remove_all_extra_white_space()
Definition tkstring.cpp:525
bool contains(const char *_pat, ECaseCompare _cmp=kExact) const
Definition tkstring.h:184
tkstring & append(const tkstring &_st)
Definition tkstring.h:220
static double get_precision(tkstring _st)
Extract the precision for a given ENSDF data.
Definition tkstring.cpp:642
tkstring & replace_all(const tkstring &_s1, const tkstring &_s2)
Definition tkstring.h:196
double atof() const
Converts a string to double value.
Definition tkstring.cpp:226
Definition tklog.cpp:16
tklog & error(tklog &log)
Definition tklog.h:344
tklog & do_endl(tklog &log)
Definition tklog.h:212