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