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 File Reference
#include "G4RunManager.hh"
#include "G4UIExecutive.hh"
#include "G4UIcommand.hh"
#include "G4UImanager.hh"
#include "G4VisExecutive.hh"
#include "GarfieldDetectorConstruction.hh"
#include "GarfieldEventAction.hh"
#include "GarfieldPhysics.hh"
#include "GarfieldPhysicsList.hh"
#include "GarfieldPrimaryGeneratorAction.hh"
#include "GarfieldRunAction.hh"
#include "GarfieldSteppingAction.hh"
#include "Randomize.hh"
#include "Garfield/Random.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 58 of file exampleGarfield.cc.

58 {
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}
static void Dispose()
void Seed(const unsigned int s) override
Initialise the random number generator.
RandomEngineRoot randomEngine
Random number generator.