Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-28 09:13:40

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     /** \brief add the particle to the missed particle list (for dbar).
0202      * 
0203      * \param p pointer to the particle to be added
0204      */
0205     void addToMissed(Particle *p) { missed.push_back(p); }
0206 
0207     /**
0208      * Remove the particle from the system. This also removes all
0209      * avatars related to this particle.
0210      */
0211     void particleHasBeenDestroyed(Particle * const);
0212 
0213     /** \brief Move a particle from incoming to inside
0214      *
0215      * \param particle pointer to a particle
0216      **/
0217     void particleHasEntered(Particle * const particle);
0218 
0219     /**
0220      * Return the list of incoming particles (i.e. particles that have yet to
0221      * enter the cascade).
0222      */
0223     ParticleList const & getIncomingParticles() const { return incoming; }
0224 
0225     /**
0226      * Return the list of outgoing particles (i.e. particles that have left the
0227      * cascade).
0228      */
0229     ParticleList const & getOutgoingParticles() const { return outgoing; }
0230  
0231     /**
0232      * Return the list of missed particles (i.e. particles that have missed the
0233      * nucleus and so do not participate in the cascade, only for dbar).
0234      */
0235     ParticleList const & getMissedParticles() const { return missed; }
0236 
0237     /** \brief Returns a list of dynamical spectators
0238      *
0239      * Looks in the outgoing list for particles without collisions and decays,
0240      * removes them from outgoing and returns them in a list.
0241      *
0242      * \return the (possibly empty) list of dynamical spectators
0243      */
0244     ParticleList extractDynamicalSpectators() {
0245       ParticleList spectators;
0246       for(ParticleIter p=outgoing.begin(), e=outgoing.end(); p!=e; ++p) {
0247         if((*p)->isProjectileSpectator()) {
0248 //          assert((*p)->isNucleon() || (*p)->isLambda() || (*p)->isAntiNucleon());
0249           spectators.push_back(*p); // add them to the list we will return
0250         }
0251       }
0252 
0253       // Now erase them from outgoing
0254       for(ParticleIter i=spectators.begin(); i!=spectators.end(); ++i) {
0255         outgoing.remove(*i);
0256       }
0257 
0258       return spectators;
0259     }
0260 
0261     /**
0262      * Return the list of "active" particles (i.e. particles that can
0263      * participate in collisions).
0264      */
0265     ParticleList const & getParticles() const { return inside; }
0266  
0267      /**
0268      * Return the list of "active" particles (i.e. particles that can
0269      * participate in collisions) to define the src-pairs.
0270      */
0271     ParticleList & getParticlesforSrc() { return inside; }
0272 
0273     /**
0274      * Return the pointer to the Book object which keeps track of
0275      * various counters.
0276      */
0277     Book &getBook() { return theBook; };
0278 
0279     G4int countCascading() {
0280       G4int n=0;
0281       for(ParticleIter i=inside.begin(), e=inside.end(); i!=e; ++i) {
0282         if(!(*i)->isTargetSpectator())
0283           ++n;
0284       }
0285       return n;
0286     }
0287 
0288     /**
0289      * Get the config object
0290      */
0291     Config const * getConfig() { return theConfig; };
0292 
0293     /**
0294      * Clear all avatars and particles from the store.
0295      *
0296      * Warning! This actually deletes the objects as well!
0297      */
0298     void clear();
0299 
0300     /**
0301      * Clear all inside particles from the store.
0302      *
0303      * Warning! This actually deletes the objects as well!
0304      */
0305     void clearInside();
0306 
0307     /**
0308      * Clear all outgoing particles from the store.
0309      *
0310      * Warning! This actually deletes the objects as well!
0311      */
0312     void clearOutgoing();
0313 
0314     /**
0315      * Clear avatars only.
0316      */
0317     void clearAvatars();
0318 
0319     /**
0320      * Load particle configuration from ASCII file (see
0321      * avatarPredictionTest).
0322      */
0323     void loadParticles(std::string const &filename);
0324 
0325     /**
0326      * Get the value of the nucleus mass number that we read from file
0327      * with loadParticles.
0328      */
0329     G4int getLoadedA() { return loadedA; };
0330 
0331     /**
0332      * Get the value of the nucleus charge number that we read from file
0333      * with loadParticles.
0334      */
0335     G4int getLoadedZ() { return loadedZ; };
0336 
0337     /**
0338      * Get the value of the stopping time that we read from file
0339      * with loadParticles.
0340      */
0341     G4double getLoadedStoppingTime() { return loadedStoppingTime; };
0342 
0343     /**
0344      * Print the nucleon configuration of the nucleus.
0345      */
0346     std::string printParticleConfiguration();
0347 
0348     /**
0349      * Print the nucleon configuration of the nucleus.
0350      */
0351     void writeParticles(std::string const &filename);
0352 
0353     /**
0354      * Print the list of avatars
0355      */
0356     std::string printAvatars();
0357 
0358     G4bool containsCollisions() const;
0359 
0360 #if defined(INCL_AVATAR_SEARCH_FullSort) || defined(INCL_AVATAR_SEARCH_MinElement)
0361   /** \brief Comparison predicate for avatars.
0362    *
0363    * avatarComparisonPredicate is used by the std::sort or std::min_element
0364    * functions to compare the avatar objects according to their time.
0365    *
0366    * \param lhs pointer to the first avatar
0367    * \param rhs pointer to the second avatar
0368    * \return true iff lhs' time is smaller than rhs'.
0369    */
0370     static G4bool avatarComparisonPredicate(IAvatar *lhs, IAvatar *rhs) {
0371       return (lhs->getTime() < rhs->getTime());
0372     }
0373 #endif
0374 
0375   private:
0376     /// \brief Dummy copy constructor to shut up Coverity warnings
0377     Store(const Store &rhs);
0378 
0379     /// \brief Dummy assignment operator to shut up Coverity warnings
0380     Store &operator=(Store const &rhs);
0381 
0382 
0383     /** \brief Connect an avatar to a particle
0384      *
0385      * Adds the avatar to the list of avatars where the particle appears. This
0386      * is typically called when the avatar is created.
0387      *
0388      * \param p the particle
0389      * \param a the avatar
0390      */
0391     void connectAvatarToParticle(IAvatar * const a, Particle * const p);
0392 
0393     /** \brief Disconnect an avatar from a particle
0394      *
0395      * Removes the avatar from the list of avatars where the particle appears.
0396      * This is typically called when the avatar has been invalidated or
0397      * realised.
0398      *
0399      * \param p the particle
0400      * \param a the avatar
0401      */
0402     void disconnectAvatarFromParticle(IAvatar * const a, Particle * const p);
0403 
0404     /** \brief Remove an avatar from the list of avatars
0405      *
0406      * Removes an avatar from the list of all avatars. The avatar is *not*
0407      * deleted.
0408      *
0409      * \param a the avatar to remove
0410      */
0411     void removeAvatar(IAvatar * const a);
0412 
0413   private:
0414     /**
0415      * Map particle -> [avatar]
0416      */
0417     std::multimap<Particle*, IAvatar*> particleAvatarConnections;
0418     typedef std::multimap<Particle*, IAvatar*>::value_type PAPair;
0419     typedef std::multimap<Particle*, IAvatar*>::iterator PAIter;
0420     typedef std::pair<PAIter, PAIter> PAIterPair;
0421 
0422     /// \brief Set of avatars to be removed
0423     std::set<IAvatar*> avatarsToBeRemoved;
0424     typedef std::set<IAvatar*>::const_iterator ASIter;
0425 
0426   private:
0427     /**
0428      * List of all avatars
0429      */
0430     IAvatarList avatarList;
0431 
0432     /**
0433      * List of incoming particles
0434      */
0435     ParticleList incoming;
0436 
0437     /**
0438      * List of particles that are inside the nucleus
0439      */
0440     ParticleList inside;
0441 
0442     /**
0443      * List of outgoing particles
0444      */
0445     ParticleList outgoing;
0446  
0447     /**
0448      * List of missed particles (for dbar)
0449      */
0450     ParticleList missed;
0451 
0452     /**
0453      * List of geometrical spectators
0454      */
0455     ParticleList geomSpectators;
0456 
0457     /**
0458      * The current time in the simulation
0459      */
0460     G4double currentTime;
0461 
0462     /**
0463      * The Book object keeps track of global counters
0464      */
0465     Book theBook;
0466 
0467     /**
0468      * The target nucleus mass number that was loaded from a particle file
0469      */
0470     G4int loadedA;
0471 
0472     /**
0473      * The target nucleus charge number that was loaded from a particle file
0474      */
0475     G4int loadedZ;
0476 
0477     /**
0478      * The stopping time that was loaded from a particle file
0479      */
0480     G4double loadedStoppingTime;
0481 
0482     /**
0483      * Pointer to the Config object
0484      */
0485     Config const * theConfig;
0486 
0487   };
0488 }
0489 
0490 #endif