Garfield++ 4.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
exampleGarfield.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// $Id: exampleB4a.cc 86065 2014-11-07 08:51:15Z gcosmo $
27//
28/// \file exampleB4a.cc
29/// \brief Main program of the B4a example
30
31#include "G4RunManager.hh"
32#include "G4UIExecutive.hh"
33#include "G4UIcommand.hh"
34#include "G4UImanager.hh"
35#include "G4VisExecutive.hh"
38#include "GarfieldPhysics.hh"
41#include "GarfieldRunAction.hh"
43#include "Randomize.hh"
44
45// Header for Garfield random engine
46#include "Garfield/Random.hh"
47//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
48
49namespace {
50void PrintUsage() {
51 G4cerr << " Usage: " << G4endl;
52 G4cerr << " Garfield++ [-m macro ] [-u UIsession]" << G4endl;
53}
54} // namespace
55
56//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
57
58int main(int argc, char** argv) {
59 // Evaluate arguments
60 if (argc > 7) {
61 PrintUsage();
62 return 1;
63 }
64
65 G4String macro;
66 G4String session;
67
68 for (G4int i = 1; i < argc; i = i + 2) {
69 if (G4String(argv[i]) == "-m")
70 macro = argv[i + 1];
71 else if (G4String(argv[i]) == "-u")
72 session = argv[i + 1];
73 else {
74 PrintUsage();
75 return 1;
76 }
77 }
78
79 // Detect interactive mode (if no macro provided) and define UI session
80 G4UIExecutive* ui = 0;
81 if (!macro.size()) {
82 ui = new G4UIExecutive(argc, argv);
83 }
84
85 // Choose the Random engine
86 G4Random::setTheEngine(new CLHEP::RanecuEngine);
87 G4Random::setTheSeed(1);
88 // Choose seed for Garfield random engine
90
91 // Construct the default run manager
92 G4RunManager* runManager = new G4RunManager;
93
94 GarfieldDetectorConstruction* detConstruction =
96 runManager->SetUserInitialization(detConstruction);
97
98 runManager->SetUserInitialization(new GarfieldPhysicsList());
99
100 runManager->SetUserAction(new GarfieldPrimaryGeneratorAction);
101 runManager->SetUserAction(new GarfieldRunAction);
102 GarfieldEventAction* eventAction = new GarfieldEventAction;
103 runManager->SetUserAction(eventAction);
104 runManager->SetUserAction(
105 new GarfieldSteppingAction(detConstruction, eventAction));
106
107 // Initialize visualization
108 G4VisManager* visManager = new G4VisExecutive;
109 // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
110 // G4VisManager* visManager = new G4VisExecutive("Quiet");
111 visManager->Initialize();
112
113 // Get the pointer to the User Interface manager
114 G4UImanager* UImanager = G4UImanager::GetUIpointer();
115
116 // Process macro or start UI session
117 if (macro.size()) {
118 // batch mode
119 G4String command = "/control/execute ";
120 UImanager->ApplyCommand(command + macro);
121 } else {
122 // interactive mode : define UI session
123 UImanager->ApplyCommand("/control/execute init_vis.mac");
124 if (ui->IsGUI()) {
125 UImanager->ApplyCommand("/control/execute gui.mac");
126 }
127 ui->SessionStart();
128 delete ui;
129 }
130
131 // Job termination
132 // Free the store: user actions, physics_list and detector_description are
133 // owned and deleted by the run manager, so they should not be deleted
134 // in the main() program !
135
136 delete visManager;
137 delete runManager;
139}
140
141//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
Definition of the GarfieldDetectorConstruction class.
Definition of the GarfieldEventAction class.
Definition of the GarfieldPhysicsList class.
Definition of the GarfieldPhysics class.
Definition of the GarfieldPrimaryGeneratorAction class.
Definition of the GarfieldRunAction class.
Definition of the GarfieldSteppingAction class.
static void Dispose()
void Seed(const unsigned int s) override
Initialise the random number generator.
int main(int argc, char **argv)
RandomEngineRoot randomEngine
Random number generator.