| 1 | <!-- ******************************************************** -->
|
|---|
| 2 | <!-- -->
|
|---|
| 3 | <!-- [History] -->
|
|---|
| 4 | <!-- Changed by: Katsuya Amako, 9-Jul-1998 -->
|
|---|
| 5 | <!-- Changed by: Katsuya Amako, 4-Aug-1998 -->
|
|---|
| 6 | <!-- Changed by: John Allison, 4-Aug-1998 -->
|
|---|
| 7 | <!-- Changed by: Katsuya Amako, 30-Nov-1998 -->
|
|---|
| 8 | <!-- Changed by: Dennis Wright, 27-Nov-2001 -->
|
|---|
| 9 | <!-- Proof read by: Joe Chuma, 2-Jul-1999 -->
|
|---|
| 10 | <!-- Converted to DocBook: Katsuya Amako, Aug-2006 -->
|
|---|
| 11 | <!-- -->
|
|---|
| 12 | <!-- ******************************************************** -->
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 | <!-- ******************* Section (Level#1) ****************** -->
|
|---|
| 16 | <sect1 id="sect.OptUAct">
|
|---|
| 17 | <title>
|
|---|
| 18 | Optional User Actions
|
|---|
| 19 | </title>
|
|---|
| 20 |
|
|---|
| 21 | <para>
|
|---|
| 22 | There are five virtual classes whose methods the user may override
|
|---|
| 23 | in order to gain control of the simulation at various stages. Each
|
|---|
| 24 | method of each action class has an empty default implementation,
|
|---|
| 25 | allowing the user to inherit and implement desired classes and
|
|---|
| 26 | methods. Objects of user action classes must be registered with
|
|---|
| 27 | <literal>G4RunManager</literal>.
|
|---|
| 28 | </para>
|
|---|
| 29 |
|
|---|
| 30 | <!-- ******************* Section (Level#2) ****************** -->
|
|---|
| 31 | <sect2 id="sect.OptUAct.Usage">
|
|---|
| 32 | <title>
|
|---|
| 33 | Usage of User Actions
|
|---|
| 34 | </title>
|
|---|
| 35 |
|
|---|
| 36 | <!-- ******* Bridgehead ******* -->
|
|---|
| 37 | <bridgehead renderas='sect4'>
|
|---|
| 38 | <literal>G4UserRunAction</literal>
|
|---|
| 39 | </bridgehead>
|
|---|
| 40 |
|
|---|
| 41 | <para>
|
|---|
| 42 | This class has three virtual methods which are invoked by
|
|---|
| 43 | <literal>G4RunManager</literal> for each run:
|
|---|
| 44 |
|
|---|
| 45 | <variablelist><title></title>
|
|---|
| 46 | <varlistentry>
|
|---|
| 47 | <term>
|
|---|
| 48 | <literal>GenerateRun()</literal>
|
|---|
| 49 | </term>
|
|---|
| 50 | <listitem><para>
|
|---|
| 51 | This method is invoked at the beginning of <literal>BeamOn</literal>.
|
|---|
| 52 | Because the user can inherit the class <literal>G4Run</literal> and create
|
|---|
| 53 | his/her own concrete class to store some information about the run,
|
|---|
| 54 | the <literal>GenerateRun()</literal> method is the place to instantiate such
|
|---|
| 55 | an object. It is also the ideal place to set variables which affect
|
|---|
| 56 | the physics table (such as production thresholds) for a particular
|
|---|
| 57 | run, because <literal>GenerateRun()</literal> is invoked before the
|
|---|
| 58 | calculation of the physics table.
|
|---|
| 59 | </para></listitem>
|
|---|
| 60 | </varlistentry>
|
|---|
| 61 | <varlistentry>
|
|---|
| 62 | <term>
|
|---|
| 63 | <literal>BeginOfRunAction()</literal>
|
|---|
| 64 | </term>
|
|---|
| 65 | <listitem><para>
|
|---|
| 66 | This method is invoked before entering the event loop. A
|
|---|
| 67 | typical use of this method would be to initialize and/or book
|
|---|
| 68 | histograms for a particular run. This method is invoked after the
|
|---|
| 69 | calculation of the physics tables.
|
|---|
| 70 | </para></listitem>
|
|---|
| 71 | </varlistentry>
|
|---|
| 72 | <varlistentry>
|
|---|
| 73 | <term>
|
|---|
| 74 | <literal>EndOfRunAction()</literal>
|
|---|
| 75 | </term>
|
|---|
| 76 | <listitem><para>
|
|---|
| 77 | This method is invoked at the very end of the run processing.
|
|---|
| 78 | It is typically used for a simple analysis of the processed run.
|
|---|
| 79 | </para></listitem>
|
|---|
| 80 | </varlistentry>
|
|---|
| 81 | </variablelist>
|
|---|
| 82 | </para>
|
|---|
| 83 |
|
|---|
| 84 | <para>
|
|---|
| 85 | <example id="programlist_OptUAct_1">
|
|---|
| 86 | <title>
|
|---|
| 87 | <literal>G4UserRunAction</literal>
|
|---|
| 88 | </title>
|
|---|
| 89 | <programlisting>
|
|---|
| 90 | class G4UserRunAction
|
|---|
| 91 | {
|
|---|
| 92 | public:
|
|---|
| 93 | G4UserRunAction();
|
|---|
| 94 | virtual ~G4UserRunAction();
|
|---|
| 95 |
|
|---|
| 96 | public:
|
|---|
| 97 | virtual G4Run* GenerateRun();
|
|---|
| 98 | virtual void BeginOfRunAction(const G4Run*);
|
|---|
| 99 | virtual void EndOfRunAction(const G4Run*);
|
|---|
| 100 | };
|
|---|
| 101 | </programlisting>
|
|---|
| 102 | </example>
|
|---|
| 103 | </para>
|
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 | <!-- ******* Bridgehead ******* -->
|
|---|
| 107 | <bridgehead renderas='sect4'>
|
|---|
| 108 | <literal>G4UserEventAction</literal>
|
|---|
| 109 | </bridgehead>
|
|---|
| 110 |
|
|---|
| 111 | <para>
|
|---|
| 112 | This class has two virtual methods which are invoked by
|
|---|
| 113 | <literal>G4EventManager</literal> for each event:
|
|---|
| 114 |
|
|---|
| 115 | <variablelist><title></title>
|
|---|
| 116 | <varlistentry>
|
|---|
| 117 | <term>
|
|---|
| 118 | <literal>beginOfEventAction()</literal>
|
|---|
| 119 | </term>
|
|---|
| 120 | <listitem><para>
|
|---|
| 121 | This method is invoked before converting the primary particles
|
|---|
| 122 | to <literal>G4Track</literal> objects. A typical use of this method
|
|---|
| 123 | would be to initialize and/or book histograms for a particular event.
|
|---|
| 124 | </para></listitem>
|
|---|
| 125 | </varlistentry>
|
|---|
| 126 | <varlistentry>
|
|---|
| 127 | <term>
|
|---|
| 128 | <literal>endOfEventAction()</literal>
|
|---|
| 129 | </term>
|
|---|
| 130 | <listitem><para>
|
|---|
| 131 | This method is invoked at the very end of event processing. It
|
|---|
| 132 | is typically used for a simple analysis of the processed event.
|
|---|
| 133 | If the user wants to keep the currently processing event until the
|
|---|
| 134 | end of the current run, the user can invoke
|
|---|
| 135 | <literal>fpEventManager->KeepTheCurrentEvent();</literal>
|
|---|
| 136 | so that it is kept in <emphasis>G4Run</emphasis> object. This should
|
|---|
| 137 | be quite useful if you simulate quite many events and want to
|
|---|
| 138 | visualize only the most interest ones after the long execution.
|
|---|
| 139 | Given the memory size of an event and its contents may be large,
|
|---|
| 140 | it is the user's responsibility not to keep unnecessary events.
|
|---|
| 141 | </para></listitem>
|
|---|
| 142 | </varlistentry>
|
|---|
| 143 | </variablelist>
|
|---|
| 144 | </para>
|
|---|
| 145 |
|
|---|
| 146 | <para>
|
|---|
| 147 | <example id="programlist_OptUAct_2">
|
|---|
| 148 | <title>
|
|---|
| 149 | <literal>G4UserEventAction</literal>
|
|---|
| 150 | </title>
|
|---|
| 151 |
|
|---|
| 152 | <programlisting>
|
|---|
| 153 | class G4UserEventAction
|
|---|
| 154 | {
|
|---|
| 155 | public:
|
|---|
| 156 | G4UserEventAction() {;}
|
|---|
| 157 | virtual ~G4UserEventAction() {;}
|
|---|
| 158 | virtual void BeginOfEventAction(const G4Event*);
|
|---|
| 159 | virtual void EndOfEventAction(const G4Event*);
|
|---|
| 160 | protected:
|
|---|
| 161 | G4EventManager* fpEventManager;
|
|---|
| 162 | };
|
|---|
| 163 | </programlisting>
|
|---|
| 164 | </example>
|
|---|
| 165 | </para>
|
|---|
| 166 |
|
|---|
| 167 | <!-- ******* Bridgehead ******* -->
|
|---|
| 168 | <bridgehead renderas='sect4'>
|
|---|
| 169 | <literal>G4UserStackingAction</literal>
|
|---|
| 170 | </bridgehead>
|
|---|
| 171 |
|
|---|
| 172 | <para>
|
|---|
| 173 | This class has three virtual methods, <literal>ClassifyNewTrack</literal>,
|
|---|
| 174 | <literal>NewStage</literal> and <literal>PrepareNewEvent</literal> which the
|
|---|
| 175 | user may override in order to control the various track stacking mechanisms.
|
|---|
| 176 | ExampleN04 could be a good example to understand the usage of this class.
|
|---|
| 177 | </para>
|
|---|
| 178 |
|
|---|
| 179 | <para>
|
|---|
| 180 | <literal>ClassifyNewTrack()</literal> is invoked by
|
|---|
| 181 | <literal>G4StackManager</literal> whenever a new <literal>G4Track</literal>
|
|---|
| 182 | object is "pushed" onto a stack by <literal>G4EventManager</literal>.
|
|---|
| 183 | <literal>ClassifyNewTrack()</literal> returns an enumerator,
|
|---|
| 184 | <literal>G4ClassificationOfNewTrack</literal>, whose value indicates to which
|
|---|
| 185 | stack, if any, the track will be sent. This value should be
|
|---|
| 186 | determined by the user. <literal>G4ClassificationOfNewTrack</literal> has
|
|---|
| 187 | four possible values:
|
|---|
| 188 |
|
|---|
| 189 | <itemizedlist spacing="compact">
|
|---|
| 190 | <listitem><para>
|
|---|
| 191 | <literal>fUrgent</literal> - track is placed in the
|
|---|
| 192 | <emphasis>urgent</emphasis> stack
|
|---|
| 193 | </para></listitem>
|
|---|
| 194 | <listitem><para>
|
|---|
| 195 | <literal>fWaiting</literal> - track is placed in the
|
|---|
| 196 | <emphasis>waiting</emphasis> stack, and will not be simulated until
|
|---|
| 197 | the <emphasis>urgent</emphasis> stack is empty
|
|---|
| 198 | </para></listitem>
|
|---|
| 199 | <listitem><para>
|
|---|
| 200 | <literal>fPostpone</literal> - track is postponed to the next event
|
|---|
| 201 | </para></listitem>
|
|---|
| 202 | <listitem><para>
|
|---|
| 203 | <literal>fKill</literal> - the track is deleted immediately and not
|
|---|
| 204 | stored in any stack.
|
|---|
| 205 | </para></listitem>
|
|---|
| 206 | </itemizedlist>
|
|---|
| 207 | </para>
|
|---|
| 208 |
|
|---|
| 209 | <para>
|
|---|
| 210 | These assignments may be made based on the origin of the track
|
|---|
| 211 | which is obtained as follows:
|
|---|
| 212 |
|
|---|
| 213 | <informalexample>
|
|---|
| 214 | <programlisting>
|
|---|
| 215 | G4int parent_ID = aTrack->get_parentID();
|
|---|
| 216 | </programlisting>
|
|---|
| 217 | </informalexample>
|
|---|
| 218 |
|
|---|
| 219 | where
|
|---|
| 220 |
|
|---|
| 221 | <itemizedlist spacing="compact">
|
|---|
| 222 | <listitem><para>
|
|---|
| 223 | <literal>parent_ID = 0</literal> indicates a primary particle
|
|---|
| 224 | </para></listitem>
|
|---|
| 225 | <listitem><para>
|
|---|
| 226 | <literal>parent_ID > 0</literal> indicates a secondary particle
|
|---|
| 227 | </para></listitem>
|
|---|
| 228 | <listitem><para>
|
|---|
| 229 | <literal>parent_ID < 0</literal> indicates postponed particle from
|
|---|
| 230 | previous event.
|
|---|
| 231 | </para></listitem>
|
|---|
| 232 | </itemizedlist>
|
|---|
| 233 | </para>
|
|---|
| 234 |
|
|---|
| 235 | <para>
|
|---|
| 236 | <literal>NewStage()</literal> is invoked when the <emphasis>urgent</emphasis>
|
|---|
| 237 | stack is empty and the <emphasis>waiting</emphasis> stack contains at least one
|
|---|
| 238 | <literal>G4Track</literal> object. Here the user may kill or re-assign to
|
|---|
| 239 | different stacks all the tracks in the <emphasis>waiting</emphasis> stack by
|
|---|
| 240 | calling the <literal>stackManager->ReClassify()</literal> method which, in
|
|---|
| 241 | turn, calls the <literal>ClassifyNewTrack()</literal> method. If no user
|
|---|
| 242 | action is taken, all tracks in the <emphasis>waiting</emphasis> stack are
|
|---|
| 243 | transferred to the <emphasis>urgent</emphasis> stack. The user may also decide to
|
|---|
| 244 | abort the current event even though some tracks may remain in the
|
|---|
| 245 | <emphasis>waiting</emphasis> stack by calling <literal>stackManager->clear()</literal>.
|
|---|
| 246 | This method is valid and safe only if it is called from the
|
|---|
| 247 | <literal>G4UserStackingAction</literal> class. A global method of event
|
|---|
| 248 | abortion is
|
|---|
| 249 |
|
|---|
| 250 | <informalexample>
|
|---|
| 251 | <programlisting>
|
|---|
| 252 | G4UImanager * UImanager = G4UImanager::GetUIpointer();
|
|---|
| 253 | UImanager->ApplyCommand("/event/abort");
|
|---|
| 254 | </programlisting>
|
|---|
| 255 | </informalexample>
|
|---|
| 256 | </para>
|
|---|
| 257 |
|
|---|
| 258 | <para>
|
|---|
| 259 | <literal>PrepareNewEvent()</literal> is invoked at the beginning of each
|
|---|
| 260 | event. At this point no primary particles have been converted to
|
|---|
| 261 | tracks, so the <emphasis>urgent</emphasis> and <emphasis>waiting</emphasis>
|
|---|
| 262 | stacks are empty. However, there may be tracks in the
|
|---|
| 263 | <emphasis>postponed-to-next-event</emphasis> stack;
|
|---|
| 264 | for each of these the <literal>ClassifyNewTrack()</literal> method is
|
|---|
| 265 | called and the track is assigned to the appropriate stack.
|
|---|
| 266 |
|
|---|
| 267 | <example id="programlist_OptUAct_3">
|
|---|
| 268 | <title>
|
|---|
| 269 | <literal>G4UserStackingAction</literal>
|
|---|
| 270 | </title>
|
|---|
| 271 |
|
|---|
| 272 | <programlisting>
|
|---|
| 273 | #include "G4ClassificationOfNewTrack.hh"
|
|---|
| 274 |
|
|---|
| 275 | class G4UserStackingAction
|
|---|
| 276 | {
|
|---|
| 277 | public:
|
|---|
| 278 | G4UserStackingAction();
|
|---|
| 279 | virtual ~G4UserStackingAction();
|
|---|
| 280 | protected:
|
|---|
| 281 | G4StackManager * stackManager;
|
|---|
| 282 |
|
|---|
| 283 | public:
|
|---|
| 284 | //---------------------------------------------------------------
|
|---|
| 285 | // virtual methods to be implemented by user
|
|---|
| 286 | //---------------------------------------------------------------
|
|---|
| 287 | //
|
|---|
| 288 | virtual G4ClassificationOfNewTrack
|
|---|
| 289 | ClassifyNewTrack(const G4Track*);
|
|---|
| 290 | //
|
|---|
| 291 | //---------------------------------------------------------------
|
|---|
| 292 | //
|
|---|
| 293 | virtual void NewStage();
|
|---|
| 294 | //
|
|---|
| 295 | //---------------------------------------------------------------
|
|---|
| 296 | //
|
|---|
| 297 | virtual void PrepareNewEvent();
|
|---|
| 298 | //
|
|---|
| 299 | //---------------------------------------------------------------
|
|---|
| 300 |
|
|---|
| 301 | };
|
|---|
| 302 | </programlisting>
|
|---|
| 303 | </example>
|
|---|
| 304 | </para>
|
|---|
| 305 |
|
|---|
| 306 |
|
|---|
| 307 | <!-- ******* Bridgehead ******* -->
|
|---|
| 308 | <bridgehead renderas='sect4'>
|
|---|
| 309 | <literal>G4UserTrackingAction</literal>
|
|---|
| 310 | </bridgehead>
|
|---|
| 311 |
|
|---|
| 312 | <para>
|
|---|
| 313 | <example id="programlist_OptUAct_4">
|
|---|
| 314 | <title>
|
|---|
| 315 | <literal>G4UserTrackingAction</literal>
|
|---|
| 316 | </title>
|
|---|
| 317 |
|
|---|
| 318 | <programlisting>
|
|---|
| 319 | //---------------------------------------------------------------
|
|---|
| 320 | //
|
|---|
| 321 | // G4UserTrackingAction.hh
|
|---|
| 322 | //
|
|---|
| 323 | // Description:
|
|---|
| 324 | // This class represents actions taken place by the user at each
|
|---|
| 325 | // end of stepping.
|
|---|
| 326 | //
|
|---|
| 327 | //---------------------------------------------------------------
|
|---|
| 328 |
|
|---|
| 329 | ///////////////////////////
|
|---|
| 330 | class G4UserTrackingAction
|
|---|
| 331 | ///////////////////////////
|
|---|
| 332 | {
|
|---|
| 333 |
|
|---|
| 334 | //--------
|
|---|
| 335 | public:
|
|---|
| 336 | //--------
|
|---|
| 337 |
|
|---|
| 338 | // Constructor & Destructor
|
|---|
| 339 | G4UserTrackingAction(){};
|
|---|
| 340 | virtual ~G4UserTrackingAction(){}
|
|---|
| 341 |
|
|---|
| 342 | // Member functions
|
|---|
| 343 | virtual void PreUserTrackingAction(const G4Track*){}
|
|---|
| 344 | virtual void PostUserTrackingAction(const G4Track*){}
|
|---|
| 345 |
|
|---|
| 346 | //-----------
|
|---|
| 347 | protected:
|
|---|
| 348 | //-----------
|
|---|
| 349 |
|
|---|
| 350 | // Member data
|
|---|
| 351 | G4TrackingManager* fpTrackingManager;
|
|---|
| 352 |
|
|---|
| 353 | };
|
|---|
| 354 | </programlisting>
|
|---|
| 355 | </example>
|
|---|
| 356 | </para>
|
|---|
| 357 |
|
|---|
| 358 |
|
|---|
| 359 | <!-- ******* Bridgehead ******* -->
|
|---|
| 360 | <bridgehead renderas='sect4'>
|
|---|
| 361 | <literal>G4UserSteppingAction</literal>
|
|---|
| 362 | </bridgehead>
|
|---|
| 363 |
|
|---|
| 364 | <para>
|
|---|
| 365 | <example id="programlist_OptUAct_5">
|
|---|
| 366 | <title>
|
|---|
| 367 | <literal>G4UserSteppingAction</literal>
|
|---|
| 368 | </title>
|
|---|
| 369 |
|
|---|
| 370 | <programlisting>
|
|---|
| 371 | //---------------------------------------------------------------
|
|---|
| 372 | //
|
|---|
| 373 | // G4UserSteppingAction.hh
|
|---|
| 374 | //
|
|---|
| 375 | // Description:
|
|---|
| 376 | // This class represents actions taken place by the user at each
|
|---|
| 377 | // end of stepping.
|
|---|
| 378 | //
|
|---|
| 379 | //---------------------------------------------------------------
|
|---|
| 380 |
|
|---|
| 381 | ///////////////////////////
|
|---|
| 382 | class G4UserSteppingAction
|
|---|
| 383 | ///////////////////////////
|
|---|
| 384 | {
|
|---|
| 385 |
|
|---|
| 386 | //--------
|
|---|
| 387 | public:
|
|---|
| 388 | //--------
|
|---|
| 389 |
|
|---|
| 390 | // Constructor and destructor
|
|---|
| 391 | G4UserSteppingAction(){}
|
|---|
| 392 | virtual ~G4UserSteppingAction(){}
|
|---|
| 393 |
|
|---|
| 394 | // Member functions
|
|---|
| 395 | virtual void UserSteppingAction(const G4Step*){}
|
|---|
| 396 |
|
|---|
| 397 | //-----------
|
|---|
| 398 | protected:
|
|---|
| 399 | //-----------
|
|---|
| 400 |
|
|---|
| 401 | // Member data
|
|---|
| 402 | G4SteppingManager* fpSteppingManager;
|
|---|
| 403 |
|
|---|
| 404 | };
|
|---|
| 405 | </programlisting>
|
|---|
| 406 | </example>
|
|---|
| 407 | </para>
|
|---|
| 408 |
|
|---|
| 409 | </sect2>
|
|---|
| 410 |
|
|---|
| 411 | <!-- ******************* Section (Level#2) ****************** -->
|
|---|
| 412 | <sect2 id="sect.OptUAct.EngyConsv">
|
|---|
| 413 | <title>
|
|---|
| 414 | Killing Tracks in User Actions and Energy Conservation
|
|---|
| 415 | </title>
|
|---|
| 416 |
|
|---|
| 417 | <para>
|
|---|
| 418 | In either of user action classes described in the previous section,
|
|---|
| 419 | the user can implement an unnatural/unphysical action. A typical
|
|---|
| 420 | example is to kill a track, which is under the simulation, in the
|
|---|
| 421 | user stepping action. In this case the user have to be cautious of
|
|---|
| 422 | the total energy conservation. The user stepping action itself does
|
|---|
| 423 | not take care the energy or any physics quantity associated with
|
|---|
| 424 | the killed track. Therefore if the user want to keep the total
|
|---|
| 425 | energy of an event in this case, the lost track energy need to be
|
|---|
| 426 | recorded by the user.
|
|---|
| 427 | </para>
|
|---|
| 428 |
|
|---|
| 429 | <para>
|
|---|
| 430 | The same is true for user stacking or tracking actions. If the
|
|---|
| 431 | user has killed a track in these actions the all physics information
|
|---|
| 432 | associated with it would be lost and, for example, the total energy
|
|---|
| 433 | conservation be broken.
|
|---|
| 434 | </para>
|
|---|
| 435 |
|
|---|
| 436 | <para>
|
|---|
| 437 | If the user wants the Geant4 kernel to take care the total energy
|
|---|
| 438 | conservation automatically when he/she has killed artificially
|
|---|
| 439 | a track, the user has to use a killer process. For example if the
|
|---|
| 440 | user uses G4UserLimits and G4UserSpecialCuts process, energy of
|
|---|
| 441 | the killed track is added to the total energy deposit.
|
|---|
| 442 | </para>
|
|---|
| 443 |
|
|---|
| 444 |
|
|---|
| 445 | </sect2>
|
|---|
| 446 | </sect1>
|
|---|