Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172

     Geant4 - an Object-Oriented Toolkit for Simulation in HEP

                            Example B1

 This example demonstrates a very simple application where an energy
 deposit is accounted in user actions and their associated objects
 and a dose in a selected volume is calculated. 

   The geometry is constructed in the B1DetectorConstruction class.
   The setup consists of a an envelope of box shape containing two
   volumes: a spherical cone and a trapezoid.

   In this example we use  some common materials materials for medical
   applications. The envelope is made of water and the two inner volumes
   are made from tissue and bone materials.  
   The materials are created with the help of the G4NistManager class,
   which allows to build a material from the NIST database using their
   names. All available materials can be found in the Geant4 User's Guide
   for Application Developers, Appendix 10: Geant4 Materials Database.
   The particle's type and the physic processes which will be available
   in this example are set in the QBBC physics list. This physics list 
   requires data files for electromagnetic and hadronic processes.
   See more on installation of the datasets in Geant4 Installation Guide,
   Chapter 3.3: Note On Geant4 Datasets:
   G4SAIDXSDATA and G4ENSDFSTATEDATA are mandatory for this example.

   In addition the build-in interactive command:
               /process/(in)activate processName
   allows to activate/inactivate the processes one by one.

   A newly introduced class, B1ActionInitialization, instantiates and registers 
   to Geant4 kernel all user action classes.

   While in sequential mode the action classes are instatiated just once,
   via invoking the method:
   in multi-threading mode the same method is invoked for each thread worker
   and so all user action classes are defined thread-local.

   A run action class is instantiated both thread-local 
   and global that's why its instance is created also in the method
   which is invoked only in multi-threading mode.
   The primary generator is defined in the B1PrimaryGeneratorAction class.
   The default kinematics is a 6 MeV gamma, randomly distributed in front
   of the envelope across 80% of the transverse (X,Y) envelope size. 
   This default setting can be changed via the Geant4 built-in commands 
   of the G4ParticleGun class.

   This example demonstrates a simple scoring implemented directly
   in the user action classes.  Alternative ways of scoring via Geant4 classes 
   can be found in the other examples.
   The energy deposited is collected step by step for a selected volume
   in B1SteppingAction and accumulated event by event in B1EventAction.

   At end of event, the value acummulated in B1EventAction is added in B1RunAction
   and summed over the whole run (see B1EventAction::EndOfevent()).

   Total dose deposited is computed at B1RunAction::EndOfRunAction(), 
   and printed together with informations about the primary particle.
   In multi-threading mode the energy accumulated in G4Accumulable objects per
   workers is merged to the master in B1RunAction::EndOfRunAction() and the final
   result is printed on the screen.
   G4Parameter<G4double> type instead of G4double type is used for the B1RunAction
   data members in order to facilitate merging of the values accumulated on workers 
   to the master.  Currently the accumulables have to be registered to G4AccumulablesManager
   and G4AccumulablesManager::Merge() has to be called from the users code. This is planned
   to be further simplified with a closer integration of G4Accumulable classes in
   the Geant4 kernel next year.

   An example of creating and computing new units (e.g., dose) is also shown 
   in the class constructor. 

 The following paragraphs are common to all basic examples


   The visualization manager is set via the G4VisExecutive class
   in the main() function in    
   The initialisation of the drawing is done via a set of /vis/ commands
   in the macro vis.mac. This macro is automatically read from
   the main function when the example is used in interactive running mode.

   By default, vis.mac opens an OpenGL viewer (/vis/open OGL).
   The user can change the initial viewer by commenting out this line
   and instead uncommenting one of the other /vis/open statements, such as
   HepRepFile or DAWNFILE (which produce files that can be viewed with the
   HepRApp and DAWN viewers, respectively).  Note that one can always
   open new viewers at any time from the command line.  For example, if
   you already have a view in, say, an OpenGL window with a name
   "viewer-0", then
      /vis/open DAWNFILE
   then to get the same view
      /vis/viewer/copyView viewer-0
   or to get the same view *plus* scene-modifications
      /vis/viewer/set/all viewer-0
   then to see the result

   The DAWNFILE, HepRepFile drivers are always available
   (since they require no external libraries), but the OGL driver requires
   that the Geant4 libraries have been built with the OpenGL option.

   From Release 9.6 the vis.mac macro in example B1 has additional commands
   that demonstrate additional functionality of the vis system, such as
   displaying text, axes, scales, date, logo and shows how to change
   viewpoint and style.  Consider copying these to other examples or
   your application.  To see even more commands use help or
   ls or browse the available UI commands in the Application
   Developers Guide, Section 7.1.

   For more information on visualization, including information on how to
   install and run DAWN, OpenGL and HepRApp, see the visualization tutorials,
   for example,[VIS]Tutorial/G4[VIS]Tutorial.html
   (where [VIS] can be replaced by DAWN, OpenGL and HepRApp)

   The tracks are automatically drawn at the end of each event, accumulated
   for all events and erased at the beginning of the next run.

   The user command interface is set via the G4UIExecutive class
   in the main() function in 
   The selection of the user command interface is then done automatically 
   according to the Geant4 configuration or it can be done explicitly via 
   the third argument of the G4UIExecutive constructor (see 

    - Execute exampleB1 in the 'interactive mode' with visualization:
        % ./exampleB1
      and type in the commands from run1.mac line by line:  
        Idle> /control/verbose 2
        Idle> /tracking/verbose 1
        Idle> /run/beamOn 10 
        Idle> ...
        Idle> exit
        Idle> /control/execute run1.mac
        Idle> exit

    - Execute exampleB1  in the 'batch' mode from macro files 
      (without visualization)
        % ./exampleB1 run2.mac
        % ./exampleB1 > exampleB1.out