65{
66
68 G4bool useInteractiveMode = false;
69 G4int numOfThreadsOrTasks = 8;
70 G4int runManagerTypeInt = 0;
71 G4RunManagerType runManagerType = G4RunManagerType::Serial;
74 " [option(s)] \n You need to specify the mode and the macro file.\nOptions:"
75 "\n\t-h\t\tdisplay this help message\n\t-m MACRO\ttriggers a batch mode "
76 "executing MACRO\n\t-i\t\truns interactive mode, use it together with <-m vis*mac> macros"
77 "\n\t-r\t\trun manager type (0=serial,1=MT,2=tasking)"
78 "\n\t-t\t\tnumber of threads for MT mode (no change for other modes)."
79 );
80 if(argc < 2 ) {
81 G4Exception("main", "No arguments", FatalErrorInArgument,
82 (
"No arguments passed to " +
G4String(argv[0]) +
"\n" + helpMsg)
83 .c_str());
84 }
85 for(G4int i = 1; i < argc; ++i)
86 {
88 if(argument == "-h" || argument == "--help")
89 {
90 G4cout << helpMsg << G4endl;
91 return 0;
92 }
93 else if(argument == "-m")
94 {
95 batchMacroName =
G4String(argv[i + 1]);
96 ++i;
97 }
98 else if(argument == "-i")
99 {
100 useInteractiveMode = true;
101 }
102 else if(argument == "-r")
103 {
104 G4int tmp = atoi(argv[i + 1]);
105 ++i;
106 switch (tmp) {
107 case 0:
108 runManagerTypeInt = tmp;
109 runManagerType = G4RunManagerType::Serial;
110 break;
111 case 1:
112 runManagerTypeInt = tmp;
113 runManagerType = G4RunManagerType::MTOnly;
114 break;
115 case 2:
116 runManagerTypeInt = tmp;
117 runManagerType = G4RunManagerType::Tasking;
118 break;
119 default:
120 G4Exception("main", "Wrong Run Manager type", FatalErrorInArgument,
121 "Choose 0 (serial, default), 1 (MT), 2 (tasking)");
122 break;
123 }
124 }
125 else if(argument == "-t")
126 {
127 numOfThreadsOrTasks = atoi(argv[i + 1]);
128 ++i;
129 }
130 else
131 {
132 G4Exception("main", "Unknown argument", FatalErrorInArgument,
133 (
"Unknown argument passed to " +
G4String(argv[0]) +
" : " +
134 argument + "\n" + helpMsg)
135 .c_str());
136 }
137 }
138
139
141
142 G4long seed = time(NULL);
143 CLHEP::HepRandom::setTheSeed(seed);
144
145
147
148 if(useInteractiveMode)
149 {
151 runManagerType = G4RunManagerType::Serial;
152 }
153
154
155 auto* runManager =
156 G4RunManagerFactory::CreateRunManager(runManagerType);
157 if(runManagerTypeInt == 1)
158 runManager->SetNumberOfThreads(numOfThreadsOrTasks);
159
163 parallelWorldFull);
164 detector->RegisterParallelWorld(parallelWorldFull);
165 detector->RegisterParallelWorld(parallelWorldFast);
166 runManager->SetUserInitialization(detector);
167
168
170
172 fastSimulationPhysics->BeVerbose();
173 fastSimulationPhysics->ActivateFastSimulation("e-");
174 fastSimulationPhysics->ActivateFastSimulation("e+");
175 fastSimulationPhysics->ActivateFastSimulation("gamma");
176 physicsList->RegisterPhysics(fastSimulationPhysics);
177
180
181 G4EmParameters::Instance()->SetVerbose(0);
182 runManager->SetUserInitialization(physicsList);
183
184
185
186
188
189
190
191 G4cout << "Instantiating Visualization Manager......." << G4endl;
193 visManager->Initialize();
194 G4UImanager* UImanager = G4UImanager::GetUIpointer();
195
196 if(useInteractiveMode)
197 {
198 if(batchMacroName.empty())
199 {
200 G4Exception("main", "Unknown macro name", FatalErrorInArgument,
201 (
"No macro name passed to " +
G4String(argv[0]))
202 .c_str());
203 }
204 G4String command =
"/control/execute ";
205 UImanager->ApplyCommand(command + batchMacroName);
206 ui->SessionStart();
207 delete ui;
208 }
209 else
210 {
211 G4String command =
"/control/execute ";
212 UImanager->ApplyCommand(command + batchMacroName);
213 }
214
215
216
217
218
219 delete visManager;
220 delete runManager;
221
222 return 0;
223}
Initialization of user actions.