Visualisation and GUI http cern chgeant 4 Visualization

  • Slides: 53
Download presentation
Visualisation and (G)UI http: //cern. ch/geant 4 Visualization & (G)UI Geant 4 Course

Visualisation and (G)UI http: //cern. ch/geant 4 Visualization & (G)UI Geant 4 Course

PART I Geant 4 visualisation Visualization & (G)UI Geant 4 Course

PART I Geant 4 visualisation Visualization & (G)UI Geant 4 Course

1. Introduction n Geant 4 Visualisation must respond to varieties of user requirements n

1. Introduction n Geant 4 Visualisation must respond to varieties of user requirements n n n n Quick response to survey successive events Impressive special effects for demonstration High-quality output to prepare journal papers Flexible camera control for debugging geometry Highlighting overlapping of physical volumes Interactive picking of visualised objects … Visualization & (G)UI - Geant 4 Course 3

2. Visualisable Objects (1) n Simulation data you may like to see: n n

2. Visualisable Objects (1) n Simulation data you may like to see: n n n Detector components A hierarchical structure of physical volumes A piece of physical volume, logical volume, and solid Particle trajectories and tracking steps Hits of particles in detector components Visualisation is performed either with commands (macro or interactive) or by writing C++ source codes of user-action classes Visualization & (G)UI - Geant 4 Course 4

2. Visualisable Objects (2) n You can also visualize other userdefined objects such as:

2. Visualisable Objects (2) n You can also visualize other userdefined objects such as: A polyline, that is, a set of successive line segments (example: coordinate axes) n A marker which marks an arbitrary 3 D position (example: eye guides) n Text n • character strings for description • comments or titles … Visualization & (G)UI - Geant 4 Course 5

3. Visualization Attributes n n Necessary for visualization, but not included in geometrical information

3. Visualization Attributes n n Necessary for visualization, but not included in geometrical information n Colour, visibility, forced-wireframe style, etc n A set of visualisation attributes is held by the class G 4 Vis. Attributes A G 4 Vis. Attributes object is assigned to a visualisable object (e. g. a logical volume) with its method Set. Vis. Attributes() : my. Volume. Logical ->Set. Vis. Attributes (G 4 Vis. Attributes: : Invisible) Visualization & (G)UI - Geant 4 Course 6

3. 2 Visibility A boolean flag (G 4 bool) to control the visibility of

3. 2 Visibility A boolean flag (G 4 bool) to control the visibility of objects n Access function n G 4 Vis. Attributes: : Set. Visibility (G 4 bool visibility) If false is given as argument, visualization is skipped for objects for which this set of visualization attributes is assigned. The default value of visibility is true. Visualization & (G)UI - Geant 4 Course 7

3. 3 Colour (1) n n Class G 4 Vis. Attributes holds its colour

3. 3 Colour (1) n n Class G 4 Vis. Attributes holds its colour entry as an instance of class G 4 Colour is instantiated by giving RGB components to its constructor: n n n G 4 Colour: : G 4 Colour(G 4 double r = 1. 0, G 4 double g = 1. 0, G 4 double b = 1. 0 ) The default arguments define “white” color For instance: G 4 Color red(1. 0, 0. 0); G 4 Color blue(0. 0, 1. 0); G 4 Color yellow(1. 0, 0. 0); Visualization & (G)UI - Geant 4 Course 8

3. 3 Colour (2) n. A colour can be set in a G 4

3. 3 Colour (2) n. A colour can be set in a G 4 Vis. Atttributes object via the functions of G 4 Vis. Attributes Set. Colour(const G 4 Colour& colour) n Set. Colour( G 4 double r , G 4 double g , G 4 double b) n Visualization & (G)UI - Geant 4 Course 9

3. 4 Assigning G 4 Vis. Attributes to a logical volume Class G 4

3. 4 Assigning G 4 Vis. Attributes to a logical volume Class G 4 Logical. Volume holds a pointer of G 4 Vis. Attributes n Access functions of G 4 Logical. Volume n n n Set. Vis. Attributes ( const G 4 Vis. Attributes* pva ) For instance: G 4 Colour brown(0. 7, 0. 4, 0. 1); G 4 Vis. Attributes* copper. Vis. Attributes = new G 4 Vis. Attributes(brown); logical copper_liquid_log volume ->Set. Vis. Attributes(copper. Vis. Attributes); Visualization & (G)UI - Geant 4 Course 10

