TkN 2.5
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
133
134protected:
135 std::map<tkstring, int> fmap_of_dataset_name_id;
136 std::map<int, shared_ptr<tkdataset>> fmap_of_dataset;
137
138 bool floaded = false;
139
140 int fdatasetid{};
141 tkstring fnucleus;
142
143 int fA, fZ;
144
145public:
146 tklevel_scheme(const tkstring &_nuc, int _zz, int _aa, bool _load_default_dataset = true);
147 virtual ~tklevel_scheme() = default;
148
150 bool select_dataset(const tkstring &_dataset_name);
152 bool select_dataset(int _dataset_id = 0);
153
155 const shared_ptr<tkdataset> &get_dataset() { return fmap_of_dataset[fdatasetid]; }
157 const std::map<int, shared_ptr<tkdataset>> &get_datasets() const { return fmap_of_dataset; }
158
160 const std::vector<shared_ptr<tklevel>> &get_levels() { return fmap_of_dataset[fdatasetid]->get_levels(); }
162 std::vector<shared_ptr<tklevel>> get_levels(std::function<bool(shared_ptr<tklevel>)> const &_selection);
163
165 const std::vector<shared_ptr<tkdecay>> &get_decays() { return fmap_of_dataset[fdatasetid]->get_decays(); }
167 std::vector<shared_ptr<tkdecay>> get_decays(std::function<bool(shared_ptr<tkdecay>)> const &_selection);
168
175 template <typename T>
176 const std::vector<shared_ptr<T>> get_decays()
177 {
178 std::vector<shared_ptr<T>> decays;
179 for (const auto &dec : get_decays()) {
180 auto test = dynamic_pointer_cast<T>(dec);
181 if (test) {
182 shared_ptr<T> gam = dynamic_pointer_cast<T>(dec);
183 decays.push_back(gam);
184 }
185 }
186 return decays;
187 }
188
201 template <typename T>
202 const std::vector<shared_ptr<T>> get_decays(const std::function<bool(shared_ptr<T>)> &_selection)
203 {
204 vector<shared_ptr<T>> res;
205 const auto &decays = get_decays<T>();
206 std::copy_if(decays.begin(), decays.end(), std::back_inserter(res),
207 [&_selection](const auto &dec) { return _selection(dec); });
208 return res;
209 }
210
212 shared_ptr<tklevel> get_level(const tkstring &_name, bool _exact = true);
213
215 shared_ptr<tklevel> get_level(double _energy, tkstring _offset = "");
216
228 template <typename T>
229 const shared_ptr<T> get_decay(const tkstring &_name, bool _exact = true)
230 {
231 std::vector<tkstring> lvls = _name.tokenize_from_string("->");
232 if (lvls.size() != 2) {
233 glog << warning << "get_decay(" << _name << ") -- wrong syntax (ex: 2+1->0+1)" << do_endl;
234 return nullptr;
235 }
236 shared_ptr<tklevel> lvl_from = get_level(lvls.at(0), _exact);
237 shared_ptr<tklevel> lvl_to = get_level(lvls.at(1), _exact);
238 if (!lvl_from) {
239 glog << warning << "get_decay(" << _name << ") -- " << lvls.at(0) << " level not found" << do_endl;
240 return nullptr;
241 }
242 if (!lvl_to) {
243 glog << warning << "get_decay(" << _name << ") -- " << lvls.at(1) << " level not found" << do_endl;
244 return nullptr;
245 }
246 int lvl_from_id = lvl_from->get_id();
247 int lvl_to_id = lvl_to->get_id();
248 for (auto dec : get_decays<T>()) {
249 if ((dec->get_level_from_id() == lvl_from_id) && (dec->get_level_to_id() == lvl_to_id)) return dec;
250 }
251 return nullptr;
252 }
253
264 template <typename T>
265 const shared_ptr<T> get_decay(double _energy)
266 {
267 shared_ptr<T> clostest_dec;
268 double best_ediff = 1e6;
269 for (auto &dec : get_decays<T>()) {
270 double ediff = abs(dec->get_energy() - _energy);
271 if (ediff < best_ediff) {
272 best_ediff = ediff;
273 clostest_dec = dec;
274 }
275 }
276 return clostest_dec;
277 }
278
280 void print(const tkstring &_data = "", const tkstring &_option = "");
281
282private:
283 void init(bool _load_default_dataset);
284
285#ifdef HAS_ROOT
287 ClassDef(tklevel_scheme, 0);
288#endif
289};
290} // namespace tkn
291
292#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.
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(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:32
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:315
Definition tklog.cpp:16
tklog & do_endl(tklog &log)
Definition tklog.h:212
tklog & warning(tklog &log)
Definition tklog.h:331