source: trunk/Documentation/geant4/UserDocumentation/UsersGuides/ForApplicationDeveloper/html/ch08s07.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: 18.0 KB
Line 
1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>8.7.  Enhanced Trajectory Drawing</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="ch08.html" title="Chapter 8.  Visualization"><link rel="prev" href="ch08s06.html" title="8.6.  Visualization Attributes"><link rel="next" href="ch08s08.html" title="8.8.  Trajectory Filtering"><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">8.7. 
9Enhanced Trajectory Drawing
10</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch08s06.html"><img src="AllResources/IconsGIF/prev.gif" alt="Prev"></a> </td><th width="60%" align="center">Chapter 8. 
11Visualization
12</th><td width="20%" align="right"> <a accesskey="n" href="ch08s08.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.VisEnhTrj"></a>8.7. 
13Enhanced Trajectory Drawing
14</h2></div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sect.VisEnhTrj.DflCnfg"></a>8.7.1. 
15Default Configuration
16</h3></div></div></div><p>
17Trajectory drawing styles are specified through trajectory drawing
18models. Each drawing model has a default configuration provided
19through a G4VisTrajContext object. The default context settings are
20shown below.
21
22</p><div class="informaltable"><table border="1"><colgroup><col><col></colgroup><tbody><tr><td>
23 <span class="bold"><strong>Property</strong></span>
24 </td><td>
25 <span class="bold"><strong>Default Setting</strong></span>
26 </td></tr><tr><td>
27 Line colour
28 </td><td>
29 grey
30 </td></tr><tr><td>
31 Line visibility
32 </td><td>
33 true
34 </td></tr><tr><td>
35 Draw line
36 </td><td>
37 true
38 </td></tr><tr><td>
39 Draw auxiliary points
40 </td><td>
41 false
42 </td></tr><tr><td>
43 Auxiliary point type
44 </td><td>
45 squares
46 </td></tr><tr><td>
47 Auxiliary point size
48 </td><td>
49 0
50 </td></tr><tr><td>
51 Auxiliary point fill style
52 </td><td>
53 filled
54 </td></tr><tr><td>
55 Auxiliary point colour
56 </td><td>
57 magenta
58 </td></tr><tr><td>
59 Auxiliary point visibility
60 </td><td>
61 true
62 </td></tr><tr><td>
63 Draw step point
64 </td><td>
65 false
66 </td></tr><tr><td>
67 Step point type
68 </td><td>
69 circles
70 </td></tr><tr><td>
71 Step point size
72 </td><td>
73 0
74 </td></tr><tr><td>
75 Step point fill style
76 </td><td>
77 filled
78 </td></tr><tr><td>
79 Step point colour
80 </td><td>
81 yellow
82 </td></tr><tr><td>
83 Step point visibility
84 </td><td>
85 true
86 </td></tr><tr><td>
87 Time slice interval
88 </td><td>
89 0
90 </td></tr></tbody></table></div><p>
91</p><p>
92Points to note:
93
94</p><div class="itemizedlist"><ul type="disc" compact><li><p>
95 The context approach is intended to replace the configuration
96 through the imode parameter. The use of imode is depreciated and
97 will be removed in Geant4 v9.0.
98 </p></li><li><p>
99 Different visualisation drivers handle trajectory configuration
100 in different ways, so trajectories may not necessarily get
101 displayed as you have configured them.
102 </p></li></ul></div><p>
103</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sect.VisEnhTrj.DrdMdl"></a>8.7.2. 
104Trajectory Drawing Models
105</h3></div></div></div><p>
106A trajectory drawing model can override the default context
107according to the properties of a given trajectory. The following
108models are supplied with the Geant4 distribution:
109
110</p><div class="itemizedlist"><ul type="disc" compact><li><p>
111 G4TrajectoryGenericDrawer (generic)
112 </p></li><li><p>
113 G4TrajectoryDrawByCharge (drawByCharge)
114 </p></li><li><p>
115 G4TrajectoryDrawByParticleID (drawByParticleID)
116 </p></li><li><p>
117 G4TrajectoryDrawByOriginVolume (drawByOriginVolume)
118 </p></li><li><p>
119 G4TrajectoryDrawByAttribute (drawByAttribute)
120 </p></li></ul></div><p>
121</p><p>
122Both the context and model properties can be configured by the
123user. The models are described briefly below, followed by some
124example configuration commands.
125</p><h5><a name="id517690"></a>
126G4TrajectoryGenericDrawer
127</h5><p>
128This model simply draws all trajectories in the same style, with
129the properties provided by the context.
130</p><h5><a name="id517703"></a>
131G4TrajectoryDrawByCharge
132</h5><p>
133This is the default model - if no model is specified by the user,
134this model will be constructed automatically. The trajectory lines
135are coloured according to charge, with all other configuration
136parameters provided by the default context. The default colouring
137scheme is shown below.
138
139</p><div class="informalexample"><pre class="programlisting">
140 Charge Colour
141 ----------------------
142 1 Blue
143 -1 Red
144 0 Green
145</pre></div><p>
146</p><h5><a name="id517728"></a>
147G4TrajectoryDrawByParticleID
148</h5><p>
149This model colours trajectory lines according to particle type. All
150other configuration parameters are provided by the default context.
151By default, all trajectories are coloured grey. Chosen particle
152types can be highlighted with specified colours.
153</p><h5><a name="id517742"></a>
154G4TrajectoryDrawByOriginVolume
155</h5><p>
156This model colours trajectory lines according to the trajectories
157originating volume name. The volume can be either a logical or
158physical volume. Physical volume takes precedence over logical
159volume. All trajectories are coloured grey by default.
160</p><h5><a name="id517756"></a>
161G4TrajectoryDrawByAttribute
162</h5><p>
163This model draws trajectories based on the HepRep style attributes
164associated with trajectories. Each attribute drawer can be configured
165with interval and/or single value data. A new context object is
166created for each interval/single value. This makes it possible to
167have different step point markers etc, as well as line colour for
168trajectory attributes falling into different intervals, or matching
169single values. The single value data should override the interval data,
170allowing specific values to be highlighted. Units should be specified
171on the command line if the attribute unit is specified either as a
172G4BestUnit or if the unit is part of the value string.
173</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sect.VisEnhTrj.CntlComm"></a>8.7.3. 
174Controlling from Commands
175</h3></div></div></div><p>
176Multiple trajectory models can be created and configured using
177commands in the "<code class="literal">/vis/modeling/trajectories/</code>" directory.
178It is then possible to list available models and select one to be
179current.
180</p><p>
181Model configuration commands are generated dynamically when a
182model is instantiated. These commands apply directly to that
183instance. This makes it possible to have multiple instances of the
184drawByCharge model for example, each independently configurable
185through it's own set of commands.
186</p><p>
187See the interactive help for more information on the available
188commands.
189</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="sect.VisEnhTrj.CntlComm.ExpComm"></a>8.7.3.1. 
190Example commands
191</h4></div></div></div><p>
192#Create a generic model named generic-0 by default
193
194</p><div class="informalexample"><pre class="programlisting">
195/vis/modeling/trajectories/create/generic
196</pre></div><p>
197</p><p>
198#Configure context to colour all trajectories red
199
200</p><div class="informalexample"><pre class="programlisting">
201/vis/modeling/trajectories/generic-0/default/setLineColour red
202</pre></div><p>
203</p><p>
204#Create a drawByCharge model named drawCharge-0 by default
205(Subsequent models will be named drawByCharge-1, drawByCharge-2,
206etc.)
207
208</p><div class="informalexample"><pre class="programlisting">
209/vis/modeling/trajectories/create/drawByCharge
210</pre></div><p>
211</p><p>
212#Create a drawByCharge model named testChargeModel
213
214</p><div class="informalexample"><pre class="programlisting">
215/vis/modeling/trajectories/create/drawByCharge testChargeModel
216</pre></div><p>
217</p><p>
218#Configure drawByCharge-0 model
219
220</p><div class="informalexample"><pre class="programlisting">
221/vis/modeling/trajectories/drawByCharge-0/set 1 red
222/vis/modeling/trajectories/drawByCharge-0/set -1 red
223/vis/modeling/trajectories/drawByCharge-0/set 0 white
224</pre></div><p>
225</p><p>
226#Configure testCharge model through G4Colour components
227
228</p><div class="informalexample"><pre class="programlisting">
229/vis/modeling/trajectories/testChargeModel/setRGBA 1 0 1 1 1
230/vis/modeling/trajectories/testChargeModel/setRGBA -1 0.5 0.5 0.5 1
231/vis/modeling/trajectories/testChargeModel/setRGBA 0 1 1 0 1
232</pre></div><p>
233</p><p>
234#Create a drawByParticleID model named drawByParticleID-0
235
236</p><div class="informalexample"><pre class="programlisting">
237/vis/modeling/trajectories/create/drawByParticleID
238</pre></div><p>
239</p><p>
240#Configure drawByParticleID-0 model
241
242</p><div class="informalexample"><pre class="programlisting">
243/vis/modeling/trajectories/drawByParticleID-0/set gamma red
244/vis/modeling/trajectories/drawByParticleID-0/setRGBA e+ 1 0 1 1
245</pre></div><p>
246</p><p>
247#List available models
248
249</p><div class="informalexample"><pre class="programlisting">
250/vis/modeling/trajectories/list
251</pre></div><p>
252</p><p>
253#select drawByParticleID-0 to be current
254
255</p><div class="informalexample"><pre class="programlisting">
256/vis/modeling/trajectories/select drawByParticleID-0
257</pre></div><p>
258</p><p>
259#Create a drawByAttribute model named drawByAttribute-0
260
261</p><div class="informalexample"><pre class="programlisting">
262/vis/modeling/trajectories/create/drawByAttribute
263</pre></div><p>
264</p><p>
265#Configure drawByAttribute-0 model
266
267</p><div class="informalexample"><pre class="programlisting">
268/vis/modeling/trajectories/drawByAttribute-0/verbose true
269</pre></div><p>
270</p><p>
271#Select attribute "CPN"
272
273</p><div class="informalexample"><pre class="programlisting">
274/vis/modeling/trajectories/drawByAttribute-0/setAttribute CPN
275</pre></div><p>
276</p><p>
277#Configure single value data
278
279</p><div class="informalexample"><pre class="programlisting">
280/vis/modeling/trajectories/drawByAttribute-0/addValue brem_key eBrem
281/vis/modeling/trajectories/drawByAttribute-0/addValue annihil_key annihil
282/vis/modeling/trajectories/drawByAttribute-0/addValue decay_key Decay
283/vis/modeling/trajectories/drawByAttribute-0/addValue muIon_key muIoni
284/vis/modeling/trajectories/drawByAttribute-0/addValue eIon_key eIoni
285
286/vis/modeling/trajectories/drawByAttribute-0/brem_key/setLineColour red
287/vis/modeling/trajectories/drawByAttribute-0/annihil_key/setLineColour green
288/vis/modeling/trajectories/drawByAttribute-0/decay_key/setLineColour cyan
289/vis/modeling/trajectories/drawByAttribute-0/eIon_key/setLineColour yellow
290/vis/modeling/trajectories/drawByAttribute-0/muIon_key/setLineColour magenta
291</pre></div><p>
292</p><p>
293#Create a drawByAttribute model named drawByAttribute-1
294
295</p><div class="informalexample"><pre class="programlisting">
296/vis/modeling/trajectories/create/drawByAttribute
297</pre></div><p>
298</p><p>
299#Select "IMag" attribute
300
301</p><div class="informalexample"><pre class="programlisting">
302/vis/modeling/trajectories/drawByAttribute-1/setAttribute IMag
303</pre></div><p>
304</p><p>
305#Configure interval data
306
307</p><div class="informalexample"><pre class="programlisting">
308/vis/modeling/trajectories/drawByAttribute-1/addInterval interval1 0.0 keV 2.5MeV
309/vis/modeling/trajectories/drawByAttribute-1/addInterval interval2 2.5 MeV 5 MeV
310/vis/modeling/trajectories/drawByAttribute-1/addInterval interval3 5 MeV 7.5 MeV
311/vis/modeling/trajectories/drawByAttribute-1/addInterval interval4 7.5 MeV 10 MeV
312/vis/modeling/trajectories/drawByAttribute-1/addInterval interval5 10 MeV 12.5 MeV
313/vis/modeling/trajectories/drawByAttribute-1/addInterval interval6 12.5 MeV 10000 MeV
314
315/vis/modeling/trajectories/drawByAttribute-1/interval1/setLineColourRGBA 0.8 0 0.8 1
316/vis/modeling/trajectories/drawByAttribute-1/interval2/setLineColourRGBA 0.23 0.41 1 1
317/vis/modeling/trajectories/drawByAttribute-1/interval3/setLineColourRGBA 0 1 0 1
318/vis/modeling/trajectories/drawByAttribute-1/interval4/setLineColourRGBA 1 1 0 1
319/vis/modeling/trajectories/drawByAttribute-1/interval5/setLineColourRGBA 1 0.3 0 1
320/vis/modeling/trajectories/drawByAttribute-1/interval6/setLineColourRGBA 1 0 0 1
321</pre></div><p>
322</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sect.VisEnhTrj.CntlCmpl"></a>8.7.4. 
323Controlling from Compiled Code
324</h3></div></div></div><p>
325It is possible to use the enhanced trajectory drawing functionality
326in compiled code as well as from commands. Multiple trajectory
327models can be instantiated, configured and registered with
328G4VisManager. Only one model may be current. For example:
329
330</p><div class="informalexample"><pre class="programlisting">
331 G4VisManager* visManager = new G4VisExecutive;
332 visManager-&gt;Initialize();
333
334 G4TrajectoryDrawByParticleID* model = new G4TrajectoryDrawByParticleID;
335 G4TrajectoryDrawByParticleID* model2 = new G4TrajectoryDrawByParticleID("test");
336
337 model-&gt;SetDefault("cyan");
338 model-&gt;Set("gamma", "green");
339 model-&gt;Set("e+", "magenta");
340 model-&gt;Set("e-", G4Colour(0.3, 0.3, 0.3));
341
342 visManager-&gt;RegisterModel(model);
343 visManager-&gt;RegisterModel(model2);
344
345 visManager-&gt;SelectTrajectoryModel(model-&gt;Name());
346</pre></div><p>
347</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sect.VisEnhTrj.DrwByTime"></a>8.7.5. 
348Drawing by time
349</h3></div></div></div><p>
350To draw by time, you need to use a trajectory that records the
351track time at the beginning and end of each step. To do this, write
352a tracking action that sets G4RichTrajectory, for example:
353
354</p><div class="informalexample"><pre class="programlisting">
355#include "G4UserTrackingAction.hh"
356class G4Track;
357class MyTrackingAction : public G4UserTrackingAction
358{
359 public:
360 virtual void PreUserTrackingAction(const G4Track* aTrack);
361};
362#include "G4RichTrajectory.hh"
363#include "G4TrackingManager.hh"
364#include "G4IdentityTrajectoryFilter.hh"
365#include "G4TransportationManager.hh"
366#include "G4PropagatorInField.hh"
367void MyTrackingAction::PreUserTrackingAction(const G4Track* aTrack)
368{
369 // Require rich trajectory...
370 fpTrackingManager-&gt;SetTrajectory(new G4RichTrajectory(aTrack));
371
372 // Activate storing of auxiliary points for smoother trajectory...
373 static G4IdentityTrajectoryFilter curvedFilter;
374 G4TransportationManager::GetTransportationManager()-&gt;
375 GetPropagatorInField()-&gt;SetTrajectoryFilter(&amp;curvedFilter);
376}
377</pre></div><p>
378
379and register an instance of this with the run manager (this can be
380done once and for all as soon as the run manager is instantiated,
381probably in your main program):
382
383</p><div class="informalexample"><pre class="programlisting">
384#include "MyTrackingAction.hh"
385...
386 runManager -&gt; SetUserAction (new MyTrackingAction);
387</pre></div><p>
388</p><p>
389When you run, you need to create a trajectory model and set the
390time slice interval (remembering that paticles are often
391relativistic and travel 30 cm/ns):
392
393</p><div class="informalexample"><pre class="programlisting">
394/vis/modeling/trajectories/create/drawByCharge
395/vis/modeling/trajectories/drawByCharge-0/default/setDrawStepPts true
396/vis/modeling/trajectories/drawByCharge-0/default/setStepPtsSize 5
397/vis/modeling/trajectories/drawByCharge-0/default/setDrawAuxPts true
398/vis/modeling/trajectories/drawByCharge-0/default/setAuxPtsSize 5
399/vis/modeling/trajectories/drawByCharge-0/default/setTimeSliceInterval 0.1 ns
400/vis/modeling/trajectories/list
401</pre></div><p>
402
403and use a graphics driver that can display by time:
404
405</p><div class="informalexample"><pre class="programlisting">
406/vis/open OGLSX
407/vis/drawVolume
408/vis/scene/add/trajectories
409/vis/ogl/set/startTime 0.5 ns
410/vis/ogl/set/endTime 0.8 ns
411/run/beamOn
412/vis/viewer/refresh
413</pre></div><p>
414</p><p>
415A good way to see the particles moving through the detector is:
416
417</p><div class="informalexample"><pre class="programlisting">
418/vis/ogl/set/fade 1
419/vis/ogl/set/displayHeadTime true
420/control/alias timeRange 1
421/control/loop movie.loop -{timeRange} 40 0.1
422</pre></div><p>
423
424where <code class="literal">fade</code> gives a vapour-trail effect,
425<code class="literal">displayHeadTime</code> displays the time of the leading edge as
4262D text, and <code class="literal">movie.loop</code> is a macro file:
427
428</p><div class="informalexample"><pre class="programlisting">
429/vis/ogl/set/startTime {startTime} ns {timeRange} ns
430</pre></div><p>
431</p><p>
432From there, it's straightforward to <a href="ch08s10.html" title="8.10. 
433Making a Movie
434">Section 8.10</a>
435make a movie.
436</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch08s06.html"><img src="AllResources/IconsGIF/prev.gif" alt="Prev"></a> </td><td width="20%" align="center"><a accesskey="u" href="ch08.html"><img src="AllResources/IconsGIF/up.gif" alt="Up"></a></td><td width="40%" align="right"> <a accesskey="n" href="ch08s08.html"><img src="AllResources/IconsGIF/next.gif" alt="Next"></a></td></tr><tr><td width="40%" align="left" valign="top">8.6. 
437Visualization Attributes
438 </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"> 8.8. 
439Trajectory Filtering
440</td></tr></table></div></body></html>
Note: See TracBrowser for help on using the repository browser.