Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
G4INCLStore.hh
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// INCL++ intra-nuclear cascade model
27// Pekka Kaitaniemi, CEA and Helsinki Institute of Physics
28// Davide Mancusi, CEA
29// Alain Boudard, CEA
30// Sylvie Leray, CEA
31// Joseph Cugnon, University of Liege
32//
33// INCL++ revision: v5.1.8
34//
35#define INCLXX_IN_GEANT4_MODE 1
36
37#include "globals.hh"
38
39#ifndef G4INCLParticleStore_hh
40#define G4INCLParticleStore_hh 1
41
42#include <map>
43#include <list>
44#include <vector>
45#include <string>
46#include <algorithm>
47
48#include "G4INCLParticle.hh"
49#include "G4INCLIAvatar.hh"
50#include "G4INCLBook.hh"
51#include "G4INCLConfig.hh"
52
53#ifdef INCLXX_IN_GEANT4_MODE
54#define INCL_AVATAR_SEARCH_MinElement 1
55#endif // INCLXX_IN_GEANT4_MODE
56
57namespace G4INCL {
58
59 /**
60 * The purpose of the Store object is to act as a "particle manager"
61 * that keeps track ofall the particles in our simulation. It also
62 * tracks the avatars and their connections to particles.
63 */
64 class Store {
65 public:
66 /**
67 * Store constructor
68 */
69 Store(Config const * const config);
70
71 /**
72 * Store destructor
73 */
74 ~Store();
75
76 /**
77 * Add one particle to the store.
78 *
79 * Particle objects don't know anything about avatars so this
80 * method will only do two things:
81 * 1. add the particle to the particle map ParticleID -> Particle*
82 * 2. add an empty entry for this particle into map AvatarID -> [ParticleID]
83 */
84 void add(Particle *p);
85
86 /// \brief Add one ParticleEntry avatar
88
89 /// \brief Add one ParticleEntry avatar
91
92 /**
93 * Add one avatar to the store
94 *
95 * Avatars know about the particles they are associated
96 * with. Adding an avatar consists of the following steps:
97 * 1. Add the new avatar to the avatar list
98 * 2. Add any related new particles to the store by calling add(Particle*)
99 * (this should not happen, by the time we are adding avatars all particles
100 * should have already been added)
101 * 3. Connect the particles involved to the avatar in the map:
102 * particleAvatarConnections :: ParticleID -> [AvatarID]
103 * 4. Add the new avatar to the map:
104 * avatarParticleConnections :: AvatarID -> [ParticleID]
105 */
106 void add(IAvatar *a);
107
108 /**
109 * Return the list of avatars
110 */
111 IAvatarList const &getAvatars() const {
112 return avatarList;
113 }
114
115 /**
116 * Add a particle to the incoming list.
117 *
118 * \param p particle to add
119 */
120 void addIncomingParticle(Particle * const p);
121
122 /**
123 * Add a particle to the incoming list.
124 *
125 * \param p particle to add
126 */
127 void removeFromIncoming(Particle * const p) { incoming.remove(p); }
128
129 /// \brief Clear the incoming list
130 inline void clearIncoming() {
131 incoming.clear();
132 }
133
134 /// \brief Clear the incoming list and delete the particles
135 inline void deleteIncoming() {
136 for(ParticleIter iter = incoming.begin(); iter != incoming.end(); ++iter) {
137 delete (*iter);
138 }
140 }
141
142 /**
143 * Notify the Store that a particle has been updated. This
144 * triggers the removal of obsolete avatars and their
145 * disconnection from the particle.
146 */
147 void particleHasBeenUpdated(long);
148
149 /**
150 * Find the avatar that has the smallest time.
151 */
153
154 /**
155 * Make one time step: propagate particles and subtract the length
156 * of the step from the avatar times.
157 */
158 void timeStep(G4double step);
159
160 /**
161 * Mark the particle as ejected. This removes it from the list of
162 * inside particles and removes all avatars related to this
163 * particle.
164 */
165 void particleHasBeenEjected(long);
166
167 /** \brief add the particle to the outgoing particle list.
168 *
169 * \param p pointer to the particle to be added
170 */
171 void addToOutgoing(Particle *p) { outgoing.push_back(p); }
172
173 /** \brief Add a list of particles to the outgoing particle list.
174 *
175 * \param pl list of particles to be added
176 */
177 void addToOutgoing(ParticleList const &pl) {
178 for(ParticleIter p=pl.begin(); p!=pl.end(); ++p)
179 addToOutgoing(*p);
180 }
181
182 /**
183 * Remove the particle from the system. This also removes all
184 * avatars related to this particle.
185 */
186 void particleHasBeenDestroyed(long);
187
188 /** \brief Move a particle from incoming to inside
189 *
190 * \param particle pointer to a particle
191 **/
192 void particleHasEntered(Particle * const particle);
193
194 /**
195 * Return the list of incoming particles (i.e. particles that have yet to
196 * enter the cascade).
197 */
198 ParticleList const & getIncomingParticles() const { return incoming; }
199
200 /**
201 * Return the list of outgoing particles (i.e. particles that have left the
202 * cascade).
203 */
204 ParticleList const & getOutgoingParticles() const { return outgoing; }
205
206 /** \brief Returns a list of dynamical spectators
207 *
208 * Looks in the outgoing list for particles without collisions and decays,
209 * removes them from outgoing and returns them in a list.
210 *
211 * \return the (possibly empty) list of dynamical spectators
212 */
214 ParticleList spectators;
215 std::list<std::list<Particle*>::iterator> toBeErased;
216 for(std::list<Particle*>::iterator p=outgoing.begin(); p!=outgoing.end(); ++p) {
217 if((*p)->isProjectileSpectator()) {
218// assert((*p)->isNucleon());
219 spectators.push_back(*p); // add them to the list we will return
220 toBeErased.push_back(p); // we will remove them from outgoing later
221 }
222 }
223
224 // Now erase them from outgoing
225 for(std::list<std::list<Particle*>::iterator>::iterator i=toBeErased.begin();
226 i!=toBeErased.end(); ++i) {
227 outgoing.erase(*i);
228 }
229
230 return spectators;
231 }
232
233 /**
234 * Return the list of "active" particles (i.e. particles that can
235 * participate in collisions).
236 */
237 ParticleList const & getParticles() const { return inside; }
238
239 /**
240 * Return the pointer to the Book object which keeps track of
241 * various counters.
242 */
243 Book* getBook() {return theBook; };
244
246 G4int n=0;
247 for(ParticleIter i=inside.begin(); i!=inside.end(); ++i) {
248 if(!(*i)->isTargetSpectator())
249 ++n;
250 }
251 return n;
252 }
253
254 /**
255 * Get the config object
256 */
257 Config const * getConfig() { return theConfig; };
258
259 /**
260 * Get list of participants (active nucleons).
261 *
262 * Warning: This (slow) method may be deprecated in the near future...
263 */
265
266 /**
267 * Get list of spectators (active nucleons).
268 *
269 * Warning: This (slow) method may be deprecated in the near future...
270 */
272
273 /**
274 * Clear all avatars and particles from the store.
275 *
276 * Warning! This actually deletes the objects as well!
277 */
278 void clear();
279
280 /**
281 * Clear all outgoing particles from the store.
282 *
283 * Warning! This actually deletes the objects as well!
284 */
285 void clearOutgoing();
286
287 /**
288 * Clear avatars only.
289 */
290 void clearAvatars();
291
292 /** \brief Initialise the particleAvatarConnections map
293 *
294 * Generate an empty avatar-ID vector for each particle in the inside list
295 * and fill in the relevant particle-avatar map entry.
296 */
298
299 /**
300 * Load particle configuration from ASCII file (see
301 * avatarPredictionTest).
302 */
303 void loadParticles(std::string filename);
304
305 /**
306 * Get the value of the nucleus mass number that we read from file
307 * with loadParticles.
308 */
309 G4int getLoadedA() { return loadedA; };
310
311 /**
312 * Get the value of the nucleus charge number that we read from file
313 * with loadParticles.
314 */
315 G4int getLoadedZ() { return loadedZ; };
316
317 /**
318 * Get the value of the stopping time that we read from file
319 * with loadParticles.
320 */
321 G4double getLoadedStoppingTime() { return loadedStoppingTime; };
322
323 /**
324 * Print the nucleon configuration of the nucleus.
325 */
326 std::string printParticleConfiguration();
327
328 /**
329 * Print the nucleon configuration of the nucleus.
330 */
331 void writeParticles(std::string filename);
332
333 /**
334 * Print the list of avatars
335 */
336 std::string printAvatars();
337
339
340#if defined(INCL_AVATAR_SEARCH_FullSort) || defined(INCL_AVATAR_SEARCH_MinElement)
341 /** \brief Comparison predicate for avatars.
342 *
343 * avatarComparisonPredicate is used by the std::sort or std::min_element
344 * functions to compare the avatar objects according to their time.
345 *
346 * \param lhs pointer to the first avatar
347 * \param rhs pointer to the second avatar
348 * \return true iff lhs' time is smaller than rhs'.
349 */
351 return (lhs->getTime() < rhs->getTime());
352 }
353#elif defined(INCL_AVATAR_SEARCH_INCLSort)
354 /** \brief Perform a binary search on the avatarIterList.
355 *
356 * By construction, the avatarIterList is always sorted in descending time
357 * order. Thus, we can use binary search if we need to look for a specific
358 * avatar in the list.
359 *
360 * Adapted from STL's binary_search algorithm, as seen on
361 * http://www.cplusplus.com/reference/algorithm/binary_search/.
362 *
363 * \param avatar a pointer to the searched avatar.
364 * \return an iterator to the IAvatarIter, if the avatar is found; otherwise,
365 * IAvatarList.end().
366 */
367 std::list<IAvatarIter>::iterator binaryIterSearch(IAvatar const * const avatar);
368#endif
369
370 private:
371 /// \brief Dummy copy constructor to shut up Coverity warnings
372 Store(const Store &rhs);
373
374 /// \brief Dummy assignment operator to shut up Coverity warnings
375 Store &operator=(Store const &rhs);
376
377 /**
378 * Remove all avatars connected to a particle
379 */
380 void removeAvatarsFromParticle(long ID);
381
382 /**
383 * Check if a particle is in the avatarParticleConnections map
384 */
385 G4bool avatarInConnectionMap(long);
386
387
388 /**
389 * Connects a particle and an avatar
390 */
391 void connectParticleAndAvatar(long particleID, long avatarID);
392
393 /**
394 * Removes an avatar
395 */
396 void removeAvatarFromParticle(long particleID, long avatarID);
397 void removeAvatarByID(long ID);
398
399 private:
400 /**
401 * Map of particle ID -> Particle*
402 */
403 std::map<long, Particle*> particles;
404
405 /**
406 * Map of avatar ID -> IAvatar*
407 */
408 std::map<long, IAvatar*> avatars;
409
410 /**
411 * Map particle ID -> [avatar IDs]
412 */
413 std::map<long, std::vector<long>* > particleAvatarConnections;
414
415 /**
416 * List of all avatars
417 */
418 IAvatarList avatarList;
419
420 /**
421 * List of incoming particles
422 */
423 ParticleList incoming;
424
425 /**
426 * List of particles that are inside the nucleus
427 */
428 ParticleList inside;
429
430 /**
431 * List of outgoing particles
432 */
433 ParticleList outgoing;
434
435 /**
436 * List of geometrical spectators
437 */
438 ParticleList geomSpectators;
439
440 /**
441 * The current time in the simulation
442 */
443 G4double currentTime;
444
445 /**
446 * The Book object keeps track of global counters
447 */
448 Book *theBook;
449
450 /**
451 * The target nucleus mass number that was loaded from a particle file
452 */
453 G4int loadedA;
454
455 /**
456 * The target nucleus charge number that was loaded from a particle file
457 */
458 G4int loadedZ;
459
460 /**
461 * The stopping time that was loaded from a particle file
462 */
463 G4double loadedStoppingTime;
464
465 /**
466 * Pointer to the Config object
467 */
468 Config const * theConfig;
469
470#ifdef INCL_AVATAR_SEARCH_INCLSort
471 /** \brief Internal stack for the INCLSort search algorithm.
472 *
473 * List of std::list<IAvatar*>::const_iterator to keep track of the best
474 * avatars so far.
475 */
476 std::list<IAvatarIter> avatarIterList;
477#endif
478
479 };
480}
481#endif
double G4double
Definition: G4Types.hh:64
int G4int
Definition: G4Types.hh:66
bool G4bool
Definition: G4Types.hh:67
G4double getTime() const
Book * getBook()
Definition: G4INCLStore.hh:243
void clearAvatars()
Definition: G4INCLStore.cc:318
ParticleList const & getIncomingParticles() const
Definition: G4INCLStore.hh:198
void particleHasBeenDestroyed(long)
Definition: G4INCLStore.cc:280
void addParticleEntryAvatars(IAvatarList const &al)
Add one ParticleEntry avatar.
Definition: G4INCLStore.cc:86
void timeStep(G4double step)
Definition: G4INCLStore.cc:263
void addToOutgoing(ParticleList const &pl)
Add a list of particles to the outgoing particle list.
Definition: G4INCLStore.hh:177
IAvatar * findSmallestTime()
Definition: G4INCLStore.cc:212
void deleteIncoming()
Clear the incoming list and delete the particles.
Definition: G4INCLStore.hh:135
void initialiseParticleAvatarConnections()
Initialise the particleAvatarConnections map.
Definition: G4INCLStore.cc:335
void particleHasBeenEjected(long)
Definition: G4INCLStore.cc:271
ParticleList const & getOutgoingParticles() const
Definition: G4INCLStore.hh:204
std::string printAvatars()
Definition: G4INCLStore.cc:485
void particleHasBeenUpdated(long)
Definition: G4INCLStore.cc:164
void addToOutgoing(Particle *p)
add the particle to the outgoing particle list.
Definition: G4INCLStore.hh:171
void addIncomingParticle(Particle *const p)
Definition: G4INCLStore.cc:112
void clearOutgoing()
Definition: G4INCLStore.cc:365
void add(Particle *p)
Definition: G4INCLStore.cc:62
G4double getLoadedStoppingTime()
Definition: G4INCLStore.hh:321
void particleHasEntered(Particle *const particle)
Move a particle from incoming to inside.
Definition: G4INCLStore.cc:289
G4int countCascading()
Definition: G4INCLStore.hh:245
std::string printParticleConfiguration()
Definition: G4INCLStore.cc:428
void writeParticles(std::string filename)
Definition: G4INCLStore.cc:479
G4int getLoadedA()
Definition: G4INCLStore.hh:309
G4bool containsCollisions() const
Definition: G4INCLStore.cc:494
void clearIncoming()
Clear the incoming list.
Definition: G4INCLStore.hh:130
G4int getLoadedZ()
Definition: G4INCLStore.hh:315
static G4bool avatarComparisonPredicate(IAvatar *lhs, IAvatar *rhs)
Comparison predicate for avatars.
Definition: G4INCLStore.hh:350
void loadParticles(std::string filename)
Definition: G4INCLStore.cc:381
ParticleList const & getParticles() const
Definition: G4INCLStore.hh:237
Config const * getConfig()
Definition: G4INCLStore.hh:257
void addParticleEntryAvatar(IAvatar *a)
Add one ParticleEntry avatar.
Definition: G4INCLStore.cc:73
void removeFromIncoming(Particle *const p)
Definition: G4INCLStore.hh:127
ParticleList extractDynamicalSpectators()
Returns a list of dynamical spectators.
Definition: G4INCLStore.hh:213
ParticleList getSpectators()
Definition: G4INCLStore.cc:306
ParticleList getParticipants()
Definition: G4INCLStore.cc:294
IAvatarList const & getAvatars() const
Definition: G4INCLStore.hh:111
std::list< IAvatar * > IAvatarList
std::list< G4INCL::Particle * > ParticleList
std::list< G4INCL::Particle * >::const_iterator ParticleIter