Getting Started - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

Getting Started

Description:

the definitions of these types are all placed in a single header file (globals. ... G4RunManager is the root class of the Geant4 hierarchy. It controls the main ... – PowerPoint PPT presentation

Number of Views:26
Avg rating:3.0/5.0
Slides: 20
Provided by: andrea383
Category:

less

Transcript and Presenter's Notes

Title: Getting Started


1
Getting Started
2
Naming conventions
  • Sorry, but it is necessary
  • All Geant4 source files have a .cc extensions,
    all Geant4 header files carry a .hh extension
  • All Geant4 classes have their name prefixed with
    a G4
  • G4RunManager, G4Step, G4LogicalVolume
  • Abstract classes add a V to the prefix
  • G4VHit, G4VPhysicalVolume
  • Each word in a composite name is capitalized
  • G4UserAction, G4VPVParameterisation
  • Methods and functions obey the same naming
    conventions as the class names
  • G4RunManagerSetUserAction(), G4LogicalVolumeGe
    tName()

3
Basic types
  • For basic numeric types, different compilers on
    different plattforms provide different value
    ranges
  • To assure portability, Geant4 redefines the basic
    types for them to have always the same bit yield
  • the definitions of these types are all placed in
    a single header file (globals.hh), which also
    provides inclusion of all system headers, as well
    as global functions needed by the Geant4 kernel

int ? G4int long ? G4long float ? G4float double
? G4double bool ? G4bool (native, or from RW, or
from CLHEP) string ? G4String (from RW, and now
from STL)
4
The main program
  • Geant4 is a detector simulation toolkit, hence it
    does not provide a main() method
  • Users must supply their own main program to build
    their simulation program
  • The G4RunManager class is the only manager class
    in the Geant4 kernel which should be explicitly
    instantiated in the main program to specify
  • How the detector geometry should be built
  • Which physics processes one is interested in
  • How the primary particles in an event should be
    produced
  • Additional requests during the simulation
    procedures

5
G4RunManager
  • G4RunManager is the root class of the Geant4
    hierarchy
  • It controls the main flow of the program
  • Construct the manager classes of Geant4 (in its
    constructor)
  • Manages initialization procedures including
    methods in the user initialization classes (in
    its method Initialize() )
  • Manages event loops (in its method BeamOn() )
  • Terminates manager classes in Geant4 (in its
    destructor)
  • The method Initialize() takes care of building
    the detector geometry (as specified by the user),
    the physics processes and takes care of setting
    all parameters needed for G4 to run
  • The detector setup and the physics processes and
    cuts cannot be modified during a run. The
    G4RunManager must be notified is one of these
    were to change, before a new run

6
User initialization and action classes
  • Geant4 has two kinds of user defined classes
  • User initialization classes
  • used for customizing the Geant4 initialization
  • assigned to G4RunManager by invoking the
    SetUserInitialization() method
  • User action classes
  • used during the run processing
  • assigned to G4RunManager by invoking the
    SetUserAction() method
  • The implementation of three user defined classes
    is mandatory
  • setting up of the geometry
  • event kinematics
  • physics processes

7
Mandatory user classes
  • Three user classes have to be implemented by the
    user (two initialization classes and one action
    class)
  • The base classes of these mandatory classes are
    abstract and no default implementation is
    provided
  • G4RunManager checks whether objects belonging to
    these classes have been instanciated when
    Initialize() and BeamOn() are invoked
  • Users must inherit from the abstract base classes
    provided by Geant4 and derive their own classes

8
Mandatory user classes (2)
  • G4VUserDetectorConstruction (initialization)
  • the detector set-up must be described in a class
    derived from this
  • Materials
  • Geometry of the detector
  • Definition of sensitive detectors
  • Readout schemes
  • G4VUserPhysicsList (initialization)
  • Particles and processes to be used in the
    simulation
  • cutoff parameters
  • G4VUserPrimaryGeneratorAction (action)
  • Primary event kinematics

9
Optional user action classes
  • G4UserRunAction
  • run by run
  • G4UserEventAction
  • event by event
  • G4UserStackingAction
  • to control the order with which particles are
    propagated through the detector
  • G4UserTrackingAction
  • Actions to be undertaken at each end of the step
  • G4UserSteppingAction
  • Actions to be undertaken at the end of every step

10
An example of main() (batch program)
include G4RunManager.hh // from Geant4,
declaration of the run manager include
G4UImanager.hh // from Geant4, declaration of
the User Interface manager include
MyDetectorConstruction.hh // by the user
definition of the detector geometry include
MyPhysicsList.hh // by the user, list of
physics processes to be added include
MyPrimaryGenerator.hh // by the user,
kinematics of the event int main ()
G4RunManager runManagernew G4RunManager
// the run manager runManager-gtSetUserInitializa
tion(new MyDetectorConstruction) // the
geometry runManager-gtSetUserInitialization(new
MyPhysicsList) // the physics
runManager-gtSetUserAction(new
MyPrimaryGenerator) // the kinematics runMana
ger-gtInitialize() // run
initialization G4UImanager UIG4UImanagerGetUI
pointer() // pointer to the
UI UI-gtApplyCommand(run/verbose 1) //
set the printlevel int numberOfEvent3
// nr. of evts to be run runManager-gtBeamOn(numb
erOfEvent) // generate the events delete
runManager // end of run return 0
11
Batch mode with macro file
  • You can ask the UI manager to execute a macro
    file

