Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 09:15:39

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 //
0027 // Author: Mathieu Karamitros
0028 
0029 // The code is developed in the framework of the ESA AO7146
0030 //
0031 // We would be very happy hearing from you, send us your feedback! :)
0032 //
0033 // In order for Geant4-DNA to be maintained and still open-source,
0034 // article citations are crucial.
0035 // If you use Geant4-DNA chemistry and you publish papers about your software,
0036 // in addition to the general paper on Geant4-DNA:
0037 //
0038 // Int. J. Model. Simul. Sci. Comput. 1 (2010) 157–178
0039 //
0040 // we would be very happy if you could please also cite the following
0041 // reference papers on chemistry:
0042 //
0043 // J. Comput. Phys. 274 (2014) 841-882
0044 // Prog. Nucl. Sci. Tec. 2 (2011) 503-508
0045 
0046 #ifndef G4Scheduler_h
0047 #define G4Scheduler_h
0048 
0049 #include "G4ITModelHandler.hh"
0050 #include "G4ITReaction.hh"
0051 #include "G4ITStepStatus.hh"
0052 #include "G4ITTrackHolder.hh"
0053 #include "G4VScavengerMaterial.hh"
0054 #include "G4VStateDependent.hh"
0055 #include "globals.hh"
0056 
0057 #include <G4VScheduler.hh>
0058 
0059 #include <map>
0060 #include <memory>
0061 #include <vector>
0062 
0063 class G4ITTrackingManager;
0064 class G4ITModelProcessor;
0065 class G4ITStepProcessor;
0066 class G4Track;
0067 class G4UserTimeStepAction;
0068 class G4SchedulerMessenger;
0069 class G4ITTrackingInteractivity;
0070 class G4ITGun;
0071 
0072 #ifndef compTrackPerID__
0073 #  define compTrackPerID__
0074 struct compTrackPerID
0075 {
0076     G4bool operator()(G4Track* rhs, G4Track* lhs) const
0077     {
0078       return rhs->GetTrackID() < lhs->GetTrackID();
0079     }
0080 };
0081 #endif
0082 
0083 /**
0084  * G4Scheduler synchronizes (in time) track stepping
0085  */
0086 class G4Scheduler : public G4VScheduler, public G4VStateDependent
0087 {
0088   protected:
0089     ~G4Scheduler() override;
0090 
0091   public:
0092     G4Scheduler(const G4Scheduler&) = delete;
0093     G4Scheduler& operator=(const G4Scheduler&) = delete;
0094 
0095     static G4Scheduler* Instance();
0096     /** DeleteInstance should be used instead
0097      * of the destructor
0098      */
0099     static void DeleteInstance();
0100     G4bool Notify(G4ApplicationState requestedState) override;
0101 
0102     void RegisterModel(G4VITStepModel*, G4double) override;
0103 
0104     void Initialize() override;
0105     void ForceReinitialization();
0106     inline G4bool IsInitialized();
0107     inline G4bool IsRunning() override { return fRunning; }
0108     void Reset() override;
0109     void Process() override;
0110     void ClearList();
0111 
0112     inline void SetGun(G4ITGun*) override;
0113     inline G4ITGun* GetGun();
0114 
0115     inline void Stop();
0116     void Clear();
0117 
0118     // To be called only in UserReactionAction::EndProcessing()
0119     // after fRunning flag has been turned off.
0120     // This is not done automatically before UserReactionAction::EndProcessing()
0121     // is called in case one would like to access some track information
0122     void EndTracking();
0123 
0124     void SetEndTime(const G4double) override;
0125 
0126     /* Two tracks below the time tolerance are supposed to be
0127      * in the same time slice
0128      */
0129     inline void SetTimeTolerance(G4double) override;
0130     inline G4double GetTimeTolerance() const override;
0131 
0132     inline void SetMaxZeroTimeAllowed(G4int) override;
0133     inline G4int GetMaxZeroTimeAllowed() const override;
0134 
0135     inline G4ITModelHandler* GetModelHandler() override;
0136 
0137     inline void SetTimeSteps(std::map<G4double, G4double>*) override;
0138     inline void AddTimeStep(G4double, G4double) override;
0139     inline void SetDefaultTimeStep(G4double) override;
0140     G4double GetLimitingTimeStep() const override;
0141     inline G4int GetNbSteps() const override;
0142     inline void SetMaxNbSteps(G4int) override;
0143     inline G4int GetMaxNbSteps() const override;
0144     inline G4double GetStartTime() const override;
0145     inline G4double GetEndTime() const override;
0146     inline G4double GetTimeStep() const override;
0147     inline G4double GetPreviousTimeStep() const override;
0148     inline G4double GetGlobalTime() const override;
0149     inline void SetUserAction(G4UserTimeStepAction*) override;
0150     inline G4UserTimeStepAction* GetUserTimeStepAction() const override;
0151 
0152     // To use with transportation only, no reactions
0153     inline void UseDefaultTimeSteps(G4bool);
0154     inline G4bool AreDefaultTimeStepsUsed();
0155 
0156     inline G4ITStepStatus GetStatus() const;
0157 
0158     /* 1 : Reaction information
0159      * 2 : (1) + time step information
0160      * 3 : (2) + step info for individual tracks
0161      * 4 : (2) + trackList processing info + pushed and killed track info
0162      */
0163     inline void SetVerbose(G4int) override;
0164 
0165     inline G4int GetVerbose() const;
0166 
0167     inline void WhyDoYouStop();
0168 
0169     void SetInteractivity(G4ITTrackingInteractivity*) override;
0170     inline G4ITTrackingInteractivity* GetInteractivity() override;
0171 
0172     virtual size_t GetNTracks();
0173 
0174     void GetCollisionType(G4String& interactionType);
0175 
0176     void AddWatchedTime(G4double time) { fWatchedTimes.insert(time); }
0177 
0178     G4double GetNextWatchedTime() const;
0179 
0180     inline void SetMaxTimeStep(G4double maxTimeStep) { fMaxTimeStep = maxTimeStep; }
0181 
0182     inline G4double GetMaxTimeStep() const { return fMaxTimeStep; }
0183 
0184     inline G4VScavengerMaterial* GetScavengerMaterial() const { return fpUserScavenger.get(); }
0185     inline void SetScavengerMaterial(std::unique_ptr<G4VScavengerMaterial> scavengerMaterial)
0186     {
0187       fpUserScavenger = std::move(scavengerMaterial);
0188     }
0189 
0190   protected:
0191     void DoProcess();
0192     void SynchronizeTracks();
0193     void Stepping();
0194 
0195     void FindUserPreDefinedTimeStep();
0196 
0197     G4bool CanICarryOn();
0198 
0199     void PrintWhyDoYouStop();
0200 
0201   private:
0202     G4Scheduler();
0203     void Create();
0204 
0205     G4SchedulerMessenger* fpMessenger = nullptr;
0206 
0207     static G4ThreadLocal G4Scheduler* fgScheduler;
0208     G4int fVerbose;
0209     G4bool fWhyDoYouStop;
0210     G4bool fInitialized;
0211     G4bool fRunning;
0212     G4bool fContinue;
0213 
0214     G4int fNbSteps;
0215     G4int fMaxSteps;
0216 
0217     G4ITStepStatus fITStepStatus;
0218 
0219     // Time members
0220     G4bool fUseDefaultTimeSteps;
0221     G4double fTimeTolerance;
0222     G4double fGlobalTime;
0223     G4double fStartTime;
0224     G4double fStopTime;
0225     G4double fEndTime;
0226     G4double fPreviousTimeStep;
0227     G4int fZeroTimeCount;
0228     G4int fMaxNZeroTimeStepsAllowed;
0229 
0230     G4double fTimeStep;  // The selected minimum time step
0231     G4double fMaxTimeStep;
0232 
0233     // User steps
0234     G4bool fUsePreDefinedTimeSteps;
0235     G4double fDefaultMinTimeStep;
0236     std::map<G4double, G4double>* fpUserTimeSteps = nullptr;
0237     // One can give time steps in respect to the global time
0238     mutable G4double fUserUpperTimeLimit;
0239     G4double fDefinedMinTimeStep;
0240     // selected user time step in respect to the global time
0241     G4bool fReachedUserTimeLimit;  // if fMinTimeStep == the user time step
0242 
0243     std::set<G4double> fWatchedTimes;
0244 
0245     G4UserTimeStepAction* fpUserTimeStepAction;
0246 
0247     std::unique_ptr<G4VScavengerMaterial> fpUserScavenger;
0248 
0249     // ==========================================
0250     // TO BE REMOVED
0251     G4ITStepProcessor* fpStepProcessor = nullptr;
0252     G4ITModelProcessor* fpModelProcessor = nullptr;
0253     G4ITTrackingManager* fpTrackingManager = nullptr;
0254     G4ITTrackingInteractivity* fpTrackingInteractivity = nullptr;
0255     G4ITReactionSet* fReactionSet = nullptr;
0256     G4ITTrackHolder& fTrackContainer;
0257     G4ITModelHandler* fpModelHandler = nullptr;
0258     // ==========================================
0259 
0260     G4double fTSTimeStep;
0261     // Time calculated by the time stepper in CalculateMinTimeStep()
0262     G4double fILTimeStep;
0263     // Time calculated by the interaction length methods
0264     // in ComputeInteractionLength()
0265 
0266     G4bool fInteractionStep;
0267     // Flag : if the step is driven by the interaction with the matter and
0268     // NOT by the reaction between tracks
0269 
0270     G4ITGun* fpGun;
0271 
0272     // ==========================================
0273     // Hoang
0274     G4bool fResetScavenger;
0275 
0276   public:
0277     void ResetScavenger(bool);
0278 };
0279 
0280 inline G4bool G4Scheduler::IsInitialized()
0281 {
0282   return fInitialized;
0283 }
0284 
0285 inline G4ITModelHandler* G4Scheduler::GetModelHandler()
0286 {
0287   return fpModelHandler;
0288 }
0289 
0290 inline void G4Scheduler::SetEndTime(const G4double __endtime)
0291 {
0292   fEndTime = __endtime;
0293 }
0294 
0295 inline void G4Scheduler::SetTimeSteps(std::map<G4double, G4double>* steps)
0296 {
0297   fUsePreDefinedTimeSteps = true;
0298   fpUserTimeSteps = steps;
0299 }
0300 
0301 inline void G4Scheduler::AddTimeStep(G4double startingTime, G4double timeStep)
0302 {
0303   if (fpUserTimeSteps == nullptr) {
0304     fpUserTimeSteps = new std::map<G4double, G4double>();
0305     fUsePreDefinedTimeSteps = true;
0306   }
0307 
0308   (*fpUserTimeSteps)[startingTime] = timeStep;
0309 }
0310 
0311 inline G4int G4Scheduler::GetNbSteps() const
0312 {
0313   return fNbSteps;
0314 }
0315 
0316 inline void G4Scheduler::SetMaxNbSteps(G4int maxSteps)
0317 {
0318   fMaxSteps = maxSteps;
0319 }
0320 
0321 inline G4int G4Scheduler::GetMaxNbSteps() const
0322 {
0323   return fMaxSteps;
0324 }
0325 
0326 inline G4double G4Scheduler::GetStartTime() const
0327 {
0328   return fStartTime;
0329 }
0330 
0331 inline G4double G4Scheduler::GetEndTime() const
0332 {
0333   return fEndTime;
0334 }
0335 
0336 inline G4double G4Scheduler::GetTimeStep() const
0337 {
0338   return fTimeStep;
0339 }
0340 
0341 inline void G4Scheduler::SetDefaultTimeStep(G4double timeStep)
0342 {
0343   fDefaultMinTimeStep = timeStep;
0344 }
0345 
0346 inline G4double G4Scheduler::GetGlobalTime() const
0347 {
0348   return fGlobalTime;
0349 }
0350 
0351 inline void G4Scheduler::SetUserAction(G4UserTimeStepAction* userITAction)
0352 {
0353   fpUserTimeStepAction = userITAction;
0354 }
0355 
0356 inline G4UserTimeStepAction* G4Scheduler::GetUserTimeStepAction() const
0357 {
0358   return fpUserTimeStepAction;
0359 }
0360 
0361 inline void G4Scheduler::SetVerbose(G4int verbose)
0362 {
0363   fVerbose = verbose;
0364 }
0365 
0366 inline G4int G4Scheduler::GetVerbose() const
0367 {
0368   return fVerbose;
0369 }
0370 
0371 inline void G4Scheduler::SetMaxZeroTimeAllowed(G4int maxTimeStepAllowed)
0372 {
0373   fMaxNZeroTimeStepsAllowed = maxTimeStepAllowed;
0374 }
0375 
0376 inline G4int G4Scheduler::GetMaxZeroTimeAllowed() const
0377 {
0378   return fMaxNZeroTimeStepsAllowed;
0379 }
0380 
0381 inline void G4Scheduler::SetTimeTolerance(G4double time)
0382 {
0383   fTimeTolerance = time;
0384 }
0385 
0386 inline G4double G4Scheduler::GetTimeTolerance() const
0387 {
0388   return fTimeTolerance;
0389 }
0390 
0391 inline G4double G4Scheduler::GetPreviousTimeStep() const
0392 {
0393   return fPreviousTimeStep;
0394 }
0395 
0396 inline G4ITStepStatus G4Scheduler::GetStatus() const
0397 {
0398   return fITStepStatus;
0399 }
0400 
0401 inline void G4Scheduler::Stop()
0402 {
0403   fContinue = false;
0404 }
0405 
0406 inline G4ITTrackingInteractivity* G4Scheduler::GetInteractivity()
0407 {
0408   return fpTrackingInteractivity;
0409 }
0410 
0411 inline void G4Scheduler::SetGun(G4ITGun* gun)
0412 {
0413   fpGun = gun;
0414 }
0415 
0416 inline G4ITGun* G4Scheduler::GetGun()
0417 {
0418   return fpGun;
0419 }
0420 
0421 inline void G4Scheduler::WhyDoYouStop()
0422 {
0423   fWhyDoYouStop = true;
0424 }
0425 
0426 inline void G4Scheduler::UseDefaultTimeSteps(G4bool flag)
0427 {
0428   fUseDefaultTimeSteps = flag;
0429 }
0430 
0431 inline G4bool G4Scheduler::AreDefaultTimeStepsUsed()
0432 {
0433   return (!fUseDefaultTimeSteps && !fUsePreDefinedTimeSteps);
0434 }
0435 
0436 inline void G4Scheduler::ResetScavenger(bool value)
0437 {
0438   fResetScavenger = value;
0439 }
0440 
0441 #endif