|
Lines 51-56
Link Here
|
| 51 |
// |
51 |
// |
| 52 |
|
52 |
|
| 53 |
#include "G4GeneralParticleSourceData.hh" |
53 |
#include "G4GeneralParticleSourceData.hh" |
|
|
54 |
#include "G4GeneralParticleSource.hh" |
| 54 |
#include "G4Threading.hh" |
55 |
#include "G4Threading.hh" |
| 55 |
#include "G4AutoLock.hh" |
56 |
#include "G4AutoLock.hh" |
| 56 |
|
57 |
|
|
Lines 68-73
G4GeneralParticleSourceData::G4GeneralParticleSourceData() : flat_sampling(false
Link Here
|
| 68 |
{ |
69 |
{ |
| 69 |
G4MUTEXINIT(mutex); |
70 |
G4MUTEXINIT(mutex); |
| 70 |
|
71 |
|
|
|
72 |
gpsVector.clear(); |
| 71 |
sourceVector.clear(); |
73 |
sourceVector.clear(); |
| 72 |
sourceIntensity.clear(); |
74 |
sourceIntensity.clear(); |
| 73 |
sourceProbability.clear(); |
75 |
sourceProbability.clear(); |
|
Lines 85-90
G4GeneralParticleSourceData::~G4GeneralParticleSourceData()
Link Here
|
| 85 |
for ( std::vector<G4SingleParticleSource*>::const_iterator it = sourceVector.begin() ; |
87 |
for ( std::vector<G4SingleParticleSource*>::const_iterator it = sourceVector.begin() ; |
| 86 |
it != sourceVector.end() ; ++it ) { delete *it; } |
88 |
it != sourceVector.end() ; ++it ) { delete *it; } |
| 87 |
sourceVector.clear(); |
89 |
sourceVector.clear(); |
|
|
90 |
gpsVector.clear(); |
| 88 |
} |
91 |
} |
| 89 |
|
92 |
|
| 90 |
|
93 |
|
|
Lines 100-105
G4GeneralParticleSourceData* G4GeneralParticleSourceData::Instance()
Link Here
|
| 100 |
// return theInstance; |
103 |
// return theInstance; |
| 101 |
} |
104 |
} |
| 102 |
|
105 |
|
|
|
106 |
void G4GeneralParticleSourceData::RegisterGPS(G4GeneralParticleSource *gps) |
| 107 |
{ |
| 108 |
gpsVector.push_back(gps); |
| 109 |
} |
| 110 |
|
| 103 |
void G4GeneralParticleSourceData::IntensityNormalise() |
111 |
void G4GeneralParticleSourceData::IntensityNormalise() |
| 104 |
{ |
112 |
{ |
| 105 |
G4double total = 0.; |
113 |
G4double total = 0.; |
|
Lines 137-146
void G4GeneralParticleSourceData::IntensityNormalise()
Link Here
|
| 137 |
normalised = true; |
145 |
normalised = true; |
| 138 |
} |
146 |
} |
| 139 |
|
147 |
|
|
|
148 |
void G4GeneralParticleSourceData::ListSource() |
| 149 |
{ |
| 150 |
G4cout << "The number of particle sources is: " << G4int(sourceIntensity.size()) << G4endl; |
| 151 |
for(G4int i=0; i<G4int(sourceIntensity.size()); i++) |
| 152 |
{ |
| 153 |
G4cout << "\tsource " << i << " intensity is: " << sourceIntensity.at(i) << G4endl;; |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 140 |
void G4GeneralParticleSourceData::SetCurrentSourceIntensity(G4double intensity) |
157 |
void G4GeneralParticleSourceData::SetCurrentSourceIntensity(G4double intensity) |
| 141 |
{ |
158 |
{ |
| 142 |
sourceIntensity.at(currentSourceIdx) = intensity; |
159 |
sourceIntensity.at(currentSourceIdx) = intensity; |
| 143 |
normalised = false; |
160 |
normalised = false; |
|
|
161 |
for ( std::vector<G4GeneralParticleSource*>::iterator it = gpsVector.begin(); |
| 162 |
it != gpsVector.end(); ++it ) { (*it)->SetCurrentSourceIntensity(); } |
| 144 |
} |
163 |
} |
| 145 |
|
164 |
|
| 146 |
void G4GeneralParticleSourceData::AddASource(G4double intensity) |
165 |
void G4GeneralParticleSourceData::AddASource(G4double intensity) |
|
Lines 150-177
void G4GeneralParticleSourceData::AddASource(G4double intensity)
Link Here
|
| 150 |
sourceIntensity.push_back(intensity); |
169 |
sourceIntensity.push_back(intensity); |
| 151 |
currentSourceIdx = sourceVector.size() - 1; |
170 |
currentSourceIdx = sourceVector.size() - 1; |
| 152 |
normalised = false; |
171 |
normalised = false; |
|
|
172 |
for ( std::vector<G4GeneralParticleSource*>::iterator it = gpsVector.begin(); |
| 173 |
it != gpsVector.end(); ++it ) { (*it)->AddaSource(); } |
| 153 |
} |
174 |
} |
| 154 |
|
175 |
|
| 155 |
void G4GeneralParticleSourceData::DeleteASource(G4int idx) |
176 |
void G4GeneralParticleSourceData::DeleteASource(G4int idx) |
| 156 |
{ |
177 |
{ |
| 157 |
delete sourceVector[idx]; |
178 |
if ( idx <= G4int(sourceIntensity.size()) ) |
| 158 |
sourceVector.erase(sourceVector.begin() + idx); |
|
|
| 159 |
sourceIntensity.erase(sourceIntensity.begin()+idx); |
| 160 |
normalised = false ; |
| 161 |
if (currentSourceIdx == idx ) |
| 162 |
{ |
179 |
{ |
| 163 |
if ( this->GetIntensityVectorSize() > 0 ) |
180 |
delete sourceVector[idx]; |
| 164 |
{ |
181 |
sourceVector.erase(sourceVector.begin() + idx); |
| 165 |
currentSource = this->GetCurrentSource(0); |
182 |
sourceIntensity.erase(sourceIntensity.begin()+idx); |
| 166 |
currentSourceIdx = 0; |
183 |
normalised = false ; |
| 167 |
} |
184 |
if (currentSourceIdx == idx ) |
| 168 |
else |
|
|
| 169 |
{ |
185 |
{ |
| 170 |
currentSource = NULL; |
186 |
if ( this->GetIntensityVectorSize() > 0 ) |
| 171 |
currentSourceIdx = -1; |
187 |
{ |
|
|
188 |
currentSource = this->GetCurrentSource(0); |
| 189 |
currentSourceIdx = 0; |
| 190 |
} |
| 191 |
else |
| 192 |
{ |
| 193 |
currentSource = NULL; |
| 194 |
currentSourceIdx = -1; |
| 195 |
} |
| 172 |
} |
196 |
} |
|
|
197 |
for ( std::vector<G4GeneralParticleSource*>::iterator it = gpsVector.begin(); |
| 198 |
it != gpsVector.end(); ++it ) { (*it)->DeleteaSource(); } |
| 199 |
} |
| 200 |
else |
| 201 |
{ |
| 202 |
G4cout << " source index is invalid " << G4endl; |
| 203 |
G4cout << " it shall be <= " << G4int(sourceIntensity.size()) << G4endl; |
| 173 |
} |
204 |
} |
| 174 |
|
|
|
| 175 |
} |
205 |
} |
| 176 |
|
206 |
|
| 177 |
void G4GeneralParticleSourceData::ClearSources() |
207 |
void G4GeneralParticleSourceData::ClearSources() |
|
Lines 180-187
void G4GeneralParticleSourceData::ClearSources()
Link Here
|
| 180 |
currentSource = NULL; |
210 |
currentSource = NULL; |
| 181 |
sourceVector.clear(); |
211 |
sourceVector.clear(); |
| 182 |
sourceIntensity.clear(); |
212 |
sourceIntensity.clear(); |
|
|
213 |
for ( std::vector<G4GeneralParticleSource*>::iterator it = gpsVector.begin(); |
| 214 |
it != gpsVector.end(); ++it ) { (*it)->ClearAll(); } |
| 183 |
} |
215 |
} |
| 184 |
|
216 |
|
|
|
217 |
G4int G4GeneralParticleSourceData::GetCurrentSourceIndex() |
| 218 |
{ |
| 219 |
return currentSourceIdx; |
| 220 |
} |
| 221 |
|
| 222 |
G4double G4GeneralParticleSourceData::GetCurrentSourceIntensity() |
| 223 |
{ |
| 224 |
return sourceIntensity[currentSourceIdx]; |
| 225 |
} |
| 185 |
|
226 |
|
| 186 |
G4SingleParticleSource* G4GeneralParticleSourceData::GetCurrentSource(G4int idx) |
227 |
G4SingleParticleSource* G4GeneralParticleSourceData::GetCurrentSource(G4int idx) |
| 187 |
{ |
228 |
{ |
|
Lines 190-195
G4SingleParticleSource* G4GeneralParticleSourceData::GetCurrentSource(G4int idx)
Link Here
|
| 190 |
return sourceVector[idx]; |
231 |
return sourceVector[idx]; |
| 191 |
} |
232 |
} |
| 192 |
|
233 |
|
|
|
234 |
void G4GeneralParticleSourceData::SetCurrentSourceto(G4int idx) |
| 235 |
{ |
| 236 |
for ( std::vector<G4GeneralParticleSource*>::iterator it = gpsVector.begin(); |
| 237 |
it != gpsVector.end(); ++it ) { (*it)->SetCurrentSourceto(idx); } |
| 238 |
} |
| 239 |
|
| 240 |
void G4GeneralParticleSourceData::SetMultipleVertex(G4bool aV) |
| 241 |
{ |
| 242 |
for ( std::vector<G4GeneralParticleSource*>::iterator it = gpsVector.begin(); |
| 243 |
it != gpsVector.end(); ++it ) { (*it)->SetMultipleVertex(aV); } |
| 244 |
} |
| 245 |
|
| 246 |
void G4GeneralParticleSourceData::SetFlatSampling(G4bool fSamp) |
| 247 |
{ |
| 248 |
flat_sampling = fSamp; |
| 249 |
for ( std::vector<G4GeneralParticleSource*>::iterator it = gpsVector.begin(); |
| 250 |
it != gpsVector.end(); ++it ) { (*it)->SetFlatSampling(fSamp); } |
| 251 |
} |
| 252 |
|
| 193 |
void G4GeneralParticleSourceData::Lock() |
253 |
void G4GeneralParticleSourceData::Lock() |
| 194 |
{ |
254 |
{ |
| 195 |
G4MUTEXLOCK(&mutex); |
255 |
G4MUTEXLOCK(&mutex); |