int main(int argc, char argv) // construct
the default run manager G4RunManager runManager
new G4RunManager runManager-gtSetUserInitiali
zation(new MyDetectorConstruction) runManager-gtS
etUserInitialization(new MyPhysicsList) runManage
r-gtSetUserAction(new MyPrimaryGeneratorAction)
runManager-gtInitialize() // read a macro file
G4UIManager UI G4UImanagerGetUIpointer()
G4String command /control/execute G4String
fileName argv1 UI-gtApplyCommand(commandfile
Name) delete runManager return 0
12
Batch mode with macro file (2)
  • The previous example can be run with the command
  • gt myProgram run.macro
  • where myProgram is the name of the executable
    and run.macro is a command macro which could look
    like
  • set verbose level for this run
  • /run/verbose 2
  • /event/verbose 0
  • /tracking/verbose 2
  • 100 electrons of 1GeV Energy
  • /gun/particle e-
  • /gun/energy 1 GeV
  • /run/beamOn 100

13
Interactive mode
int main(int argc, char argv) G4RunManager
runManager new G4RunManager runManager-gtSetU
serInitialization(new MyDetectorConstruction) ru
nManager-gtSetUserInitialization(new
MyPhysicsList) G4VisManager visManager new
MyVisManager visManager-gtinitialize() runMana
ger-gtSetUserAction(new MyPrimaryGeneratorAction)
runManager-gtInitialize() G4UIsession
session new G4UIterminal session-gtSessionStart
() delete session delete visManager delete
runManager return 0
14
Interactive mode (2)
  • The previous example will be run with the command
  • gt myProgram
  • where myProgram is the name of your executable
    object
  • After the initialization phase, Geant4 will
    prompt
  • Idlegt
  • At this point, an interactive session can begin
  • Idlegt /vis/create_view/new_graphics_system DAWN
  • Idlegt /vis/draw/current
  • Idlegt /run/verbose 1
  • Idlegt /event/verbose 1
  • Idlegt /tracking/verbose 1
  • Idlegt /gun/particle mu
  • Idlegt /gun/energy 10 GeV
  • Idlegt /run/beamOn 1
  • Idlegt /vis/show/view

15
G4UItcsh
  • For ages, people asked for the possibility of
    recalling the previous command (by using the up
    arrow) or completing the current command (by
    using the Tab key)
  • Finally, someone listened to them

include G4UIterminal.hh include
G4UItcsh.hh int main(int argc, char argv)
... G4UIsession session new
G4UIterminal(new G4UItcsh) session-gtSessionStart
() delete session ...
16
ExampleN02
  • Very basic example, depicting some kind of fix
    target experimental setup
  • not very well written but very much complete and
    good for reference
  • Change directory to geant4/N02 which contains
  • a GNUmakefile
  • very basic, essentially defining the name of the
    executable and running binmake.gmk
  • the main program (exampleN02.cc)
  • a macro file (prerun.g4mac)
  • an include directory
  • class header files
  • a src directory
  • implementation of all methods

17
ExampleN02 (contd)
  • create the executable with gmake
  • run the executable by typing
  • G4WORKDIR/bin/G4SYSTEM/exampleN02
  • a macro file should initialize grapics for you.
    This is run automatically
  • draw the experimental setup and get the GUI by
  • /vis/show/view
  • tell the tracking of storing all track segments
    by
  • /tracking/storeTrajectory 1
  • and run one event
  • /run/beamOn 1

18
ExampleN02 (contd)
  • You can change the beam condition by using the
    /gun commands
  • /gun/List // to have a list of all
    possible particles
  • /gun/particle e
  • /gun/energy 10 GeV
  • /gun/position 0 10 30 cm
  • /gun/direction .3 .3 .1
  • have a look at the online help to see what can
    you do...

19
ExampleN02 (contd)
Write a Comment
User Comments (0)
About PowerShow.com