Newer
Older
1
2
3
4
5
6
7
8
9
10
11
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
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
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
/*
* (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu
*
* See file AUTHORS for a list of contributors.
*
* This software is distributed under the terms of the GNU General Public
* Licence version 3 (GPL Version 3). See file LICENSE for a full version of
* the license.
*/
#ifndef _include_stack_nuclearstackextension_h_
#define _include_stack_nuclearstackextension_h_
#include <corsika/stack/super_stupid/SuperStupidStack.h>
#include <vector>
namespace corsika::stack {
namespace nuclear_extension {
using corsika::stack::super_stupid::MomentumVector;
template <typename StackIteratorInterface>
class ParticleInterface
: public corsika::stack::super_stupid::ParticleInterface<StackIteratorInterface> {
protected:
// using corsika::stack::ParticleBase<StackIteratorInterface>::GetStack;
//using corsika::stack::super_stupid::ParticleInterface<StackIteratorInterface>::GetStackData;
using corsika::stack::ParticleBase<StackIteratorInterface>::GetStackData;
using corsika::stack::ParticleBase<StackIteratorInterface>::GetIndex;
public:
void SetParticleData(const corsika::particles::Code vDataPID,
const corsika::units::si::HEPEnergyType vDataE,
const corsika::stack::super_stupid::MomentumVector& vMomentum,
const corsika::geometry::Point& vPosition,
const corsika::units::si::TimeType vTime,
const int vA = 0,
const int vZ = 0) {
if (vDataPID == corsika::particles::Code::Nucleus) {
if (vA==0 || vZ==0) {
std::ostringstream err;
err << "NuclearStackExtension: no A and Z specified for new Nucleus!";
throw std::runtime_error(err.str());
}
SetNuclearRef(corsika::stack::ParticleBase<StackIteratorInterface>::GetStackData().GetNucleusNextRef()); // store this nucleus data ref
SetNuclearA(vA);
SetNuclearZ(vZ);
} else {
SetNuclearRef(-1); // this is not a nucleus
}
corsika::stack::super_stupid::ParticleInterface<StackIteratorInterface>::SetParticleData(vDataPID,
vDataE,
vMomentum,
vPosition,
vTime);
}
void SetParticleData(ParticleInterface<StackIteratorInterface>& parent,
const corsika::particles::Code vDataPID,
const corsika::units::si::HEPEnergyType vDataE,
const corsika::stack::super_stupid::MomentumVector& vMomentum,
const corsika::geometry::Point& vPosition,
const corsika::units::si::TimeType vTime,
const int vA = 0,
const int vZ = 0) {
SetParticleData(vDataPID,
vDataE,
vMomentum,
vPosition,
vTime,
vA,
vZ);
}
/**
* @name individual setters
* @{
*/
void SetNuclearA(const int vA) { GetStackData().SetNuclearA(GetIndex(), vA); }
void SetNuclearZ(const int vZ) { GetStackData().SetNuclearZ(GetIndex(), vZ); }
/// @}
/**
* @name individual getters
* @{
*/
int GetNuclearA() const { return GetStackData().GetNuclearA(GetIndex()); }
int GetNuclearZ() const { return GetStackData().GetNuclearZ(GetIndex()); }
/// @}
protected:
void SetNuclearRef(const int vR) { GetStackData().SetNuclearRef(GetIndex(), vR); }
};
/**
* Memory implementation of the most simple (stupid) particle stack object.
*/
class NuclearStackExtensionImpl
: public corsika::stack::super_stupid::SuperStupidStackImpl {
public:
void Init() { corsika::stack::super_stupid::SuperStupidStackImpl::Init(); }
void Clear() {
corsika::stack::super_stupid::SuperStupidStackImpl::Clear();
fNuclearRef.clear();
fNuclearA.clear();
fNuclearZ.clear();
}
int GetSize() const { return fNuclearRef.size(); }
int GetCapacity() const { return fNuclearRef.size(); }
void SetNuclearA(const int i, const int vA) { fNuclearA[GetNucleusRef(i)] = vA; }
void SetNuclearZ(const int i, const int vZ) { fNuclearZ[GetNucleusRef(i)] = vZ; }
void SetNuclearRef(const int i, const int v) { fNuclearRef[i] = v; }
int GetNuclearA(const int i) const { return fNuclearA[GetNucleusRef(i)]; }
int GetNuclearZ(const int i) const { return fNuclearZ[GetNucleusRef(i)]; }
// this function will create new storage for Nuclear Properties, and return the reference to it
int GetNucleusNextRef() { fNuclearA.push_back(0); fNuclearZ.push_back(0); return fNuclearA.size()-1; }
int GetNucleusRef(const int i) const {
if (fNuclearRef[i]>=0)
return fNuclearRef[i];
std::ostringstream err;
err << "NuclearStackExtension: no nucleus at ref=" << i;
throw std::runtime_error(err.str());
}
/**
* Function to copy particle at location i1 in stack to i2
*/
void Copy(const int i1, const int i2) {
corsika::stack::super_stupid::SuperStupidStackImpl::Copy(i1, i2);
const int ref1 = fNuclearRef[i1];
const int ref2 = fNuclearRef[i2];
if (ref2<0) {
if (ref1>=0) {
// i1 is nucleus, i2 is not
fNuclearRef[i2] = GetNucleusNextRef();
fNuclearA[fNuclearRef[i2]] = fNuclearA[ref1];
fNuclearZ[fNuclearRef[i2]] = fNuclearZ[ref1];
} else {
// neither i1 nor i2 are nuclei
}
} else {
if (ref1>=0) {
// both are nuclei, i2 is overwritten with nucleus i1
fNuclearA[ref2] = fNuclearA[ref1];
fNuclearZ[ref2] = fNuclearZ[ref1];
} else {
// i2 is overwritten with non-nucleus i1
fNuclearA.erase(fNuclearA.begin() + ref2);
fNuclearZ.erase(fNuclearZ.begin() + ref2);
const int n = fNuclearRef.size();
for (int i=0; i<n; ++i) {
if (fNuclearRef[i]>=ref2) {
fNuclearRef[i] -= 1;
}
}
}
}
}
/**
* Function to copy particle at location i2 in stack to i1
*/
void Swap(const int i1, const int i2) {
corsika::stack::super_stupid::SuperStupidStackImpl::Swap(i1, i2);
const int ref1 = fNuclearRef[i1];
const int ref2 = fNuclearRef[i2];
if (ref2<0) {
if (ref1>=0) {
// i1 is nucleus, i2 is not
std::swap(fNuclearRef[i2], fNuclearRef[i1]);
} else {
// neither i1 nor i2 are nuclei
}
} else {
if (ref1>=0) {
// both are nuclei, i2 is overwritten with nucleus i1
std::swap(fNuclearRef[i2], fNuclearRef[i1]);
} else {
// i2 is overwritten with non-nucleus i1
std::swap(fNuclearRef[i2], fNuclearRef[i1]);
}
}
}
protected:
void IncrementSize() {
corsika::stack::super_stupid::SuperStupidStackImpl::IncrementSize();
fNuclearRef.push_back(-1);
}
void DecrementSize() {
corsika::stack::super_stupid::SuperStupidStackImpl::DecrementSize();
if (fNuclearRef.size() > 0) {
const int ref = fNuclearRef.back();
fNuclearRef.pop_back();
if (ref>=0) {
fNuclearA.erase(fNuclearA.begin() + ref);
fNuclearZ.erase(fNuclearZ.begin() + ref);
const int n = fNuclearRef.size();
for (int i=0; i<n; ++i) {
if (fNuclearRef[i] >= ref) {
fNuclearRef[i] -= 1;
}
}
}
}
}
private:
/// the actual memory to store particle data
std::vector<int> fNuclearRef;
std::vector<int> fNuclearA;
std::vector<int> fNuclearZ;
}; // end class SuperStupidStackImpl
typedef Stack<NuclearStackExtensionImpl, ParticleInterface> NuclearStackExtension;
} // namespace nuclear_extension
} // namespace corsika::stack
#endif