TkN 2.7.1
Toolkit for Nuclei
Loading...
Searching...
No Matches
tklevel_scheme.h
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#ifndef tklevel_scheme_H
15#define tklevel_scheme_H
16
17#include <algorithm>
18#include <functional>
19#include <iterator>
20#include <map>
21#include <vector>
22
23#include "tkn_config.h"
24#include "tklevel.h"
25#include "tkdecay.h"
26
27#ifdef HAS_ROOT
28#include "TClass.h"
29#endif
30
31namespace tkn {
32
43class tkdataset {
44
45 friend class tklevel;
46 friend class tklevel_scheme;
47
48protected:
49 int fid{};
50 int fA{};
51 int fZ{};
52 tkstring fname{};
53 tkstring fnucleus{};
54 tkstring fdataset_comment{};
55 tkstring fdataset_date{};
56 tkstring fdataset_source{};
57
58 std::vector<shared_ptr<tklevel>> flevels;
59 std::vector<shared_ptr<tkdecay>> fdecays;
60 std::map<int, shared_ptr<tklevel>> fmapoflevels;
61
62 bool floaded = false;
63
64 map<int, shared_ptr<tklevel>> fyrastmap_exact; // 2J -> level
65 map<int, shared_ptr<tklevel>> fyrastmap_uncertain;
66
67public:
68 tkdataset(const tkstring &_nuc, int _zz, int _aa, const tkstring &_name, int _id) : fid(_id), fA(_aa), fZ(_zz), fname(_name), fnucleus(_nuc) {}
69 tkdataset() = default;
70 virtual ~tkdataset() = default;
71
73 int get_id() const { return fid; }
75 const tkstring &get_name() const { return fname; }
77 const tkstring &get_nucleus_name() const { return fnucleus; }
79 const tkstring &get_comment() const { return fdataset_comment; }
81 bool has_comment() const { return !fdataset_comment.is_empty(); }
83 const tkstring &get_date() const { return fdataset_date; }
85 bool has_date() const { return !fdataset_date.is_empty(); }
87 const tkstring &get_source() const { return fdataset_source; }
89 bool is_xundl() const { return fdataset_source == "XUNDL"; }
90
92 shared_ptr<tklevel> add_level(double _ener, double _unc, tkstring _unit, tkstring _jpistr);
93
95 shared_ptr<tkgammadecay> add_gamma_decay(shared_ptr<tklevel> _lvlfrom, shared_ptr<tklevel> _lvlto, double _ener = 0., double _unc = 0.);
96
97protected:
99 void load_dataset();
101 const std::vector<shared_ptr<tklevel>> &get_levels() { return flevels; }
103 const std::vector<shared_ptr<tkdecay>> &get_decays() { return fdecays; }
104
106 void check_yrast(shared_ptr<tklevel> _lvl);
107
109 void print(const tkstring &_data, const tkstring &_option = "");
110};
111
137
138protected:
139 std::map<tkstring, int> fmap_of_dataset_name_id;
140 std::map<int, shared_ptr<tkdataset>> fmap_of_dataset;
141
142 bool floaded = false;
143
144 int fdatasetid{};
145 tkstring fnucleus;
146
147 int fA, fZ;
148
149public:
150 tklevel_scheme(const tkstring &_nuc, int _zz, int _aa, bool _load_default_dataset = true);
151 virtual ~tklevel_scheme() = default;
152
154 bool select_dataset(const tkstring &_dataset_name);
156 bool select_dataset(int _dataset_id = 0);
157
160 shared_ptr<tklevel> get_ground_state();
161
163 const shared_ptr<tkdataset> &get_dataset() { return fmap_of_dataset[fdatasetid]; }
165 const std::map<int, shared_ptr<tkdataset>> &get_datasets() const { return fmap_of_dataset; }
166
168 const std::vector<shared_ptr<tklevel>> &get_levels() { return fmap_of_dataset[fdatasetid]->get_levels(); }
170 std::vector<shared_ptr<tklevel>> get_levels(std::function<bool(shared_ptr<tklevel>)> const &_selection);
171
173 const std::vector<shared_ptr<tkdecay>> &get_decays() { return fmap_of_dataset[fdatasetid]->get_decays(); }
175 std::vector<shared_ptr<tkdecay>> get_decays(std::function<bool(shared_ptr<tkdecay>)> const &_selection);
176
183 template <typename T>
184 const std::vector<shared_ptr<T>> get_decays()
185 {
186 std::vector<shared_ptr<T>> decays;
187 for (const auto &dec : get_decays()) {
188 auto test = dynamic_pointer_cast<T>(dec);
189 if (test) {
190 shared_ptr<T> gam = dynamic_pointer_cast<T>(dec);
191 decays.push_back(gam);
192 }
193 }
194 return decays;
195 }
196
209 template <typename T>
210 const std::vector<shared_ptr<T>> get_decays(const std::function<bool(shared_ptr<T>)> &_selection)
211 {
212 vector<shared_ptr<T>> res;
213 const auto &decays = get_decays<T>();
214 std::copy_if(decays.begin(), decays.end(), std::back_inserter(res),
215 [&_selection](const auto &dec) { return _selection(dec); });
216 return res;
217 }
218
220 shared_ptr<tklevel> get_level(const tkstring &_name, bool _exact = true);
221
223 shared_ptr<tklevel> get_level(double _energy, tkstring _offset = "");
225 shared_ptr<tklevel> get_level(double _energy, const char *_offset)
226 { return get_level(_energy, tkstring(_offset)); }
227
239 template <typename T>
240 const shared_ptr<T> get_decay(const tkstring &_name, bool _exact = true)
241 {
242 std::vector<tkstring> lvls = _name.tokenize_from_string("->");
243 if (lvls.size() != 2) {
244 glog << warning << "get_decay(" << _name << ") -- wrong syntax (ex: 2+1->0+1)" << do_endl;
245 return nullptr;
246 }
247 shared_ptr<tklevel> lvl_from = get_level(lvls.at(0), _exact);
248 shared_ptr<tklevel> lvl_to = get_level(lvls.at(1), _exact);
249 if (!lvl_from) {
250 glog << warning << "get_decay(" << _name << ") -- " << lvls.at(0) << " level not found" << do_endl;
251 return nullptr;
252 }
253 if (!lvl_to) {
254 glog << warning << "get_decay(" << _name << ") -- " << lvls.at(1) << " level not found" << do_endl;
255 return nullptr;
256 }
257 int lvl_from_id = lvl_from->get_id();
258 int lvl_to_id = lvl_to->get_id();
259 for (auto dec : get_decays<T>()) {
260 if ((dec->get_level_from_id() == lvl_from_id) && (dec->get_level_to_id() == lvl_to_id)) return dec;
261 }
262 return nullptr;
263 }
264
275 template <typename T>
276 const shared_ptr<T> get_decay(double _energy)
277 {
278 shared_ptr<T> clostest_dec;
279 double best_ediff = 1e6;
280 for (auto &dec : get_decays<T>()) {
281 double ediff = abs(dec->get_energy() - _energy);
282 if (ediff < best_ediff) {
283 best_ediff = ediff;
284 clostest_dec = dec;
285 }
286 }
287 return clostest_dec;
288 }
289
291 void print(const tkstring &_data = "", const tkstring &_option = "");
292
293private:
294 void init(bool _load_default_dataset);
295
296#ifdef HAS_ROOT
298 ClassDef(tklevel_scheme, 0);
299#endif
300};
301} // namespace tkn
302
303#endif
shared_ptr< tklevel > add_level(double _ener, double _unc, tkstring _unit, tkstring _jpistr)
manually add a new level to the dataset
virtual ~tkdataset()=default
const tkstring & get_comment() const
returns the dataset comment
shared_ptr< tkgammadecay > add_gamma_decay(shared_ptr< tklevel > _lvlfrom, shared_ptr< tklevel > _lvlto, double _ener=0., double _unc=0.)
add a new decay between two levels to the dataset
bool has_comment() const
returns true if the dataset has a comment
tkdataset()=default
friend class tklevel
const tkstring & get_source() const
returns the dataset source ("ENSDF" or "XUNDL")
bool is_xundl() const
returns true if the dataset comes from XUNDL
bool has_date() const
returns true if the dataset has a date
const tkstring & get_name() const
returns the dataset name
tkdataset(const tkstring &_nuc, int _zz, int _aa, const tkstring &_name, int _id)
const tkstring & get_nucleus_name() const
returns the nucleus name associated to this dataset
friend class tklevel_scheme
int get_id() const
returns the dataset ID
const tkstring & get_date() const
returns the dataset date (YYYY-MM format)
Manages the available datasets for a given nucleus.
virtual ~tklevel_scheme()=default
void print(const tkstring &_data="", const tkstring &_option="")
print the level scheme information
const std::vector< shared_ptr< tklevel > > & get_levels()
get the vector containing all the levels
const shared_ptr< T > get_decay(double _energy)
Template method to get the decay of type T (ex: tkgammadecay) corresponding to the closest energy.
shared_ptr< tklevel > get_ground_state()
const std::vector< shared_ptr< T > > get_decays()
Template method to get the vector containing all the decays of type T (ex: tkgammadecay)
const std::map< int, shared_ptr< tkdataset > > & get_datasets() const
returns the list of available datasets
const shared_ptr< T > get_decay(const tkstring &_name, bool _exact=true)
Template method to get the decay of type T (ex: tkgammadecay) corresponding to the given name.
bool select_dataset(const tkstring &_dataset_name)
select a dataset using its name
const std::vector< shared_ptr< T > > get_decays(const std::function< bool(shared_ptr< T >)> &_selection)
Template method to get the vector containing all the decays of type T (ex: tkgammadecay) filtered by ...
const shared_ptr< tkdataset > & get_dataset()
returns the current dataset
shared_ptr< tklevel > get_level(double _energy, const char *_offset)
Avoid ambiguity with the spin-name overload for get_level(E, "dec").
shared_ptr< tklevel > get_level(const tkstring &_name, bool _exact=true)
get the level corresponding to the given name
tklevel_scheme(const tkstring &_nuc, int _zz, int _aa, bool _load_default_dataset=true)
const std::vector< shared_ptr< tkdecay > > & get_decays()
get the vector containing all the decays
std::string with usefull tricks from TString (ROOT) and KVString (KaliVeda) and more....
Definition tkstring.h:33
std::vector< tkstring > tokenize_from_string(const tkstring &_delim) const
Create a vector of string separated by a full string as delimiter.
Definition tkstring.cpp:312
Definition tklog.cpp:16
tklog & do_endl(tklog &log)
Definition tklog.h:212
tklog & warning(tklog &log)
Definition tklog.h:331