Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TVirtualMCApplication.h
Go to the documentation of this file.
1 // @(#)root/vmc:$Id$
2 // Author: Ivana Hrivnacova, 23/03/2002
3 
4 /*************************************************************************
5  * Copyright (C) 2006, Rene Brun and Fons Rademakers. *
6  * Copyright (C) 2002, ALICE Experiment at CERN. *
7  * All rights reserved. *
8  * *
9  * For the licensing terms see $ROOTSYS/LICENSE. *
10  * For the list of contributors see $ROOTSYS/README/CREDITS. *
11  *************************************************************************/
12 
13 #ifndef ROOT_TVirtualMCApplication
14 #define ROOT_TVirtualMCApplication
15 //
16 // Class TVirtualMCApplication
17 // ---------------------------
18 // Interface to a user Monte Carlo application.
19 //
20 
21 #include "TNamed.h"
22 #include "TMath.h"
23 
24 #include "TMCtls.h"
25 
26 class TVirtualMC;
27 class TMCManager;
28 
29 class TVirtualMCApplication : public TNamed {
30 
31 public:
32  /// Standard constructor
33  TVirtualMCApplication(const char *name, const char *title);
34 
35  /// Default constructor
36  TVirtualMCApplication();
37 
38  /// Destructor
39  virtual ~TVirtualMCApplication();
40 
41  /// Static access method
42  static TVirtualMCApplication *Instance();
43 
44  //
45  // methods
46  //
47 
48  /// Request a TMCManager which is required if multiple engines should be run
49  void RequestMCManager();
50 
51  /// Register the an engine.
52  void Register(TVirtualMC *mc);
53 
54  /// Return the transport engine registered to this application
55  TVirtualMC *GetMC() const;
56 
57  /// Construct user geometry
58  virtual void ConstructGeometry() = 0;
59 
60  /// Misalign user geometry (optional)
61  virtual Bool_t MisalignGeometry() { return kFALSE; }
62 
63  /// Define parameters for optical processes (optional)
64  virtual void ConstructOpGeometry() {}
65 
66  /// Define sensitive detectors (optional)
67  virtual void ConstructSensitiveDetectors() {}
68 
69  /// Initialize geometry
70  /// (Usually used to define sensitive volumes IDs)
71  virtual void InitGeometry() = 0;
72 
73  /// Add user defined particles (optional)
74  virtual void AddParticles() {}
75 
76  /// Add user defined ions (optional)
77  virtual void AddIons() {}
78 
79  /// Generate primary particles
80  virtual void GeneratePrimaries() = 0;
81 
82  /// Define actions at the beginning of the event
83  virtual void BeginEvent() = 0;
84 
85  /// Define actions at the beginning of the primary track
86  virtual void BeginPrimary() = 0;
87 
88  /// Define actions at the beginning of each track
89  virtual void PreTrack() = 0;
90 
91  /// Define action at each step
92  virtual void Stepping() = 0;
93 
94  /// Define actions at the end of each track
95  virtual void PostTrack() = 0;
96 
97  /// Define actions at the end of the primary track
98  virtual void FinishPrimary() = 0;
99 
100  /// Define actions at the end of the event before calling SD's end of the event
101  virtual void EndOfEvent() {}
102 
103  /// Define actions at the end of the event
104  virtual void FinishEvent() = 0;
105 
106  /// Define maximum radius for tracking (optional)
107  virtual Double_t TrackingRmax() const { return DBL_MAX; }
108 
109  /// Define maximum z for tracking (optional)
110  virtual Double_t TrackingZmax() const { return DBL_MAX; }
111 
112  /// Calculate user field \a b at point \a x
113  virtual void Field(const Double_t *x, Double_t *b) const;
114 
115  /// Define action at each step for Geane
116  virtual void GeaneStepping() { ; }
117 
118  // Functions for multi-threading applications
119  /// Clone MC application on worker
120  virtual TVirtualMCApplication *CloneForWorker() const { return 0; }
121 
122  /// Const Initialize MC application on worker - now deprecated
123  /// Use new non-const InitOnWorker() instead
124  virtual void InitForWorker() const {}
125  /// Const Define actions at the beginning of the worker run if needed - now deprecated
126  /// Use new non-const BeginRunOnWorker() instead
127  virtual void BeginWorkerRun() const {}
128  /// Const Define actions at the end of the worker run if needed - now deprecated
129  /// Use new non-const FinishRunOnWorker() instead
130  virtual void FinishWorkerRun() const {}
131 
132  /// Initialize MC application on worker
133  virtual void InitOnWorker() {}
134  /// Define actions at the beginning of the worker run if needed
135  virtual void BeginRunOnWorker() {}
136  /// Define actions at the end of the worker run if needed
137  virtual void FinishRunOnWorker() {}
138  /// Merge the data accumulated on workers to the master if needed
139  virtual void Merge(TVirtualMCApplication * /*localMCApplication*/) {}
140 
141 protected:
142  /// The current transport engine in use. In case of a multi-run the TMCManager
143  /// will update this whenever the engine changes.
144  TVirtualMC *fMC;
145 
146  /// Pointer to requested TMCManager which will only be instantiated by a call
147  /// to RequestMCManager()
148  TMCManager *fMCManager;
149 
150 private:
151  // static data members
152 #if !defined(__CINT__)
153  static TMCThreadLocal TVirtualMCApplication
154  *fgInstance; ///< Singleton instance
155 #else
156  static TVirtualMCApplication *fgInstance; ///< Singleton instance
157 #endif
158  /// Forbid multithreading mode if multi run via global static flag
159  static Bool_t fLockMultiThreading;
160 
161  ClassDef(TVirtualMCApplication, 1) // Interface to MonteCarlo application
162 };
163 
164 inline void TVirtualMCApplication::Field(const Double_t * /*x*/, Double_t *b) const
165 {
166  // No magnetic field
167  b[0] = 0;
168  b[1] = 0;
169  b[2] = 0;
170 }
171 
172 #endif // ROOT_TVirtualMCApplication