[1208] | 1 | <HTML> |
---|
| 2 | <TITLE>Enhanced Trajectory Drawing</title> |
---|
| 3 | <HEAD> |
---|
| 4 | </HEAD> |
---|
| 5 | <BODY> |
---|
| 6 | |
---|
| 7 | <TABLE WIDTH="100%" > |
---|
| 8 | <TR> |
---|
| 9 | <TD> |
---|
| 10 | </A> |
---|
| 11 | <A HREF="index.html"> |
---|
| 12 | <IMG SRC="../../../../resources/html/IconsGIF/Contents.gif" ALT="Contents" HEIGHT=16 WIDTH=59></A> |
---|
| 13 | <A HREF="attributes.html"> |
---|
| 14 | <IMG SRC="../../../../resources/html/IconsGIF/Previous.gif" ALT="Previous" HEIGHT=16 WIDTH=59></A> |
---|
| 15 | <a href="filtering.html"> |
---|
| 16 | <IMG SRC="../../../../resources/html/IconsGIF/Next.gif" ALT="Next" HEIGHT=16 WIDTH=59></a> |
---|
| 17 | </TD> |
---|
| 18 | |
---|
| 19 | <TD ALIGN="Right"><FONT COLOR="#238E23"><FONT SIZE=-1> |
---|
| 20 | <B>Geant4 User's Guide</B> <BR> |
---|
| 21 | <B>For Application Developers</B> <BR> |
---|
| 22 | <B>Visualization</B> </FONT></FONT> </TD> |
---|
| 23 | </TR> |
---|
| 24 | </TABLE> |
---|
| 25 | |
---|
| 26 | <CENTER><FONT COLOR="#238E23"><FONT SIZE=+3> |
---|
| 27 | <b>8.7 Enhanced Trajectory Drawing</b><BR> |
---|
| 28 | </FONT></FONT></CENTER> |
---|
| 29 | <BR> |
---|
| 30 | |
---|
| 31 | <HR ALIGN="Center" SIZE="7%"><BR> |
---|
| 32 | |
---|
| 33 | <!-- ============================================== Section --> |
---|
| 34 | <h4>8.7.1 Default Configuration</h4> |
---|
| 35 | Trajectory drawing styles are specified through trajectory drawing models. Each |
---|
| 36 | drawing model has a default configuration provided through a G4VisTrajContext object. |
---|
| 37 | The default context settings are shown below. |
---|
| 38 | |
---|
| 39 | <BR> |
---|
| 40 | <BR></br> |
---|
| 41 | <TABLE BORDER=1 cellpadding=2> |
---|
| 42 | <TR> |
---|
| 43 | <TD><B>Property</B></TD><TD><B>Default Setting</B></TD></TR> |
---|
| 44 | <TR> |
---|
| 45 | <TD>Line colour </TD><TD>grey</TD></TR> |
---|
| 46 | <TR> |
---|
| 47 | <TD>Line visibility</TD><TD> true</TD></TR> |
---|
| 48 | <TR> |
---|
| 49 | <TD>Draw line</TD><TD>true</TD></TR> |
---|
| 50 | <TR> |
---|
| 51 | <TD>Draw auxiliary points</TD><TD> false</TD></TR> |
---|
| 52 | <TR> |
---|
| 53 | <TD>Auxiliary point type</TD><TD>squares</TD></TR> |
---|
| 54 | <TR> |
---|
| 55 | <TD>Auxiliary point size</TD><TD>0</TD></TR> |
---|
| 56 | <TR> |
---|
| 57 | <TD>Auxiliary point fill style</TD><TD>filled</TD></TR> |
---|
| 58 | <TR> |
---|
| 59 | <TD>Auxiliary point colour</TD><TD>magenta</TD></TR> |
---|
| 60 | <TR> |
---|
| 61 | <TD>Auxiliary point visibility</TD><TD>true</TD></TR> |
---|
| 62 | <TR> |
---|
| 63 | <TD>Draw step point</TD><TD>false</TD></TR> |
---|
| 64 | <TR> |
---|
| 65 | <TD>Step point type</TD><TD> circles</TD></TR> |
---|
| 66 | <TR> |
---|
| 67 | <TD>Step point size</TD><TD> 0</TD></TR> |
---|
| 68 | <TR> |
---|
| 69 | <TD>Step point fill style</TD><TD> filled</TD></TR> |
---|
| 70 | <TR> |
---|
| 71 | <TD>Step point colour</TD><TD>yellow</TD></TR> |
---|
| 72 | <TR> |
---|
| 73 | <TD>Step point visibility</TD><TD>true</TD></TR> |
---|
| 74 | <TR> |
---|
| 75 | <TD>Time slice interval</TD><TD>0</TD></TR> |
---|
| 76 | <TR> |
---|
| 77 | </TABLE> |
---|
| 78 | <BR> |
---|
| 79 | <BR> |
---|
| 80 | Points to note: |
---|
| 81 | <UL> |
---|
| 82 | <LI>The context approach is intended to replace the configuration through the imode parameter. |
---|
| 83 | The use of imode is depreciated and will be removed in Geant4 v9.0. |
---|
| 84 | <LI>Different visualisation drivers handle trajectory configuration in different ways, so trajectories |
---|
| 85 | may not necessarily get displayed as you have configured them. |
---|
| 86 | </UL> |
---|
| 87 | |
---|
| 88 | <h4>8.7.2 Trajectory Drawing Models</h4> |
---|
| 89 | A trajectory drawing model can override the default context according to the properties of a |
---|
| 90 | given trajectory. The following models are supplied with the Geant4 distribution: |
---|
| 91 | <BR> |
---|
| 92 | <UL> |
---|
| 93 | <LI>G4TrajectoryGenericDrawer (generic) |
---|
| 94 | <LI>G4TrajectoryDrawByCharge (drawByCharge) |
---|
| 95 | <LI>G4TrajectoryDrawByParticleID (drawByParticleID) |
---|
| 96 | <LI>G4TrajectoryDrawByOriginVolume (drawByOriginVolume) |
---|
| 97 | <LI>G4TrajectoryDrawByAttribute (drawByAttribute) |
---|
| 98 | </UL> |
---|
| 99 | |
---|
| 100 | Both the context and model properties can be configured by the user. The models are described |
---|
| 101 | briefly below, followed by some example configuration commands. |
---|
| 102 | |
---|
| 103 | <h4>G4TrajectoryGenericDrawer</h4> |
---|
| 104 | |
---|
| 105 | This model simply draws all trajectories in the same style, with the properties |
---|
| 106 | provided by the context. |
---|
| 107 | |
---|
| 108 | <h4>G4TrajectoryDrawByCharge</h4> |
---|
| 109 | |
---|
| 110 | This is the default model - if no model is specified by the user, this model will be |
---|
| 111 | constructed automatically. The trajectory lines are coloured according to charge, with |
---|
| 112 | all other configuration parameters provided by the default context. The default colouring |
---|
| 113 | scheme is shown below. |
---|
| 114 | |
---|
| 115 | <PRE> |
---|
| 116 | Charge Colour |
---|
| 117 | ---------------------- |
---|
| 118 | 1 Blue |
---|
| 119 | -1 Red |
---|
| 120 | 0 Green |
---|
| 121 | </PRE> |
---|
| 122 | |
---|
| 123 | <h4>G4TrajectoryDrawByParticleID</h4> |
---|
| 124 | |
---|
| 125 | This model colours trajectory lines according to particle type. All other configuration |
---|
| 126 | parameters are provided by the default context. By default, all trajectories are coloured grey. Chosen |
---|
| 127 | particle types can be highlighted with specified colours. |
---|
| 128 | |
---|
| 129 | <h4>G4TrajectoryDrawByOriginVolume</h4> |
---|
| 130 | |
---|
| 131 | This model colours trajectory lines according to the trajectories originating volume name. The |
---|
| 132 | volume can be either a logical or physical volume. Physical volume takes precedence |
---|
| 133 | over logical volume. All trajectories are coloured grey by default. |
---|
| 134 | |
---|
| 135 | <h4>G4TrajectoryDrawByAttribute</h4> |
---|
| 136 | This model draws trajectories based on the HepRep style attributes associated with trajectories. Each attribute drawer can be configured with interval and/or single value data. A new context object is created for each interval/single value. This makes it possible to have different step point markers etc, as well as line colour for trajectory attributes falling into different intervals, or matching single values. The single value data should override the interval data, allowing specific values to be highlighted. Units should be specified on the command line if the attribute unit is specified either as a G4BestUnit or if the unit is part of the value string. |
---|
| 137 | |
---|
| 138 | <h4>8.7.3 <A NAME="commandcontrol">Controlling from Commands</A></h4> |
---|
| 139 | Multiple trajectory models can be created and configured using commands in the |
---|
| 140 | "<TT>/vis/modeling/trajectories/</TT>" directory. It is then possible to list available |
---|
| 141 | models and select one to be current. |
---|
| 142 | |
---|
| 143 | <P> |
---|
| 144 | Model configuration commands are generated dynamically when a model is instantiated. |
---|
| 145 | These commands apply directly to that instance. This makes it possible to have multiple |
---|
| 146 | instances of the drawByCharge model for example, each independently configurable through |
---|
| 147 | it's own set of commands. |
---|
| 148 | <BR></br> |
---|
| 149 | See the interactive help for more information on the available commands. |
---|
| 150 | <BR> |
---|
| 151 | <h4>8.7.3.1 Example commands</h4> |
---|
| 152 | #Create a generic model named generic-0 by default<BR> |
---|
| 153 | <TT>/vis/modeling/trajectories/create/generic</TT> <BR><BR> |
---|
| 154 | |
---|
| 155 | #Configure context to colour all trajectories red<BR> |
---|
| 156 | <TT>/vis/modeling/trajectories/generic-0/default/setLineColour red</tt> <BR></br> |
---|
| 157 | |
---|
| 158 | #Create a drawByCharge model named drawCharge-0 by default |
---|
| 159 | (Subsequent models will be named drawByCharge-1, drawByCharge-2, etc.)<BR> |
---|
| 160 | <TT>/vis/modeling/trajectories/create/drawByCharge</TT> <BR><BR> |
---|
| 161 | |
---|
| 162 | #Create a drawByCharge model named testChargeModel<BR> |
---|
| 163 | <TT>/vis/modeling/trajectories/create/drawByCharge testChargeModel</TT><BR><BR> |
---|
| 164 | |
---|
| 165 | #Configure drawByCharge-0 model <BR> |
---|
| 166 | <TT>/vis/modeling/trajectories/drawByCharge-0/set 1 red</TT><BR> |
---|
| 167 | <TT>/vis/modeling/trajectories/drawByCharge-0/set -1 red</TT><BR> |
---|
| 168 | <TT>/vis/modeling/trajectories/drawByCharge-0/set 0 white</TT><BR><BR> |
---|
| 169 | |
---|
| 170 | #Configure testCharge model through G4Colour components<BR> |
---|
| 171 | <TT>/vis/modeling/trajectories/testChargeModel/setRGBA 1 0 1 1 1</TT><BR> |
---|
| 172 | <TT>/vis/modeling/trajectories/testChargeModel/setRGBA -1 0.5 0.5 0.5 1</TT><BR> |
---|
| 173 | <TT>/vis/modeling/trajectories/testChargeModel/setRGBA 0 1 1 0 1</TT><BR><BR> |
---|
| 174 | |
---|
| 175 | #Create a drawByParticleID model named drawByParticleID-0<BR> |
---|
| 176 | <TT>/vis/modeling/trajectories/create/drawByParticleID</TT> <BR><BR> |
---|
| 177 | |
---|
| 178 | #Configure drawByParticleID-0 model<BR> |
---|
| 179 | <TT>/vis/modeling/trajectories/drawByParticleID-0/set gamma red</TT><BR> |
---|
| 180 | <TT>/vis/modeling/trajectories/drawByParticleID-0/setRGBA e+ 1 0 1 1</TT><BR><BR> |
---|
| 181 | |
---|
| 182 | #List available models<BR> |
---|
| 183 | <TT>/vis/modeling/trajectories/list</TT><BR><BR> |
---|
| 184 | |
---|
| 185 | #select drawByParticleID-0 to be current<BR> |
---|
| 186 | <TT>/vis/modeling/trajectories/select drawByParticleID-0</TT><BR><BR> |
---|
| 187 | |
---|
| 188 | #Create a drawByAttribute model named drawByAttribute-0<BR> |
---|
| 189 | <TT>/vis/modeling/trajectories/create/drawByAttribute</TT><BR><BR> |
---|
| 190 | |
---|
| 191 | #Configure drawByAttribute-0 model<BR> |
---|
| 192 | <TT>/vis/modeling/trajectories/drawByAttribute-0/verbose true </TT><BR><BR> |
---|
| 193 | |
---|
| 194 | #Select attribute "CPN"<BR> |
---|
| 195 | <TT>/vis/modeling/trajectories/drawByAttribute-0/setAttribute CPN </TT><BR><BR> |
---|
| 196 | |
---|
| 197 | #Configure single value data<BR> |
---|
| 198 | <TT>/vis/modeling/trajectories/drawByAttribute-0/addValue brem_key eBrem </TT><BR> |
---|
| 199 | <TT>/vis/modeling/trajectories/drawByAttribute-0/addValue annihil_key annihil </TT><BR> |
---|
| 200 | <TT>/vis/modeling/trajectories/drawByAttribute-0/addValue decay_key Decay </TT><BR> |
---|
| 201 | <TT>/vis/modeling/trajectories/drawByAttribute-0/addValue muIon_key muIoni </TT><BR> |
---|
| 202 | <TT>/vis/modeling/trajectories/drawByAttribute-0/addValue eIon_key eIoni </TT><BR><BR> |
---|
| 203 | |
---|
| 204 | <TT>/vis/modeling/trajectories/drawByAttribute-0/brem_key/setLineColour red </TT><BR> |
---|
| 205 | <TT>/vis/modeling/trajectories/drawByAttribute-0/annihil_key/setLineColour green </TT><BR> |
---|
| 206 | <TT>/vis/modeling/trajectories/drawByAttribute-0/decay_key/setLineColour cyan </TT><BR> |
---|
| 207 | <TT>/vis/modeling/trajectories/drawByAttribute-0/eIon_key/setLineColour yellow </TT><BR> |
---|
| 208 | <TT>/vis/modeling/trajectories/drawByAttribute-0/muIon_key/setLineColour magenta </TT><BR><BR> |
---|
| 209 | |
---|
| 210 | #Create a drawByAttribute model named drawByAttribute-1<BR> |
---|
| 211 | <TT>/vis/modeling/trajectories/create/drawByAttribute</TT><BR><BR> |
---|
| 212 | |
---|
| 213 | #Select "IMag" attribute<BR> |
---|
| 214 | <TT>/vis/modeling/trajectories/drawByAttribute-1/setAttribute IMag </TT><BR><BR> |
---|
| 215 | |
---|
| 216 | #Configure interval data<BR> |
---|
| 217 | <TT>/vis/modeling/trajectories/drawByAttribute-1/addInterval interval1 0.0 keV 2.5MeV </TT><BR> |
---|
| 218 | <TT>/vis/modeling/trajectories/drawByAttribute-1/addInterval interval2 2.5 MeV 5 MeV </TT><BR> |
---|
| 219 | <TT>/vis/modeling/trajectories/drawByAttribute-1/addInterval interval3 5 MeV 7.5 MeV </TT><BR> |
---|
| 220 | <TT>/vis/modeling/trajectories/drawByAttribute-1/addInterval interval4 7.5 MeV 10 MeV </TT><BR> |
---|
| 221 | <TT>/vis/modeling/trajectories/drawByAttribute-1/addInterval interval5 10 MeV 12.5 MeV </TT><BR> |
---|
| 222 | <TT>/vis/modeling/trajectories/drawByAttribute-1/addInterval interval6 12.5 MeV 10000 MeV </TT><BR><BR> |
---|
| 223 | |
---|
| 224 | <TT>/vis/modeling/trajectories/drawByAttribute-1/interval1/setLineColourRGBA 0.8 0 0.8 1 </TT><BR> |
---|
| 225 | <TT>/vis/modeling/trajectories/drawByAttribute-1/interval2/setLineColourRGBA 0.23 0.41 1 1 </TT><BR> |
---|
| 226 | <TT>/vis/modeling/trajectories/drawByAttribute-1/interval3/setLineColourRGBA 0 1 0 1 </TT><BR> |
---|
| 227 | <TT>/vis/modeling/trajectories/drawByAttribute-1/interval4/setLineColourRGBA 1 1 0 1 </TT><BR> |
---|
| 228 | <TT>/vis/modeling/trajectories/drawByAttribute-1/interval5/setLineColourRGBA 1 0.3 0 1 </TT><BR> |
---|
| 229 | <TT>/vis/modeling/trajectories/drawByAttribute-1/interval6/setLineColourRGBA 1 0 0 1</TT><BR><BR> |
---|
| 230 | |
---|
| 231 | <h4>8.7.4 <A NAME="compiledcontrol">Controlling from Compiled Code</a></h4> |
---|
| 232 | It is possible to use the enhanced trajectory drawing functionality in compiled code |
---|
| 233 | as well as from commands. |
---|
| 234 | Multiple trajectory models can be instantiated, configured and registered with G4VisManager. |
---|
| 235 | Only one model may be current. For example: |
---|
| 236 | |
---|
| 237 | <PRE> |
---|
| 238 | G4VisManager* visManager = new G4VisExecutive; |
---|
| 239 | visManager->Initialize(); |
---|
| 240 | |
---|
| 241 | G4TrajectoryDrawByParticleID* model = new G4TrajectoryDrawByParticleID; |
---|
| 242 | G4TrajectoryDrawByParticleID* model2 = new G4TrajectoryDrawByParticleID("test"); |
---|
| 243 | |
---|
| 244 | model->SetDefault("cyan"); |
---|
| 245 | model->Set("gamma", "green"); |
---|
| 246 | model->Set("e+", "magenta"); |
---|
| 247 | model->Set("e-", G4Colour(0.3, 0.3, 0.3)); |
---|
| 248 | |
---|
| 249 | visManager->RegisterModel(model); |
---|
| 250 | visManager->RegisterModel(model2); |
---|
| 251 | |
---|
| 252 | visManager->SelectTrajectoryModel(model->Name()); |
---|
| 253 | </PRE> |
---|
| 254 | |
---|
| 255 | <h4>8.7.5 <A NAME="drawingByTime">Drawing by time</a></h4> |
---|
| 256 | |
---|
| 257 | To draw by time, you need to use a trajectory that records the track |
---|
| 258 | time at the beginning and end of each step. To do this, write a |
---|
| 259 | tracking action that sets G4RichTrajectory, for example: |
---|
| 260 | |
---|
| 261 | <PRE> |
---|
| 262 | #include "G4UserTrackingAction.hh" |
---|
| 263 | class G4Track; |
---|
| 264 | class MyTrackingAction : public G4UserTrackingAction |
---|
| 265 | { |
---|
| 266 | public: |
---|
| 267 | virtual void PreUserTrackingAction(const G4Track* aTrack); |
---|
| 268 | }; |
---|
| 269 | #include "G4RichTrajectory.hh" |
---|
| 270 | #include "G4TrackingManager.hh" |
---|
| 271 | #include "G4IdentityTrajectoryFilter.hh" |
---|
| 272 | #include "G4TransportationManager.hh" |
---|
| 273 | #include "G4PropagatorInField.hh" |
---|
| 274 | void MyTrackingAction::PreUserTrackingAction(const G4Track* aTrack) |
---|
| 275 | { |
---|
| 276 | // Require rich trajectory... |
---|
| 277 | fpTrackingManager->SetTrajectory(new G4RichTrajectory(aTrack)); |
---|
| 278 | |
---|
| 279 | // Activate storing of auxiliary points for smoother trajectory... |
---|
| 280 | static G4IdentityTrajectoryFilter curvedFilter; |
---|
| 281 | G4TransportationManager::GetTransportationManager()-> |
---|
| 282 | GetPropagatorInField()->SetTrajectoryFilter(&curvedFilter); |
---|
| 283 | } |
---|
| 284 | </PRE> |
---|
| 285 | |
---|
| 286 | and register an instance of this with the run manager (this can be |
---|
| 287 | done once and for all as soon as the run manager is instantiated, |
---|
| 288 | probably in your main program): |
---|
| 289 | |
---|
| 290 | <PRE> |
---|
| 291 | #include "MyTrackingAction.hh" |
---|
| 292 | ... |
---|
| 293 | runManager -> SetUserAction (new MyTrackingAction); |
---|
| 294 | </PRE> |
---|
| 295 | |
---|
| 296 | When you run, you need to create a trajectory model and set the time |
---|
| 297 | slice interval (remembering that paticles are often relativistic and |
---|
| 298 | travel 30 cm/ns): |
---|
| 299 | |
---|
| 300 | <PRE> |
---|
| 301 | /vis/modeling/trajectories/create/drawByCharge |
---|
| 302 | /vis/modeling/trajectories/drawByCharge-0/default/setDrawStepPts true |
---|
| 303 | /vis/modeling/trajectories/drawByCharge-0/default/setStepPtsSize 5 |
---|
| 304 | /vis/modeling/trajectories/drawByCharge-0/default/setDrawAuxPts true |
---|
| 305 | /vis/modeling/trajectories/drawByCharge-0/default/setAuxPtsSize 5 |
---|
| 306 | /vis/modeling/trajectories/drawByCharge-0/default/setTimeSliceInterval 0.1 ns |
---|
| 307 | /vis/modeling/trajectories/list |
---|
| 308 | </PRE> |
---|
| 309 | |
---|
| 310 | and use a graphics driver that can display by time: |
---|
| 311 | |
---|
| 312 | <PRE> |
---|
| 313 | /vis/open OGLSX |
---|
| 314 | /vis/drawVolume |
---|
| 315 | /vis/scene/add/trajectories |
---|
| 316 | /vis/ogl/set/startTime 0.5 ns |
---|
| 317 | /vis/ogl/set/endTime 0.8 ns |
---|
| 318 | /run/beamOn |
---|
| 319 | /vis/viewer/refresh |
---|
| 320 | </PRE> |
---|
| 321 | |
---|
| 322 | A good way to see the particles moving through the detector is: |
---|
| 323 | |
---|
| 324 | <PRE> |
---|
| 325 | /vis/ogl/set/fade 1 |
---|
| 326 | /vis/ogl/set/displayHeadTime true |
---|
| 327 | /control/alias timeRange 1 |
---|
| 328 | /control/loop movie.loop -{timeRange} 40 0.1 |
---|
| 329 | </PRE> |
---|
| 330 | |
---|
| 331 | where <tt>fade</tt> gives a vapour-trail effect, |
---|
| 332 | <tt>displayHeadTime</tt> displays the time of the leading edge as 2D |
---|
| 333 | text, and <tt>movie.loop</tt> is a macro file: |
---|
| 334 | |
---|
| 335 | <PRE> |
---|
| 336 | /vis/ogl/set/startTime {startTime} ns {timeRange} ns |
---|
| 337 | </PRE> |
---|
| 338 | |
---|
| 339 | From there, it's straightforward to <A HREF="makingamovie.html">make |
---|
| 340 | a movie.</A> |
---|
| 341 | |
---|
| 342 | <P> |
---|
| 343 | <HR> |
---|
| 344 | <A HREF="markertext.html">Next section</A><BR> |
---|
| 345 | <A HREF="index.html">Back to contents</A> |
---|
| 346 | |
---|
| 347 | </BODY> |
---|
| 348 | </HTML> |
---|