emitdb.cc 8.37 KB
Newer Older
1
2
3
4
5
#include <fstream>

#include "radixcore/stringfunctions.hh"
#include "radixcore/system.hh"

6
7
8
9
10
11
#include "radixio/emitdb.hh"

namespace radix
{
EmitDb::EmitDb()
{
12
13
14
15
16
17
18
19
20
  load_mpdkxgam(EmitDb::XGAMDATA4);
  // load_mpdkxgam(EmitDb::XGAMDATA3);
  load_ensdfbeta(EmitDb::BETADATA);
}

EmitDb::EmitDb(const EmitDb& orig)
{
  mIsotope      = orig.mIsotope;
  mIsotopeTitle = orig.mIsotopeTitle;
21
22
23
24
25
}

void EmitDb::load_mpdkxgam(std::string file)
{
  std::string revStr = radix::split_string(".", file)[1];
26
  int revNum         = std::atoi(revStr.substr(revStr.size() - 1, 1).c_str());
27
28
29
30
31
  int indexThreshold, indexIterator;
  int linecount = 0;
  if (revNum == 3)
  {
    indexThreshold = 70;
32
    indexIterator  = 20;
33
34
35
36
  }
  else if (revNum == 4)
  {
    indexThreshold = 77;
37
    indexIterator  = 22;
38
39
40
41
  }
  std::ifstream xgamFile(file);
  std::string line, prev;
  std::vector<float> energies, intensities;
42
43
  int zaid          = -1;
  int totalLines    = 0;
44
45
46
47
48
49
50
51
52
53
  float totalEnergy = 0.f;
  while (std::getline(xgamFile, line))
  {
    linecount += 1;
    int thisZaid = std::atoi(line.substr(1, 6).c_str());
    if (thisZaid != 0)
    {
      if (zaid != -1 && energies.size() > 0)
      {
        EmitDBEntry emitEntry;
54
55
56
57
58
59
60
61
62
        emitEntry.z                 = int(zaid / 10000);
        emitEntry.a                 = int((zaid % 10000) / 10);
        emitEntry.m                 = int(zaid % 10);
        emitEntry.nLines            = totalLines;
        emitEntry.nBetas            = 0;
        emitEntry.xgamEnergy        = totalEnergy;
        emitEntry.betaEnergy        = 0.0f;
        emitEntry.photonEnergies    = energies;
        emitEntry.betaEnergies      = {};
63
        emitEntry.photonIntensities = intensities;
64
        emitEntry.betaIntensities   = {};
65
66
67
68
        mIsotope.insert(std::make_pair(zaid, emitEntry));
        energies.clear();
        intensities.clear();
      }
69
70
      zaid        = thisZaid;
      totalLines  = std::atoi(line.substr(9, 12).c_str());
71
72
73
74
75
76
77
78
      totalEnergy = std::atof(line.substr(60, 10).c_str());
    }
    else
    {
      int index;
      int jumpLength;
      if (revNum == 3)
      {
79
        index      = 10;
80
81
82
83
        jumpLength = 10;
      }
      else
      {
84
        index      = 10;
85
86
87
88
89
        jumpLength = 11;
      }
      while (index < indexThreshold && index < line.size())
      {
        float energy = std::atof(line.substr(index, 10).c_str());
90
91
        float intensity =
            std::atof(line.substr(index + jumpLength, 10).c_str());
92
93
94
95
96
97
98
99
        energies.push_back(energy);
        intensities.push_back(intensity);
        index += indexIterator;
      }
    }
    prev = line;
  }
  EmitDBEntry emitEntry;
100
101
102
103
104
105
106
107
108
  emitEntry.z                 = int(zaid / 10000);
  emitEntry.a                 = int((zaid % 10000) / 10);
  emitEntry.m                 = int(zaid % 10);
  emitEntry.nLines            = totalLines;
  emitEntry.nBetas            = 0;
  emitEntry.xgamEnergy        = totalEnergy;
  emitEntry.betaEnergy        = 0.0f;
  emitEntry.photonEnergies    = energies;
  emitEntry.betaEnergies      = {};
109
  emitEntry.photonIntensities = intensities;
110
  emitEntry.betaIntensities   = {};
111
112
113
  mIsotope.insert(std::make_pair(zaid, emitEntry));
  energies.clear();
  intensities.clear();
114
}
115
116
117
118
119
120

void EmitDb::load_ensdfbeta(std::string file)
{
  std::ifstream betaFile(file);
  std::string line, prev;
  int zaidCount = 0;
121
  int zaid      = -1;
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
  int linecount = 0;
  std::vector<float> energies, intensities;
  while (std::getline(betaFile, line))
  {
    linecount += 1;
    if (line.substr(0, 2) == "  ")
    {
      if (line.size() > 10)
      {
        if (zaid == std::atoi(line.substr(2, 6).c_str()))
        {
          zaidCount++;
        }
        else
        {
          zaid = std::atoi(line.substr(2, 6).c_str());
          zaidCount++;
        }
        float intensity = std::atof(line.substr(10, 8).c_str());
141
        float energy    = std::atof(line.substr(19, 9).c_str());
142
143
144
145
146
147
148
149
150
151
152
153
154
        energies.push_back(energy);
        intensities.push_back(intensity);
      }
      else
      {
        if (energies.size() > 0 && zaid != -1)
        {
          float totalEnergy = 0.0f;
          for (size_t i = 0; i < intensities.size(); ++i)
          {
            totalEnergy += (intensities[i] * energies[i]);
          }
          EmitDBEntry emitEntry;
155
156
157
158
159
160
161
162
163
          emitEntry.z                 = int(zaid / 10000);
          emitEntry.a                 = int((zaid % 10000) / 10);
          emitEntry.m                 = int(zaid % 10);
          emitEntry.nLines            = 0;
          emitEntry.nBetas            = zaidCount;
          emitEntry.xgamEnergy        = 0.0f;
          emitEntry.betaEnergy        = totalEnergy;
          emitEntry.photonEnergies    = {};
          emitEntry.betaEnergies      = energies;
164
          emitEntry.photonIntensities = {};
165
166
167
          emitEntry.betaIntensities   = intensities;
          const auto& isOutside =
              mIsotope.insert(std::make_pair(zaid, emitEntry));
168
169
          if (!isOutside.second)
          {
170
171
172
            isOutside.first->second.nBetas          = zaidCount;
            isOutside.first->second.betaEnergy      = totalEnergy;
            isOutside.first->second.betaEnergies    = energies;
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
            isOutside.first->second.betaIntensities = intensities;
          }
          zaidCount = 0;
          energies.clear();
          intensities.clear();
        }
      }
    }
    prev = line;
  }
  if (energies.size() > 0)
  {
    float totalEnergy = 0.0f;
    for (size_t i = 0; i < intensities.size(); ++i)
    {
      totalEnergy += (intensities[i] * energies[i]);
    }
    EmitDBEntry emitEntry;
191
192
193
194
195
196
197
198
199
    emitEntry.z                 = int(zaid / 10000);
    emitEntry.a                 = int((zaid % 10000) / 10);
    emitEntry.m                 = int(zaid % 10);
    emitEntry.nLines            = 0;
    emitEntry.nBetas            = zaidCount;
    emitEntry.xgamEnergy        = 0.0f;
    emitEntry.betaEnergy        = totalEnergy;
    emitEntry.photonEnergies    = {};
    emitEntry.betaEnergies      = energies;
200
    emitEntry.photonIntensities = {};
201
    emitEntry.betaIntensities   = intensities;
202
203
204
    const auto& isOutside = mIsotope.insert(std::make_pair(zaid, emitEntry));
    if (!isOutside.second)
    {
205
206
207
      isOutside.first->second.nBetas          = zaidCount;
      isOutside.first->second.betaEnergy      = totalEnergy;
      isOutside.first->second.betaEnergies    = energies;
208
209
210
211
212
213
214
215
      isOutside.first->second.betaIntensities = intensities;
    }
    zaidCount = 0;
    energies.clear();
    intensities.clear();
  }
}

216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
const std::string& EmitDb::isotope_title() const { return mIsotopeTitle; }
void EmitDb::set_isotope_title(const std::string& title)
{
  mIsotopeTitle = title;
}
const std::unordered_map<int, EmitDBEntry>& EmitDb::isotopes() const
{
  return mIsotope;
}
std::unordered_map<int, EmitDBEntry>& EmitDb::isotopes() { return mIsotope; }
const EmitDBEntry& EmitDb::emitter(const int zaid) const
{
  const auto& it = mIsotope.find(zaid);
  return it->second;
}
const std::vector<std::vector<float>> EmitDb::photons(const int zaid) const
{
  const auto& it                         = mIsotope.find(zaid);
  std::vector<float> energies            = it->second.photonEnergies;
  std::vector<float> intensities         = it->second.photonIntensities;
  std::vector<std::vector<float>> paired = {energies, intensities};
  return paired;
}
std::vector<std::vector<float>> EmitDb::photons(const int zaid)
{
  const auto& it                         = mIsotope.find(zaid);
  std::vector<float> energies            = it->second.photonEnergies;
  std::vector<float> intensities         = it->second.photonIntensities;
  std::vector<std::vector<float>> paired = {energies, intensities};
  return paired;
}
const std::vector<std::vector<float>> EmitDb::betas(const int zaid) const
{
  const auto& it                         = mIsotope.find(zaid);
  std::vector<float> energies            = it->second.betaEnergies;
  std::vector<float> intensities         = it->second.betaIntensities;
  std::vector<std::vector<float>> paired = {energies, intensities};
  return paired;
}
std::vector<std::vector<float>> EmitDb::betas(const int zaid)
{
  const auto& it                         = mIsotope.find(zaid);
  std::vector<float> energies            = it->second.betaEnergies;
  std::vector<float> intensities         = it->second.betaIntensities;
  std::vector<std::vector<float>> paired = {energies, intensities};
  return paired;
}

264
265
266
267
268
269
void EmitDb::operator=(const EmitDb& orig)
{
  mIsotope      = orig.mIsotope;
  mIsotopeTitle = orig.mIsotopeTitle;
}

270
}  // namespace radix