12.07.2015 Views

Geant4 User's Guide for Application Developers - Geant4 - CERN

Geant4 User's Guide for Application Developers - Geant4 - CERN

Geant4 User's Guide for Application Developers - Geant4 - CERN

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Getting Started with <strong>Geant4</strong>- Running a Simple ExampleExample 2.2. An example of main() using interactive terminal and visualization. Codemodified from the previous example are shown in blue.#include "G4RunManager.hh"#include "G4UImanager.hh"#include "G4UIExecutive.hh"#include "G4VisExecutive.hh"#include "N02DetectorConstruction.hh"#include "N02PhysicsList.hh"#include "N02PrimaryGeneratorAction.hh"#include "N02RunAction.hh"#include "N02EventAction.hh"#include "N02SteppingAction.hh"#include "g4templates.hh"int main(int argc,char** argv){// construct the default run managerG4RunManager * runManager = new G4RunManager;// set mandatory initialization classesN02DetectorConstruction* detector = new N02DetectorConstruction;runManager->SetUserInitialization(detector);runManager->SetUserInitialization(new N02PhysicsList);// visualization managerG4VisManager* visManager = new G4VisExecutive;visManager->Initialize();// set user action classesrunManager->SetUserAction(new N02PrimaryGeneratorAction(detector));runManager->SetUserAction(new N02RunAction);runManager->SetUserAction(new N02EventAction);runManager->SetUserAction(new N02SteppingAction);// get the pointer to the User Interface managerG4UImanager* UImanager = G4UImanager::GetUIpointer();if(argc==1)// Define (G)UI terminal <strong>for</strong> interactive mode{G4UIExecutive * ui = new G4UIExecutive(argc,argv);UImanager->ApplyCommand("/control/execute prerun.g4mac");ui->sessionStart();delete ui;}else// Batch mode{G4String command = "/control/execute ";G4String fileName = argv[1];UImanager->ApplyCommand(command+fileName);}// job terminationdelete visManager;delete runManager;}return 0;2.1.5. G4cout and G4cerrAlthough not yet included in the above examples, output streams will be needed. G4cout and G4cerr are iostreamobjects defined by <strong>Geant4</strong>. The usage of these objects is exactly the same as the ordinary cout and cerr, except thatthe output streams will be handled by G4UImanager. Thus, output strings may be displayed on another windowor stored in a file. Manipulation of these output streams will be described in Section 7.2.4. These objects shouldbe used instead of the ordinary cout and cerr.5

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!