4. Polyline and Marker n Polyline and marker are defined in the graphics_reps category

4. Polyline and Marker n Polyline and marker are defined in the graphics_reps category n They are available to model 3 D scenes for visualization Visualization & (G)UI - Geant 4 Course 11

4. 1 Polyline A set of successive line segments n Defined with a class

4. 1 Polyline A set of successive line segments n Defined with a class G 4 Polyline n Used to visualize tracking steps, particle trajectories, coordinate axes, etc n G 4 Polyline is defined as a list of G 4 Point 3 D objects. Elements of the list define vertex positions of a polyline. n Visualization & (G)UI - Geant 4 Course 12

Example C++ code for polyline: //-- C++ source code: An example of defining a

Example C++ code for polyline: //-- C++ source code: An example of defining a line segment // Instantiation G 4 Polyline x_axis; Create a polyline // Vertex positions x_axis. append ( G 4 Point 3 D ( 0. , 0. ) ); x_axis. append ( G 4 Point 3 D ( 5. * cm, 0. ) ); Color G 4 Colour red ( 1. 0, 0. 0 ); G 4 Vis. Attributes att ( red ); x_axis. Set. Vis. Attributes( att ); Define the points of the polyline // Set the visualization attributes of the polyline //-- end of C++ source code Visualization & (G)UI - Geant 4 Course 13

4. 2 Marker (1) n n Set a mark to an arbitrary 3 D

4. 2 Marker (1) n n Set a mark to an arbitrary 3 D position Usually used to visualize hits of particles Designed as a 2 -dimensional primitive with shape (square, circle, text), color. Set marker properties with n Set. Position( const G 4 Point 3 D& ) Set. World. Size( G 4 double real_3 d_size ) n Set. Screen. Size( G 4 double 2 d_size_pixel ) n Visualization & (G)UI - Geant 4 Course 14

4. 2 Marker (2) n Kinds of markers Square : G 4 Square n

4. 2 Marker (2) n Kinds of markers Square : G 4 Square n Circle : G 4 Circle n Text : G 4 Text n n Constructors n n n G 4 Circle (const G 4 Point 3 D& pos) G 4 Square (const G 4 Point 3 D& pos) G 4 Text (const G 4 String& text, const G 4 Point 3 D& pos) Visualization & (G)UI - Geant 4 Course 15

Example C++ code for marker: G 4 Point 3 D position(0, 0, 0); Create

Example C++ code for marker: G 4 Point 3 D position(0, 0, 0); Create a circle in a given position G 4 Circle circle(position); // Instantiate a circle with its 3 D position. The // argument "position" is defined as G 4 Point 3 D instance circle. Set. Screen. Diameter(1. 0); Set diameter circle. Set. Fill. Style (G 4 Circle: : filled); and style // Make it a filled circle G 4 Colour colour(1. , 0. ); G 4 Vis. Attributes attribs(colour); // Define a red visualization attribute circle. Set. Vis. Attributes(attribs); // Assign the red end of C++ source code Set colour and vis attributes Visualization & (G)UI - Geant 4 Course 16

5. Visualisation Drivers n n Visualization drivers are interfaces of Geant 4 to 3

5. Visualisation Drivers n n Visualization drivers are interfaces of Geant 4 to 3 D graphics software You can select your favorite one(s) depending on your purposes such as n n n Demo Preparing precise figures for journal papers Publication of results on Web Debugging geometry Etc. Visualization & (G)UI - Geant 4 Course 17

5. 1 Available Graphics Software n Geant 4 provides several visualization drivers tailored to

5. 1 Available Graphics Software n Geant 4 provides several visualization drivers tailored to different purposes: n n n n DAWN : Technical High-quality Post. Script output OPACS: Interactivity, unified GUI Open. GL: Quick and flexible visualisation Open. Inventor: Interactivity, virtual reality, etc Ray. Tracer : Photo-realistic rendering VRML: Interactivity, 3 D graphics on Web. . . Visualization & (G)UI - Geant 4 Course 18

