Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:06

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 // G4StackManager
0027 //
0028 // Class description:
0029 //
0030 // This is the manager class of handling stacks of G4Track objects.
0031 // This class must be a singleton and be constructed by G4EventManager.
0032 // Almost all methods must be invoked exclusively by G4EventManager.
0033 // Especially, some Clear() methods MUST NOT be invoked by the user.
0034 // Event abortion is handled by G4EventManager.
0035 //
0036 // G4StackManager has three stacks, the urgent stack, the
0037 // waiting stack, and the postpone to next event stack. The meanings
0038 // of each stack is descrived in the Geant4 User's Manual.
0039 
0040 // Author: Makoto Asai, 1996
0041 //
0042 // History:
0043 // - 01/Feb/1996, Makoto Asai - Created
0044 // - 04/Oct/2011, Pere Mato - Use of G4TrackStack with value semantics
0045 // - 28/Aug/2023, Makoto Asai - Adding sub-event parallelism
0046 // --------------------------------------------------------------------
0047 #ifndef G4StackManager_hh
0048 #define G4StackManager_hh 1
0049 
0050 #include <map>
0051 #include <vector>
0052 
0053 #include "G4UserStackingAction.hh"
0054 #include "G4StackedTrack.hh"
0055 #include "G4TrackStack.hh"
0056 #include "G4SmartTrackStack.hh"
0057 #include "G4SubEventTrackStack.hh"
0058 #include "G4ClassificationOfNewTrack.hh"
0059 #include "G4Track.hh"
0060 #include "G4TrackStatus.hh"
0061 #include "G4ExceptionSeverity.hh"
0062 #include "globals.hh"
0063 
0064 class G4StackingMessenger;
0065 class G4VTrajectory;
0066 class G4Event;
0067 class G4ParticleDefinition;
0068 
0069 class G4StackManager 
0070 {
0071   public:
0072 
0073     G4StackManager();
0074    ~G4StackManager();
0075 
0076     const G4StackManager& operator=(const G4StackManager&) = delete;
0077     G4bool operator==(const G4StackManager&) const = delete;
0078     G4bool operator!=(const G4StackManager&) const = delete;
0079 
0080     G4int PushOneTrack(G4Track* newTrack,
0081                        G4VTrajectory* newTrajectory = nullptr);
0082     G4Track* PopNextTrack(G4VTrajectory** newTrajectory);
0083     G4int PrepareNewEvent(G4Event* currentEvent);
0084 
0085     void ReClassify();
0086       // Send all tracks stored in the Urgent stack one by one to 
0087       // the user's concrete ClassifyNewTrack() method. This method
0088       // can be invoked from the user's G4UserStackingAction concrete
0089       // class, especially fron its NewStage() method. Be aware that
0090       // when the urgent stack becomes empty, all tracks in the waiting
0091       // stack are send to the urgent stack and then the user's NewStage()
0092       // method is invoked.
0093 
0094     void SetNumberOfAdditionalWaitingStacks(G4int iAdd);
0095       // Set the number of additional (optional) waiting stacks.
0096       // This method must be invoked at PreInit, Init or Idle states.
0097       // Once the user set the number of additional waiting stacks,
0098       // he/she can use the corresponding ENUM in G4ClassificationOfNewTrack.
0099       // The user should invoke G4RunManager::SetNumberOfAdditionalWaitingStacks
0100       // method, which invokes this method.
0101 
0102     void TransferStackedTracks(G4ClassificationOfNewTrack origin,
0103                                G4ClassificationOfNewTrack destination);
0104       // Transfer all stacked tracks from the origin stack to the
0105       // destination stack. The destination stack needs not be empty.
0106       // If the destination is fKill, tracks are deleted.
0107       // If the origin is fKill, nothing happen.
0108 
0109     void TransferOneStackedTrack(G4ClassificationOfNewTrack origin,
0110                                  G4ClassificationOfNewTrack destination);
0111       // Transfter one stacked track from the origin stack to the destination
0112       // stack.
0113       // The transfered track is the one which came last to the origin stack.
0114       // The destination stack needs not be empty.
0115       // If the destination is fKill, the track is deleted.
0116       // If the origin is fKill, nothing happen.
0117 
0118     void RegisterSubEventType(G4int ty, G4int maxEnt);
0119       // Registering a sub-event type and the capacity of the tracks to be 
0120       // stored in a G4SubEvent object of the corresponding sub-event type
0121 
0122     void SetDefaultClassification(
0123              G4TrackStatus, G4ClassificationOfNewTrack,
0124              G4ExceptionSeverity es = G4ExceptionSeverity::IgnoreTheIssue);
0125     void SetDefaultClassification(
0126              const G4ParticleDefinition*, G4ClassificationOfNewTrack,
0127              G4ExceptionSeverity es = G4ExceptionSeverity::IgnoreTheIssue);
0128       // Define the default classification for a newly arriving track.
0129       // Default can be alternated by the UserStackingAction.
0130       // G4ExceptionSeverity can be set to warn the user if the classification
0131       // is inproperly changed.
0132 
0133     inline G4ClassificationOfNewTrack GetDefaultClassification()
0134     { return fDefaultClassification; }
0135 
0136   public:
0137     void ReleaseSubEvent(G4int ty);
0138     inline std::size_t GetNSubEventTypes()
0139     { return subEvtTypes.size(); }
0140     inline G4int GetSubEventType(std::size_t i)
0141     { return subEvtTypes[i]; }
0142     
0143     void clear();
0144     void ClearUrgentStack();
0145     void ClearWaitingStack(G4int i=0);
0146     void ClearPostponeStack();
0147     G4int GetNTotalTrack() const;
0148     G4int GetNUrgentTrack() const;
0149     G4int GetNWaitingTrack(G4int i=0) const;
0150     G4int GetNPostponedTrack() const;
0151     void SetVerboseLevel( G4int const value );
0152     void SetUserStackingAction(G4UserStackingAction* value);
0153 
0154   private:
0155     void DefineDefaultClassification(const G4Track* aTrack);
0156     void SortOut(G4StackedTrack&,G4ClassificationOfNewTrack);
0157 
0158   private:
0159 
0160     G4UserStackingAction* userStackingAction = nullptr;
0161     G4int verboseLevel = 0;
0162 #ifdef G4_USESMARTSTACK
0163     G4SmartTrackStack* urgentStack = nullptr;
0164 #else
0165     G4TrackStack* urgentStack = nullptr;
0166 #endif
0167     G4TrackStack* waitingStack = nullptr;
0168     G4TrackStack* postponeStack = nullptr;
0169     G4StackingMessenger* theMessenger = nullptr;
0170     std::vector<G4TrackStack*> additionalWaitingStacks;
0171     G4int numberOfAdditionalWaitingStacks = 0;
0172 
0173     std::map<G4TrackStatus,
0174              std::pair<G4ClassificationOfNewTrack,G4ExceptionSeverity>>
0175              defClassTrackStatus;
0176     std::map<const G4ParticleDefinition*,
0177              std::pair<G4ClassificationOfNewTrack,G4ExceptionSeverity>>
0178              defClassPartDef;
0179     G4ClassificationOfNewTrack fDefaultClassification = fUrgent;
0180     G4ExceptionSeverity fExceptionSeverity = G4ExceptionSeverity::IgnoreTheIssue;
0181 
0182     std::map<G4int,G4SubEventTrackStack*> subEvtStackMap;
0183     std::vector<G4int> subEvtTypes;
0184 };
0185 
0186 #endif