source: trunk/Documentation/geant4/UserDocumentation/UsersGuides/ForApplicationDeveloper/html/ch06s02.html@ 901

Last change on this file since 901 was 901, checked in by garnier, 17 years ago

Add Geant4 Documentation at 8.12.2008

File size: 14.4 KB
Line 
1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>6.2.  Optional User Actions</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="ch06.html" title="Chapter 6.  User Actions"><link rel="prev" href="ch06.html" title="Chapter 6.  User Actions"><link rel="next" href="ch06s03.html" title="6.3.  User Information Classes"><script language="JavaScript">
2function 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">6.2. 
9Optional User Actions
10</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch06.html"><img src="AllResources/IconsGIF/prev.gif" alt="Prev"></a> </td><th width="60%" align="center">Chapter 6. 
11User Actions
12</th><td width="20%" align="right"> <a accesskey="n" href="ch06s03.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.OptUAct"></a>6.2. 
13Optional User Actions
14</h2></div></div></div><p>
15There are five virtual classes whose methods the user may override
16in order to gain control of the simulation at various stages. Each
17method of each action class has an empty default implementation,
18allowing the user to inherit and implement desired classes and
19methods. Objects of user action classes must be registered with
20<code class="literal">G4RunManager</code>.
21</p><h5><a name="id491337"></a>
22<code class="literal">G4UserRunAction</code>
23</h5><p>
24This class has three virtual methods which are invoked by
25<code class="literal">G4RunManager</code> for each run:
26
27</p><div class="variablelist"><p class="title"><b></b></p><dl><dt><span class="term">
28 <code class="literal">GenerateRun()</code>
29 </span></dt><dd><p>
30 This method is invoked at the beginning of <code class="literal">BeamOn</code>.
31 Because the user can inherit the class <code class="literal">G4Run</code> and create
32 his/her own concrete class to store some information about the run,
33 the <code class="literal">GenerateRun()</code> method is the place to instantiate such
34 an object. It is also the ideal place to set variables which affect
35 the physics table (such as production thresholds) for a particular
36 run, because <code class="literal">GenerateRun()</code> is invoked before the
37 calculation of the physics table.
38 </p></dd><dt><span class="term">
39 <code class="literal">BeginOfRunAction()</code>
40 </span></dt><dd><p>
41 This method is invoked before entering the event loop. A
42 typical use of this method would be to initialize and/or book
43 histograms for a particular run. This method is invoked after the
44 calculation of the physics tables.
45 </p></dd><dt><span class="term">
46 <code class="literal">EndOfRunAction()</code>
47 </span></dt><dd><p>
48 This method is invoked at the very end of the run processing.
49 It is typically used for a simple analysis of the processed run.
50 </p></dd></dl></div><p>
51</p><p>
52</p><div class="example"><a name="programlist_OptUAct_1"></a><p class="title"><b>Example 6.4. 
53<code class="literal">G4UserRunAction</code>
54</b></p><div class="example-contents"><pre class="programlisting">
55 class G4UserRunAction
56 {
57 public:
58 G4UserRunAction();
59 virtual ~G4UserRunAction();
60
61 public:
62 virtual G4Run* GenerateRun();
63 virtual void BeginOfRunAction(const G4Run*);
64 virtual void EndOfRunAction(const G4Run*);
65 };
66</pre></div></div><p><br class="example-break">
67</p><h5><a name="id491471"></a>
68<code class="literal">G4UserEventAction</code>
69</h5><p>
70This class has two virtual methods which are invoked by
71<code class="literal">G4EventManager</code> for each event:
72
73</p><div class="variablelist"><p class="title"><b></b></p><dl><dt><span class="term">
74 <code class="literal">beginOfEventAction()</code>
75 </span></dt><dd><p>
76 This method is invoked before converting the primary particles
77 to <code class="literal">G4Track</code> objects. A typical use of this method
78 would be to initialize and/or book histograms for a particular event.
79 </p></dd><dt><span class="term">
80 <code class="literal">endOfEventAction()</code>
81 </span></dt><dd><p>
82 This method is invoked at the very end of event processing. It
83 is typically used for a simple analysis of the processed event.
84 If the user wants to keep the currently processing event until the
85 end of the current run, the user can invoke
86 <code class="literal">fpEventManager-&gt;KeepTheCurrentEvent();</code>
87 so that it is kept in <span class="emphasis"><em>G4Run</em></span> object. This should
88 be quite useful if you simulate quite many events and want to
89 visualize only the most interest ones after the long execution.
90 Given the memory size of an event and its contents may be large,
91 it is the user's responsibility not to keep unnecessary events.
92 </p></dd></dl></div><p>
93</p><p>
94</p><div class="example"><a name="programlist_OptUAct_2"></a><p class="title"><b>Example 6.5. 
95<code class="literal">G4UserEventAction</code>
96</b></p><div class="example-contents"><pre class="programlisting">
97 class G4UserEventAction
98 {
99 public:
100 G4UserEventAction() {;}
101 virtual ~G4UserEventAction() {;}
102 virtual void BeginOfEventAction(const G4Event*);
103 virtual void EndOfEventAction(const G4Event*);
104 protected:
105 G4EventManager* fpEventManager;
106 };
107</pre></div></div><p><br class="example-break">
108</p><h5><a name="id491582"></a>
109<code class="literal">G4UserStackingAction</code>
110</h5><p>
111This class has three virtual methods, <code class="literal">ClassifyNewTrack</code>,
112<code class="literal">NewStage</code> and <code class="literal">PrepareNewEvent</code> which the
113user may override in order to control the various track stacking mechanisms.
114ExampleN04 could be a good example to understand the usage of this class.
115</p><p>
116<code class="literal">ClassifyNewTrack()</code> is invoked by
117<code class="literal">G4StackManager</code> whenever a new <code class="literal">G4Track</code>
118object is "pushed" onto a stack by <code class="literal">G4EventManager</code>.
119<code class="literal">ClassifyNewTrack()</code> returns an enumerator,
120<code class="literal">G4ClassificationOfNewTrack</code>, whose value indicates to which
121stack, if any, the track will be sent. This value should be
122determined by the user. <code class="literal">G4ClassificationOfNewTrack</code> has
123four possible values:
124
125</p><div class="itemizedlist"><ul type="disc" compact><li><p>
126 <code class="literal">fUrgent</code> - track is placed in the
127 <span class="emphasis"><em>urgent</em></span> stack
128 </p></li><li><p>
129 <code class="literal">fWaiting</code> - track is placed in the
130 <span class="emphasis"><em>waiting</em></span> stack, and will not be simulated until
131 the <span class="emphasis"><em>urgent</em></span> stack is empty
132 </p></li><li><p>
133 <code class="literal">fPostpone</code> - track is postponed to the next event
134 </p></li><li><p>
135 <code class="literal">fKill</code> - the track is deleted immediately and not
136 stored in any stack.
137 </p></li></ul></div><p>
138</p><p>
139These assignments may be made based on the origin of the track
140which is obtained as follows:
141
142</p><div class="informalexample"><pre class="programlisting">
143 G4int parent_ID = aTrack-&gt;get_parentID();
144</pre></div><p>
145
146where
147
148</p><div class="itemizedlist"><ul type="disc" compact><li><p>
149 <code class="literal">parent_ID = 0</code> indicates a primary particle
150 </p></li><li><p>
151 <code class="literal">parent_ID &gt; 0</code> indicates a secondary particle
152 </p></li><li><p>
153 <code class="literal">parent_ID &lt; 0</code> indicates postponed particle from
154 previous event.
155 </p></li></ul></div><p>
156</p><p>
157<code class="literal">NewStage()</code> is invoked when the <span class="emphasis"><em>urgent</em></span>
158stack is empty and the <span class="emphasis"><em>waiting</em></span> stack contains at least one
159<code class="literal">G4Track</code> object. Here the user may kill or re-assign to
160different stacks all the tracks in the <span class="emphasis"><em>waiting</em></span> stack by
161calling the <code class="literal">stackManager-&gt;ReClassify()</code> method which, in
162turn, calls the <code class="literal">ClassifyNewTrack()</code> method. If no user
163action is taken, all tracks in the <span class="emphasis"><em>waiting</em></span> stack are
164transferred to the <span class="emphasis"><em>urgent</em></span> stack. The user may also decide to
165abort the current event even though some tracks may remain in the
166<span class="emphasis"><em>waiting</em></span> stack by calling <code class="literal">stackManager-&gt;clear()</code>.
167This method is valid and safe only if it is called from the
168<code class="literal">G4UserStackingAction</code> class. A global method of event
169abortion is
170
171</p><div class="informalexample"><pre class="programlisting">
172 G4UImanager * UImanager = G4UImanager::GetUIpointer();
173 UImanager-&gt;ApplyCommand("/event/abort");
174</pre></div><p>
175</p><p>
176<code class="literal">PrepareNewEvent()</code> is invoked at the beginning of each
177event. At this point no primary particles have been converted to
178tracks, so the <span class="emphasis"><em>urgent</em></span> and <span class="emphasis"><em>waiting</em></span>
179stacks are empty. However, there may be tracks in the
180<span class="emphasis"><em>postponed-to-next-event</em></span> stack;
181for each of these the <code class="literal">ClassifyNewTrack()</code> method is
182called and the track is assigned to the appropriate stack.
183
184</p><div class="example"><a name="programlist_OptUAct_3"></a><p class="title"><b>Example 6.6. 
185<code class="literal">G4UserStackingAction</code>
186</b></p><div class="example-contents"><pre class="programlisting">
187 #include "G4ClassificationOfNewTrack.hh"
188
189 class G4UserStackingAction
190 {
191 public:
192 G4UserStackingAction();
193 virtual ~G4UserStackingAction();
194 protected:
195 G4StackManager * stackManager;
196
197 public:
198 //---------------------------------------------------------------
199 // virtual methods to be implemented by user
200 //---------------------------------------------------------------
201 //
202 virtual G4ClassificationOfNewTrack
203 ClassifyNewTrack(const G4Track*);
204 //
205 //---------------------------------------------------------------
206 //
207 virtual void NewStage();
208 //
209 //---------------------------------------------------------------
210 //
211 virtual void PrepareNewEvent();
212 //
213 //---------------------------------------------------------------
214
215 };
216</pre></div></div><p><br class="example-break">
217</p><h5><a name="id491907"></a>
218<code class="literal">G4UserTrackingAction</code>
219</h5><p>
220</p><div class="example"><a name="programlist_OptUAct_4"></a><p class="title"><b>Example 6.7. 
221<code class="literal">G4UserTrackingAction</code>
222</b></p><div class="example-contents"><pre class="programlisting">
223 //---------------------------------------------------------------
224 //
225 // G4UserTrackingAction.hh
226 //
227 // Description:
228 // This class represents actions taken place by the user at each
229 // end of stepping.
230 //
231 //---------------------------------------------------------------
232
233 ///////////////////////////
234 class G4UserTrackingAction
235 ///////////////////////////
236 {
237
238 //--------
239 public:
240 //--------
241
242 // Constructor &amp; Destructor
243 G4UserTrackingAction(){};
244 virtual ~G4UserTrackingAction(){}
245
246 // Member functions
247 virtual void PreUserTrackingAction(const G4Track*){}
248 virtual void PostUserTrackingAction(const G4Track*){}
249
250 //-----------
251 protected:
252 //-----------
253
254 // Member data
255 G4TrackingManager* fpTrackingManager;
256
257 };
258</pre></div></div><p><br class="example-break">
259</p><h5><a name="id491954"></a>
260<code class="literal">G4UserSteppingAction</code>
261</h5><p>
262</p><div class="example"><a name="programlist_OptUAct_5"></a><p class="title"><b>Example 6.8. 
263<code class="literal">G4UserSteppingAction</code>
264</b></p><div class="example-contents"><pre class="programlisting">
265 //---------------------------------------------------------------
266 //
267 // G4UserSteppingAction.hh
268 //
269 // Description:
270 // This class represents actions taken place by the user at each
271 // end of stepping.
272 //
273 //---------------------------------------------------------------
274
275 ///////////////////////////
276 class G4UserSteppingAction
277 ///////////////////////////
278 {
279
280 //--------
281 public:
282 //--------
283
284 // Constructor and destructor
285 G4UserSteppingAction(){}
286 virtual ~G4UserSteppingAction(){}
287
288 // Member functions
289 virtual void UserSteppingAction(const G4Step*){}
290
291 //-----------
292 protected:
293 //-----------
294
295 // Member data
296 G4SteppingManager* fpSteppingManager;
297
298 };
299</pre></div></div><p><br class="example-break">
300</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch06.html"><img src="AllResources/IconsGIF/prev.gif" alt="Prev"></a> </td><td width="20%" align="center"><a accesskey="u" href="ch06.html"><img src="AllResources/IconsGIF/up.gif" alt="Up"></a></td><td width="40%" align="right"> <a accesskey="n" href="ch06s03.html"><img src="AllResources/IconsGIF/next.gif" alt="Next"></a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 6. 
301User Actions
302 </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"> 6.3. 
303User Information Classes
304</td></tr></table></div></body></html>
Note: See TracBrowser for help on using the repository browser.