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