TkN 2.3
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 * 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#ifndef tklevel_scheme_H
38#define tklevel_scheme_H
39
40#include <algorithm>
41#include <functional>
42#include <iterator>
43#include <map>
44#include <vector>
45
46#include "tkn_config.h"
47#include "tklevel.h"
48#include "tkdecay.h"
49
50#ifdef HAS_ROOT
51#include "TClass.h"
52#endif
53
54
55namespace tkn {
56class tkdataset {
57
58 friend class tklevel;
59 friend class tklevel_scheme;
60
61protected:
62
63 int fid{};
64 int fA{};
65 int fZ{};
66 tkstring fname{};
67 tkstring fnucleus{};
68
69 std::vector<shared_ptr<tklevel>> flevels;
70 std::vector<shared_ptr<tkdecay>> fdecays;
71 std::map<int, shared_ptr<tklevel>> fmapoflevels;
72
73 bool floaded = false;
74
75 map<int,shared_ptr<tklevel>> fyrastmap_exact; // 2J -> level
76 map<int,shared_ptr<tklevel>> fyrastmap_uncertain;
77
78public:
79 tkdataset(const tkstring &_nuc,int _zz, int _aa, const tkstring &_name, int _id) : fid(_id), fA(_aa), fZ(_zz), fname(_name), fnucleus(_nuc) {}
80 tkdataset() = default;
81 virtual ~tkdataset() = default;
82
84 int get_id() const {return fid;}
86 const tkstring &get_name() const {return fname;}
88 const tkstring &get_nucleus_name() const {return fnucleus;}
89
91 shared_ptr<tklevel> add_level(double _ener, double _unc, tkstring _unit, tkstring _jpistr);
92
94 shared_ptr<tkgammadecay> add_gamma_decay(shared_ptr<tklevel> _lvlfrom, shared_ptr<tklevel> _lvlto, double _ener=0., double _unc=0.);
95
96protected:
98 void load_dataset();
100 const std::vector<shared_ptr<tklevel>> &get_levels() {return flevels;}
102 const std::vector<shared_ptr<tkdecay>> &get_decays() {return fdecays;}
103
105 void check_yrast(shared_ptr<tklevel> _lvl);
106
108 void print(const tkstring &_data, const tkstring &_option="");
109};
110
112
113protected:
114
115 std::map<tkstring, int> fmap_of_dataset_name_id;
116 std::map<int, shared_ptr<tkdataset>> fmap_of_dataset;
117
118 bool floaded = false;
119
120 int fdatasetid{};
121 tkstring fnucleus;
122
123 int fA, fZ;
124
125public:
126 tklevel_scheme(const tkstring &_nuc, int _zz, int _aa);
127 virtual ~tklevel_scheme() = default;
128
130 bool select_dataset(const tkstring &_dataset_name);
132 bool select_dataset(int _dataset_id=0);
133
135 const shared_ptr<tkdataset> &get_dataset() {return fmap_of_dataset[fdatasetid];}
137 const std::map<int, shared_ptr<tkdataset>> &get_datasets() const {return fmap_of_dataset;}
138
140 const std::vector<shared_ptr<tklevel>> &get_levels() {return fmap_of_dataset[fdatasetid]->get_levels();}
142 std::vector<shared_ptr<tklevel>> get_levels(std::function<bool(shared_ptr<tklevel>)>const& _selection);
143
145 const std::vector<shared_ptr<tkdecay>> &get_decays() {return fmap_of_dataset[fdatasetid]->get_decays();}
147 std::vector<shared_ptr<tkdecay>> get_decays(std::function<bool(shared_ptr<tkdecay>)>const& _selection);
148
155 template<typename T>
156 const std::vector<shared_ptr<T>> get_decays() {
157 std::vector<shared_ptr<T>> decays;
158 for(const auto &dec: get_decays()) {
159 auto test = dynamic_pointer_cast<T>(dec);
160 if(test) {
161 shared_ptr<T> gam = dynamic_pointer_cast<T>(dec);
162 decays.push_back(gam);
163 }
164 }
165 return decays;
166 }
167
180 template<typename T>
181 const std::vector<shared_ptr<T>> get_decays(const std::function<bool (shared_ptr<T>)> &_selection) {
182 vector<shared_ptr<T>> res;
183 const auto &decays = get_decays<T>();
184 std::copy_if(decays.begin(), decays.end(), std::back_inserter(res),
185 [&_selection](const auto &dec) { return _selection(dec); });
186 return res;
187 }
188
190 shared_ptr<tklevel> get_level(const tkstring &_name, bool _exact=true);
191
193 shared_ptr<tklevel> get_level(double _energy, tkstring _offset="");
194
206 template<typename T>
207 const shared_ptr<T> get_decay(const tkstring &_name, bool _exact=true) {
208 std::vector<tkstring> lvls = _name.tokenize_from_string("->");
209 if(lvls.size()!=2) {glog << warning << "get_decay(" << _name << ") -- wrong syntax (ex: 2+1->0+1)" << do_endl; return nullptr;}
210 shared_ptr<tklevel> lvl_from = get_level(lvls.at(0),_exact);
211 shared_ptr<tklevel> lvl_to = get_level(lvls.at(1),_exact);
212 if(!lvl_from) {glog << warning << "get_decay(" << _name << ") -- " << lvls.at(0) << " level not found" << do_endl; return nullptr;}
213 if(!lvl_to) {glog << warning << "get_decay(" << _name << ") -- " << lvls.at(1) << " level not found" << do_endl; return nullptr;}
214 int lvl_from_id = lvl_from->get_id();
215 int lvl_to_id = lvl_to->get_id();
216 for(auto dec : get_decays<T>()) {
217 if((dec->get_level_from_id() == lvl_from_id) && (dec->get_level_to_id() == lvl_to_id)) return dec;
218 }
219 return nullptr;
220 }
221
232 template<typename T>
233 const shared_ptr<T> get_decay(double _energy) {
234 shared_ptr<T> clostest_dec;
235 double best_ediff=1e6;
236 for(auto &dec: get_decays<T>()) {
237 double ediff = abs(dec->get_energy()-_energy);
238 if(ediff<best_ediff) {
239 best_ediff=ediff;
240 clostest_dec = dec;
241 }
242 }
243 return clostest_dec;
244 }
245
247 void print(const tkstring &_data="", const tkstring &_option="");
248
249private:
250 void init();
251
252#ifdef HAS_ROOT
254 ClassDef(tklevel_scheme,0);
255#endif
256};
257}
258
259#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:54
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:294
Definition tklog.cpp:39
tklog & do_endl(tklog &log)
Definition tklog.h:235
tklog & warning(tklog &log)
Definition tklog.h:354