|
||||
File indexing completed on 2025-01-18 09:58:29
0001 // 0002 // ******************************************************************** 0003 // * License and Disclaimer * 0004 // * * 0005 // * The Geant4 software is copyright of the Copyright Holders of * 0006 // * the Geant4 Collaboration. It is provided under the terms and * 0007 // * conditions of the Geant4 Software License, included in the file * 0008 // * LICENSE and available at http://cern.ch/geant4/license . These * 0009 // * include a list of copyright holders. * 0010 // * * 0011 // * Neither the authors of this software system, nor their employing * 0012 // * institutes,nor the agencies providing financial support for this * 0013 // * work make any representation or warranty, express or implied, * 0014 // * regarding this software system or assume any liability for its * 0015 // * use. Please see the license in the file LICENSE and URL above * 0016 // * for the full disclaimer and the limitation of liability. * 0017 // * * 0018 // * This code implementation is the result of the scientific and * 0019 // * technical work of the GEANT4 collaboration. * 0020 // * By using, copying, modifying or distributing the software (or * 0021 // * any work based on the software) you agree to acknowledge its * 0022 // * use in resulting scientific publications, and indicate your * 0023 // * acceptance of all terms of the Geant4 Software license. * 0024 // ******************************************************************** 0025 // 0026 // INCL++ intra-nuclear cascade model 0027 // Alain Boudard, CEA-Saclay, France 0028 // Joseph Cugnon, University of Liege, Belgium 0029 // Jean-Christophe David, CEA-Saclay, France 0030 // Pekka Kaitaniemi, CEA-Saclay, France, and Helsinki Institute of Physics, Finland 0031 // Sylvie Leray, CEA-Saclay, France 0032 // Davide Mancusi, CEA-Saclay, France 0033 // 0034 #define INCLXX_IN_GEANT4_MODE 1 0035 0036 #include "globals.hh" 0037 0038 #ifndef G4INCLParticleStore_hh 0039 #define G4INCLParticleStore_hh 1 0040 0041 #include <map> 0042 #include <set> 0043 #include <list> 0044 #include <string> 0045 #include <algorithm> 0046 0047 #include "G4INCLParticle.hh" 0048 #include "G4INCLIAvatar.hh" 0049 #include "G4INCLBook.hh" 0050 #include "G4INCLConfig.hh" 0051 0052 #ifdef INCLXX_IN_GEANT4_MODE 0053 #define INCL_AVATAR_SEARCH_MinElement 1 0054 #endif // INCLXX_IN_GEANT4_MODE 0055 0056 #if !defined(NDEBUG) && !defined(INCLXX_IN_GEANT4_MODE) 0057 // Force instantiation of all the std::multimap<Particle*,IAvatar*> methods for 0058 // debugging purposes 0059 namespace G4INCL { 0060 class Particle; 0061 class IAvatar; 0062 } 0063 template class std::multimap<G4INCL::Particle*, G4INCL::IAvatar*>; 0064 #endif 0065 0066 namespace G4INCL { 0067 0068 /** 0069 * The purpose of the Store object is to act as a "particle manager" 0070 * that keeps track ofall the particles in our simulation. It also 0071 * tracks the avatars and their connections to particles. 0072 */ 0073 class Store { 0074 public: 0075 /** 0076 * Store constructor 0077 */ 0078 Store(Config const * const config); 0079 0080 /** 0081 * Store destructor 0082 */ 0083 ~Store(); 0084 0085 /** 0086 * Add one particle to the store. 0087 * 0088 * Particle objects don't know anything about avatars so this 0089 * method will only do two things: 0090 * 1. add the particle to the particle map ParticleID -> Particle* 0091 * 2. add an empty entry for this particle into map AvatarID -> [ParticleID] 0092 */ 0093 void add(Particle *p); 0094 0095 /** \brief Add a list of particles to the Store 0096 * 0097 * This acts as if add(Particle *) was called on each element of the list. 0098 */ 0099 void add(ParticleList const &pL); 0100 0101 /// \brief Add one ParticleEntry avatar 0102 void addParticleEntryAvatar(IAvatar *a); 0103 0104 /// \brief Add one ParticleEntry avatar 0105 void addParticleEntryAvatars(IAvatarList const &al); 0106 0107 /** 0108 * Add one avatar to the store 0109 * 0110 * Avatars know about the particles they are associated 0111 * with. Adding an avatar consists of the following steps: 0112 * 1. Add the new avatar to the avatar list 0113 * 2. Add any related new particles to the store by calling add(Particle*) 0114 * (this should not happen, by the time we are adding avatars all particles 0115 * should have already been added) 0116 * 3. Connect the particles involved to the avatar in the map: 0117 * particleAvatarConnections :: ParticleID -> [AvatarID] 0118 * 4. Add the new avatar to the map: 0119 * avatarParticleConnections :: AvatarID -> [ParticleID] 0120 */ 0121 void add(IAvatar *a); 0122 0123 /** 0124 * Return the list of avatars 0125 */ 0126 IAvatarList const &getAvatars() const { 0127 return avatarList; 0128 } 0129 0130 /** 0131 * Add a particle to the incoming list. 0132 * 0133 * \param p particle to add 0134 */ 0135 void addIncomingParticle(Particle * const p); 0136 0137 /** 0138 * Add a particle to the incoming list. 0139 * 0140 * \param p particle to add 0141 */ 0142 void removeFromIncoming(Particle * const p) { incoming.remove(p); } 0143 0144 /// \brief Clear the incoming list 0145 inline void clearIncoming() { 0146 incoming.clear(); 0147 } 0148 0149 /// \brief Clear the incoming list and delete the particles 0150 inline void deleteIncoming() { 0151 for(ParticleIter iter=incoming.begin(), e=incoming.end(); iter!=e; ++iter) { 0152 delete (*iter); 0153 } 0154 clearIncoming(); 0155 } 0156 0157 /** \brief Notify the Store about a particle update 0158 * 0159 * Notify the Store that a particle has been updated. This 0160 * schedules the removal of obsolete avatars and their disconnection from 0161 * the particle. 0162 */ 0163 void particleHasBeenUpdated(Particle * const); 0164 0165 /// \brief Remove avatars that have been scheduled 0166 void removeScheduledAvatars(); 0167 0168 /** 0169 * Find the avatar that has the smallest time. 0170 */ 0171 IAvatar* findSmallestTime(); 0172 0173 /** 0174 * Make one time step: propagate particles and subtract the length 0175 * of the step from the avatar times. 0176 */ 0177 void timeStep(G4double step); 0178 0179 /** 0180 * Mark the particle as ejected. This removes it from the list of 0181 * inside particles and removes all avatars related to this 0182 * particle. 0183 */ 0184 void particleHasBeenEjected(Particle * const); 0185 0186 /** \brief add the particle to the outgoing particle list. 0187 * 0188 * \param p pointer to the particle to be added 0189 */ 0190 void addToOutgoing(Particle *p) { outgoing.push_back(p); } 0191 0192 /** \brief Add a list of particles to the outgoing particle list. 0193 * 0194 * \param pl list of particles to be added 0195 */ 0196 void addToOutgoing(ParticleList const &pl) { 0197 for(ParticleIter p=pl.begin(), e=pl.end(); p!=e; ++p) 0198 addToOutgoing(*p); 0199 } 0200 0201 /** 0202 * Remove the particle from the system. This also removes all 0203 * avatars related to this particle. 0204 */ 0205 void particleHasBeenDestroyed(Particle * const); 0206 0207 /** \brief Move a particle from incoming to inside 0208 * 0209 * \param particle pointer to a particle 0210 **/ 0211 void particleHasEntered(Particle * const particle); 0212 0213 /** 0214 * Return the list of incoming particles (i.e. particles that have yet to 0215 * enter the cascade). 0216 */ 0217 ParticleList const & getIncomingParticles() const { return incoming; } 0218 0219 /** 0220 * Return the list of outgoing particles (i.e. particles that have left the 0221 * cascade). 0222 */ 0223 ParticleList const & getOutgoingParticles() const { return outgoing; } 0224 0225 /** \brief Returns a list of dynamical spectators 0226 * 0227 * Looks in the outgoing list for particles without collisions and decays, 0228 * removes them from outgoing and returns them in a list. 0229 * 0230 * \return the (possibly empty) list of dynamical spectators 0231 */ 0232 ParticleList extractDynamicalSpectators() { 0233 ParticleList spectators; 0234 for(ParticleIter p=outgoing.begin(), e=outgoing.end(); p!=e; ++p) { 0235 if((*p)->isProjectileSpectator()) { 0236 // assert((*p)->isNucleon() || (*p)->isLambda()); 0237 spectators.push_back(*p); // add them to the list we will return 0238 } 0239 } 0240 0241 // Now erase them from outgoing 0242 for(ParticleIter i=spectators.begin(); i!=spectators.end(); ++i) { 0243 outgoing.remove(*i); 0244 } 0245 0246 return spectators; 0247 } 0248 0249 /** 0250 * Return the list of "active" particles (i.e. particles that can 0251 * participate in collisions). 0252 */ 0253 ParticleList const & getParticles() const { return inside; } 0254 0255 /** 0256 * Return the pointer to the Book object which keeps track of 0257 * various counters. 0258 */ 0259 Book &getBook() { return theBook; }; 0260 0261 G4int countCascading() { 0262 G4int n=0; 0263 for(ParticleIter i=inside.begin(), e=inside.end(); i!=e; ++i) { 0264 if(!(*i)->isTargetSpectator()) 0265 ++n; 0266 } 0267 return n; 0268 } 0269 0270 /** 0271 * Get the config object 0272 */ 0273 Config const * getConfig() { return theConfig; }; 0274 0275 /** 0276 * Clear all avatars and particles from the store. 0277 * 0278 * Warning! This actually deletes the objects as well! 0279 */ 0280 void clear(); 0281 0282 /** 0283 * Clear all inside particles from the store. 0284 * 0285 * Warning! This actually deletes the objects as well! 0286 */ 0287 void clearInside(); 0288 0289 /** 0290 * Clear all outgoing particles from the store. 0291 * 0292 * Warning! This actually deletes the objects as well! 0293 */ 0294 void clearOutgoing(); 0295 0296 /** 0297 * Clear avatars only. 0298 */ 0299 void clearAvatars(); 0300 0301 /** 0302 * Load particle configuration from ASCII file (see 0303 * avatarPredictionTest). 0304 */ 0305 void loadParticles(std::string const &filename); 0306 0307 /** 0308 * Get the value of the nucleus mass number that we read from file 0309 * with loadParticles. 0310 */ 0311 G4int getLoadedA() { return loadedA; }; 0312 0313 /** 0314 * Get the value of the nucleus charge number that we read from file 0315 * with loadParticles. 0316 */ 0317 G4int getLoadedZ() { return loadedZ; }; 0318 0319 /** 0320 * Get the value of the stopping time that we read from file 0321 * with loadParticles. 0322 */ 0323 G4double getLoadedStoppingTime() { return loadedStoppingTime; }; 0324 0325 /** 0326 * Print the nucleon configuration of the nucleus. 0327 */ 0328 std::string printParticleConfiguration(); 0329 0330 /** 0331 * Print the nucleon configuration of the nucleus. 0332 */ 0333 void writeParticles(std::string const &filename); 0334 0335 /** 0336 * Print the list of avatars 0337 */ 0338 std::string printAvatars(); 0339 0340 G4bool containsCollisions() const; 0341 0342 #if defined(INCL_AVATAR_SEARCH_FullSort) || defined(INCL_AVATAR_SEARCH_MinElement) 0343 /** \brief Comparison predicate for avatars. 0344 * 0345 * avatarComparisonPredicate is used by the std::sort or std::min_element 0346 * functions to compare the avatar objects according to their time. 0347 * 0348 * \param lhs pointer to the first avatar 0349 * \param rhs pointer to the second avatar 0350 * \return true iff lhs' time is smaller than rhs'. 0351 */ 0352 static G4bool avatarComparisonPredicate(IAvatar *lhs, IAvatar *rhs) { 0353 return (lhs->getTime() < rhs->getTime()); 0354 } 0355 #endif 0356 0357 private: 0358 /// \brief Dummy copy constructor to shut up Coverity warnings 0359 Store(const Store &rhs); 0360 0361 /// \brief Dummy assignment operator to shut up Coverity warnings 0362 Store &operator=(Store const &rhs); 0363 0364 0365 /** \brief Connect an avatar to a particle 0366 * 0367 * Adds the avatar to the list of avatars where the particle appears. This 0368 * is typically called when the avatar is created. 0369 * 0370 * \param p the particle 0371 * \param a the avatar 0372 */ 0373 void connectAvatarToParticle(IAvatar * const a, Particle * const p); 0374 0375 /** \brief Disconnect an avatar from a particle 0376 * 0377 * Removes the avatar from the list of avatars where the particle appears. 0378 * This is typically called when the avatar has been invalidated or 0379 * realised. 0380 * 0381 * \param p the particle 0382 * \param a the avatar 0383 */ 0384 void disconnectAvatarFromParticle(IAvatar * const a, Particle * const p); 0385 0386 /** \brief Remove an avatar from the list of avatars 0387 * 0388 * Removes an avatar from the list of all avatars. The avatar is *not* 0389 * deleted. 0390 * 0391 * \param a the avatar to remove 0392 */ 0393 void removeAvatar(IAvatar * const a); 0394 0395 private: 0396 /** 0397 * Map particle -> [avatar] 0398 */ 0399 std::multimap<Particle*, IAvatar*> particleAvatarConnections; 0400 typedef std::multimap<Particle*, IAvatar*>::value_type PAPair; 0401 typedef std::multimap<Particle*, IAvatar*>::iterator PAIter; 0402 typedef std::pair<PAIter, PAIter> PAIterPair; 0403 0404 /// \brief Set of avatars to be removed 0405 std::set<IAvatar*> avatarsToBeRemoved; 0406 typedef std::set<IAvatar*>::const_iterator ASIter; 0407 0408 private: 0409 /** 0410 * List of all avatars 0411 */ 0412 IAvatarList avatarList; 0413 0414 /** 0415 * List of incoming particles 0416 */ 0417 ParticleList incoming; 0418 0419 /** 0420 * List of particles that are inside the nucleus 0421 */ 0422 ParticleList inside; 0423 0424 /** 0425 * List of outgoing particles 0426 */ 0427 ParticleList outgoing; 0428 0429 /** 0430 * List of geometrical spectators 0431 */ 0432 ParticleList geomSpectators; 0433 0434 /** 0435 * The current time in the simulation 0436 */ 0437 G4double currentTime; 0438 0439 /** 0440 * The Book object keeps track of global counters 0441 */ 0442 Book theBook; 0443 0444 /** 0445 * The target nucleus mass number that was loaded from a particle file 0446 */ 0447 G4int loadedA; 0448 0449 /** 0450 * The target nucleus charge number that was loaded from a particle file 0451 */ 0452 G4int loadedZ; 0453 0454 /** 0455 * The stopping time that was loaded from a particle file 0456 */ 0457 G4double loadedStoppingTime; 0458 0459 /** 0460 * Pointer to the Config object 0461 */ 0462 Config const * theConfig; 0463 0464 }; 0465 } 0466 0467 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |