TkN 2.4
Toolkit for Nuclei
Loading...
Searching...
No Matches
tkspin_parity.cpp
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#include "tkspin_parity.h"
15
16#include <iomanip>
17#include <cmath>
18
19#include "tklog.h"
20
21namespace tkn {
42}
43
44using namespace tkn;
45using namespace std;
46
47tkspin::tkspin(int N, int D)
48{
49 set(N,D);
50}
51
59{
60 tkstring spin;
61
62 if (fD != 1)
63 spin = tkstring::Form("%d/%d", fN, fD);
64 else
65 spin = tkstring::Form("%d", fN);
66
67 if(is_info(kTentative)) {
68 spin.prepend("(");spin.append(")");
69 }
70 else if(is_info(kTheo)) {
71 spin.prepend("[");spin.append("]");
72 }
73 else if(is_info(kAbout)) {
74 spin.prepend("~");
75 }
76
77 return spin;
78}
79
80void tkspin::set(const tkstring &_st)
81{
82 tkstring st = _st;
83
84 if(st.ends_with("(-)") || st.ends_with("(+)")) st.erase(st.length()-3,3);
85
86 std::istringstream input; input.clear();
87 switch( what_is(st.data()) ){
88 case kKnown:
89 if ( st.contains("/") ) { // not an integer
90 st.replace_all("/"," "); input.str(st); input >> fN >> fD;
91 }
92 else { input.str(st); input >> fN; fD = 1; }
93 if ( input.fail() )
95 else
97 break;
98 case kUnknown:
100 break;
101 case kAbout:
102 st.replace_all("~"," ");
103 if ( st.contains("/") ) { // not an integer
104 st.replace_all("/"," "); input.str(st); input >> fN >> fD;
105 }
106 else { input.str(st); input >> fN; fD = 1; }
107 if ( input.fail() )
109 else
111 break;
112 case kTentative:
113 st.replace_all("("," ");
114 st.replace_all(")"," ");
115 if ( st.contains("/") ) { // not an integer
116 st.replace_all("/"," "); input.str(st); input >> fN >> fD;
117 }
118 else { input.str(st); input >> fN; fD = 1; }
119 if ( input.fail() )
121 else
123 break;
124 case kTheo:
125 st.replace_all("["," ");
126 st.replace_all("]"," ");
127 if ( st.contains("/") ) { // not an integer
128 st.replace_all("/"," "); input.str(st); input >> fN >> fD;
129 }
130 else { input.str(st); input >> fN; fD = 1; }
131 if ( input.fail() )
133 else
135 break;
136 default:
138 break;
139 }
140}
141
146void tkspin::set(int _n, int _d)
147{
148 fN = _n; fD = _d;
150 if ( fD < 1 || fD > 2 ) {
151 glog << warning << "A spin should be an integer or half an integer !\n";
152 glog << tkstring::form("\t [%d/%d] --> [%d/1]",fN,fD,fN) << do_endl;
153 fD = 1;
155 }
156}
157
161void tkspin::set(double _spin)
162{
163 int _2spin = lround(2*_spin);
164 if(_2spin%2==0) {
165 fN = _2spin/2;
166 fD = 1;
167 }
168 else {
169 fN = _2spin;
170 fD = 2;
171 }
173 if ( fD < 1 || fD > 2 ) {
174 glog << warning << "A spin should be an integer or half an integer !\n";
175 glog << tkstring::form("\t [%d/%d] --> [%d/1]",fN,fD,fN) << do_endl;
176 fD = 1;
178 }
179}
180
182{
183 if(!is_info(kUnknown)) {
184 glog << info_o << "spin: " << get_string() << " type: " << get_info_str() << do_endl;
185 }
186 else {
187 glog << warning_o << "spin is unknown" << do_endl;
188 }
189}
190
191#ifdef HAS_ROOT
193ClassImp(tkspin);
194#endif
195
196void tkparity::set(const tkstring &_st)
197{
199 fParity = kParityUnknown;
200
201 if(_st.contains("+")) {
202 fParity = kParityPlus;
203 if(_st.ends_with("+")) set_info(kKnown);
204 if(_st.ends_with(")")) set_info(kTentative);
205 else if(_st.ends_with("]")) set_info(kTheo);
206 }
207 if(_st.contains("-")) {
208 fParity = kParityMinus;
209 if(_st.ends_with("-")) set_info(kKnown);
210 if(_st.ends_with(")")) set_info(kTentative);
211 else if(_st.ends_with("]")) set_info(kTheo);
212 }
213}
214
218void tkparity::set(int _parity)
219{
220 if(_parity==0) {
221 fParity = kParityPlus;
223 }
224 else if(_parity==1) {
225 fParity = kParityMinus;
227 }
228 else {
230 fParity = kParityUnknown;
231 }
232}
233
235{
236 tkstring parity;
237
238 if(is_info(kUnknown)) return ("");
239
240 if (fParity == kParityPlus) parity = "+";
241 else parity = "-";
242
243 if(is_info(kTentative)) {
244 parity.prepend("(");parity.append(")");
245 }
246 else if(is_info(kTheo)) {
247 parity.prepend("[");parity.append("]");
248 }
249 else if(is_info(kAbout)) {
250 parity.prepend("~");
251 }
252
253 return parity;
254}
255
257{
258 if(!is_info(kUnknown)) {
259 glog << info_o << "parity: " << get_string() << " type: " << get_info_str() << do_endl;
260 }
261 else {
262 glog << warning_o << "parity is unknown: " << do_endl;
263 }
264}
265
266#ifdef HAS_ROOT
268ClassImp(tkparity);
269#endif
270
272
274{
275 fJpi_str = tkstring::form("%s",_st.data());
276 fJpi_str.remove_all_extra_white_space();
277 fJpi_str.replace_all("GE",">=");
278 fJpi_str.replace_all("LE","<=");
279 fJpi_str.replace_all("GT",">");
280 fJpi_str.replace_all("LT","<");
281}
282
283void tkspin_parity::set_spin(double _spin)
284{
285 fSpin.set(_spin);
286}
287
289{
290 fParity.set(_parity);
291}
292
294{
295 return fJpi_str;
296}
297
299{
300 if(!is_known()) glog << warning_o << "Unknown Jpi: " << fJpi_str << do_endl;
301 else glog << info_o << "Jpi: " << setw(10) << fJpi_str << do_endl;
302}
303
304#ifdef HAS_ROOT
306ClassImp(tkspin_parity)
307#endif
Nuclear excited state parity.
void print()
print the spin properties
tkstring get_string()
returns the parity as a string
virtual void set(const tkstring &_st)
define the parity from a string
void set_info(tkproperty::data_info _info)
to set some information about this data
Definition tkproperty.h:55
tkstring get_info_str(bool _showknown=true) const
to print in string the data_info
static data_info what_is(const tkstring &_st)
It deduces from a string the kind of data.
bool is_info(data_info _info) const
to get some information about this data
Definition tkproperty.h:65
Nuclear excited state spin-parity.
void set_from_str(const tkstring &_st)
define the spin parity from a string
void print()
print the spin and parity properties
void set_parity(int _parity)
define the parity from an integer
void set_spin(double _spin)
define the spin from a float
virtual bool is_known()
test if the spin and parity are known
const tkstring & get_jpi_str() const
returns the spin and parity string
Nuclear excited state spin.
virtual void print()
print the spin properties
tkstring get_string()
returns the spin as a string
void set(int n, int d=1)
define the spin value
std::string with usefull tricks from TString (ROOT) and KVString (KaliVeda) and more....
Definition tkstring.h:31
static const char * form(const char *_format,...)
Definition tkstring.cpp:408
static tkstring Form(const char *_format,...)
Definition tkstring.cpp:322
bool ends_with(const char *_s, ECaseCompare _cmp=kExact) const
Definition tkstring.cpp:218
bool contains(const char *_pat, ECaseCompare _cmp=kExact) const
Definition tkstring.h:174
tkstring & prepend(const tkstring &_st)
Definition tkstring.h:201
tkstring & append(const tkstring &_st)
Definition tkstring.h:204
tkstring & replace_all(const tkstring &_s1, const tkstring &_s2)
Definition tkstring.h:180
Definition tklog.cpp:16
tklog & warning_o(tklog &log)
Definition tklog.h:325
tklog & info_o(tklog &log)
Definition tklog.h:308
tklog & do_endl(tklog &log)
Definition tklog.h:212
tklog & warning(tklog &log)
Definition tklog.h:331