Back to home page

EIC code displayed by LXR

 
 

    


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

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