TkN 2.4
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);
75 auto DRI_str = _record.substr(29,2);
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 frelative_intensity.err = DRI_str.atof();
87}
88
89void tkensdf_gamma_rec::set_multipolarity(const tkstring &_record)
90{
91 auto str = _record.substr(31,10);
92 if(!str.is_empty()) fmultipolarity = str.remove_all_extra_white_space();
93}
94
95void tkensdf_gamma_rec::set_mixing_ratio(const tkstring &_record)
96{
97 auto MR_str = _record.substr(41,8).strip_all_extra_white_space();
98 auto DMR_str = _record.substr(49,6).strip_all_extra_white_space();
99
100 fmixing_ratio.value = MR_str.atof();
101 if(fmixing_ratio.value==0) return;
102
103 if(!DMR_str.is_empty()) {
104
105 if(DMR_str.is_alpha()) {
106 fmixing_ratio.info += ";ERR=" + DMR_str;
107 }
108 else {
109 // define precision according to the value string
110 double precision = tkstring::get_precision(MR_str);
111
112 // check if asym errors
113 if(DMR_str.contains("+") && DMR_str.contains("-")) {
114 bool inv = DMR_str.index("-") < DMR_str.index("+");
115 DMR_str.replace_all("+"," ");
116 DMR_str.replace_all("-"," ");
117 auto tokens_lt_err = DMR_str.tokenize(" ");
118 if(tokens_lt_err.size()!=2) {
119 glog << error << " bad asymetric error decoding in record " << frecord << do_endl;
120 return;
121 }
122 tkstring err_low_str = tokens_lt_err.back();
123 tkstring err_high_str = tokens_lt_err.front();
124 if(inv) {
125 err_low_str = tokens_lt_err.front();
126 err_high_str = tokens_lt_err.back();
127 }
128
129 fmixing_ratio.err_low = err_low_str.atof()*precision;
130 fmixing_ratio.err_high = err_high_str.atof()*precision;
131 }
132 else {
133 fmixing_ratio.err = DMR_str.atof()*precision;
134 }
135 }
136 }
137 else
138 fmixing_ratio.info += ";ERR=?";
139
140 fmixing_ratio.filled = true;
141}
142
143void tkensdf_gamma_rec::set_conv_coeff(const tkstring &_record)
144{
145 auto CC_str = _record.substr(55,7);
146 auto DCC_str = _record.substr(62,2);
147
148 fconv_coeff.value = CC_str.atof();
149 if(fconv_coeff.value>0) fconv_coeff.filled = true;
150 else return;
151
152 fconv_coeff.unit = "";
153 fconv_coeff.err = DCC_str.atof();
154}
155
156void tkensdf_gamma_rec::set_red_trans_prob(const tkstring &_record)
157{
158 auto tmp_rec = _record;
160
161 tkstring trans_name{};
162
163 bool is_elec=false;
164 bool is_mag=false;
165 if(tmp_rec.begins_with("BM")) {
166 is_mag=true;
167 trans_name += "BM";
168 }
169 if(tmp_rec.begins_with("BE")) {
170 is_elec=true;
171 trans_name += "BE";
172 }
173 if(!(is_elec || is_mag)) return;
174
175 trans_name += tmp_rec[2];
176 int mult = tmp_rec.substr(2,1).atoi();
177
178 bool wu = (tmp_rec.substr(3,1) == "W");
179 if(wu) trans_name += "W";
180
181 tkdb_table::measure_data_struct *the_struct=nullptr;
182 if(is_elec && wu) the_struct = &fBEW;
183 else if(is_elec && !wu) the_struct = &fBE;
184 else if(is_mag && wu) the_struct = &fBMW;
185 else if(is_mag && !wu) the_struct = &fBM;
186 if(!the_struct) return;
187 if(the_struct->filled) return;
188
189 if(!wu) {
190 if(is_elec) {
191 the_struct->value *= pow(100,mult);
192 the_struct->err *= pow(100,mult);
193 the_struct->err_low *= pow(100,mult);
194 the_struct->err_high *= pow(100,mult);
195 the_struct->unit = tkstring::form("e^2 x (fm)^%d",mult*2);
196 }
197 else {
198 the_struct->value *= pow(100,mult-1);
199 the_struct->err *= pow(100,mult-1);
200 the_struct->err_low *= pow(100,mult-1);
201 the_struct->err_high *= pow(100,mult-1);
202 if(mult==1) the_struct->unit = "mu^2";
203 else the_struct->unit = tkstring::form("mu^2 x (fm)^%d",2*(mult-1));
204 }
205 }
206 else the_struct->unit = "Weisskopf";
207
208 the_struct->info += ";TYPE=" + trans_name;
209
210 tmp_rec.remove_all(trans_name);
211 // no info on what are the parenthesis, so we remove it
212 tmp_rec.remove_all("(").remove_all(")");
213
214 // check if the value is known
215 if(tmp_rec.substr(0,1) == "=") {
216 tmp_rec.remove_all("=");
217 auto toks = tmp_rec.tokenize(" ");
218 tkstring val = toks.at(0);
219 tkstring err = "";
220 if(toks.size()>1) err = toks.at(1);
221
222 the_struct->value = val.atof();
223
224 if(!err.is_empty()) {
225 // define precision according to the value string
226 double precision = tkstring::get_precision(val);
227
228 // check if asym errors
229 if(err.contains("+") && err.contains("-")) {
230 bool inv = err.index("-") < err.index("+");
231 err.replace_all("+"," ");
232 err.replace_all("-"," ");
233 auto tokens_lt_err = err.tokenize(" ");
234 if(tokens_lt_err.size()!=2) {
235 glog << error << " bad asymetric error decoding in record " << frecord << do_endl;
236 return;
237 }
238 tkstring err_low_str = tokens_lt_err.back();
239 tkstring err_high_str = tokens_lt_err.front();
240 if(inv) {
241 err_low_str = tokens_lt_err.front();
242 err_high_str = tokens_lt_err.back();
243 }
244
245 the_struct->err_low = err_low_str.atof()*precision;
246 the_struct->err_high = err_high_str.atof()*precision;
247 }
248 else {
249 the_struct->err = err.atof()*precision;
250 }
251 }
252 else
253 the_struct->info += ";ERR=?";
254 }
255 else {
256 tmp_rec.replace_all(">", " GT ").replace_all("<", " LT ");
257
258 auto toks = tmp_rec.tokenize(" ");
259 tkstring lim = toks.at(0);
260 tkstring value = toks.at(1);
261
262 the_struct->value = value.atof();
263 the_struct->info += ";ERR=" + lim;
264 }
265
266 the_struct->filled = true;
267}
268
270{
271 auto tokens = fcontinuation_record.tokenize("$");
272 for(auto &token: tokens) {
273 // check if final level energy is defined
274 if(token.contains("FL=")) {
275 fIs_final_level_set = true;
276 token.remove_all_extra_white_space().remove_all("FL=");
277 if(token.is_float()) fFinal_level_energy = token.atof();
278 else fFinal_level_energy = -1;
279 }
280 if(token.contains("BE") || token.contains("BM")) {
281 set_red_trans_prob(token);
282 }
283 }
284
285 check_red_trans_prob();
286}
287
288void tkensdf_gamma_rec::check_red_trans_prob()
289{
290 if((fBE.filled && !fBEW.filled) || (!fBE.filled && fBEW.filled) || (fBM.filled && !fBMW.filled) || (!fBM.filled && fBMW.filled) ) {
291 double mass = frecord.substr(0,3).atof();
292 if(!fBE.filled && fBEW.filled) {
293 tkstring transname = fBEW.info.tokenize(";").front().remove_all("TYPE=");
294 int mult = transname.substr(2,1).atoi();
295 double conv = weisskopf_conversion(true,mass,mult);
296 fBE.value = fBEW.value*conv;
297 fBE.err = fBEW.err*conv;
298 fBE.err_low = fBEW.err_low*conv;
299 fBE.err_high = fBEW.err_high*conv;
300 fBE.unit = tkstring::form("e^2 x (fm)^%d",2*mult);
301 fBE.info = fBEW.info.copy().replace_all(transname,transname.copy().remove_all("W"));
302 fBE.info += ";ERR=CONV";
303 fBE.filled = true;
304 }
305 if(fBE.filled && !fBEW.filled) {
306 tkstring transname = fBE.info.tokenize(";").front().remove_all("TYPE=");
307 int mult = transname.substr(2,1).atoi();
308 double conv = 1./weisskopf_conversion(true,mass,mult);
309 fBEW.value = fBE.value*conv;
310 fBEW.err = fBE.err*conv;
311 fBEW.err_low = fBE.err_low*conv;
312 fBEW.err_high = fBE.err_high*conv;
313 fBEW.unit = "Weisskopf";
314 fBEW.info = fBE.info.copy().replace_all(transname,transname.copy().append("W"));
315 fBEW.info += ";ERR=CONV";
316 fBEW.filled = true;
317 }
318 if(!fBM.filled && fBMW.filled) {
319 tkstring transname = fBMW.info.tokenize(";").front().remove_all("TYPE=");
320 int mult = transname.substr(2,1).atoi();
321 double conv = weisskopf_conversion(false,mass,mult);
322 fBM.value = fBMW.value*conv;
323 fBM.err = fBMW.err*conv;
324 fBM.err_low = fBMW.err_low*conv;
325 fBM.err_high = fBMW.err_high*conv;
326 if(mult==1) fBM.unit = "mu^2";
327 else fBM.unit = tkstring::form("mu^2 x (fm)^%d",2*(mult-1));
328 fBM.info = fBMW.info.copy().replace_all(transname,transname.copy().remove_all("W"));
329 fBM.info += ";ERR=CONV";
330 fBM.filled = true;
331 }
332 if(fBM.filled && !fBMW.filled) {
333 tkstring transname = fBM.info.tokenize(";").front().remove_all("TYPE=");
334 int mult = transname.substr(2,1).atoi();
335 double conv = 1./weisskopf_conversion(false,mass,mult);
336 fBMW.value = fBM.value*conv;
337 fBMW.err = fBM.err*conv;
338 fBMW.err_low = fBM.err_low*conv;
339 fBMW.err_high = fBM.err_high*conv;
340 fBMW.unit = "Weisskopf";
341 fBMW.info = fBM.info.copy().replace_all(transname,transname.copy().append("W"));
342 fBMW.info += ";ERR=CONV";
343 fBMW.filled = true;
344 }
345 }
346}
347
348double tkensdf_gamma_rec::weisskopf_conversion(bool electric, double mass, double mult)
349{
350 if(electric) return pow(1.2,2.*mult)/(4.*M_PI)*3./(mult+3.)*3./(mult+3.)*pow(mass,2.*mult/3.);
351 return 10./M_PI*pow(1.2,2.*mult-2.)*3./(mult+3.)*3./(mult+3.)*pow(mass,(2.*mult-2.)/3.);
352}
353
355{
357
358 fIs_final_level_set = false;
359 fFinal_level_energy = -1.;
360 frelative_intensity.clear();
361 fmultipolarity.clear();
362 fmixing_ratio.clear();
363 fconv_coeff.clear();
364 fBE.clear();
365 fBEW.clear();
366 fBM.clear();
367 fBMW.clear();
368
369}
370
371void tkensdf_gamma_rec::print(std::ostream &/*out*/) const
372{
373
374}
375
376
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:31
tkstring strip_all_extra_white_space() const
Definition tkstring.cpp:537
tkstring copy() const
Returns a copy of this string.
Definition tkstring.cpp:347
static const char * form(const char *_format,...)
Definition tkstring.cpp:408
std::vector< tkstring > tokenize(const tkstring &_delim=" ") const
Create a vector of string separated by at least one delimiter.
Definition tkstring.cpp:231
bool is_empty() const
Definition tkstring.h:140
tkstring & remove_all(const tkstring &_s1)
Definition tkstring.h:192
tkstring substr(size_type __pos=0, size_type __n=npos) const
Inlines.
Definition tkstring.h:156
int atoi() const
Converts a string to integer value.
Definition tkstring.cpp:152
size_t index(const char *_s, size_t _pos=0, ECaseCompare _cmp=kExact) const
Returns the index of the substring _s.
Definition tkstring.cpp:195
tkstring & remove_all_extra_white_space()
Definition tkstring.cpp:503
bool contains(const char *_pat, ECaseCompare _cmp=kExact) const
Definition tkstring.h:174
tkstring & append(const tkstring &_st)
Definition tkstring.h:204
static double get_precision(tkstring _st)
Extract the precision for a given ENSDF data.
Definition tkstring.cpp:626
tkstring & replace_all(const tkstring &_s1, const tkstring &_s2)
Definition tkstring.h:180
double atof() const
Converts a string to double value.
Definition tkstring.cpp:168
Definition tklog.cpp:16
tklog & error(tklog &log)
Definition tklog.h:344
tklog & do_endl(tklog &log)
Definition tklog.h:212