33 #define INCLXX_IN_GEANT4_MODE 1
47 loadedStoppingTime(0.),
60 if(particleAvatarConnections.find(p)==particleAvatarConnections.end()) {
62 particleAvatarConnections[
p] = avatars;
68 avatarList.push_back(a);
71 for(
ParticleIter i=pList.begin(), e=pList.end(); i!=e; ++i) {
74 connectAvatarToParticle(a, *i);
85 avatarList.push_back(a);
88 for(
ParticleIter i=pList.begin(), e=pList.end(); i!=e; ++i) {
95 connectAvatarToParticle(a, *i);
101 incoming.push_back(p);
105 std::map<Particle*, IAvatarList*>::const_iterator iter = particleAvatarConnections.find(p);
107 if(iter!=particleAvatarConnections.end()) {
108 iter->second->push_back(a);
111 avatars->push_back(a);
112 particleAvatarConnections[
p] = avatars;
116 void Store::disconnectAvatarFromParticle(IAvatar *
const a, Particle *
const p) {
117 particleAvatarConnections.find(p)->second->remove(a);
120 void Store::removeAvatar(IAvatar *
const avatar) {
122 ParticleList particlesRelatedToAvatar = avatar->getParticles();
123 for(
ParticleIter particleIter = particlesRelatedToAvatar.begin(), e = particlesRelatedToAvatar.end();
124 particleIter != e; ++particleIter) {
125 disconnectAvatarFromParticle(avatar, *particleIter);
128 #ifdef INCL_AVATAR_SEARCH_INCLSort
130 std::list<IAvatarIter>::iterator it=binaryIterSearch(avatar);
131 if(it != avatarIterList.end())
132 avatarIterList.erase(it);
136 avatarList.
remove(avatar);
139 void Store::removeAndDeleteAvatar(IAvatar *
const avatar) {
140 removeAvatar(avatar);
147 IAvatarList avatars = *(particleAvatarConnections.find(particle)->second);
148 std::for_each(avatars.begin(), avatars.end(), std::bind1st(std::mem_fun(&G4INCL::Store::removeAndDeleteAvatar),
this));
151 #ifdef INCL_AVATAR_SEARCH_INCLSort
152 std::list<IAvatarIter>::iterator Store::binaryIterSearch(
IAvatar const *
const avatar) {
153 std::list<IAvatarIter>::iterator it;
154 std::iterator_traits<std::list<IAvatarIter>::iterator>::difference_type count, step;
155 std::list<IAvatarIter>::iterator
first = avatarIterList.begin();
156 std::list<IAvatarIter>::iterator last = avatarIterList.end();
158 count = distance(first,last);
161 it =
first; step=count/2; advance(it,step);
162 if ((**it)->getTime()>avatarTime)
163 { first=++it; count-=step+1; }
166 if(first!=last && (**first)->getID()==avatar->
getID())
174 if(avatarList.empty())
return NULL;
176 #ifdef INCL_AVATAR_SEARCH_FullSort
183 IAvatar *avatar = avatarList.front();
185 #elif defined(INCL_AVATAR_SEARCH_INCLSort)
195 if(avatarIterList.empty())
196 best = avatarList.begin();
198 best = avatarIterList.back();
199 G4double bestTime = (*best)->getTime();
202 for(++a; a!=avatarList.end(); ++
a)
203 if((*a)->getTime() < bestTime) {
205 bestTime = (*best)->getTime();
206 avatarIterList.push_back(best);
210 #elif defined(INCL_AVATAR_SEARCH_MinElement)
213 IAvatar *avatar = *(std::min_element(avatarList.begin(), avatarList.end(),
217 #error Unrecognized INCL_AVATAR_SEARCH. Allowed values are: FullSort, INCLSort, MinElement.
220 removeAvatar(avatar);
225 for(
ParticleIter particleIter = inside.begin(), particleEnd=inside.end();
226 particleIter != particleEnd; ++particleIter) {
227 (*particleIter)->propagate(step);
235 std::map<Particle*, IAvatarList*>::iterator mapItem = particleAvatarConnections.find(p);
236 delete mapItem->second;
237 particleAvatarConnections.erase(mapItem);
253 for(
IAvatarIter iter = avatarList.begin(), e = avatarList.end(); iter != e; ++iter) {
257 for(std::map<Particle*, IAvatarList*>::iterator iter = particleAvatarConnections.begin(),
258 e = particleAvatarConnections.end(); iter != e; ++iter) {
262 particleAvatarConnections.clear();
268 for(
ParticleIter ip=inside.begin(), e=inside.end(); ip!=e; ++ip) {
279 if( incoming.size() != 0 ) {
280 INCL_WARN(
"Incoming list is not empty when Store::clear() is called" << std::endl);
284 #ifdef INCL_AVATAR_SEARCH_INCLSort
285 avatarIterList.clear();
291 for(
ParticleIter iter=inside.begin(), e=inside.end(); iter!=e; ++iter) {
298 for(
ParticleIter iter=outgoing.begin(), e=outgoing.end(); iter!=e; ++iter) {
299 if((*iter)->isCluster()) {
302 #ifdef INCLXX_IN_GEANT4_MODE
315 G4int projectileA, projectileZ, A,
Z;
317 G4int ID, type, isParticipant;
321 std::ifstream
in(filename.c_str());
322 in >> projectileA >> projectileZ >> A >> Z >> stoppingTime >> cutNN;
325 loadedStoppingTime = stoppingTime;
330 in >> ID >> type >> isParticipant >> x >> y >> z >> px >> py >> pz >> E >>
v;
331 if(!
in.good())
break;
338 else if(type == -1) {
343 INCL_FATAL(
"Unrecognized particle type while loading particles; type=" << type << std::endl);
350 if(isParticipant == 1) {
361 std::stringstream ss;
363 for(
ParticleIter i=inside.begin(), e=inside.end(); i!=e; ++i) {
364 if((*i)->getType() ==
Proton) {
368 if((*i)->getType() ==
Neutron) {
374 ss <<
"0 0 " << A <<
" " <<
Z <<
" "
376 <<
"0.0" << std::endl;
378 for(
ParticleIter i=inside.begin(), e=inside.end(); i!=e; ++i) {
379 G4int ID = (*i)->getID();
381 if((*i)->getType() ==
Proton) {
384 if((*i)->getType() ==
Neutron) {
388 G4int isParticipant = 0;
389 if((*i)->isParticipant()) {
397 G4double px = (*i)->getMomentum().getX();
398 G4double py = (*i)->getMomentum().getY();
399 G4double pz = (*i)->getMomentum().getZ();
400 G4double V = (*i)->getPotentialEnergy();
402 ss << ID <<
" " << type <<
" " << isParticipant <<
" "
403 << x <<
" " << y <<
" " << z <<
" "
404 << px <<
" " << py <<
" " << pz <<
" "
405 << E <<
" " << V << std::endl;
412 std::ofstream out(filename.c_str());
418 std::stringstream ss;
419 for(
IAvatarIter i = avatarList.begin(), e = avatarList.end(); i != e; ++i) {
420 ss << (*i)->toString() << std::endl;
426 for(
IAvatarIter i = avatarList.begin(), e = avatarList.end(); i != e; ++i)
std::string printParticleConfiguration()
void writeParticles(std::string filename)
static G4bool avatarComparisonPredicate(IAvatar *lhs, IAvatar *rhs)
Comparison predicate for avatars.
std::string printAvatars()
G4bool containsCollisions() const
UnorderedVector< IAvatar * >::const_iterator IAvatarIter
IAvatar * findSmallestTime()
Store(Config const *const config)
void addParticleEntryAvatars(IAvatarList const &al)
Add one ParticleEntry avatar.
UnorderedVector< Particle * > ParticleList
void particleHasBeenDestroyed(Particle *const)
void initialiseParticleAvatarConnections()
Initialise the particleAvatarConnections map.
void particleHasBeenEjected(Particle *const)
virtual ParticleList getParticles() const =0
void setPotentialEnergy(G4double v)
Set the particle potential energy.
UnorderedVector< IAvatar * > IAvatarList
void incrementCascading()
void addParticleEntryAvatar(IAvatar *a)
Add one ParticleEntry avatar.
void particleHasBeenUpdated(Particle *const)
void loadParticles(std::string filename)
void addIncomingParticle(Particle *const p)
virtual void makeParticipant()
void timeStep(G4double step)
ParticleList::const_iterator ParticleIter
void removeFromIncoming(Particle *const p)
void particleHasEntered(Particle *const particle)
Move a particle from incoming to inside.