TkN 2.1
Toolkit for Nuclei
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 <map>
41#include <vector>
42#include <functional>
43
44#include "tkn_config.h"
45#include "tklevel.h"
46#include "tkdecay.h"
47
48#ifdef HAS_ROOT
49#include "TClass.h"
50#endif
51
52
53namespace tkn {
54class tkdataset {
55
56 friend class tklevel;
57 friend class tklevel_scheme;
58
59protected:
60
61 int fid{};
62 int fA{};
63 int fZ{};
64 tkstring fname{};
65 tkstring fnucleus{};
66
67 std::vector<shared_ptr<tklevel>> flevels;
68 std::vector<shared_ptr<tkdecay>> fdecays;
69 std::map<int, shared_ptr<tklevel>> fmapoflevels;
70
71 bool floaded = false;
72
73 map<int,shared_ptr<tklevel>> fyrastmap_exact; // 2J -> level
74 map<int,shared_ptr<tklevel>> fyrastmap_uncertain;
75
76public:
77 tkdataset(const tkstring &_nuc,int _zz, int _aa, const tkstring &_name, int _id) : fid(_id), fA(_aa), fZ(_zz), fname(_name), fnucleus(_nuc) {}
78 tkdataset() = default;
79 virtual ~tkdataset() = default;
80
82 int get_id() const {return fid;}
84 const tkstring &get_name() const {return fname;}
86 const tkstring &get_nucleus_name() const {return fnucleus;}
87
89 shared_ptr<tklevel> add_level(double _ener, double _unc, tkstring _unit, tkstring _jpistr);
90
92 shared_ptr<tkgammadecay> add_gamma_decay(shared_ptr<tklevel> _lvlfrom, shared_ptr<tklevel> _lvlto, double _ener=0., double _unc=0.);
93
94protected:
96 void load_dataset();
98 const std::vector<shared_ptr<tklevel>> &get_levels() {return flevels;}
100 const std::vector<shared_ptr<tkdecay>> &get_decays() {return fdecays;}
101
103 void check_yrast(shared_ptr<tklevel> _lvl);
104
106 void print(const tkstring &_data, const tkstring &_option="");
107};
108
110
111protected:
112
113 std::map<tkstring, int> fmap_of_dataset_name_id;
114 std::map<int, shared_ptr<tkdataset>> fmap_of_dataset;
115
116 bool floaded = false;
117
118 int fdatasetid{};
119 tkstring fnucleus;
120
121 int fA, fZ;
122
123public:
124 tklevel_scheme(const tkstring &_nuc, int _zz, int _aa);
125 virtual ~tklevel_scheme() = default;
126
128 bool select_dataset(const tkstring &_dataset_name);
130 bool select_dataset(int _dataset_id=0);
131
133 const shared_ptr<tkdataset> &get_dataset() {return fmap_of_dataset[fdatasetid];}
135 const std::map<int, shared_ptr<tkdataset>> get_datasets() {return fmap_of_dataset;}
136
138 const std::vector<shared_ptr<tklevel>> &get_levels() {return fmap_of_dataset[fdatasetid]->get_levels();}
140 std::vector<shared_ptr<tklevel>> get_levels(std::function<bool(shared_ptr<tklevel>)>const& _selection);
141
143 const std::vector<shared_ptr<tkdecay>> &get_decays() {return fmap_of_dataset[fdatasetid]->get_decays();}
145 std::vector<shared_ptr<tkdecay>> get_decays(std::function<bool(shared_ptr<tkdecay>)>const& _selection);
146
153 template<typename T>
154 const std::vector<shared_ptr<T>> get_decays() {
155 std::vector<shared_ptr<T>> decays;
156 for(const auto &dec: get_decays()) {
157 auto test = dynamic_pointer_cast<T>(dec);
158 if(test) {
159 shared_ptr<T> gam = dynamic_pointer_cast<T>(dec);
160 decays.push_back(gam);
161 }
162 }
163 return decays;
164 }
165
178 template<typename T>
179 const std::vector<shared_ptr<T>> get_decays(const std::function<bool (shared_ptr<T>)> &_selection) {
180 vector<shared_ptr<T>> res;
181 for(const auto &dec : get_decays<T>()) if(_selection(dec)) res.push_back(dec);
182 return res;
183 }
184
186 shared_ptr<tklevel> get_level(const tkstring &_name, bool _exact=true);
187
189 shared_ptr<tklevel> get_level(double _energy, tkstring _offset="");
190
202 template<typename T>
203 const shared_ptr<T> get_decay(const tkstring &_name, bool _exact=true) {
204 std::vector<tkstring> lvls = _name.tokenize_from_string("->");
205 if(lvls.size()!=2) {glog << warning << "get_decay(" << _name << ") -- wrong syntax (ex: 2+1->0+1)" << do_endl; return nullptr;}
206 shared_ptr<tklevel> lvl_from = get_level(lvls.at(0),_exact);
207 shared_ptr<tklevel> lvl_to = get_level(lvls.at(1),_exact);
208 if(!lvl_from) {glog << warning << "get_decay(" << _name << ") -- " << lvls.at(0) << " level not found" << do_endl; return nullptr;}
209 if(!lvl_to) {glog << warning << "get_decay(" << _name << ") -- " << lvls.at(1) << " level not found" << do_endl; return nullptr;}
210 int lvl_from_id = lvl_from->get_id();
211 int lvl_to_id = lvl_to->get_id();
212 for(auto dec : get_decays<T>()) {
213 if((dec->get_level_from_id() == lvl_from_id) && (dec->get_level_to_id() == lvl_to_id)) return dec;
214 }
215 return nullptr;
216 }
217
228 template<typename T>
229 const shared_ptr<T> get_decay(double _energy) {
230 shared_ptr<T> clostest_dec;
231 double best_ediff=1e6;
232 for(auto &dec: get_decays<T>()) {
233 double ediff = abs(dec->get_energy()-_energy);
234 if(ediff<best_ediff) {
235 best_ediff=ediff;
236 clostest_dec = dec;
237 }
238 }
239 return clostest_dec;
240 }
241
243 void print(const tkstring &_data="", const tkstring &_option="");
244
245private:
246 void init();
247
248#ifdef HAS_ROOT
250 ClassDef(tklevel_scheme,0);
251#endif
252};
253}
254
255#endif
Stores information on a specific dataset.
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
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
int get_id() const
returns the dataset ID
Collection of levels and decay.
virtual ~tklevel_scheme()=default
const std::map< int, shared_ptr< tkdataset > > get_datasets()
returns the list of available datasets
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 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
Stores information on a nuclear level.
Definition: tklevel.h:54
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