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.20. An example of the main() routine <strong>for</strong> an application which will run inbatch mode.int main(){// Construct the default run managerG4RunManager* runManager = new G4RunManager;// set mandatory initialization classesrunManager->SetUserInitialization(new ExN01DetectorConstruction);runManager->SetUserInitialization(new ExN01PhysicsList);// set mandatory user action classrunManager->SetUserAction(new ExN01PrimaryGeneratorAction);// Initialize G4 kernelrunManager->Initialize();// start a runint numberOfEvent = 1000;runManager->BeamOn(numberOfEvent);// job terminationdelete runManager;return 0;}Even the number of events in the run is `frozen`. To change this number you must at least recompile main().2.9.3. Batch Mode with Macro FileBelow is an example of the main program <strong>for</strong> an application which will run in batch mode, but reading a file ofcommands.Example 2.21. An example of the main() routine <strong>for</strong> an application which will run inbatch mode, but reading a file of commands.int main(int argc,char** argv) {// Construct the default run managerG4RunManager * runManager = new G4RunManager;// set mandatory initialization classesrunManager->SetUserInitialization(new MyDetectorConstruction);runManager->SetUserInitialization(new MyPhysicsList);// set mandatory user action classrunManager->SetUserAction(new MyPrimaryGeneratorAction);// Initialize G4 kernelrunManager->Initialize();//read a macro file of commandsG4UImanager * UI = G4UImanager::getUIpointer();G4String command = "/control/execute ";G4String fileName = argv[1];UI->applyCommand(command+fileName);delete runManager;return 0;}This example will be executed with the command:> myProgram run1.macwhere myProgram is the name of your executable and run1.mac is a macro of commands located in the currentdirectory, which could look like:24

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

Saved successfully!

Ooh no, something went wrong!