TkN 2.4
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
31
32namespace tkn {
33class tkdataset {
34
35 friend class tklevel;
36 friend class tklevel_scheme;
37
38protected:
39
40 int fid{};
41 int fA{};
42 int fZ{};
43 tkstring fname{};
44 tkstring fnucleus{};
45
46 std::vector<shared_ptr<tklevel>> flevels;
47 std::vector<shared_ptr<tkdecay>> fdecays;
48 std::map<int, shared_ptr<tklevel>> fmapoflevels;
49
50 bool floaded = false;
51
52 map<int,shared_ptr<tklevel>> fyrastmap_exact; // 2J -> level
53 map<int,shared_ptr<tklevel>> fyrastmap_uncertain;
54
55public:
56 tkdataset(const tkstring &_nuc,int _zz, int _aa, const tkstring &_name, int _id) : fid(_id), fA(_aa), fZ(_zz), fname(_name), fnucleus(_nuc) {}
57 tkdataset() = default;
58 virtual ~tkdataset() = default;
59
61 int get_id() const {return fid;}
63 const tkstring &get_name() const {return fname;}
65 const tkstring &get_nucleus_name() const {return fnucleus;}
66
68 shared_ptr<tklevel> add_level(double _ener, double _unc, tkstring _unit, tkstring _jpistr);
69
71 shared_ptr<tkgammadecay> add_gamma_decay(shared_ptr<tklevel> _lvlfrom, shared_ptr<tklevel> _lvlto, double _ener=0., double _unc=0.);
72
73protected:
75 void load_dataset();
77 const std::vector<shared_ptr<tklevel>> &get_levels() {return flevels;}
79 const std::vector<shared_ptr<tkdecay>> &get_decays() {return fdecays;}
80
82 void check_yrast(shared_ptr<tklevel> _lvl);
83
85 void print(const tkstring &_data, const tkstring &_option="");
86};
87
89
90protected:
91
92 std::map<tkstring, int> fmap_of_dataset_name_id;
93 std::map<int, shared_ptr<tkdataset>> fmap_of_dataset;
94
95 bool floaded = false;
96
97 int fdatasetid{};
98 tkstring fnucleus;
99
100 int fA, fZ;
101
102public:
103 tklevel_scheme(const tkstring &_nuc, int _zz, int _aa);
104 virtual ~tklevel_scheme() = default;
105
107 bool select_dataset(const tkstring &_dataset_name);
109 bool select_dataset(int _dataset_id=0);
110
112 const shared_ptr<tkdataset> &get_dataset() {return fmap_of_dataset[fdatasetid];}
114 const std::map<int, shared_ptr<tkdataset>> &get_datasets() const {return fmap_of_dataset;}
115
117 const std::vector<shared_ptr<tklevel>> &get_levels() {return fmap_of_dataset[fdatasetid]->get_levels();}
119 std::vector<shared_ptr<tklevel>> get_levels(std::function<bool(shared_ptr<tklevel>)>const& _selection);
120
122 const std::vector<shared_ptr<tkdecay>> &get_decays() {return fmap_of_dataset[fdatasetid]->get_decays();}
124 std::vector<shared_ptr<tkdecay>> get_decays(std::function<bool(shared_ptr<tkdecay>)>const& _selection);
125
132 template<typename T>
133 const std::vector<shared_ptr<T>> get_decays() {
134 std::vector<shared_ptr<T>> decays;
135 for(const auto &dec: get_decays()) {
136 auto test = dynamic_pointer_cast<T>(dec);
137 if(test) {
138 shared_ptr<T> gam = dynamic_pointer_cast<T>(dec);
139 decays.push_back(gam);
140 }
141 }
142 return decays;
143 }
144
157 template<typename T>
158 const std::vector<shared_ptr<T>> get_decays(const std::function<bool (shared_ptr<T>)> &_selection) {
159 vector<shared_ptr<T>> res;
160 const auto &decays = get_decays<T>();
161 std::copy_if(decays.begin(), decays.end(), std::back_inserter(res),
162 [&_selection](const auto &dec) { return _selection(dec); });
163 return res;
164 }
165
167 shared_ptr<tklevel> get_level(const tkstring &_name, bool _exact=true);
168
170 shared_ptr<tklevel> get_level(double _energy, tkstring _offset="");
171
183 template<typename T>
184 const shared_ptr<T> get_decay(const tkstring &_name, bool _exact=true) {
185 std::vector<tkstring> lvls = _name.tokenize_from_string("->");
186 if(lvls.size()!=2) {glog << warning << "get_decay(" << _name << ") -- wrong syntax (ex: 2+1->0+1)" << do_endl; return nullptr;}
187 shared_ptr<tklevel> lvl_from = get_level(lvls.at(0),_exact);
188 shared_ptr<tklevel> lvl_to = get_level(lvls.at(1),_exact);
189 if(!lvl_from) {glog << warning << "get_decay(" << _name << ") -- " << lvls.at(0) << " level not found" << do_endl; return nullptr;}
190 if(!lvl_to) {glog << warning << "get_decay(" << _name << ") -- " << lvls.at(1) << " level not found" << do_endl; return nullptr;}
191 int lvl_from_id = lvl_from->get_id();
192 int lvl_to_id = lvl_to->get_id();
193 for(auto dec : get_decays<T>()) {
194 if((dec->get_level_from_id() == lvl_from_id) && (dec->get_level_to_id() == lvl_to_id)) return dec;
195 }
196 return nullptr;
197 }
198
209 template<typename T>
210 const shared_ptr<T> get_decay(double _energy) {
211 shared_ptr<T> clostest_dec;
212 double best_ediff=1e6;
213 for(auto &dec: get_decays<T>()) {
214 double ediff = abs(dec->get_energy()-_energy);
215 if(ediff<best_ediff) {
216 best_ediff=ediff;
217 clostest_dec = dec;
218 }
219 }
220 return clostest_dec;
221 }
222
224 void print(const tkstring &_data="", const tkstring &_option="");
225
226private:
227 void init();
228
229#ifdef HAS_ROOT
231 ClassDef(tklevel_scheme,0);
232#endif
233};
234}
235
236#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
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
tkdataset()=default
friend class tklevel
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
virtual ~tklevel_scheme()=default
tklevel_scheme(const tkstring &_nuc, int _zz, int _aa)
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
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:31
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:271
Definition tklog.cpp:16
tklog & do_endl(tklog &log)
Definition tklog.h:212
tklog & warning(tklog &log)
Definition tklog.h:331