5. 2 Available Visualisation Drivers n n n n DAWN OPENGLX Hep. Rep OIX

5. 2 Available Visualisation Drivers n n n n DAWN OPENGLX Hep. Rep OIX Ray. Tracer VRML etc Fukui Renderer DAWN Open. GL with Xlib Hep. Rep graphics Open. Inventor with Xlib JPEG files VRML 1. 0/2. 0 Visualization & (G)UI - Geant 4 Course 19

5. 3 How to Use Visualization Drivers n n Visualization should be switched on

5. 3 How to Use Visualization Drivers n n Visualization should be switched on using the variable G 4 VIS_USE You can select/use visualisation driver(s) by setting environmental variables before compilation, according to what is installed on your computer: n n setenv G 4 VIS_USE_DRIVERNAME Example n n n 1 (DAWN, Open. GLXlib, and VRML drivers): setenv G 4 VIS_USE_DAWN 1 setenv G 4 VIS_USE_OPENGLX 1 setenv G 4 VIS_USE_VRML 1 Visualization & (G)UI - Geant 4 Course 20

6. main() Function (1) To have a Geant 4 executable to handle visualization, you

6. main() Function (1) To have a Geant 4 executable to handle visualization, you have two choices: n n Instantiate and initialize your own Visualization Manager in the main(). It must inherit by G 4 Vis. Manager and implement the void Register. Graphic. System() method (Easiest) To use the ready-for-the-use G 4 Vis. Executive class available in Geant 4. It must be instantiated and initialized in the main() program ( see next slide) Visualization & (G)UI - Geant 4 Course 21

6. main() Function (2) //----- C++ source codes: Instantiation and initialization of G 4

6. main() Function (2) //----- C++ source codes: Instantiation and initialization of G 4 Vis. Manager in main() #include "G 4 Vis. Executive. hh“ Includes the G 4 Vis. Executive class // Instantiation and initialization of the Visualization Manager #ifdef G 4 VIS_USE Instantiate and initialize G 4 Vis. Manager* vis. Manager = the Visualization Manager if new G 4 Vis. Executive; G 4 VIS_USE is “true” vis. Manager -> initialize(); #endif #ifdef G 4 VIS_USE delete vis. Manager; #endif Don’t forget to delete the pointer to G 4 Vis. Executive at the end of main() Visualization & (G)UI - Geant 4 Course 22

7. Visualisation commands There are some frequently-used builtin visualization commands in Geant 4, that

7. Visualisation commands There are some frequently-used builtin visualization commands in Geant 4, that you may like to try n Geant 4 executable in this tutorial is compiled incorporating DAWN, Open. GL and VRML drivers n setenv G 4 VIS_USE_DAWN 1 n setenv G 4 VIS_USE_OPENGLX 1 n setenv G 4 VIS_USE_VRML 1 n Visualization & (G)UI - Geant 4 Course 23

7. 1 An example of commands to visualize a detector /vis/open OGLIX # or

7. 1 An example of commands to visualize a detector /vis/open OGLIX # or /vis/open DAWNFILE create a scene handler and a viewer /vis/viewer/reset /vis/viewer/viewpoint. Theta. Phi 70 20 /vis/viewer/set/style wireframe /vis/draw. Volume /vis/viewer/flush set vis options set the detector geometry as object to visualize, and registers it close visualization These commands can be given interactively or executed via macro (e. g. vis 1. mac of N 03) Visualization & (G)UI - Geant 4 Course 24

7. 2 An Example of Visualizing Events Store particle trajectories for visualization Scene handler

7. 2 An Example of Visualizing Events Store particle trajectories for visualization Scene handler and viewer for DAWN /tracking/store. Trajectory /vis/open DAWNFILE … Optional settings (viewpoint, axes, etc. ) /vis/scene/create Creates an empty scene /vis/scene/add/volume /vis/scene/add/trajectories /run/beam. On 10 Adds world volumes and trajectories to the scene Shoots events (end of visualization) Again, commands can executed via macro (e. g. vis 2. mac of example N 03) or interactively Visualization & (G)UI - Geant 4 Course 25

