Geant4 Cross Reference |
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 59 namespace G4INCL { 60 class Particle; 61 class IAvatar; 62 } 63 template class std::multimap<G4INCL::Particle*, G4INCL::IAvatar*>; 64 #endif 65 66 namespace 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 102 void addParticleEntryAvatar(IAvatar *a); 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 } 154 clearIncoming(); 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 /** 202 * Remove the particle from the system. This also removes all 203 * avatars related to this particle. 204 */ 205 void particleHasBeenDestroyed(Particle * const); 206 207 /** \brief Move a particle from incoming to inside 208 * 209 * \param particle pointer to a particle 210 **/ 211 void particleHasEntered(Particle * const particle); 212 213 /** 214 * Return the list of incoming particles (i.e. particles that have yet to 215 * enter the cascade). 216 */ 217 ParticleList const & getIncomingParticles() const { return incoming; } 218 219 /** 220 * Return the list of outgoing particles (i.e. particles that have left the 221 * cascade). 222 */ 223 ParticleList const & getOutgoingParticles() const { return outgoing; } 224 225 /** \brief Returns a list of dynamical spectators 226 * 227 * Looks in the outgoing list for particles without collisions and decays, 228 * removes them from outgoing and returns them in a list. 229 * 230 * \return the (possibly empty) list of dynamical spectators 231 */ 232 ParticleList extractDynamicalSpectators() { 233 ParticleList spectators; 234 for(ParticleIter p=outgoing.begin(), e=outgoing.end(); p!=e; ++p) { 235 if((*p)->isProjectileSpectator()) { 236 // assert((*p)->isNucleon() || (*p)->isLambda()); 237 spectators.push_back(*p); // add them to the list we will return 238 } 239 } 240 241 // Now erase them from outgoing 242 for(ParticleIter i=spectators.begin(); i!=spectators.end(); ++i) { 243 outgoing.remove(*i); 244 } 245 246 return spectators; 247 } 248 249 /** 250 * Return the list of "active" particles (i.e. particles that can 251 * participate in collisions). 252 */ 253 ParticleList const & getParticles() const { return inside; } 254 255 /** 256 * Return the pointer to the Book object which keeps track of 257 * various counters. 258 */ 259 Book &getBook() { return theBook; }; 260 261 G4int countCascading() { 262 G4int n=0; 263 for(ParticleIter i=inside.begin(), e=inside.end(); i!=e; ++i) { 264 if(!(*i)->isTargetSpectator()) 265 ++n; 266 } 267 return n; 268 } 269 270 /** 271 * Get the config object 272 */ 273 Config const * getConfig() { return theConfig; }; 274 275 /** 276 * Clear all avatars and particles from the store. 277 * 278 * Warning! This actually deletes the objects as well! 279 */ 280 void clear(); 281 282 /** 283 * Clear all inside particles from the store. 284 * 285 * Warning! This actually deletes the objects as well! 286 */ 287 void clearInside(); 288 289 /** 290 * Clear all outgoing particles from the store. 291 * 292 * Warning! This actually deletes the objects as well! 293 */ 294 void clearOutgoing(); 295 296 /** 297 * Clear avatars only. 298 */ 299 void clearAvatars(); 300 301 /** 302 * Load particle configuration from ASCII file (see 303 * avatarPredictionTest). 304 */ 305 void loadParticles(std::string const &filename); 306 307 /** 308 * Get the value of the nucleus mass number that we read from file 309 * with loadParticles. 310 */ 311 G4int getLoadedA() { return loadedA; }; 312 313 /** 314 * Get the value of the nucleus charge number that we read from file 315 * with loadParticles. 316 */ 317 G4int getLoadedZ() { return loadedZ; }; 318 319 /** 320 * Get the value of the stopping time that we read from file 321 * with loadParticles. 322 */ 323 G4double getLoadedStoppingTime() { return loadedStoppingTime; }; 324 325 /** 326 * Print the nucleon configuration of the nucleus. 327 */ 328 std::string printParticleConfiguration(); 329 330 /** 331 * Print the nucleon configuration of the nucleus. 332 */ 333 void writeParticles(std::string const &filename); 334 335 /** 336 * Print the list of avatars 337 */ 338 std::string printAvatars(); 339 340 G4bool containsCollisions() const; 341 342 #if defined(INCL_AVATAR_SEARCH_FullSort) || defined(INCL_AVATAR_SEARCH_MinElement) 343 /** \brief Comparison predicate for avatars. 344 * 345 * avatarComparisonPredicate is used by the std::sort or std::min_element 346 * functions to compare the avatar objects according to their time. 347 * 348 * \param lhs pointer to the first avatar 349 * \param rhs pointer to the second avatar 350 * \return true iff lhs' time is smaller than rhs'. 351 */ 352 static G4bool avatarComparisonPredicate(IAvatar *lhs, IAvatar *rhs) { 353 return (lhs->getTime() < rhs->getTime()); 354 } 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. 390 * 391 * \param a the avatar to remove 392 */ 393 void removeAvatar(IAvatar * const a); 394 395 private: 396 /** 397 * Map particle -> [avatar] 398 */ 399 std::multimap<Particle*, IAvatar*> particleAvatarConnections; 400 typedef std::multimap<Particle*, IAvatar*>::value_type PAPair; 401 typedef std::multimap<Particle*, IAvatar*>::iterator PAIter; 402 typedef std::pair<PAIter, PAIter> PAIterPair; 403 404 /// \brief Set of avatars to be removed 405 std::set<IAvatar*> avatarsToBeRemoved; 406 typedef std::set<IAvatar*>::const_iterator ASIter; 407 408 private: 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 }; 465 } 466 467 #endif 468