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