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