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