33 #define INCLXX_IN_GEANT4_MODE 1
48 loadedStoppingTime(0.),
61 const long ID = p->
getID();
65 if(particleAvatarConnections.find(ID)==particleAvatarConnections.end()) {
66 std::vector<long> *aIDs =
new std::vector<long>;
67 particleAvatarConnections[ID] = aIDs;
74 avatarList.push_back(a);
77 for(
ParticleIter i = pList.begin(); i != pList.end(); ++i) {
80 connectParticleAndAvatar((*i)->getID(), a->
getID());
92 avatarList.push_back(a);
95 for(
ParticleIter i = pList.begin(); i != pList.end(); ++i) {
100 if(particles.find((*i)->getID()) == particles.end()) {
101 ERROR(
"Avatar was added before related particles. This is probably a bug." << std::endl);
105 connectParticleAndAvatar((*i)->getID(), a->
getID());
111 incoming.push_back(p);
114 void Store::connectParticleAndAvatar(
long particleID,
long avatarID) {
115 std::map<long, std::vector<long>* >::const_iterator iter = particleAvatarConnections.find(particleID);
117 if(iter!=particleAvatarConnections.end()) {
118 std::vector<long> *
p = iter->second;
119 p->push_back(avatarID);
121 std::vector<long> *p =
new std::vector<long>;
122 p->push_back(avatarID);
123 particleAvatarConnections[particleID]=
p;
127 void Store::removeAvatarFromParticle(
long particleID,
long avatarID) {
128 std::vector<long>* theseAvatars = particleAvatarConnections.find(particleID)->second;
129 std::vector<long>* newAvatars =
new std::vector<long>();
130 for(std::vector<long>::const_iterator iter = theseAvatars->begin();
131 iter != theseAvatars->end(); ++iter) {
132 if((*iter) != avatarID) {
133 newAvatars->push_back((*iter));
137 particleAvatarConnections[particleID] = newAvatars;
140 void Store::removeAvatarByID(
long ID) {
142 IAvatar *avatar = avatars.find(ID)->second;
143 ParticleList particlesRelatedToAvatar = avatar->getParticles();
145 = particlesRelatedToAvatar.begin();
146 particleIDiter != particlesRelatedToAvatar.end(); ++particleIDiter) {
147 removeAvatarFromParticle((*particleIDiter)->getID(), ID);
150 #ifdef INCL_AVATAR_SEARCH_INCLSort
152 std::list<IAvatarIter>::iterator it=binaryIterSearch(avatars.find(ID)->second);
153 if(it != avatarIterList.end())
154 avatarIterList.erase(it);
158 avatarList.remove(avatar);
163 std::vector<long> temp_aIDs;
164 std::vector<long> *aIDs = particleAvatarConnections.find(particleID)->second;
165 for(std::vector<long>::iterator i = aIDs->begin();
166 i != aIDs->end(); ++i) {
167 temp_aIDs.push_back((*i));
170 for(std::vector<long>::iterator i = temp_aIDs.begin();
171 i != temp_aIDs.end(); ++i) {
172 IAvatar *tmpAvatar = avatars.find(*i)->second;
173 removeAvatarByID((*i));
178 #ifdef INCL_AVATAR_SEARCH_INCLSort
179 std::list<IAvatarIter>::iterator Store::binaryIterSearch(
IAvatar const *
const avatar) {
180 std::list<IAvatarIter>::iterator it;
181 std::iterator_traits<std::list<IAvatarIter>::iterator>::difference_type count, step;
182 std::list<IAvatarIter>::iterator first = avatarIterList.begin();
183 std::list<IAvatarIter>::iterator last = avatarIterList.end();
185 count = distance(first,last);
188 it = first; step=count/2; advance(it,step);
189 if ((**it)->getTime()>avatarTime)
190 { first=++it; count-=step+1; }
193 if(first!=last && (**first)->getID()==avatar->
getID())
200 void Store::removeAvatarsFromParticle(
long ID) {
201 std::vector<long> *relatedAvatars = particleAvatarConnections.find(ID)->second;
202 for(std::vector<long>::const_iterator i = relatedAvatars->begin();
203 i != relatedAvatars->end(); ++i) {
204 removeAvatarByID((*i));
206 delete relatedAvatars;
207 particleAvatarConnections.erase(ID);
211 if(avatarList.empty())
return NULL;
213 #ifdef INCL_AVATAR_SEARCH_FullSort
220 IAvatar *avatar = avatarList.front();
222 #elif defined(INCL_AVATAR_SEARCH_INCLSort)
232 if(avatarIterList.empty())
233 best = avatarList.begin();
235 best = avatarIterList.back();
236 G4double bestTime = (*best)->getTime();
239 for(++a; a!=avatarList.end(); ++
a)
240 if((*a)->getTime() < bestTime) {
242 bestTime = (*best)->getTime();
243 avatarIterList.push_back(best);
247 #elif defined(INCL_AVATAR_SEARCH_MinElement)
250 IAvatar *avatar = *(std::min_element(avatarList.begin(), avatarList.end(),
254 #error Unrecognized INCL_AVATAR_SEARCH. Allowed values are: FullSort, INCLSort, MinElement.
257 removeAvatarByID(avatar->
getID());
262 for(std::map<long, Particle*>::iterator particleIter
264 particleIter != particles.end(); ++particleIter) {
265 (*particleIter).second->propagate(step);
272 inside.remove(particles.find(ID)->second);
274 delete particleAvatarConnections.find(ID)->second;
275 particleAvatarConnections.erase(ID);
281 Particle *
const toDelete = particles.find(ID)->second;
282 inside.remove(toDelete);
293 WARN(
"Store::getParticipants is probably slow..." << std::endl);
295 for(std::map<long, Particle*>::iterator iter = particles.begin();
296 iter != particles.end(); ++iter) {
297 if((*iter).second->isParticipant()) {
298 result.push_back((*iter).second);
305 WARN(
"Store::getSpectators is probably slow..." << std::endl);
307 for(std::map<long, Particle*>::iterator iter = particles.begin();
308 iter != particles.end(); ++iter) {
309 if(!(*iter).second->isParticipant()) {
310 result.push_back((*iter).second);
317 for(std::map<long, IAvatar*>::iterator iter = avatars.begin();
318 iter != avatars.end(); ++iter) {
319 delete (*iter).second;
322 for(std::map<
long, std::vector<long>*>::iterator iter = particleAvatarConnections.begin();
323 iter != particleAvatarConnections.end(); ++iter) {
324 delete (*iter).second;
327 particleAvatarConnections.clear();
334 for(
ParticleIter ip=inside.begin(); ip!=inside.end(); ++ip) {
335 std::vector<long> *aIDs =
new std::vector<long>;
336 particleAvatarConnections[(*ip)->getID()] = aIDs;
344 for(std::map<long, Particle*>::iterator iter = particles.begin();
345 iter != particles.end(); ++iter) {
346 delete (*iter).second;
352 if( incoming.size() != 0 ) {
353 WARN(
"Incoming list is not empty when Store::clear() is called" << std::endl);
357 #ifdef INCL_AVATAR_SEARCH_INCLSort
358 avatarIterList.clear();
364 for(
ParticleIter iter = outgoing.begin(); iter != outgoing.end(); ++iter) {
365 if((*iter)->isCluster()) {
368 #ifdef INCLXX_IN_GEANT4_MODE
381 G4int projectileA, projectileZ, A,
Z;
383 G4int ID, type, isParticipant;
387 std::ifstream
in(filename.c_str());
388 in >> projectileA >> projectileZ >> A >> Z >> stoppingTime >> cutNN;
391 loadedStoppingTime = stoppingTime;
396 in >> ID >> type >> isParticipant >> x >> y >> z >> px >> py >> pz >> E >>
v;
397 if(!
in.good())
break;
404 else if(type == -1) {
409 FATAL(
"Unrecognized particle type while loading particles; type=" << type << std::endl);
416 if(isParticipant == 1) {
427 std::stringstream ss;
429 for(
ParticleIter i = inside.begin(); i != inside.end(); ++i) {
430 if((*i)->getType() ==
Proton) {
434 if((*i)->getType() ==
Neutron) {
440 ss <<
"0 0 " << A <<
" " <<
Z <<
" "
442 <<
"0.0" << std::endl;
444 for(
ParticleIter i = inside.begin(); i != inside.end(); ++i) {
445 G4int ID = (*i)->getID();
447 if((*i)->getType() ==
Proton) {
450 if((*i)->getType() ==
Neutron) {
454 G4int isParticipant = 0;
455 if((*i)->isParticipant()) {
463 G4double px = (*i)->getMomentum().getX();
464 G4double py = (*i)->getMomentum().getY();
465 G4double pz = (*i)->getMomentum().getZ();
466 G4double V = (*i)->getPotentialEnergy();
468 ss << ID <<
" " << type <<
" " << isParticipant <<
" "
469 << x <<
" " << y <<
" " << z <<
" "
470 << px <<
" " << py <<
" " << pz <<
" "
471 << E <<
" " << V << std::endl;
478 std::ofstream out(filename.c_str());
484 std::stringstream ss;
486 for(i = avatarList.begin(); i != avatarList.end(); ++i) {
487 ss << (*i)->toString() << std::endl;
494 for(i = avatarList.begin(); i != avatarList.end(); ++i)