7. 3 /vis/open command n Command n Idle> /vis/open <driver_tag_name> n The “driver_tag_name” is

7. 3 /vis/open command n Command n Idle> /vis/open <driver_tag_name> n The “driver_tag_name” is the driver’s name n Example: Creating the OPENGLX driver in the immediate mode: n Idle> /vis/open OGLIX n How to list available driver_tag_name n Idle> help /vis/open or Idle> help /vis/scene. Handler/create Visualization & (G)UI - Geant 4 Course 26

7. 4 /vis/viewer/… commands n Commands n Viewpoint setting Idle> /vis/viewer/viewpoint. Theta. Phi <theta_deg>

7. 4 /vis/viewer/… commands n Commands n Viewpoint setting Idle> /vis/viewer/viewpoint. Theta. Phi <theta_deg> <phi_deg> n Zooming Idle> /vis/viewer/zoom <scale_factor> n Initialization parameters of camera Idle> /vis/viewer/reset Visualization & (G)UI - Geant 4 Course 27

7. 5 /vis/draw. Volume and /vis/viewer/flush commands n Commands: n Idle> /vis/draw. Volume <physical-volume-name>

7. 5 /vis/draw. Volume and /vis/viewer/flush commands n Commands: n Idle> /vis/draw. Volume <physical-volume-name> (Default: world) Idle> /vis/viewer/flush Note that /vis/viewer/flush should be executed to declare end of visualisation. n You can draw a specific volume (rather than the full geometry) You can add visualization commands of, say, coordinate axes. For example, Idle> /vis/scene/add/axes <Ox> <Oy> <Oz> <length> <unit> n n Visualization & (G)UI - Geant 4 Course 28

7. 6 Commands to Visualize Events n Commands n n Idle> /tracking/store. Trajectory 1

7. 6 Commands to Visualize Events n Commands n n Idle> /tracking/store. Trajectory 1 Idle> /vis/scene/add/trajectories Idle> /run/beam. On <number_of_events> Action: n Automatic visualization of events Visualization & (G)UI - Geant 4 Course 29

Sample Visualization (1) Visualization & (G)UI - Geant 4 Course 30

Sample Visualization (1) Visualization & (G)UI - Geant 4 Course 30

Sample Visualization (2) Visualization & (G)UI - Geant 4 Course 31

Sample Visualization (2) Visualization & (G)UI - Geant 4 Course 31

Sample Visualization (3) Visualization & (G)UI - Geant 4 Course 32

Sample Visualization (3) Visualization & (G)UI - Geant 4 Course 32

8. Visualisation from C++ code n n It is also possible to hard-code visualization

8. Visualisation from C++ code n n It is also possible to hard-code visualization commands in the C++ code (personally, I’d discourage it) You can describe the visualization commands in C++ codes via the Apply. Command() method of the UI manager, as for any other command: G 4 UImanager: : Get. UIpointer() ->Apply. Command(“/vis/…”); n Alternatively, you can use Draw() methods of visualizable classes my. Polyline->Draw(); Visualization & (G)UI - Geant 4 Course 33

9. Information n n Geant 4 User Guide (and source codes) README file: n

9. Information n n Geant 4 User Guide (and source codes) README file: n n geant 4/source/visualisation/README On-line documentation on Geant 4 visualisation n http: //cern. ch/geant 4/G 4 Users. Documents/Users. Guides/ For. Application. Developer/html/Visualization & (G)UI - Geant 4 Course 34

PART II Geant 4 (G)UI Visualization & (G)UI Geant 4 Course

PART II Geant 4 (G)UI Visualization & (G)UI Geant 4 Course

Steering the simulation (1) n A Geant 4 simulation can be steered in three

Steering the simulation (1) n A Geant 4 simulation can be steered in three ways: everything hard-coded in the C++ source (also the number of events to be shot). You need to re-compile for any change (not very smart!) n batch session (via a ASCII macro) n commands captured from an interactive session n Visualization & (G)UI - Geant 4 Course 36 1

