ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4Scheduler.hh
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4Scheduler.hh
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // Author: Mathieu Karamitros
28 
29 // The code is developed in the framework of the ESA AO7146
30 //
31 // We would be very happy hearing from you, send us your feedback! :)
32 //
33 // In order for Geant4-DNA to be maintained and still open-source,
34 // article citations are crucial.
35 // If you use Geant4-DNA chemistry and you publish papers about your software,
36 // in addition to the general paper on Geant4-DNA:
37 //
38 // Int. J. Model. Simul. Sci. Comput. 1 (2010) 157–178
39 //
40 // we would be very happy if you could please also cite the following
41 // reference papers on chemistry:
42 //
43 // J. Comput. Phys. 274 (2014) 841-882
44 // Prog. Nucl. Sci. Tec. 2 (2011) 503-508
45 
46 
47 
48 #ifndef G4Scheduler_h
49 #define G4Scheduler_h
50 
51 #include <G4VScheduler.hh>
52 #include <vector>
53 #include <map>
54 #include <memory>
55 
56 #include "globals.hh"
57 
58 #include "G4ITModelHandler.hh"
59 #include "G4ITStepStatus.hh"
60 #include "G4ITTrackHolder.hh"
61 #include "G4VStateDependent.hh"
62 #include "G4ITReaction.hh"
63 
65 class G4ITModelProcessor;
66 class G4ITStepProcessor;
67 class G4Track;
71 class G4ITGun;
72 
73 #ifndef compTrackPerID__
74 #define compTrackPerID__
75  struct compTrackPerID
76  {
77  bool operator()(G4Track* rhs, G4Track* lhs) const
78  {
79  return rhs->GetTrackID() < lhs->GetTrackID();
80  }
81  };
82 #endif
83 
87 class G4Scheduler :
88  public G4VScheduler,
89  public G4VStateDependent
90 {
91 protected:
92  virtual ~G4Scheduler();
93 
94 public:
95  static G4Scheduler* Instance();
99  static void DeleteInstance();
100  virtual G4bool Notify(G4ApplicationState requestedState);
101 
102  virtual void RegisterModel(G4VITStepModel*, double);
103 
104  void Initialize();
105  void ForceReinitialization();
106  inline bool IsInitialized();
107  inline bool IsRunning(){return fRunning;}
108  void Reset();
109  void Process();
110  void ClearList();
111 
112  inline void SetGun(G4ITGun*);
113  inline G4ITGun* GetGun();
114 
115  inline void Stop();
116  void Clear();
117 
118  // To be called only in UserReactionAction::EndProcessing()
119  // after fRunning flag has been turned off.
120  // This is not done automatically before UserReactionAction::EndProcessing()
121  // is called in case one would like to access some track information
122  void EndTracking();
123 
124  void SetEndTime(const double);
125 
126  /* Two tracks below the time tolerance are supposed to be
127  * in the same time slice
128  */
129  inline void SetTimeTolerance(double);
130  inline double GetTimeTolerance() const;
131 
132  inline void SetMaxZeroTimeAllowed(int);
133  inline int GetMaxZeroTimeAllowed() const;
134 
136 
137  inline void SetTimeSteps(std::map<double, double>*);
138  inline void AddTimeStep(double, double);
139  inline void SetDefaultTimeStep(double);
140  double GetLimitingTimeStep() const;
141  inline G4int GetNbSteps() const;
142  inline void SetMaxNbSteps(G4int);
143  inline G4int GetMaxNbSteps() const;
144  inline G4double GetStartTime() const;
145  inline G4double GetEndTime() const;
146  virtual inline G4double GetTimeStep() const;
147  inline G4double GetPreviousTimeStep() const;
148  inline G4double GetGlobalTime() const;
149  inline void SetUserAction(G4UserTimeStepAction*);
151 
152  // To use with transportation only, no reactions
153  inline void UseDefaultTimeSteps(G4bool);
155 
156  inline G4ITStepStatus GetStatus() const;
157 
158  /* 1 : Reaction information
159  * 2 : (1) + time step information
160  * 3 : (2) + step info for individual tracks
161  * 4 : (2) + trackList processing info + pushed and killed track info
162  */
163  inline void SetVerbose(int);
164 
165  inline int GetVerbose() const;
166 
167  inline void WhyDoYouStop();
168 
171 
172  virtual size_t GetNTracks();
173 
174  void GetCollisionType(G4String& interactionType);
175 
176  void AddWatchedTime(double time)
177  {
178  fWatchedTimes.insert(time);
179  }
180 
181  double GetNextWatchedTime() const;
182 
183  inline void SetMaxTimeStep(double maxTimeStep)
184  {
185  fMaxTimeStep = maxTimeStep;
186  }
187 
188  inline double GetMaxTimeStep() const
189  {
190  return fMaxTimeStep;
191  }
192 
193 protected:
194 
195  void DoProcess();
196  void SynchronizeTracks();
197  void Stepping();
198 
200 
201  bool CanICarryOn();
202 
203  void PrintWhyDoYouStop();
204 
205 private:
206  G4Scheduler();
207  void Create();
208  G4Scheduler(const G4Scheduler&);
210 
212 
214  int fVerbose;
217  bool fRunning;
219 
220  int fNbSteps;
222 
224 
225  // Time members
228  double fGlobalTime;
230  double fStartTime;
231  double fStopTime;
232  double fEndTime;
236 
237  double fTimeStep; // The selected minimum time step
238  double fMaxTimeStep;
239 
240  // User steps
243  std::map<double, double>* fpUserTimeSteps;
244  // One can give time steps in respect to the global time
245  mutable double fUserUpperTimeLimit;
247  // selected user time step in respect to the global time
248  bool fReachedUserTimeLimit; // if fMinTimeStep == the user time step
249 
250  std::set<double> fWatchedTimes;
251 
253 
254  // ==========================================
255  // TO BE REMOVED
263  // ==========================================
264 
265  double fTSTimeStep;
266  // Time calculated by the time stepper in CalculateMinTimeStep()
267  double fILTimeStep;
268  // Time calculated by the interaction length methods
269  // in ComputeInteractionLength()
270 
272  // Flag : if the step is driven by the interaction with the matter and
273  // NOT by the reaction between tracks
274 
276 
277  // ==========================================
278  //
279 
280 };
281 
283 {
284  return fInitialized;
285 }
286 
288 {
289  return fpModelHandler;
290 }
291 
292 inline void G4Scheduler::SetEndTime(const double __endtime)
293 {
294  fEndTime = __endtime;
295 }
296 
297 inline
298 void G4Scheduler::SetTimeSteps(std::map<double, double>* steps)
299 {
302 }
303 
304 inline void G4Scheduler::AddTimeStep(double startingTime, double timeStep)
305 {
306  if (fpUserTimeSteps == 0)
307  {
308  fpUserTimeSteps = new std::map<double, double>();
310  }
311 
312  (*fpUserTimeSteps)[startingTime] = timeStep;
313 }
314 
316 {
317  return fNbSteps;
318 }
319 
320 inline void G4Scheduler::SetMaxNbSteps(G4int maxSteps)
321 {
322  fMaxSteps = maxSteps;
323 }
324 
326 {
327  return fMaxSteps;
328 }
329 
331 {
332  return fStartTime;
333 }
334 
336 {
337  return fEndTime;
338 }
339 
341 {
342  return fTimeStep;
343 }
344 
345 inline void G4Scheduler::SetDefaultTimeStep(double timeStep)
346 {
347  fDefaultMinTimeStep = timeStep;
348 }
349 
351 {
352  return fGlobalTime;
353 }
354 
355 inline
357 {
358  fpUserTimeStepAction = userITAction;
359 }
360 
362 {
363  return fpUserTimeStepAction;
364 }
365 
366 inline void G4Scheduler::SetVerbose(int verbose)
367 {
368  fVerbose = verbose;
369 }
370 
371 inline int G4Scheduler::GetVerbose() const
372 {
373  return fVerbose;
374 }
375 
376 inline
377 void G4Scheduler::SetMaxZeroTimeAllowed(int maxTimeStepAllowed)
378 {
379  fMaxNZeroTimeStepsAllowed = maxTimeStepAllowed;
380 }
381 
383 {
385 }
386 
388 {
390 }
391 
392 inline double G4Scheduler::GetTimeTolerance() const
393 {
394  return fTimeTolerance;
395 }
396 
398 {
399  return fPreviousTimeStep;
400 }
401 
403 {
404  return fITStepStatus;
405 }
406 
407 inline void G4Scheduler::Stop()
408 {
409  fContinue = false;
410 }
411 
413 {
415 }
416 
417 inline void G4Scheduler::SetGun(G4ITGun* gun)
418 {
419  fpGun = gun;
420 }
421 
423 {
424  return fpGun;
425 }
426 
428 {
429  fWhyDoYouStop = true;
430 }
431 
433 {
434  fUseDefaultTimeSteps = flag;
435 }
436 
438 {
439  return (fUseDefaultTimeSteps == false && fUsePreDefinedTimeSteps == false);
440 }
441 
442 #endif