| 1 | <!-- ******************************************************** -->
|
|---|
| 2 | <!-- -->
|
|---|
| 3 | <!-- [History] -->
|
|---|
| 4 | <!-- Proof read by: Joe Chuma, 6-Jul-1999 -->
|
|---|
| 5 | <!-- Changed by: Katsuya Amako, 15-Jul-2000 -->
|
|---|
| 6 | <!-- Changed by: Dennis Wright, 27-Nov-2001 -->
|
|---|
| 7 | <!-- Converted to DocBook: Katsuya Amako, Aug-2006 -->
|
|---|
| 8 | <!-- -->
|
|---|
| 9 | <!-- ******************************************************** -->
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 | <!-- ******************* Section (Level#1) ****************** -->
|
|---|
| 13 | <sect1 id="sect.VisCntCmpl">
|
|---|
| 14 | <title>
|
|---|
| 15 | Controlling Visualization from Compiled Code
|
|---|
| 16 | </title>
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 | <para>
|
|---|
| 20 | While a Geant4 simulation is running, visualization can be
|
|---|
| 21 | performed without user intervention. This is accomplished by
|
|---|
| 22 | calling methods of the Visualization Manager from methods of the
|
|---|
| 23 | user action classes (<emphasis>G4UserRunAction</emphasis> and
|
|---|
| 24 | <emphasis>G4UserEventAction</emphasis>, for example). In this section methods of
|
|---|
| 25 | the class <emphasis>G4VVisManager</emphasis>, which is part of the
|
|---|
| 26 | <literal>graphics_reps</literal> category, are described and examples of
|
|---|
| 27 | their use are given.
|
|---|
| 28 | </para>
|
|---|
| 29 |
|
|---|
| 30 | <!-- ******************* Section (Level#2) ****************** -->
|
|---|
| 31 | <sect2 id="sect.VisCntCmpl.VsMng">
|
|---|
| 32 | <title>
|
|---|
| 33 | G4VVisManager
|
|---|
| 34 | </title>
|
|---|
| 35 |
|
|---|
| 36 | <para>
|
|---|
| 37 | The Visualization Manager is implemented by classes
|
|---|
| 38 | <emphasis>G4VisManager</emphasis> and <emphasis>G4VisExecutive</emphasis>.
|
|---|
| 39 | See <xref linkend="sect.VisAddExe" />
|
|---|
| 40 | "<emphasis role="bold">Making a Visualization Executable</emphasis>". In order
|
|---|
| 41 | that your Geant4 be compilable either with or without the visualization
|
|---|
| 42 | category, you should not use these classes directly in your C++
|
|---|
| 43 | source code, other than in the <literal>main()</literal> function. Instead,
|
|---|
| 44 | you should use their abstract base class <emphasis>G4VVisManager</emphasis>,
|
|---|
| 45 | defined in the <literal>intercoms</literal> category.
|
|---|
| 46 | </para>
|
|---|
| 47 |
|
|---|
| 48 | <para>
|
|---|
| 49 | The pointer to the concrete instance of the real Visualization
|
|---|
| 50 | Manager can be obtained as follows:
|
|---|
| 51 |
|
|---|
| 52 | <informalexample>
|
|---|
| 53 | <programlisting>
|
|---|
| 54 | //----- Getting a pointer to the concrete Visualization Manager instance
|
|---|
| 55 | G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
|
|---|
| 56 | </programlisting>
|
|---|
| 57 | </informalexample>
|
|---|
| 58 | </para>
|
|---|
| 59 |
|
|---|
| 60 | <para>
|
|---|
| 61 | The method <literal>G4VVisManager::GetConcreteInstance()</literal> returns
|
|---|
| 62 | <literal>NULL</literal> if Geant4 is not ready for visualization. Thus your
|
|---|
| 63 | C++ source code should be protected as follows:
|
|---|
| 64 |
|
|---|
| 65 | <informalexample>
|
|---|
| 66 | <programlisting>
|
|---|
| 67 | //----- How to protect your C++ source codes in visualization
|
|---|
| 68 | if (pVVisManager) {
|
|---|
| 69 | ....
|
|---|
| 70 | pVVisManager ->Draw (...);
|
|---|
| 71 | ....
|
|---|
| 72 | }
|
|---|
| 73 | </programlisting>
|
|---|
| 74 | </informalexample>
|
|---|
| 75 | </para>
|
|---|
| 76 |
|
|---|
| 77 | </sect2>
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 | <!-- ******************* Section (Level#2) ****************** -->
|
|---|
| 81 | <sect2 id="sect.VisCntCmpl.DtcCmp">
|
|---|
| 82 | <title>
|
|---|
| 83 | Visualization of detector components
|
|---|
| 84 | </title>
|
|---|
| 85 |
|
|---|
| 86 | <para>
|
|---|
| 87 | If you have already constructed detector components with logical
|
|---|
| 88 | volumes to which visualization attributes are properly assigned,
|
|---|
| 89 | you are almost ready for visualizing detector components. All you
|
|---|
| 90 | have to do is to describe proper visualization commands within your
|
|---|
| 91 | C++ codes, using the <literal>ApplyCommand()</literal> method.
|
|---|
| 92 | </para>
|
|---|
| 93 |
|
|---|
| 94 | <para>
|
|---|
| 95 | For example, the following is sample C++ source codes to
|
|---|
| 96 | visualize the detector components:
|
|---|
| 97 |
|
|---|
| 98 | <informalexample>
|
|---|
| 99 | <programlisting>
|
|---|
| 100 | //----- C++ source code: How to visualize detector components (2)
|
|---|
| 101 | // ... using visualization commands in source codes
|
|---|
| 102 |
|
|---|
| 103 | G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance() ;
|
|---|
| 104 |
|
|---|
| 105 | if(pVVisManager)
|
|---|
| 106 | {
|
|---|
| 107 | ... (camera setting etc) ...
|
|---|
| 108 | G4UImanager::GetUIpointer()->ApplyCommand("/vis/drawVolume");
|
|---|
| 109 | G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/flush");
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | //----- end of C++ source code
|
|---|
| 113 |
|
|---|
| 114 | </programlisting>
|
|---|
| 115 | </informalexample>
|
|---|
| 116 | </para>
|
|---|
| 117 |
|
|---|
| 118 | <para>
|
|---|
| 119 | In the above, you should also describe <literal>/vis/open</literal> command
|
|---|
| 120 | somewhere in your C++ codes or execute the command from (G)UI at
|
|---|
| 121 | the executing stage.
|
|---|
| 122 | </para>
|
|---|
| 123 |
|
|---|
| 124 | </sect2>
|
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 | <!-- ******************* Section (Level#2) ****************** -->
|
|---|
| 128 | <sect2 id="sect.VisCntCmpl.Trjct">
|
|---|
| 129 | <title>
|
|---|
| 130 | Visualization of trajectories
|
|---|
| 131 | </title>
|
|---|
| 132 |
|
|---|
| 133 | <para>
|
|---|
| 134 | In order to visualize trajectories, you can use the method <literal>void
|
|---|
| 135 | G4Trajectory::DrawTrajectory()</literal> defined in the tracking
|
|---|
| 136 | category. In the implementation of this method, the following
|
|---|
| 137 | drawing method of <emphasis>G4VVisManager</emphasis> is used:
|
|---|
| 138 |
|
|---|
| 139 | <informalexample>
|
|---|
| 140 | <programlisting>
|
|---|
| 141 | //----- A drawing method of G4Polyline
|
|---|
| 142 | virtual void G4VVisManager::Draw (const G4Polyline&, ...) ;
|
|---|
| 143 | </programlisting>
|
|---|
| 144 | </informalexample>
|
|---|
| 145 | </para>
|
|---|
| 146 |
|
|---|
| 147 | <para>
|
|---|
| 148 | The real implementation of this method is described in the class
|
|---|
| 149 | <emphasis>G4VisManager</emphasis>.
|
|---|
| 150 | </para>
|
|---|
| 151 |
|
|---|
| 152 | <para>
|
|---|
| 153 | At the end of one event, a set of trajectories can be stored as
|
|---|
| 154 | a list of <emphasis>G4Trajectory</emphasis> objects. Therefore you can visualize
|
|---|
| 155 | trajectories, for example, at the end of each event, by
|
|---|
| 156 | implementing the method <literal>MyEventAction::EndOfEventAction()</literal>
|
|---|
| 157 | as follows:
|
|---|
| 158 |
|
|---|
| 159 | <informalexample>
|
|---|
| 160 | <programlisting>
|
|---|
| 161 | //----- C++ source codes
|
|---|
| 162 | void ExN03EventAction::EndOfEventAction(const G4Event* evt)
|
|---|
| 163 | {
|
|---|
| 164 | .....
|
|---|
| 165 | // extract the trajectories and draw them
|
|---|
| 166 | if (G4VVisManager::GetConcreteInstance())
|
|---|
| 167 | {
|
|---|
| 168 | G4TrajectoryContainer* trajectoryContainer = evt->GetTrajectoryContainer();
|
|---|
| 169 | G4int n_trajectories = 0;
|
|---|
| 170 | if (trajectoryContainer) n_trajectories = trajectoryContainer->entries();
|
|---|
| 171 |
|
|---|
| 172 | for (G4int i=0; i < n_trajectories; i++)
|
|---|
| 173 | { G4Trajectory* trj=(G4Trajectory*)((*(evt->GetTrajectoryContainer()))[i]);
|
|---|
| 174 | if (drawFlag == "all") trj->DrawTrajectory(50);
|
|---|
| 175 | else if ((drawFlag == "charged")&&(trj->GetCharge() != 0.))
|
|---|
| 176 | trj->DrawTrajectory(50);
|
|---|
| 177 | else if ((drawFlag == "neutral")&&(trj->GetCharge() == 0.))
|
|---|
| 178 | trj->DrawTrajectory(50);
|
|---|
| 179 | }
|
|---|
| 180 | }
|
|---|
| 181 | }
|
|---|
| 182 | //----- end of C++ source codes
|
|---|
| 183 | </programlisting>
|
|---|
| 184 | </informalexample>
|
|---|
| 185 | </para>
|
|---|
| 186 |
|
|---|
| 187 | </sect2>
|
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 | <!-- ******************* Section (Level#2) ****************** -->
|
|---|
| 191 | <sect2 id="sect.VisCntCmpl.EnhTrjct">
|
|---|
| 192 | <title>
|
|---|
| 193 | Enhanced trajectory drawing
|
|---|
| 194 | </title>
|
|---|
| 195 |
|
|---|
| 196 | <para>
|
|---|
| 197 | It is possible to use the enhanced trajectory drawing functionality
|
|---|
| 198 | in compiled code as well as from commands. Multiple trajectory
|
|---|
| 199 | models can be instantiated, configured and registered with
|
|---|
| 200 | G4VisManager. For details, see the section on
|
|---|
| 201 | <xref linkend="sect.VisEnhTrj.CntlCmpl" />
|
|---|
| 202 | Enhanced Trajectory Drawing.
|
|---|
| 203 | </para>
|
|---|
| 204 |
|
|---|
| 205 | </sect2>
|
|---|
| 206 |
|
|---|
| 207 |
|
|---|
| 208 | <!-- ******************* Section (Level#2) ****************** -->
|
|---|
| 209 | <sect2 id="sect.VisCntCmpl.AttTrjct">
|
|---|
| 210 | <title>
|
|---|
| 211 | HepRep Attributes for Trajectories
|
|---|
| 212 | </title>
|
|---|
| 213 |
|
|---|
| 214 | <para>
|
|---|
| 215 | The HepRep file formats, HepRepFile and HepRepXML, attach various
|
|---|
| 216 | attributes to trajectories such that you can view these attributes,
|
|---|
| 217 | label trajectories by these attributes or make visibility cuts
|
|---|
| 218 | based on these attributes. If you use the default Geant4 trajectory
|
|---|
| 219 | class, from /tracking/src/G4Trajectory.cc, available attributes
|
|---|
| 220 | will be:
|
|---|
| 221 |
|
|---|
| 222 | <itemizedlist spacing="compact">
|
|---|
| 223 | <listitem><para>
|
|---|
| 224 | Track ID
|
|---|
| 225 | </para></listitem>
|
|---|
| 226 | <listitem><para>
|
|---|
| 227 | Parent ID
|
|---|
| 228 | </para></listitem>
|
|---|
| 229 | <listitem><para>
|
|---|
| 230 | Particle Name
|
|---|
| 231 | </para></listitem>
|
|---|
| 232 | <listitem><para>
|
|---|
| 233 | Charge
|
|---|
| 234 | </para></listitem>
|
|---|
| 235 | <listitem><para>
|
|---|
| 236 | PDG Encoding
|
|---|
| 237 | </para></listitem>
|
|---|
| 238 | <listitem><para>
|
|---|
| 239 | Momentum 3-Vector
|
|---|
| 240 | </para></listitem>
|
|---|
| 241 | <listitem><para>
|
|---|
| 242 | Momentum magnitude
|
|---|
| 243 | </para></listitem>
|
|---|
| 244 | <listitem><para>
|
|---|
| 245 | Number of points
|
|---|
| 246 | </para></listitem>
|
|---|
| 247 | </itemizedlist>
|
|---|
| 248 | </para>
|
|---|
| 249 |
|
|---|
| 250 | <para>
|
|---|
| 251 | You can add additional attributes of your choosing by modifying the
|
|---|
| 252 | relevant part of G4Trajectory (look for the methods GetAttDefs and
|
|---|
| 253 | CreateAttValues). If you are using your own trajectory class, you
|
|---|
| 254 | may want to consider copying these methods from G4Trajectory.
|
|---|
| 255 | </para>
|
|---|
| 256 |
|
|---|
| 257 | </sect2>
|
|---|
| 258 |
|
|---|
| 259 |
|
|---|
| 260 | <!-- ******************* Section (Level#2) ****************** -->
|
|---|
| 261 | <sect2 id="sect.VisCntCmpl.Hits">
|
|---|
| 262 | <title>
|
|---|
| 263 | Visualization of hits
|
|---|
| 264 | </title>
|
|---|
| 265 |
|
|---|
| 266 | <para>
|
|---|
| 267 | Hits are visualized with classes <emphasis>G4Square</emphasis> or
|
|---|
| 268 | <emphasis>G4Circle</emphasis>, or other user-defined classes inheriting the
|
|---|
| 269 | abstract base class <emphasis>G4VMarker</emphasis>. Drawing methods for hits are
|
|---|
| 270 | not supported by default. Instead, ways of their implementation are
|
|---|
| 271 | guided by virtual methods, <literal>G4VHit::Draw()</literal> and
|
|---|
| 272 | <literal>G4VHitsCollection::DrawAllHits()</literal>, of the abstract base
|
|---|
| 273 | classes <emphasis>G4VHit</emphasis> and <emphasis>G4VHitsCollection</emphasis>.
|
|---|
| 274 | These methods are defined as empty functions in the <literal>digits+hits</literal>
|
|---|
| 275 | category. You can overload these methods, using the following
|
|---|
| 276 | drawing methods of class <emphasis>G4VVisManager</emphasis>, in order to
|
|---|
| 277 | visualize hits:
|
|---|
| 278 |
|
|---|
| 279 | <informalexample>
|
|---|
| 280 | <programlisting>
|
|---|
| 281 | //----- Drawing methods of G4Square and G4Circle
|
|---|
| 282 | virtual void G4VVisManager::Draw (const G4Circle&, ...) ;
|
|---|
| 283 | virtual void G4VVisManager::Draw (const G4Square&, ...) ;
|
|---|
| 284 | </programlisting>
|
|---|
| 285 | </informalexample>
|
|---|
| 286 | </para>
|
|---|
| 287 |
|
|---|
| 288 | <para>
|
|---|
| 289 | The real implementations of these <literal>Draw()</literal> methods are
|
|---|
| 290 | described in class <emphasis>G4VisManager</emphasis>.
|
|---|
| 291 | </para>
|
|---|
| 292 |
|
|---|
| 293 | <para>
|
|---|
| 294 | The overloaded implementation of <literal>G4VHits::Draw()</literal> will
|
|---|
| 295 | be held by, for example, class <emphasis>MyTrackerHits</emphasis> inheriting
|
|---|
| 296 | <emphasis>G4VHit</emphasis> as follows:
|
|---|
| 297 |
|
|---|
| 298 | <informalexample>
|
|---|
| 299 | <programlisting>
|
|---|
| 300 | //----- C++ source codes: An example of giving concrete implementation of
|
|---|
| 301 | // G4VHit::Draw(), using class MyTrackerHit : public G4VHit {...}
|
|---|
| 302 | //
|
|---|
| 303 | void MyTrackerHit::Draw()
|
|---|
| 304 | {
|
|---|
| 305 | G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
|
|---|
| 306 | if(pVVisManager)
|
|---|
| 307 | {
|
|---|
| 308 | // define a circle in a 3D space
|
|---|
| 309 | G4Circle circle(pos);
|
|---|
| 310 | circle.SetScreenSize(0.3);
|
|---|
| 311 | circle.SetFillStyle(G4Circle::filled);
|
|---|
| 312 |
|
|---|
| 313 | // make the circle red
|
|---|
| 314 | G4Colour colour(1.,0.,0.);
|
|---|
| 315 | G4VisAttributes attribs(colour);
|
|---|
| 316 | circle.SetVisAttributes(attribs);
|
|---|
| 317 |
|
|---|
| 318 | // make a 3D data for visualization
|
|---|
| 319 | pVVisManager->Draw(circle);
|
|---|
| 320 | }
|
|---|
| 321 | }
|
|---|
| 322 |
|
|---|
| 323 | //----- end of C++ source codes
|
|---|
| 324 |
|
|---|
| 325 | </programlisting>
|
|---|
| 326 | </informalexample>
|
|---|
| 327 | </para>
|
|---|
| 328 |
|
|---|
| 329 | <para>
|
|---|
| 330 | The overloaded implementation of
|
|---|
| 331 | <literal>G4VHitsCollection::DrawAllHits()</literal> will be held by, for
|
|---|
| 332 | example, class <emphasis>MyTrackerHitsCollection</emphasis> inheriting class
|
|---|
| 333 | <emphasis>G4VHitsCollection</emphasis> as follows:
|
|---|
| 334 |
|
|---|
| 335 | <informalexample>
|
|---|
| 336 | <programlisting>
|
|---|
| 337 | //----- C++ source codes: An example of giving concrete implementation of
|
|---|
| 338 | // G4VHitsCollection::Draw(),
|
|---|
| 339 | // using class MyTrackerHit : public G4VHitsCollection{...}
|
|---|
| 340 | //
|
|---|
| 341 | void MyTrackerHitsCollection::DrawAllHits()
|
|---|
| 342 | {
|
|---|
| 343 | G4int n_hit = theCollection.entries();
|
|---|
| 344 | for(G4int i=0;i < n_hit;i++)
|
|---|
| 345 | {
|
|---|
| 346 | theCollection[i].Draw();
|
|---|
| 347 | }
|
|---|
| 348 | }
|
|---|
| 349 |
|
|---|
| 350 | //----- end of C++ source codes
|
|---|
| 351 |
|
|---|
| 352 | </programlisting>
|
|---|
| 353 | </informalexample>
|
|---|
| 354 | </para>
|
|---|
| 355 |
|
|---|
| 356 | <para>
|
|---|
| 357 | Thus, you can visualize hits as well as trajectories, for
|
|---|
| 358 | example, at the end of each event by implementing the method
|
|---|
| 359 | <literal>MyEventAction::EndOfEventAction()</literal> as follows:
|
|---|
| 360 |
|
|---|
| 361 | <informalexample>
|
|---|
| 362 | <programlisting>
|
|---|
| 363 | void MyEventAction::EndOfEventAction()
|
|---|
| 364 | {
|
|---|
| 365 | const G4Event* evt = fpEventManager->get_const_currentEvent();
|
|---|
| 366 |
|
|---|
| 367 | G4SDManager * SDman = G4SDManager::get_SDMpointer();
|
|---|
| 368 | G4String colNam;
|
|---|
| 369 | G4int trackerCollID = SDman->get_collectionID(colNam="TrackerCollection");
|
|---|
| 370 | G4int calorimeterCollID = SDman->get_collectionID(colNam="CalCollection");
|
|---|
| 371 |
|
|---|
| 372 | G4TrajectoryContainer * trajectoryContainer = evt->get_trajectoryContainer();
|
|---|
| 373 | G4int n_trajectories = 0;
|
|---|
| 374 | if(trajectoryContainer)
|
|---|
| 375 | { n_trajectories = trajectoryContainer->entries(); }
|
|---|
| 376 |
|
|---|
| 377 | G4HCofThisEvent * HCE = evt->get_HCofThisEvent();
|
|---|
| 378 | G4int n_hitCollection = 0;
|
|---|
| 379 | if(HCE)
|
|---|
| 380 | { n_hitCollection = HCE->get_capacity(); }
|
|---|
| 381 |
|
|---|
| 382 | G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
|
|---|
| 383 |
|
|---|
| 384 | if(pVVisManager)
|
|---|
| 385 | {
|
|---|
| 386 |
|
|---|
| 387 | // Declare begininng of visualization
|
|---|
| 388 | G4UImanager::GetUIpointer()->ApplyCommand("/vis/scene/notifyHandlers");
|
|---|
| 389 |
|
|---|
| 390 | // Draw trajectories
|
|---|
| 391 | for(G4int i=0; i < n_trajectories; i++)
|
|---|
| 392 | {
|
|---|
| 393 | (*(evt->get_trajectoryContainer()))[i]->DrawTrajectory();
|
|---|
| 394 | }
|
|---|
| 395 |
|
|---|
| 396 | // Construct 3D data for hits
|
|---|
| 397 | MyTrackerHitsCollection* THC
|
|---|
| 398 | = (MyTrackerHitsCollection*)(HCE->get_HC(trackerCollID));
|
|---|
| 399 | if(THC) THC->DrawAllHits();
|
|---|
| 400 | MyCalorimeterHitsCollection* CHC
|
|---|
| 401 | = (MyCalorimeterHitsCollection*)(HCE->get_HC(calorimeterCollID));
|
|---|
| 402 | if(CHC) CHC->DrawAllHits();
|
|---|
| 403 |
|
|---|
| 404 | // Declare end of visualization
|
|---|
| 405 | G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/update");
|
|---|
| 406 |
|
|---|
| 407 | }
|
|---|
| 408 |
|
|---|
| 409 | }
|
|---|
| 410 |
|
|---|
| 411 | //----- end of C++ codes
|
|---|
| 412 |
|
|---|
| 413 | </programlisting>
|
|---|
| 414 | </informalexample>
|
|---|
| 415 | </para>
|
|---|
| 416 |
|
|---|
| 417 | <para>
|
|---|
| 418 | You can re-visualize a physical volume, where a hit is detected,
|
|---|
| 419 | with a highlight color, in addition to the whole set of detector
|
|---|
| 420 | components. It is done by calling a drawing method of a physical
|
|---|
| 421 | volume directly. The method is:
|
|---|
| 422 |
|
|---|
| 423 | <informalexample>
|
|---|
| 424 | <programlisting>
|
|---|
| 425 |
|
|---|
| 426 | //----- Drawing methods of a physical volume
|
|---|
| 427 | virtual void Draw (const G4VPhysicalVolume&, ...) ;
|
|---|
| 428 |
|
|---|
| 429 | </programlisting>
|
|---|
| 430 | </informalexample>
|
|---|
| 431 | </para>
|
|---|
| 432 |
|
|---|
| 433 | <para>
|
|---|
| 434 | This method is, for example, called in a method
|
|---|
| 435 | <literal>MyXXXHit::Draw()</literal>, describing the visualization of hits
|
|---|
| 436 | with markers. The following is an example for this:
|
|---|
| 437 |
|
|---|
| 438 | <informalexample>
|
|---|
| 439 | <programlisting>
|
|---|
| 440 | //----- C++ source codes: An example of visualizing hits with
|
|---|
| 441 | void MyCalorimeterHit::Draw()
|
|---|
| 442 | {
|
|---|
| 443 | G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
|
|---|
| 444 | if(pVVisManager)
|
|---|
| 445 | {
|
|---|
| 446 | G4Transform3D trans(rot,pos);
|
|---|
| 447 | G4VisAttributes attribs;
|
|---|
| 448 | G4LogicalVolume* logVol = pPhys->GetLogicalVolume();
|
|---|
| 449 | const G4VisAttributes* pVA = logVol->GetVisAttributes();
|
|---|
| 450 | if(pVA) attribs = *pVA;
|
|---|
| 451 | G4Colour colour(1.,0.,0.);
|
|---|
| 452 | attribs.SetColour(colour);
|
|---|
| 453 | attribs.SetForceSolid(true);
|
|---|
| 454 |
|
|---|
| 455 | //----- Re-visualization of a selected physical volume with red color
|
|---|
| 456 | pVVisManager->Draw(*pPhys,attribs,trans);
|
|---|
| 457 |
|
|---|
| 458 | }
|
|---|
| 459 | }
|
|---|
| 460 |
|
|---|
| 461 | //----- end of C++ codes
|
|---|
| 462 |
|
|---|
| 463 | </programlisting>
|
|---|
| 464 | </informalexample>
|
|---|
| 465 | </para>
|
|---|
| 466 |
|
|---|
| 467 | </sect2>
|
|---|
| 468 |
|
|---|
| 469 |
|
|---|
| 470 | <!-- ******************* Section (Level#2) ****************** -->
|
|---|
| 471 | <sect2 id="sect.VisCntCmpl.AttHits">
|
|---|
| 472 | <title>
|
|---|
| 473 | HepRep Attributes for Hits
|
|---|
| 474 | </title>
|
|---|
| 475 |
|
|---|
| 476 | <para>
|
|---|
| 477 | The HepRep file formats, HepRepFile and HepRepXML, attach various
|
|---|
| 478 | attributes to hits such that you can view these attributes, label
|
|---|
| 479 | trajectories by these attributes or make visibility cuts based on
|
|---|
| 480 | these attributes. Examples of adding HepRep attributes to hit
|
|---|
| 481 | classes can be found in examples /extended/analysis/A01 and
|
|---|
| 482 | /extended/runAndEvent/RE01.
|
|---|
| 483 | </para>
|
|---|
| 484 |
|
|---|
| 485 | <para>
|
|---|
| 486 | For example, in example RE01's class RE01CalorimeterHit.cc,
|
|---|
| 487 | available attributes will be:
|
|---|
| 488 |
|
|---|
| 489 | <itemizedlist spacing="compact">
|
|---|
| 490 | <listitem><para>
|
|---|
| 491 | Hit Type
|
|---|
| 492 | </para></listitem>
|
|---|
| 493 | <listitem><para>
|
|---|
| 494 | Track ID
|
|---|
| 495 | </para></listitem>
|
|---|
| 496 | <listitem><para>
|
|---|
| 497 | Z Cell ID
|
|---|
| 498 | </para></listitem>
|
|---|
| 499 | <listitem><para>
|
|---|
| 500 | Phi Cell ID
|
|---|
| 501 | </para></listitem>
|
|---|
| 502 | <listitem><para>
|
|---|
| 503 | Energy Deposited
|
|---|
| 504 | </para></listitem>
|
|---|
| 505 | <listitem><para>
|
|---|
| 506 | Energy Deposited by Track
|
|---|
| 507 | </para></listitem>
|
|---|
| 508 | <listitem><para>
|
|---|
| 509 | Position
|
|---|
| 510 | </para></listitem>
|
|---|
| 511 | <listitem><para>
|
|---|
| 512 | Logical Volume
|
|---|
| 513 | </para></listitem>
|
|---|
| 514 | </itemizedlist>
|
|---|
| 515 | </para>
|
|---|
| 516 |
|
|---|
| 517 | <para>
|
|---|
| 518 | You can add additional attributes of your choosing by modifying the
|
|---|
| 519 | relevant part of the hit class (look for the methods GetAttDefs and
|
|---|
| 520 | CreateAttValues).
|
|---|
| 521 | </para>
|
|---|
| 522 |
|
|---|
| 523 | </sect2>
|
|---|
| 524 |
|
|---|
| 525 |
|
|---|
| 526 | <!-- ******************* Section (Level#2) ****************** -->
|
|---|
| 527 | <sect2 id="sect.VisCntCmpl.txt">
|
|---|
| 528 | <title>
|
|---|
| 529 | Visualization of text
|
|---|
| 530 | </title>
|
|---|
| 531 |
|
|---|
| 532 | <para>
|
|---|
| 533 | In Geant4 Visualization, a text, i.e., a character string, is
|
|---|
| 534 | described by class <emphasis>G4Text</emphasis> inheriting
|
|---|
| 535 | <emphasis>G4VMarker</emphasis> as well as <emphasis>G4Square</emphasis>
|
|---|
| 536 | and <emphasis>G4Circle</emphasis>. Therefore, the way to
|
|---|
| 537 | visualize text is the same as for hits. The corresponding drawing
|
|---|
| 538 | method of <emphasis>G4VVisManager</emphasis> is:
|
|---|
| 539 |
|
|---|
| 540 | <informalexample>
|
|---|
| 541 | <programlisting>
|
|---|
| 542 | //----- Drawing methods of G4Text
|
|---|
| 543 | virtual void G4VVisManager::Draw (const G4Text&, ...);
|
|---|
| 544 |
|
|---|
| 545 | </programlisting>
|
|---|
| 546 | </informalexample>
|
|---|
| 547 | </para>
|
|---|
| 548 |
|
|---|
| 549 | <para>
|
|---|
| 550 | The real implementation of this method is described in class
|
|---|
| 551 | <emphasis>G4VisManager</emphasis>.
|
|---|
| 552 | </para>
|
|---|
| 553 |
|
|---|
| 554 | </sect2>
|
|---|
| 555 |
|
|---|
| 556 |
|
|---|
| 557 | <!-- ******************* Section (Level#) ****************** -->
|
|---|
| 558 | <sect2 id="sect.VisCntCmpl.PlyTrkStp">
|
|---|
| 559 | <title>
|
|---|
| 560 | Visualization of polylines and tracking steps
|
|---|
| 561 | </title>
|
|---|
| 562 |
|
|---|
| 563 | <para>
|
|---|
| 564 | Polylines, i.e., sets of successive line segments, are described by
|
|---|
| 565 | class <emphasis>G4Polyline</emphasis>. For <emphasis>G4Polyline</emphasis>,
|
|---|
| 566 | the following drawing method of class <emphasis>G4VVisManager</emphasis>
|
|---|
| 567 | is prepared:
|
|---|
| 568 |
|
|---|
| 569 | <informalexample>
|
|---|
| 570 | <programlisting>
|
|---|
| 571 | //----- A drawing method of G4Polyline
|
|---|
| 572 | virtual void G4VVisManager::Draw (const G4Polyline&, ...) ;
|
|---|
| 573 |
|
|---|
| 574 | </programlisting>
|
|---|
| 575 | </informalexample>
|
|---|
| 576 | </para>
|
|---|
| 577 |
|
|---|
| 578 | <para>
|
|---|
| 579 | The real implementation of this method is described in class
|
|---|
| 580 | <emphasis>G4VisManager</emphasis>.
|
|---|
| 581 | </para>
|
|---|
| 582 |
|
|---|
| 583 | <para>
|
|---|
| 584 | Using this method, C++ source codes to visualize
|
|---|
| 585 | <emphasis>G4Polyline</emphasis> are described as follows:
|
|---|
| 586 |
|
|---|
| 587 | <informalexample>
|
|---|
| 588 | <programlisting>
|
|---|
| 589 | //----- C++ source code: How to visualize a polyline
|
|---|
| 590 | G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
|
|---|
| 591 |
|
|---|
| 592 | if (pVVisManager) {
|
|---|
| 593 | G4Polyline polyline ;
|
|---|
| 594 |
|
|---|
| 595 | ..... (C++ source codes to set vertex positions, color, etc)
|
|---|
| 596 |
|
|---|
| 597 | pVVisManager -> Draw(polyline);
|
|---|
| 598 |
|
|---|
| 599 | }
|
|---|
| 600 |
|
|---|
| 601 | //----- end of C++ source codes
|
|---|
| 602 |
|
|---|
| 603 | </programlisting>
|
|---|
| 604 | </informalexample>
|
|---|
| 605 | </para>
|
|---|
| 606 |
|
|---|
| 607 | <para>
|
|---|
| 608 | Tracking steps are able to be visualized based on the above
|
|---|
| 609 | visualization of <emphasis>G4Polyline</emphasis>. You can visualize tracking
|
|---|
| 610 | steps at each step automatically by writing a proper implementation
|
|---|
| 611 | of class <emphasis>MySteppingAction</emphasis> inheriting
|
|---|
| 612 | <emphasis>G4UserSteppingAction</emphasis>, and also with the help of the Run
|
|---|
| 613 | Manager.
|
|---|
| 614 | </para>
|
|---|
| 615 |
|
|---|
| 616 | <para>
|
|---|
| 617 | First, you must implement a method,
|
|---|
| 618 | <literal>MySteppingAction::UserSteppingAction()</literal>. A typical
|
|---|
| 619 | implementation of this method is as follows:
|
|---|
| 620 |
|
|---|
| 621 | <informalexample>
|
|---|
| 622 | <programlisting>
|
|---|
| 623 | //----- C++ source code: An example of visualizing tracking steps
|
|---|
| 624 | void MySteppingAction::UserSteppingAction()
|
|---|
| 625 | {
|
|---|
| 626 | G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
|
|---|
| 627 |
|
|---|
| 628 | if (pVVisManager) {
|
|---|
| 629 |
|
|---|
| 630 | //----- Get the Stepping Manager
|
|---|
| 631 | const G4SteppingManager* pSM = GetSteppingManager();
|
|---|
| 632 |
|
|---|
| 633 | //----- Define a line segment
|
|---|
| 634 | G4Polyline polyline;
|
|---|
| 635 | G4double charge = pSM->GetTrack()->GetDefinition()->GetPDGCharge();
|
|---|
| 636 | G4Colour colour;
|
|---|
| 637 | if (charge < 0.) colour = G4Colour(1., 0., 0.);
|
|---|
| 638 | else if (charge < 0.) colour = G4Colour(0., 0., 1.);
|
|---|
| 639 | else colour = G4Colour(0., 1., 0.);
|
|---|
| 640 | G4VisAttributes attribs(colour);
|
|---|
| 641 | polyline.SetVisAttributes(attribs);
|
|---|
| 642 | polyline.push_back(pSM->GetStep()->GetPreStepPoint()->GetPosition());
|
|---|
| 643 | polyline.push_back(pSM->GetStep()->GetPostStepPoint()->GetPosition());
|
|---|
| 644 |
|
|---|
| 645 | //----- Call a drawing method for G4Polyline
|
|---|
| 646 | pVVisManager -> Draw(polyline);
|
|---|
| 647 |
|
|---|
| 648 | }
|
|---|
| 649 | }
|
|---|
| 650 |
|
|---|
| 651 | //----- end of C++ source code
|
|---|
| 652 |
|
|---|
| 653 | </programlisting>
|
|---|
| 654 | </informalexample>
|
|---|
| 655 | </para>
|
|---|
| 656 |
|
|---|
| 657 | <para>
|
|---|
| 658 | Next, in order that the above C++ source code works, you have to
|
|---|
| 659 | pass the information of the <emphasis>MySteppingAction</emphasis> to the Run
|
|---|
| 660 | Manager in the <literal>main()</literal> function:
|
|---|
| 661 |
|
|---|
| 662 | <informalexample>
|
|---|
| 663 | <programlisting>
|
|---|
| 664 |
|
|---|
| 665 | //----- C++ source code: Passing what to do at each step to the Run Manager
|
|---|
| 666 |
|
|---|
| 667 | int main()
|
|---|
| 668 | {
|
|---|
| 669 | ...
|
|---|
| 670 |
|
|---|
| 671 | // Run Manager
|
|---|
| 672 | G4RunManager * runManager = new G4RunManager;
|
|---|
| 673 |
|
|---|
| 674 | // User initialization classes
|
|---|
| 675 | ...
|
|---|
| 676 | runManager->SetUserAction(new MySteppingAction);
|
|---|
| 677 | ...
|
|---|
| 678 | }
|
|---|
| 679 |
|
|---|
| 680 | //----- end of C++ source code
|
|---|
| 681 |
|
|---|
| 682 | </programlisting>
|
|---|
| 683 | </informalexample>
|
|---|
| 684 | </para>
|
|---|
| 685 |
|
|---|
| 686 | <para>
|
|---|
| 687 | Thus you can visualize tracking steps with various visualization
|
|---|
| 688 | attributes, e.g., color, at each step, automatically.
|
|---|
| 689 | </para>
|
|---|
| 690 |
|
|---|
| 691 | <para>
|
|---|
| 692 | As well as tracking steps, you can visualize any kind 3D object
|
|---|
| 693 | made of line segments, using class <emphasis>G4Polyline</emphasis> and its
|
|---|
| 694 | drawing method, defined in class <emphasis>G4VVisManager</emphasis>. See, for
|
|---|
| 695 | example, the implementation of the <literal>/vis/scene/add/axes</literal>
|
|---|
| 696 | command.
|
|---|
| 697 | </para>
|
|---|
| 698 |
|
|---|
| 699 | </sect2>
|
|---|
| 700 |
|
|---|
| 701 |
|
|---|
| 702 | <!-- ******************* Section (Level#2) ****************** -->
|
|---|
| 703 | <sect2 id="sect.VisCntCmpl.UsrAct">
|
|---|
| 704 | <title>
|
|---|
| 705 | Visualization User Action
|
|---|
| 706 | </title>
|
|---|
| 707 |
|
|---|
| 708 | <para>
|
|---|
| 709 | You can implement the <literal>Draw</literal> method of
|
|---|
| 710 | <literal>G4VUserVisAction</literal>, e.g., the class definition could be:
|
|---|
| 711 |
|
|---|
| 712 | <informalexample>
|
|---|
| 713 | <programlisting>
|
|---|
| 714 | class StandaloneVisAction: public G4VUserVisAction {
|
|---|
| 715 | void Draw();
|
|---|
| 716 | };
|
|---|
| 717 | </programlisting>
|
|---|
| 718 | </informalexample>
|
|---|
| 719 |
|
|---|
| 720 | and the implementation:
|
|---|
| 721 |
|
|---|
| 722 | <informalexample>
|
|---|
| 723 | <programlisting>
|
|---|
| 724 | void StandaloneVisAction::Draw() {
|
|---|
| 725 | G4VVisManager* pVisManager = G4VVisManager::GetConcreteInstance();
|
|---|
| 726 | if (pVisManager) {
|
|---|
| 727 |
|
|---|
| 728 | // Simple box...
|
|---|
| 729 | pVisManager->Draw(G4Box("box",2*m,2*m,2*m),
|
|---|
| 730 | G4VisAttributes(G4Colour(1,1,0)));
|
|---|
| 731 |
|
|---|
| 732 | // Boolean solid...
|
|---|
| 733 | G4Box boxA("boxA",3*m,3*m,3*m);
|
|---|
| 734 | G4Box boxB("boxB",1*m,1*m,1*m);
|
|---|
| 735 | G4SubtractionSolid subtracted("subtracted_boxes",&boxA,&boxB,
|
|---|
| 736 | G4Translate3D(3*m,3*m,3*m));
|
|---|
| 737 | pVisManager->Draw(subtracted,
|
|---|
| 738 | G4VisAttributes(G4Colour(0,1,1)),
|
|---|
| 739 | G4Translate3D(6*m,6*m,6*m));
|
|---|
| 740 | }
|
|---|
| 741 | }
|
|---|
| 742 | </programlisting>
|
|---|
| 743 | </informalexample>
|
|---|
| 744 | </para>
|
|---|
| 745 |
|
|---|
| 746 | <para>
|
|---|
| 747 | Explicit use of polyhedron objects is equivalent, e.g.:
|
|---|
| 748 |
|
|---|
| 749 | <informalexample>
|
|---|
| 750 | <programlisting>
|
|---|
| 751 |
|
|---|
| 752 | // Same, but explicit polyhedron...
|
|---|
| 753 | G4Polyhedron* pA = G4Box("boxA",3*m,3*m,3*m).CreatePolyhedron();
|
|---|
| 754 | G4Polyhedron* pB = G4Box("boxB",1*m,1*m,1*m).CreatePolyhedron();
|
|---|
| 755 | pB->Transform(G4Translate3D(3*m,3*m,3*m));
|
|---|
| 756 | G4Polyhedron* pSubtracted = new G4Polyhedron(pA->subtract(*pB));
|
|---|
| 757 | G4VisAttributes subVisAtts(G4Colour(0,1,1));
|
|---|
| 758 | pSubtracted->SetVisAttributes(&subVisAtts);
|
|---|
| 759 | pVisManager->Draw(*pSubtracted,G4Translate3D(6*m,6*m,6*m));
|
|---|
| 760 | delete pA;
|
|---|
| 761 | delete pB;
|
|---|
| 762 | delete pSubtracted;
|
|---|
| 763 | </programlisting>
|
|---|
| 764 | </informalexample>
|
|---|
| 765 | </para>
|
|---|
| 766 |
|
|---|
| 767 | <para>
|
|---|
| 768 | If efficiency is an issue, create the objects in the constructor,
|
|---|
| 769 | delete them in the destructor and draw them in your <literal>Draw</literal>
|
|---|
| 770 | method. Anyway, an instance of your class needs to be registered
|
|---|
| 771 | with the vis manager, e.g.:
|
|---|
| 772 |
|
|---|
| 773 | <informalexample>
|
|---|
| 774 | <programlisting>
|
|---|
| 775 | ...
|
|---|
| 776 | G4VisManager* visManager = new G4VisExecutive;
|
|---|
| 777 | visManager->Initialize ();
|
|---|
| 778 |
|
|---|
| 779 | visManager->SetUserAction
|
|---|
| 780 | (new StandaloneVisAction,
|
|---|
| 781 | G4VisExtent(-5*m,5*m,-5*m,5*m,-5*m,5*m)); // 2nd argument optional.
|
|---|
| 782 | ...
|
|---|
| 783 | </programlisting>
|
|---|
| 784 | </informalexample>
|
|---|
| 785 |
|
|---|
| 786 | then activate by adding to a scene, e.g:
|
|---|
| 787 |
|
|---|
| 788 | <informalexample>
|
|---|
| 789 | <programlisting>
|
|---|
| 790 | /control/verbose 2
|
|---|
| 791 | /vis/verbose c
|
|---|
| 792 | /vis/open OGLSXm
|
|---|
| 793 | /vis/scene/create
|
|---|
| 794 | #/vis/scene/add/userAction
|
|---|
| 795 | /vis/scene/add/userAction -10 10 -10 10 -10 10 m
|
|---|
| 796 | #/vis/scene/add/axes 0 0 0 10 m
|
|---|
| 797 | #/vis/scene/add/scale 10 m
|
|---|
| 798 | /vis/sceneHandler/attach
|
|---|
| 799 | /vis/viewer/refresh
|
|---|
| 800 | </programlisting>
|
|---|
| 801 | </informalexample>
|
|---|
| 802 | </para>
|
|---|
| 803 |
|
|---|
| 804 | <para>
|
|---|
| 805 | The extent can be added on registration or on the command line or
|
|---|
| 806 | neither (if the extent of the scene is set by other components).
|
|---|
| 807 | Your <literal>Draw</literal> method will be called whenever needed to refresh
|
|---|
| 808 | the screen or rebuild a graphics database, for any chosen viewer.
|
|---|
| 809 | The scene can be attached to any scene handler and your drawing
|
|---|
| 810 | will be shown.
|
|---|
| 811 | </para>
|
|---|
| 812 |
|
|---|
| 813 | </sect2>
|
|---|
| 814 |
|
|---|
| 815 |
|
|---|
| 816 | <!-- ******************* Section (Level#2) ****************** -->
|
|---|
| 817 | <sect2 id="sect.VisCntCmpl.StdAln">
|
|---|
| 818 | <title>
|
|---|
| 819 | Standalone Visualization
|
|---|
| 820 | </title>
|
|---|
| 821 |
|
|---|
| 822 | <para>
|
|---|
| 823 | The above raises the possibility of using Geant4 as a "standalone"
|
|---|
| 824 | graphics package without invoking the run manager. The following
|
|---|
| 825 | main program, together with a user visualization action and a macro
|
|---|
| 826 | file, will allow you to view your drawing interactively on any of
|
|---|
| 827 | the supported graphics systems.
|
|---|
| 828 |
|
|---|
| 829 | <informalexample>
|
|---|
| 830 | <programlisting>
|
|---|
| 831 | #include "globals.hh"
|
|---|
| 832 | #include "G4VisExecutive.hh"
|
|---|
| 833 | #include "G4VisExtent.hh"
|
|---|
| 834 | #include "G4UImanager.hh"
|
|---|
| 835 | #include "G4UIterminal.hh"
|
|---|
| 836 | #include "G4UItcsh.hh"
|
|---|
| 837 |
|
|---|
| 838 | #include "StandaloneVisAction.hh"
|
|---|
| 839 |
|
|---|
| 840 | int main() {
|
|---|
| 841 |
|
|---|
| 842 | G4VisManager* visManager = new G4VisExecutive;
|
|---|
| 843 | visManager->Initialize ();
|
|---|
| 844 |
|
|---|
| 845 | visManager->SetUserAction
|
|---|
| 846 | (new StandaloneVisAction,
|
|---|
| 847 | G4VisExtent(-5*m,5*m,-5*m,5*m,-5*m,5*m)); // 2nd argument optional.
|
|---|
| 848 |
|
|---|
| 849 | G4UImanager* UI = G4UImanager::GetUIpointer ();
|
|---|
| 850 | UI->ApplyCommand ("/control/execute standalone.g4m");
|
|---|
| 851 |
|
|---|
| 852 | G4UIsession* session = new G4UIterminal(new G4UItcsh);
|
|---|
| 853 | session->SessionStart();
|
|---|
| 854 |
|
|---|
| 855 | delete session;
|
|---|
| 856 | delete visManager;
|
|---|
| 857 | }
|
|---|
| 858 | </programlisting>
|
|---|
| 859 | </informalexample>
|
|---|
| 860 | </para>
|
|---|
| 861 |
|
|---|
| 862 |
|
|---|
| 863 | </sect2>
|
|---|
| 864 | </sect1> |
|---|