Steering the simulation (2) n Setting up batch mode (namely, read commands from a

Steering the simulation (2) n Setting up batch mode (namely, read commands from a macro file) in the main() G 4 UImanager* UI = G 4 UImanager: : Get. UIpointer(); takes the first G 4 String command = “/control/execute”; argument after G 4 String file. Name = argv[1]; the executable UI->apply. Command(command+file. Name); as the macro n Your executable can be run as name and runs it my. Executable mymacro. mac n To execute a macro interactively: /control/execute mymacro. mac Visualization & (G)UI - Geant 4 Course 37 1

Steering the simulation (3) n n Setting up interactive mode is also easy –

Steering the simulation (3) n n Setting up interactive mode is also easy – but there are many choices of interface n All of them must be derived from the abstract class G 4 UIsession n Geant 4 provides several implementations In the main(), according to the computer environments, construct a G 4 UIsession concrete class provided by Geant 4 and invoke its Session. Start() method Visualization & (G)UI - Geant 4 Course 38 1

An exemple of interactive session n For instance: in the main() G 4 UIsession*

An exemple of interactive session n For instance: in the main() G 4 UIsession* session=0; Create a (null) pointer to the base session class If there are no arguments after the if (argc==1) executable, starts an interactive session { Define the session = new G 4 UIterminal; as a dumb terminal, session->Session. Start(); and starts it delete session; } Don’t forget to delete it Visualization & (G)UI - Geant 4 Course 39

Select (G)UI n Geant 4 provides several interfaces for various (G)UI: n n n

Select (G)UI n Geant 4 provides several interfaces for various (G)UI: n n n G 4 UIterminal: C-shell like character terminal G 4 UItcsh: tcsh-like character terminal with command completion, history, etc G 4 UIGAG: Java based graphic UI (GUI) G 4 UIXm: Motif-based GUI, command completion Define and invoke them like G 4 UIterminal session = new G 4 UIGAG(); session->Start. Session(); n Note for G 4 UItcsh, it must be defined as session = new G 4 UIterminal (new G 4 UItcsh); Visualization & (G)UI - Geant 4 Course 40

Environmental variables n Users can select and plug in (G)UI by setting environmental variables

Environmental variables n Users can select and plug in (G)UI by setting environmental variables before compilation, similar to what seen for visualization drivers • setenv G 4 UI_USE_GUINAME n Example: • setenv G 4 UI_USE_TERMINAL • setenv G 4 UI_USE_GAG • setenv G 4 UI_USE_XM 1 (default) 1 1 Visualization & (G)UI - Geant 4 Course 41

User interface choices n G 4 UIterminal – C-shell-like character terminal runs on all

User interface choices n G 4 UIterminal – C-shell-like character terminal runs on all Geant 4 -supported platforms G 4 UItcsh – tcsh-like character terminal with command completion, history, etc. n runs only on Solaris and Linux G 4 UIXm, G 4 UIXaw, G 4 UIXWin 32 – G 4 UIterminal implemented over Motif, Athena and WIN 32 libraries n runs on Unix/linux and Windows, respectively G 4 UIGAG – Java-based GUI n n n runs on all Geant 4 platforms Visualization & (G)UI - Geant 4 Course 42 1

Useful GUI Tools Released by Geant 4 Developers n GGE: Geometry editor based on

Useful GUI Tools Released by Geant 4 Developers n GGE: Geometry editor based on Java GUI n n GPE: Physics editor based on Java GUI n n http: //erpc 1. naruto-u. ac. jp/~geant 4 Open. Scientist: interactive environment for analysis n http: //www. lal. in 2 p 3. fr/Open. Scientist Visualization & (G)UI - Geant 4 Course 43 1

Build-it user commands n Geant 4 provides a number of general-purpose user interface commands

Build-it user commands n Geant 4 provides a number of general-purpose user interface commands which can be used: n interactively via a (G)UI Idle> /run/set. Cut [value] [unit] n n in a macro file within C++ code using the Apply. Command() method of G 4 UImanager: : Get. UIpointer() ->Apply. Command(“/run/set. Cut 1 cm”); n A complete list of built-in commands is available in the Geant 4 Application Developers Guide, Chapter 7. 1 Visualization & (G)UI - Geant 4 Course 44 1

User-defined commands (1) n n If built-in commands are not enough, you can make

User-defined commands (1) n n If built-in commands are not enough, you can make your own (e. g. change at run-time parameters of primary generator, etc. ) Geant 4 provides several command classes, all derived from G 4 UIcommand, according to the type of argument they take n G 4 UIcmd. Without. Parameter n G 4 UIcmd. With. ABool n G 4 UIcmd. With. ADouble. And. Unit n. . . Visualization & (G)UI - Geant 4 Course 45

User-defined commands (2) n n Commands have to be defined in messenger classes, that

User-defined commands (2) n n Commands have to be defined in messenger classes, that inherit from G 4 UImessenger Define the command in the constructor: G 4 UIcmd. With. ADouble. And. Unit* f. Theta. Cmd = new G 4 UIcmd. With. ADouble. And. Unit ("/prim/angle", this); Command taking as argument a double and a unit, called /prim/angle f. Theta. Cmd->Set. Guidance(“Opening angle of the source"); f. Theta. Cmd->Set. Default. Unit("deg"); f. Theta. Cmd->Set. Unit. Candidates(“deg rad”); Sets guidance, default unit, etc. n Delete the command in the destructor Visualization & (G)UI - Geant 4 Course 46

User-defined commands (3) n Define the action of the command in the Set. New.

User-defined commands (3) n Define the action of the command in the Set. New. Value() method of the messenger: void My. Messenger: : Set. New. Value (G 4 UIcommand* cmd, G 4 String string) { if (cmd == f. Theta. Cmd) Retrieve a G 4 double { value from the (string) G 4 double value = f. Theta. Cmd argument given to the ->Get. New. Double. Value(string); command. . . ->Do. Something(value); } } Use the value in the way it is needed (e. g. pass it to other classes: opening angle for primary generator) Visualization & (G)UI - Geant 4 Course 47

PART III Summary Visualization & (G)UI Geant 4 Course

PART III Summary Visualization & (G)UI Geant 4 Course

Summary n n n Geant 4 can be used to visualize set-ups, tracks and

Summary n n n Geant 4 can be used to visualize set-ups, tracks and other objects (e. g. axes, markers) A number of visualization drivers is available, each with its pros and cons Visualization can be controlled interactively or by macro, using Geant 4 built-in commands Interactive sessions where user can give commands by keyboard can be used (from dumb terminals to graphic interfaces) A number of general-purpose commands are provided by Geant 4, but users can define more, according to their needs flexibility! Visualization & (G)UI - Geant 4 Course 49

PART IV Backup Visualization & (G)UI Geant 4 Course

PART IV Backup Visualization & (G)UI Geant 4 Course

7. 1 Scene, Scene Hander, Viewer n n n n In order to use

7. 1 Scene, Scene Hander, Viewer n n n n In order to use visualization commands, let’s define “scene”, “scene handler”, and “viewer”: Scene: A set of visualizable 3 D data (e. g. a geometry, a polyline, etc. ) Scene handler: Computer Graphics data modeler, which uses raw data in a scene Viewer: Image generator Each scene handler is assigned to a scene Each viewer is assigned to a scene handler “visualisation driver” = “scene_handler” + “viewer” Visualization & (G)UI - Geant 4 Course 51

7. 2 Logical steps of Visualization n n n Step 1: Create a scene

7. 2 Logical steps of Visualization n n n Step 1: Create a scene handler and a viewer Step 2: Create an empty scene Step 3: Set camera parameters, drawing style, etc. [Optional] Step 4: Add 3 D data to the created scene Step 5: Attach the current scene handler to the current scene Step 6: Make the viewer execute visualisation Step 7: Declare the end of visualization You can do all that interactively or using a macro (see next slide) Visualization & (G)UI - Geant 4 Course 52

7. 5 /vis/viewer/set/style command n Command n Idle> /vis/viewer/set/style <style_name> n The “style_name” can

7. 5 /vis/viewer/set/style command n Command n Idle> /vis/viewer/set/style <style_name> n The “style_name” can be “wireframe” or “surface” Visualization & (G)UI - Geant 4 Course 53