Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-18 09:15:38

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     inline G4bool IsInteractionStep(){
0190       return fInteractionStep;
0191     }
0192     inline void SetInteractionStep(G4bool InteractionStep){
0193       fInteractionStep = InteractionStep;
0194     }
0195 
0196   protected:
0197     void DoProcess();
0198     void SynchronizeTracks();
0199     void Stepping();
0200 
0201     void FindUserPreDefinedTimeStep();
0202 
0203     G4bool CanICarryOn();
0204 
0205     void PrintWhyDoYouStop();
0206 
0207   private:
0208     G4Scheduler();
0209     void Create();
0210 
0211     G4SchedulerMessenger* fpMessenger = nullptr;
0212 
0213     static G4ThreadLocal G4Scheduler* fgScheduler;
0214     G4int fVerbose;
0215     G4bool fWhyDoYouStop;
0216     G4bool fInitialized;
0217     G4bool fRunning;
0218     G4bool fContinue;
0219 
0220     G4int fNbSteps;
0221     G4int fMaxSteps;
0222 
0223     G4ITStepStatus fITStepStatus;
0224 
0225     // Time members
0226     G4bool fUseDefaultTimeSteps;
0227     G4double fTimeTolerance;
0228     G4double fGlobalTime;
0229     G4double fTmpGlobalTime;
0230     G4double fStartTime;
0231     G4double fStopTime;
0232     G4double fEndTime;
0233     G4double fPreviousTimeStep;
0234     G4int fZeroTimeCount;
0235     G4int fMaxNZeroTimeStepsAllowed;
0236 
0237     G4double fTimeStep;  // The selected minimum time step
0238     G4double fMaxTimeStep;
0239 
0240     // User steps
0241     G4bool fUsePreDefinedTimeSteps;
0242     G4double fDefaultMinTimeStep;
0243     std::map<G4double, G4double>* fpUserTimeSteps = nullptr;
0244     // One can give time steps in respect to the global time
0245     mutable G4double fUserUpperTimeLimit;
0246     G4double fDefinedMinTimeStep;
0247     // selected user time step in respect to the global time
0248     G4bool fReachedUserTimeLimit;  // if fMinTimeStep == the user time step
0249 
0250     std::set<G4double> fWatchedTimes;
0251 
0252     G4UserTimeStepAction* fpUserTimeStepAction;
0253 
0254     std::unique_ptr<G4VScavengerMaterial> fpUserScavenger;
0255 
0256     // ==========================================
0257     // TO BE REMOVED
0258     G4ITStepProcessor* fpStepProcessor = nullptr;
0259     G4ITModelProcessor* fpModelProcessor = nullptr;
0260     G4ITTrackingManager* fpTrackingManager = nullptr;
0261     G4ITTrackingInteractivity* fpTrackingInteractivity = nullptr;
0262     G4ITReactionSet* fReactionSet = nullptr;
0263     G4ITTrackHolder& fTrackContainer;
0264     G4ITModelHandler* fpModelHandler = nullptr;
0265     // ==========================================
0266 
0267     G4double fTSTimeStep;
0268     // Time calculated by the time stepper in CalculateMinTimeStep()
0269     G4double fILTimeStep;
0270     // Time calculated by the interaction length methods
0271     // in ComputeInteractionLength()
0272 
0273     G4bool fInteractionStep;
0274     // Flag : if the step is driven by the interaction with the matter and
0275     // NOT by the reaction between tracks
0276 
0277     G4ITGun* fpGun;
0278 
0279     // ==========================================
0280     // Hoang
0281     G4bool fResetScavenger;
0282 
0283   public:
0284     void ResetScavenger(bool);
0285 };
0286 
0287 inline G4bool G4Scheduler::IsInitialized()
0288 {
0289   return fInitialized;
0290 }
0291 
0292 inline G4ITModelHandler* G4Scheduler::GetModelHandler()
0293 {
0294   return fpModelHandler;
0295 }
0296 
0297 inline void G4Scheduler::SetEndTime(const G4double __endtime)
0298 {
0299   fEndTime = __endtime;
0300 }
0301 
0302 inline void G4Scheduler::SetTimeSteps(std::map<G4double, G4double>* steps)
0303 {
0304   fUsePreDefinedTimeSteps = true;
0305   fpUserTimeSteps = steps;
0306 }
0307 
0308 inline void G4Scheduler::AddTimeStep(G4double startingTime, G4double timeStep)
0309 {
0310   if (fpUserTimeSteps == nullptr) {
0311     fpUserTimeSteps = new std::map<G4double, G4double>();
0312     fUsePreDefinedTimeSteps = true;
0313   }
0314 
0315   (*fpUserTimeSteps)[startingTime] = timeStep;
0316 }
0317 
0318 inline G4int G4Scheduler::GetNbSteps() const
0319 {
0320   return fNbSteps;
0321 }
0322 
0323 inline void G4Scheduler::SetMaxNbSteps(G4int maxSteps)
0324 {
0325   fMaxSteps = maxSteps;
0326 }
0327 
0328 inline G4int G4Scheduler::GetMaxNbSteps() const
0329 {
0330   return fMaxSteps;
0331 }
0332 
0333 inline G4double G4Scheduler::GetStartTime() const
0334 {
0335   return fStartTime;
0336 }
0337 
0338 inline G4double G4Scheduler::GetEndTime() const
0339 {
0340   return fEndTime;
0341 }
0342 
0343 inline G4double G4Scheduler::GetTimeStep() const
0344 {
0345   return fTimeStep;
0346 }
0347 
0348 inline void G4Scheduler::SetDefaultTimeStep(G4double timeStep)
0349 {
0350   fDefaultMinTimeStep = timeStep;
0351 }
0352 
0353 inline G4double G4Scheduler::GetGlobalTime() const
0354 {
0355   return fGlobalTime;
0356 }
0357 
0358 inline void G4Scheduler::SetUserAction(G4UserTimeStepAction* userITAction)
0359 {
0360   fpUserTimeStepAction = userITAction;
0361 }
0362 
0363 inline G4UserTimeStepAction* G4Scheduler::GetUserTimeStepAction() const
0364 {
0365   return fpUserTimeStepAction;
0366 }
0367 
0368 inline void G4Scheduler::SetVerbose(G4int verbose)
0369 {
0370   fVerbose = verbose;
0371 }
0372 
0373 inline G4int G4Scheduler::GetVerbose() const
0374 {
0375   return fVerbose;
0376 }
0377 
0378 inline void G4Scheduler::SetMaxZeroTimeAllowed(G4int maxTimeStepAllowed)
0379 {
0380   fMaxNZeroTimeStepsAllowed = maxTimeStepAllowed;
0381 }
0382 
0383 inline G4int G4Scheduler::GetMaxZeroTimeAllowed() const
0384 {
0385   return fMaxNZeroTimeStepsAllowed;
0386 }
0387 
0388 inline void G4Scheduler::SetTimeTolerance(G4double time)
0389 {
0390   fTimeTolerance = time;
0391 }
0392 
0393 inline G4double G4Scheduler::GetTimeTolerance() const
0394 {
0395   return fTimeTolerance;
0396 }
0397 
0398 inline G4double G4Scheduler::GetPreviousTimeStep() const
0399 {
0400   return fPreviousTimeStep;
0401 }
0402 
0403 inline G4ITStepStatus G4Scheduler::GetStatus() const
0404 {
0405   return fITStepStatus;
0406 }
0407 
0408 inline void G4Scheduler::Stop()
0409 {
0410   fContinue = false;
0411 }
0412 
0413 inline G4ITTrackingInteractivity* G4Scheduler::GetInteractivity()
0414 {
0415   return fpTrackingInteractivity;
0416 }
0417 
0418 inline void G4Scheduler::SetGun(G4ITGun* gun)
0419 {
0420   fpGun = gun;
0421 }
0422 
0423 inline G4ITGun* G4Scheduler::GetGun()
0424 {
0425   return fpGun;
0426 }
0427 
0428 inline void G4Scheduler::WhyDoYouStop()
0429 {
0430   fWhyDoYouStop = true;
0431 }
0432 
0433 inline void G4Scheduler::UseDefaultTimeSteps(G4bool flag)
0434 {
0435   fUseDefaultTimeSteps = flag;
0436 }
0437 
0438 inline G4bool G4Scheduler::AreDefaultTimeStepsUsed()
0439 {
0440   return (!fUseDefaultTimeSteps && !fUsePreDefinedTimeSteps);
0441 }
0442 
0443 inline void G4Scheduler::ResetScavenger(bool value)
0444 {
0445   fResetScavenger = value;
0446 }
0447 
0448 #endif