emitdb.cc 7.68 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
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
    load_mpdkxgam(EmitDb::XGAMDATA4);
    // load_mpdkxgam(EmitDb::XGAMDATA3);
    load_ensdfbeta(EmitDb::BETADATA);
}

void EmitDb::load_mpdkxgam(std::string file)
{
  std::string revStr = radix::split_string(".", file)[1];
  int revNum = std::atoi(revStr.substr(revStr.size() - 1, 1).c_str());
  int indexThreshold, indexIterator;
  int linecount = 0;
  if (revNum == 3)
  {
    indexThreshold = 70;
    indexIterator = 20;
  }
  else if (revNum == 4)
  {
    indexThreshold = 77;
    indexIterator = 22;
  }
  std::ifstream xgamFile(file);
  std::string line, prev;
  std::vector<float> energies, intensities;
  int zaid = -1;
  int totalLines = 0;
  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;
        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 = {};
        emitEntry.photonIntensities = intensities;
        emitEntry.betaIntensities = {};
        mIsotope.insert(std::make_pair(zaid, emitEntry));
        energies.clear();
        intensities.clear();
      }
      zaid = thisZaid;
      totalLines = std::atoi(line.substr(9, 12).c_str());
      totalEnergy = std::atof(line.substr(60, 10).c_str());
    }
    else
    {
      int index;
      int jumpLength;
      if (revNum == 3)
      {
        index = 10;
        jumpLength = 10;
      }
      else
      {
        index = 10;
        jumpLength = 11;
      }
      while (index < indexThreshold && index < line.size())
      {
        float energy = std::atof(line.substr(index, 10).c_str());
        float intensity = std::atof(line.substr(index + jumpLength, 10).c_str());
        energies.push_back(energy);
        intensities.push_back(intensity);
        index += indexIterator;
      }
    }
    prev = line;
  }
  EmitDBEntry emitEntry;
  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 = {};
  emitEntry.photonIntensities = intensities;
  emitEntry.betaIntensities = {};
  mIsotope.insert(std::make_pair(zaid, emitEntry));
  energies.clear();
  intensities.clear();
107
}
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207

void EmitDb::load_ensdfbeta(std::string file)
{
  std::ifstream betaFile(file);
  std::string line, prev;
  int zaidCount = 0;
  int zaid = -1;
  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());
        float energy = std::atof(line.substr(19, 9).c_str());
        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;
          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;
          emitEntry.photonIntensities = {};
          emitEntry.betaIntensities = intensities;
          const auto& isOutside = mIsotope.insert(std::make_pair(zaid, emitEntry));
          if (!isOutside.second)
          {
            isOutside.first->second.nBetas = zaidCount;
            isOutside.first->second.betaEnergy = totalEnergy;
            isOutside.first->second.betaEnergies = energies;
            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;
    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;
    emitEntry.photonIntensities = {};
    emitEntry.betaIntensities = intensities;
    const auto& isOutside = mIsotope.insert(std::make_pair(zaid, emitEntry));
    if (!isOutside.second)
    {
      isOutside.first->second.nBetas = zaidCount;
      isOutside.first->second.betaEnergy = totalEnergy;
      isOutside.first->second.betaEnergies = energies;
      isOutside.first->second.betaIntensities = intensities;
    }
    zaidCount = 0;
    energies.clear();
    intensities.clear();
  }
}

208
209
210
211
212
213
214
215
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
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;
}

}  // namespace radix