| 1 | <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>3.4. Run</title><link rel="stylesheet" href="../xml/XSLCustomizationLayer/G4HTMLStylesheet.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.71.1"><link rel="start" href="index.html" title="Geant4 User's Guide for Application Developers"><link rel="up" href="ch03.html" title="Chapter 3. Toolkit Fundamentals"><link rel="prev" href="ch03s03.html" title="3.3. System of units"><link rel="next" href="ch03s05.html" title="3.5. Event"><script language="JavaScript">
|
|---|
| 2 | function remote_win(fName)
|
|---|
| 3 | {
|
|---|
| 4 | var url = "AllResources/Detector/geometry.src/" + fName;
|
|---|
| 5 | RemoteWin=window.open(url,"","resizable=no,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,copyhistory=0,width=520,height=520")
|
|---|
| 6 | RemoteWin.creator=self
|
|---|
| 7 | }
|
|---|
| 8 | </script></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">3.4.
|
|---|
| 9 | Run
|
|---|
| 10 | </th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch03s03.html"><img src="AllResources/IconsGIF/prev.gif" alt="Prev"></a> </td><th width="60%" align="center">Chapter 3.
|
|---|
| 11 | Toolkit Fundamentals
|
|---|
| 12 | </th><td width="20%" align="right"> <a accesskey="n" href="ch03s05.html"><img src="AllResources/IconsGIF/next.gif" alt="Next"></a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="sect.Run"></a>3.4.
|
|---|
| 13 | Run
|
|---|
| 14 | </h2></div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sect.Run.Basic"></a>3.4.1.
|
|---|
| 15 | Basic concept of <span class="emphasis"><em>Run</em></span>
|
|---|
| 16 | </h3></div></div></div><p>
|
|---|
| 17 | In Geant4, <span class="emphasis"><em>Run</em></span> is the largest unit of simulation. A run
|
|---|
| 18 | consists of a sequence of events. Within a run, the detector
|
|---|
| 19 | geometry, the set up of sensitive detectors, and the physics
|
|---|
| 20 | processes used in the simulation should be kept unchanged. A run is
|
|---|
| 21 | represented by a <span class="emphasis"><em>G4Run</em></span> class object. A run starts with
|
|---|
| 22 | <code class="literal">BeamOn()</code> method of <span class="emphasis"><em>G4RunManager</em></span>.
|
|---|
| 23 | </p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="sect.Run.Basic.Rep"></a>3.4.1.1.
|
|---|
| 24 | Representation of a run
|
|---|
| 25 | </h4></div></div></div><p>
|
|---|
| 26 | <span class="emphasis"><em>G4Run</em></span> represents a run. It has a run identification
|
|---|
| 27 | number, which should be set by the user, and the number of events
|
|---|
| 28 | simulated during the run. Please note that the run identification
|
|---|
| 29 | number is not used by the Geant4 kernel, and thus can be
|
|---|
| 30 | arbitrarily assigned at the user's convenience.
|
|---|
| 31 | </p><p>
|
|---|
| 32 | <span class="emphasis"><em>G4Run</em></span> has pointers to the tables
|
|---|
| 33 | <span class="emphasis"><em>G4VHitsCollection</em></span>
|
|---|
| 34 | and <span class="emphasis"><em>G4VDigiCollection</em></span>. These tables are associated
|
|---|
| 35 | in case <span class="emphasis"><em>sensitive detectors</em></span> and
|
|---|
| 36 | <span class="emphasis"><em>digitizer modules</em></span> are
|
|---|
| 37 | simulated, respectively. The usage of these tables will be
|
|---|
| 38 | mentioned in <a href="ch04s04.html" title="4.4.
|
|---|
| 39 | Hits
|
|---|
| 40 | ">Section 4.4</a> and <a href="ch04s05.html" title="4.5.
|
|---|
| 41 | Digitization
|
|---|
| 42 | ">Section 4.5</a>.
|
|---|
| 43 | </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="sect.Run.Basic.Manage"></a>3.4.1.2.
|
|---|
| 44 | Manage the run procedures
|
|---|
| 45 | </h4></div></div></div><p>
|
|---|
| 46 | <span class="emphasis"><em>G4RunManager</em></span> manages the procedures of a run. In the
|
|---|
| 47 | constructor of <span class="emphasis"><em>G4RunManager</em></span>, all of the manager classes in
|
|---|
| 48 | Geant4 kernel, except for some static managers, are constructed.
|
|---|
| 49 | These managers are deleted in the destructor of
|
|---|
| 50 | <span class="emphasis"><em>G4RunManager</em></span>. <span class="emphasis"><em>G4RunManager</em></span>
|
|---|
| 51 | must be a singleton, and
|
|---|
| 52 | the pointer to this singleton object can be obtained by the
|
|---|
| 53 | <code class="literal">getRunManager()</code> static method.
|
|---|
| 54 | </p><p>
|
|---|
| 55 | As already mentioned in <a href="ch02.html#sect.HowToDefMain" title="2.1.
|
|---|
| 56 | How to Define the main() Program
|
|---|
| 57 | ">Section 2.1</a>, all of the
|
|---|
| 58 | <span class="emphasis"><em>user initialization</em></span> classes and
|
|---|
| 59 | <span class="emphasis"><em>user action</em></span> classes
|
|---|
| 60 | defined by the user should be assigned to <span class="emphasis"><em>G4RunManager</em></span>
|
|---|
| 61 | before starting initialization of the Geant4 kernel. The
|
|---|
| 62 | assignments of these user classes are done by
|
|---|
| 63 | <code class="literal">SetUserInitialization()</code> and <code class="literal">SetUserAction()</code>
|
|---|
| 64 | methods. All user classes defined by the Geant4 kernel will be
|
|---|
| 65 | summarized in <a href="ch06.html" title="Chapter 6.
|
|---|
| 66 | User Actions
|
|---|
| 67 | ">Chapter 6</a>.
|
|---|
| 68 | </p><p>
|
|---|
| 69 | <span class="emphasis"><em>G4RunManager</em></span> has several public methods, which are listed
|
|---|
| 70 | below.
|
|---|
| 71 |
|
|---|
| 72 | </p><div class="variablelist"><p class="title"><b></b></p><dl><dt><span class="term"><code class="literal">Initialize()</code></span></dt><dd>
|
|---|
| 73 | All initializations required by the Geant4 kernel are triggered
|
|---|
| 74 | by this method. Initializations are:
|
|---|
| 75 |
|
|---|
| 76 | <div class="itemizedlist"><ul type="disc" compact><li><p>
|
|---|
| 77 | construction of the detector geometry and set up of sensitive
|
|---|
| 78 | detectors and/or digitizer modules,
|
|---|
| 79 | </p></li><li><p>
|
|---|
| 80 | construction of particles and physics processes,
|
|---|
| 81 | </p></li><li><p>
|
|---|
| 82 | calculation of cross-section tables.
|
|---|
| 83 | </p></li></ul></div>
|
|---|
| 84 |
|
|---|
| 85 | This method is thus mandatory before proceeding to the first run.
|
|---|
| 86 | This method will be invoked automatically for the second and later
|
|---|
| 87 | runs in case some of the initialized quantities need to be updated.
|
|---|
| 88 | </dd><dt><span class="term"><code class="literal">BeamOn(G4int numberOfEvent)</code></span></dt><dd>
|
|---|
| 89 | This method triggers the actual simulation of a run, that is,
|
|---|
| 90 | an event loop. It takes an integer argument which represents the
|
|---|
| 91 | number of events to be simulated.
|
|---|
| 92 | </dd><dt><span class="term"><code class="literal">GetRunManager()</code></span></dt><dd>
|
|---|
| 93 | This static method returns the pointer to the
|
|---|
| 94 | <span class="emphasis"><em>G4RunManager</em></span> singleton object.
|
|---|
| 95 | </dd><dt><span class="term"><code class="literal">GetCurrentEvent()</code></span></dt><dd>
|
|---|
| 96 | This method returns the pointer to the <span class="emphasis"><em>G4Event</em></span> object
|
|---|
| 97 | which is currently being simulated. This method is available only
|
|---|
| 98 | when an event is being processed. At this moment, the application
|
|---|
| 99 | state of Geant4, which is explained in the following sub-section,
|
|---|
| 100 | is <span class="emphasis"><em>"EventProc"</em></span>. When Geant4 is in a state other than
|
|---|
| 101 | <span class="emphasis"><em>"EventProc"</em></span>, this method returns
|
|---|
| 102 | <code class="literal">null</code>.
|
|---|
| 103 | Please note that the return value of this method is
|
|---|
| 104 | <code class="literal">const G4Event *</code> and thus you cannot modify the
|
|---|
| 105 | contents of the object.
|
|---|
| 106 | </dd><dt><span class="term"><code class="literal">SetNumberOfEventsToBeStored(G4int nPrevious)</code></span></dt><dd>
|
|---|
| 107 | When simulating the "pile up" of more than one event, it is
|
|---|
| 108 | essential to access more than one event at the same moment. By
|
|---|
| 109 | invoking this method, <span class="emphasis"><em>G4RunManager</em></span> keeps <code class="literal">nPrevious
|
|---|
| 110 | G4Event</code> objects. This method must be invoked before proceeding
|
|---|
| 111 | to <code class="literal">BeamOn()</code>.
|
|---|
| 112 | </dd><dt><span class="term"><code class="literal">GetPreviousEvent(G4int i_thPrevious)</code></span></dt><dd>
|
|---|
| 113 | The pointer to the <code class="literal">i_thPrevious G4Event</code> object can be
|
|---|
| 114 | obtained through this method. A pointer to a <code class="literal">const</code> object
|
|---|
| 115 | is returned. It is inevitable that <code class="literal">i_thPrevious</code> events
|
|---|
| 116 | must have already been simulated in the same run for getting the
|
|---|
| 117 | <code class="literal">i_thPrevious</code> event. Otherwise, this method returns
|
|---|
| 118 | <code class="literal">null</code>.
|
|---|
| 119 | </dd><dt><span class="term"><code class="literal">AbortRun()</code></span></dt><dd>
|
|---|
| 120 | This method should be invoked whenever the processing of a run
|
|---|
| 121 | must be stopped. It is valid for <span class="emphasis"><em>GeomClosed</em></span> and
|
|---|
| 122 | <span class="emphasis"><em>EventProc</em></span> states. Run processing will be safely aborted even
|
|---|
| 123 | in the midst of processing an event. However, the last event of the
|
|---|
| 124 | aborted run will be incomplete and should not be used for further
|
|---|
| 125 | analysis.
|
|---|
| 126 | </dd></dl></div><p>
|
|---|
| 127 | </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="sect.Run.Basic.UserRunAction"></a>3.4.1.3.
|
|---|
| 128 | <span class="emphasis"><em>G4UserRunAction</em></span>
|
|---|
| 129 | </h4></div></div></div><p>
|
|---|
| 130 | <span class="emphasis"><em>G4UserRunAction</em></span> is one of the <span class="emphasis"><em>user action</em></span>
|
|---|
| 131 | classes from which you can derive your own concrete class. This base class
|
|---|
| 132 | has two virtual methods, as follows:
|
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 | </p><div class="variablelist"><p class="title"><b></b></p><dl><dt><span class="term"><code class="literal">BeginOfRunAction()</code></span></dt><dd>
|
|---|
| 136 | This method is invoked at the beginning of the
|
|---|
| 137 | <code class="literal">BeamOn()</code> method but after confirmation of the conditions
|
|---|
| 138 | of the Geant4 kernel. Likely uses of this method include:
|
|---|
| 139 |
|
|---|
| 140 | <div class="itemizedlist"><ul type="disc" compact><li><p>
|
|---|
| 141 | setting a run identification number,
|
|---|
| 142 | </p></li><li><p>
|
|---|
| 143 | booking histograms,
|
|---|
| 144 | </p></li><li><p>
|
|---|
| 145 | setting run specific conditions of the sensitive detectors
|
|---|
| 146 | and/or digitizer modules (e.g., dead channels).
|
|---|
| 147 | </p></li></ul></div></dd><dt><span class="term"><code class="literal">EndOfRunAction()</code></span></dt><dd>
|
|---|
| 148 | This method is invoked at the very end of the <code class="literal">BeamOn()</code>
|
|---|
| 149 | method. Typical use cases of this method are
|
|---|
| 150 |
|
|---|
| 151 | <div class="itemizedlist"><ul type="disc" compact><li><p>
|
|---|
| 152 | store/print histograms,
|
|---|
| 153 | </p></li><li><p>
|
|---|
| 154 | manipulate run summaries.
|
|---|
| 155 | </p></li></ul></div></dd></dl></div><p>
|
|---|
| 156 | </p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sect.Run.StateMac"></a>3.4.2.
|
|---|
| 157 | Geant4 as a state machine
|
|---|
| 158 | </h3></div></div></div><p>
|
|---|
| 159 | Geant4 is designed as a state machine. Some methods in Geant4 are
|
|---|
| 160 | available for only a certain state(s). <span class="emphasis"><em>G4RunManager</em></span> controls
|
|---|
| 161 | the state changes of the Geant4 application. States of Geant4 are
|
|---|
| 162 | represented by the enumeration <span class="emphasis"><em>G4ApplicationState</em></span>. It has
|
|---|
| 163 | six states through the life cycle of a Geant4 application.
|
|---|
| 164 |
|
|---|
| 165 |
|
|---|
| 166 | </p><div class="variablelist"><p class="title"><b></b></p><dl><dt><span class="term"><span class="emphasis"><em>G4State_PreInit</em></span> state</span></dt><dd>
|
|---|
| 167 | A Geant4 application starts with this state. The application
|
|---|
| 168 | needs to be initialized when it is in this state. The application
|
|---|
| 169 | occasionally comes back to this state if geometry, physics
|
|---|
| 170 | processes, and/or cut-off have been changed after processing a
|
|---|
| 171 | run.
|
|---|
| 172 | </dd><dt><span class="term"><span class="emphasis"><em>G4State_Init</em></span> state</span></dt><dd>
|
|---|
| 173 | The application is in this state while the
|
|---|
| 174 | <code class="literal">Initialize()</code> method of <span class="emphasis"><em>G4RunManager</em></span>
|
|---|
| 175 | is being invoked. Methods defined in any
|
|---|
| 176 | <span class="emphasis"><em>user initialization</em></span> classes
|
|---|
| 177 | are invoked during this state.
|
|---|
| 178 | </dd><dt><span class="term"><span class="emphasis"><em>G4State_Idle</em></span> state</span></dt><dd>
|
|---|
| 179 | The application is ready for starting a run.
|
|---|
| 180 | </dd><dt><span class="term"><span class="emphasis"><em>G4State_GeomClosed</em></span> state</span></dt><dd>
|
|---|
| 181 | When <code class="literal">BeamOn()</code> is invoked, the application proceeds to
|
|---|
| 182 | this state to process a run. Geometry, physics processes, and
|
|---|
| 183 | cut-off cannot be changed during run processing.
|
|---|
| 184 | </dd><dt><span class="term"><span class="emphasis"><em>G4State_EventProc</em></span> state</span></dt><dd>
|
|---|
| 185 | A Geant4 application is in this state when a particular event
|
|---|
| 186 | is being processed. <code class="literal">GetCurrentEvent()</code> and
|
|---|
| 187 | <code class="literal">GetPreviousEvent()</code> methods of
|
|---|
| 188 | <span class="emphasis"><em>G4RunManager</em></span> are
|
|---|
| 189 | available only at this state.
|
|---|
| 190 | </dd><dt><span class="term"><span class="emphasis"><em>G4State_Quit</em></span> state</span></dt><dd>
|
|---|
| 191 | When the destructor of <span class="emphasis"><em>G4RunManager</em></span> is invoked, the
|
|---|
| 192 | application comes to this "dead end" state. Managers of the Geant4
|
|---|
| 193 | kernel are being deleted and thus the application cannot come back
|
|---|
| 194 | to any other state.
|
|---|
| 195 | </dd><dt><span class="term"><span class="emphasis"><em>G4State_Abort</em></span> state</span></dt><dd>
|
|---|
| 196 | When a <span class="emphasis"><em>G4Exception</em></span> occurs, the application comes to this
|
|---|
| 197 | "dead end" state and causes a core dump. The user still has a hook
|
|---|
| 198 | to do some "safe" opperations, e.g. storing histograms, by
|
|---|
| 199 | implementing a user concrete class of <span class="emphasis"><em>G4VStateDependent</em></span>. The
|
|---|
| 200 | user also has a choice to suppress the occurence of
|
|---|
| 201 | <span class="emphasis"><em>G4Exception</em></span> by a UI command
|
|---|
| 202 | <span class="emphasis"><em>/control/suppressAbortion</em></span>. When abortion is suppressed, you
|
|---|
| 203 | will still get error messages issued by G4Exception, and there is
|
|---|
| 204 | NO guarantee of a correct result after the G4Exception error
|
|---|
| 205 | message.
|
|---|
| 206 | </dd></dl></div><p>
|
|---|
| 207 |
|
|---|
| 208 | <span class="emphasis"><em>G4StateManager</em></span> belongs to the <span class="emphasis"><em>intercoms</em></span>
|
|---|
| 209 | category.
|
|---|
| 210 | </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sect.Run.UserHook"></a>3.4.3.
|
|---|
| 211 | User's hook for state change
|
|---|
| 212 | </h3></div></div></div><p>
|
|---|
| 213 | In case the user wants to do something at the moment of state
|
|---|
| 214 | change of Geant4, the user can create a concrete class of the
|
|---|
| 215 | <span class="emphasis"><em>G4VStateDependent</em></span> base class. For example, the user can
|
|---|
| 216 | store histograms when G4Exception occurs and Geant4 comes to the
|
|---|
| 217 | <span class="emphasis"><em>Abort</em></span> state, but before the actual core dump.
|
|---|
| 218 | </p><p>
|
|---|
| 219 | The following is an example user code which stores histograms
|
|---|
| 220 | when Geant4 becomes to the <span class="emphasis"><em>Abort</em></span> state. This class object
|
|---|
| 221 | should be mabe in, for example <span class="emphasis"><em>main()</em></span>, by the user code.
|
|---|
| 222 | This object will be automatically registered to
|
|---|
| 223 | <span class="emphasis"><em>G4StateManager</em></span> at its construction.
|
|---|
| 224 | </p><div class="example"><a name="programlist_Run_1"></a><p class="title"><b>Example 3.1.
|
|---|
| 225 | Header file of UserHookForAbortState
|
|---|
| 226 | </b></p><div class="example-contents"><pre class="programlisting">
|
|---|
| 227 | #ifndef UserHookForAbortState_H
|
|---|
| 228 | #define UserHookForAbortState_H 1
|
|---|
| 229 |
|
|---|
| 230 | #include "G4VStateDependent.hh"
|
|---|
| 231 |
|
|---|
| 232 | class UserHookForAbortState : public G4VStateDependent
|
|---|
| 233 | {
|
|---|
| 234 | public:
|
|---|
| 235 | UserHookForAbortState(); // constructor
|
|---|
| 236 | ~UserHookForAbortState(); // destructor
|
|---|
| 237 |
|
|---|
| 238 | virtual G4bool Notify(G4ApplicationState requiredState);
|
|---|
| 239 | };
|
|---|
| 240 | </pre></div></div><br class="example-break"><div class="example"><a name="programlist_Run_2"></a><p class="title"><b>Example 3.2.
|
|---|
| 241 | Source file of UserHookForAbortState
|
|---|
| 242 | </b></p><div class="example-contents"><pre class="programlisting">
|
|---|
| 243 | #include "UserHookForAbortState.hh"
|
|---|
| 244 |
|
|---|
| 245 | UserHookForAbortState::UserHookForAbortState() {;}
|
|---|
| 246 | UserHookForAbortState::~UserHookForAbortState() {;}
|
|---|
| 247 |
|
|---|
| 248 | G4bool UserHookForAbortState::Notify(G4ApplicationState requiredState)
|
|---|
| 249 | {
|
|---|
| 250 | if(requiredState!=Abort) return true;
|
|---|
| 251 |
|
|---|
| 252 | // Do book keeping here
|
|---|
| 253 |
|
|---|
| 254 | return true;
|
|---|
| 255 | }
|
|---|
| 256 | </pre></div></div><br class="example-break"></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sect.Run.Custom"></a>3.4.4.
|
|---|
| 257 | Customizing the Run Manager
|
|---|
| 258 | </h3></div></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="sect.Run.Custom.VirMeth"></a>3.4.4.1.
|
|---|
| 259 | Virtual Methods in the Run Manager
|
|---|
| 260 | </h4></div></div></div><p>
|
|---|
| 261 | <code class="literal">G4RunManager</code> is a concrete class with a complete set of
|
|---|
| 262 | functionalities for managing the Geant4 kernel. It is the only
|
|---|
| 263 | manager class in the Geant4 kernel which must be constructed in the
|
|---|
| 264 | <code class="literal">main()</code> method of the user's application. Thus, instead of
|
|---|
| 265 | constructing the <code class="literal">G4RunManager</code> provided by Geant4, you are
|
|---|
| 266 | free to construct your own <code class="literal">RunManager</code>. It is recommended,
|
|---|
| 267 | however, that your <code class="literal">RunManager</code> inherit
|
|---|
| 268 | <code class="literal">G4RunManager</code>. For this purpose, <code class="literal">G4RunManager</code> has
|
|---|
| 269 | various virtual methods which provide all the functionalities
|
|---|
| 270 | required to handle the Geant4 kernel. Hence, your customized run
|
|---|
| 271 | manager need only override the methods particular to your needs;
|
|---|
| 272 | the remaining methods in <code class="literal">G4RunManager</code> base class can still
|
|---|
| 273 | be used. A summary of the available methods is presented here:
|
|---|
| 274 |
|
|---|
| 275 |
|
|---|
| 276 | </p><div class="variablelist"><p class="title"><b></b></p><dl><dt><span class="term"><code class="literal">public: virtual void Initialize();</code></span></dt><dd>
|
|---|
| 277 | main entry point of Geant4 kernel initialization
|
|---|
| 278 | </dd><dt><span class="term"><code class="literal">protected: virtual void InitializeGeometry();</code></span></dt><dd>
|
|---|
| 279 | geometry construction
|
|---|
| 280 | </dd><dt><span class="term"><code class="literal">protected: virtual void InitializePhysics();</code></span></dt><dd>
|
|---|
| 281 | physics processes construction
|
|---|
| 282 | </dd><dt><span class="term"><code class="literal">public: virtual void BeamOn(G4int n_event);</code></span></dt><dd>
|
|---|
| 283 | main entry point of the event loop
|
|---|
| 284 | </dd><dt><span class="term"><code class="literal">protected: virtual G4bool ConfirmBeamOnCondition();</code></span></dt><dd>
|
|---|
| 285 | check the kernel conditions for the event loop
|
|---|
| 286 | </dd><dt><span class="term"><code class="literal">protected: virtual void RunInitialization();</code></span></dt><dd>
|
|---|
| 287 | prepare a run
|
|---|
| 288 | </dd><dt><span class="term"><code class="literal">protected: virtual void DoEventLoop(G4int n_events);</code></span></dt><dd>
|
|---|
| 289 | manage an event loop
|
|---|
| 290 | </dd><dt><span class="term"><code class="literal">protected: virtual G4Event* GenerateEvent(G4int i_event);</code></span></dt><dd>
|
|---|
| 291 | generation of <span class="emphasis"><em>G4Event</em></span> object
|
|---|
| 292 | </dd><dt><span class="term"><code class="literal">protected: virtual void AnalyzeEvent(G4Event* anEvent);</code></span></dt><dd>
|
|---|
| 293 | storage/analysis of an event
|
|---|
| 294 | </dd><dt><span class="term"><code class="literal">protected: virtual void RunTermination();</code></span></dt><dd>
|
|---|
| 295 | terminate a run
|
|---|
| 296 | </dd><dt><span class="term"><code class="literal">public: virtual void DefineWorldVolume(G4VPhysicalVolume * worldVol);</code></span></dt><dd>
|
|---|
| 297 | set the world volume to <span class="emphasis"><em>G4Navigator</em></span></dd><dt><span class="term"><code class="literal">public: virtual void AbortRun();</code></span></dt><dd>
|
|---|
| 298 | abort the run
|
|---|
| 299 | </dd></dl></div><p>
|
|---|
| 300 | </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="sect.Run.Custom.EventLoop"></a>3.4.4.2.
|
|---|
| 301 | Customizing the Event Loop
|
|---|
| 302 | </h4></div></div></div><p>
|
|---|
| 303 | In <code class="literal">G4RunManager</code> the event loop is handled by the
|
|---|
| 304 | virtual method <code class="literal">DoEventLoop()</code>. This method is implemented
|
|---|
| 305 | by a <code class="literal">for</code> loop consisting of the following steps:
|
|---|
| 306 |
|
|---|
| 307 | </p><div class="orderedlist"><ol type="1" compact><li><p>
|
|---|
| 308 | construct a <code class="literal">G4Event</code> object and assign to it primary
|
|---|
| 309 | vertex(es) and primary particles. This is done by the virtual
|
|---|
| 310 | <code class="literal">GeneratePrimaryEvent()</code> method.
|
|---|
| 311 | </p></li><li><p>
|
|---|
| 312 | send the <code class="literal">G4Event</code> object to <code class="literal">G4EventManager</code>
|
|---|
| 313 | for the detector simulation. <span class="emphasis"><em>Hits</em></span> and
|
|---|
| 314 | <span class="emphasis"><em>trajectories</em></span> will
|
|---|
| 315 | be associated with the <code class="literal">G4Event</code> object as a
|
|---|
| 316 | consequence.
|
|---|
| 317 | </p></li><li><p>
|
|---|
| 318 | perform bookkeeping for the current <code class="literal">G4Event</code> object.
|
|---|
| 319 | This is done by the virtual <code class="literal">AnalyzeEvent()</code> method.
|
|---|
| 320 | </p></li></ol></div><p>
|
|---|
| 321 | </p><p>
|
|---|
| 322 | <code class="literal">DoEventLoop()</code> performs the entire simulation of an
|
|---|
| 323 | event. However, it is often useful to split the above three steps
|
|---|
| 324 | into isolated application programs. If, for example, you wish to
|
|---|
| 325 | examine the effects of changing discriminator thresholds, ADC gate
|
|---|
| 326 | widths and/or trigger conditions on simulated events, much time can
|
|---|
| 327 | be saved by performing steps 1 and 2 in one program and step 3 in
|
|---|
| 328 | another. The first program need only generate the hit/trajectory
|
|---|
| 329 | information once and store it, perhaps in a database. The second
|
|---|
| 330 | program could then retrieve the stored <code class="literal">G4Event</code> objects and
|
|---|
| 331 | perform the digitization (analysis) using the above threshold, gate
|
|---|
| 332 | and trigger settings. These settings could then be changed and the
|
|---|
| 333 | digitization program re-run without re-generating the
|
|---|
| 334 | <code class="literal">G4Event</code>s.
|
|---|
| 335 | </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="sect.Run.Custom.Geometry"></a>3.4.4.3.
|
|---|
| 336 | Changing the Detector Geometry
|
|---|
| 337 | </h4></div></div></div><p>
|
|---|
| 338 | The detector geometry defined in your
|
|---|
| 339 | <span class="emphasis"><em>G4VUserDetectorConstruction</em></span> concrete class can be changed
|
|---|
| 340 | during a run break (between two runs). Two different cases are
|
|---|
| 341 | considered.
|
|---|
| 342 | </p><p>
|
|---|
| 343 | The first is the case in which you want to delete the entire
|
|---|
| 344 | structure of your old geometry and build up a completely new set of
|
|---|
| 345 | volumes. For this case, you need to set the new world physical
|
|---|
| 346 | volume pointer to the <span class="emphasis"><em>RunManager</em></span>. Thus, you should proceed
|
|---|
| 347 | in the following way.
|
|---|
| 348 |
|
|---|
| 349 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 350 | G4RunManager* runManager = G4RunManager::GetRunManager();
|
|---|
| 351 | runManager->DefineWorldVolume( newWorldPhys );
|
|---|
| 352 | </pre></div><p>
|
|---|
| 353 |
|
|---|
| 354 | Presumably this case is rather rare. The second case is more
|
|---|
| 355 | frequent for the user.
|
|---|
| 356 | </p><p>
|
|---|
| 357 | The second case is the following. Suppose you want to move
|
|---|
| 358 | and/or rotate a particular piece of your detector component. This
|
|---|
| 359 | case can easily happen for a beam test of your detector. It is
|
|---|
| 360 | obvious for this case that you need not change the world volume.
|
|---|
| 361 | Rather, it should be said that your world volume (experimental hall
|
|---|
| 362 | for your beam test) should be big enough for moving/rotating your
|
|---|
| 363 | test detector. For this case, you can still use all of your
|
|---|
| 364 | detector geometries, and just use a <code class="literal">Set</code> method of a
|
|---|
| 365 | particular physical volume to update the transformation vector as
|
|---|
| 366 | you want. Thus, you don't need to re-set your world volume pointer
|
|---|
| 367 | to <span class="emphasis"><em>RunManager</em></span>.
|
|---|
| 368 | </p><p>
|
|---|
| 369 | If you want to change your geometry for every run, you can
|
|---|
| 370 | implement it in the <code class="literal">BeginOfRunAction()</code> method of
|
|---|
| 371 | <span class="emphasis"><em>G4UserRunAction</em></span> class, which will be invoked at the
|
|---|
| 372 | beginning of each run, or, derive the <code class="literal">RunInitialization()</code>
|
|---|
| 373 | method. Please note that, for both of the above mentioned cases,
|
|---|
| 374 | you need to let <span class="emphasis"><em>RunManager</em></span> know "the geometry needs to be
|
|---|
| 375 | closed again". Thus, you need to invoke
|
|---|
| 376 |
|
|---|
| 377 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 378 | runManager->GeometryHasBeenModified();
|
|---|
| 379 | </pre></div><p>
|
|---|
| 380 |
|
|---|
| 381 | before proceeding to the next run. An example of changing geometry
|
|---|
| 382 | is given in a Geant4 tutorial in Geant4 Training kit #2.
|
|---|
| 383 | </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="sect.Run.Custom.SwitchPhys"></a>3.4.4.4.
|
|---|
| 384 | Switch physics processes
|
|---|
| 385 | </h4></div></div></div><p>
|
|---|
| 386 | In the <code class="literal">InitializePhysics()</code> method,
|
|---|
| 387 | <code class="literal">G4VUserPhysicsList::Construct</code> is invoked in order to
|
|---|
| 388 | define particles and physics processes in your application.
|
|---|
| 389 | Basically, you can not add nor remove any particles during
|
|---|
| 390 | execution, because particles are static objects in Geant4 (see
|
|---|
| 391 | <a href="ch02s04.html" title="2.4.
|
|---|
| 392 | How to Specify Particles
|
|---|
| 393 | ">Section 2.4</a> and
|
|---|
| 394 | <a href="ch05s03.html" title="5.3.
|
|---|
| 395 | Particles
|
|---|
| 396 | ">Section 5.3</a> for details).
|
|---|
| 397 | In addition, it is very difficult to add and/or remove physics
|
|---|
| 398 | processes during execution, because registration procedures are
|
|---|
| 399 | very complex, except for experts (see <a href="ch02s05.html" title="2.5.
|
|---|
| 400 | How to Specify Physics Processes
|
|---|
| 401 | ">Section 2.5</a>
|
|---|
| 402 | and <a href="ch05s02.html" title="5.2.
|
|---|
| 403 | Physics Processes
|
|---|
| 404 | ">Section 5.2</a>).
|
|---|
| 405 | This is why the <code class="literal">initializePhysics()</code> method is assumed
|
|---|
| 406 | to be invoked at once in Geant4 kernel initialization.
|
|---|
| 407 | </p><p>
|
|---|
| 408 | However, you can switch on/off physics processes defined in your
|
|---|
| 409 | <span class="emphasis"><em>G4VUserPhysicsList</em></span> concrete class and also change parameters
|
|---|
| 410 | in physics processes during the run break.
|
|---|
| 411 | </p><p>
|
|---|
| 412 | You can use <code class="literal">ActivateProcess()</code> and
|
|---|
| 413 | <code class="literal">InActivateProcess()</code> methods of <span class="emphasis"><em>G4ProcessManager</em></span>
|
|---|
| 414 | anywhere outside the event loop to switch on/off some process. You
|
|---|
| 415 | should be very careful to switch on/off processes inside the event
|
|---|
| 416 | loop, though it is not prohibited to use these methods even in the
|
|---|
| 417 | <span class="emphasis"><em>EventProc</em></span> state.
|
|---|
| 418 | </p><p>
|
|---|
| 419 | It is a likely case to change cut-off values in a run. You can
|
|---|
| 420 | change <code class="literal">defaultCutValue</code> in
|
|---|
| 421 | <span class="emphasis"><em>G4VUserPhysicsList</em></span>
|
|---|
| 422 | during the <span class="emphasis"><em>Idle</em></span> state. In this case, all cross section
|
|---|
| 423 | tables need to be recalculated before the event loop. You should use the
|
|---|
| 424 | <code class="literal">CutOffHasBeenModified()</code> method when you change cut-off
|
|---|
| 425 | values so that the <code class="literal">SetCuts</code> method of your
|
|---|
| 426 | <span class="emphasis"><em>PhysicsList</em></span> concrete class will be invoked.
|
|---|
| 427 | </p></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch03s03.html"><img src="AllResources/IconsGIF/prev.gif" alt="Prev"></a> </td><td width="20%" align="center"><a accesskey="u" href="ch03.html"><img src="AllResources/IconsGIF/up.gif" alt="Up"></a></td><td width="40%" align="right"> <a accesskey="n" href="ch03s05.html"><img src="AllResources/IconsGIF/next.gif" alt="Next"></a></td></tr><tr><td width="40%" align="left" valign="top">3.3.
|
|---|
| 428 | System of units
|
|---|
| 429 | </td><td width="20%" align="center"><a accesskey="h" href="index.html"><img src="AllResources/IconsGIF/home.gif" alt="Home"></a></td><td width="40%" align="right" valign="top"> 3.5.
|
|---|
| 430 | Event
|
|---|
| 431 | </td></tr></table></div></body></html>
|
|---|