Loading...
Searching...
No Matches
Functions
examplePar04.cc File Reference
#include "FTFP_BERT.hh"
#include "Par04ActionInitialisation.hh"
#include "Par04DetectorConstruction.hh"
#include "Par04ParallelFastWorld.hh"
#include "Par04ParallelFullWorld.hh"
#include "G4EmParameters.hh"
#include "G4FastSimulationPhysics.hh"
#include "G4HadronicProcessStore.hh"
#include "G4ParallelWorldPhysics.hh"
#include "G4RunManagerFactory.hh"
#include "G4Types.hh"
#include "G4UIExecutive.hh"
#include "G4UImanager.hh"
#include "G4VisExecutive.hh"
#include "G4Exception.hh"
#include "G4ExceptionSeverity.hh"
#include "G4RunManager.hh"
#include "G4String.hh"
#include "G4VisManager.hh"
#include "G4ios.hh"
#include <ctime>
#include <sstream>
#include <string>

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 64 of file examplePar04.cc.

65{
66 // Macro name from arguments
67 G4String batchMacroName;
68 G4bool useInteractiveMode = false;
69 G4int numOfThreadsOrTasks = 8;
70 G4int runManagerTypeInt = 0;
71 G4RunManagerType runManagerType = G4RunManagerType::Serial;
72 G4String helpMsg(
73 "Usage: " + G4String(argv[0]) +
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 {
87 G4String argument(argv[i]);
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 //choose the Random engine
140 CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine());
141 //set random seed with system time
142 G4long seed = time(NULL);
143 CLHEP::HepRandom::setTheSeed(seed);
144
145 // Instantiate G4UIExecutive if interactive mode
146 G4UIExecutive* ui = nullptr;
147
148 if(useInteractiveMode)
149 {
150 ui = new G4UIExecutive(argc, argv);
151 runManagerType = G4RunManagerType::Serial;
152 }
153
154 // Initialization of default Run manager
155 auto* runManager =
156 G4RunManagerFactory::CreateRunManager(runManagerType);
157 if(runManagerTypeInt == 1)
158 runManager->SetNumberOfThreads(numOfThreadsOrTasks);
159 // Detector geometry:
160 auto detector = new Par04DetectorConstruction();
161 auto parallelWorldFull = new Par04ParallelFullWorld("parallelWorldFullSim", detector);
162 auto parallelWorldFast = new Par04ParallelFastWorld("parallelWorldFastSim", detector,
163 parallelWorldFull);
164 detector->RegisterParallelWorld(parallelWorldFull);
165 detector->RegisterParallelWorld(parallelWorldFast);
166 runManager->SetUserInitialization(detector);
167
168 // Physics list
169 auto physicsList = new FTFP_BERT();
170 // Add fast simulation physics
171 auto fastSimulationPhysics = new G4FastSimulationPhysics();
172 fastSimulationPhysics->BeVerbose();
173 fastSimulationPhysics->ActivateFastSimulation("e-");
174 fastSimulationPhysics->ActivateFastSimulation("e+");
175 fastSimulationPhysics->ActivateFastSimulation("gamma");
176 physicsList->RegisterPhysics(fastSimulationPhysics);
177 // Add parallel world for readout
178 physicsList->RegisterPhysics( new G4ParallelWorldPhysics("parallelWorldFullSim") );
179 physicsList->RegisterPhysics( new G4ParallelWorldPhysics("parallelWorldFastSim") );
180 // reduce verbosity of physics lists
181 G4EmParameters::Instance()->SetVerbose(0);
182 runManager->SetUserInitialization(physicsList);
183
184 //-------------------------------
185 // UserAction classes
186 //-------------------------------
187 runManager->SetUserInitialization(new Par04ActionInitialisation(detector, parallelWorldFull));
188 //----------------
189 // Visualization:
190 //----------------
191 G4cout << "Instantiating Visualization Manager......." << G4endl;
192 G4VisManager* visManager = new G4VisExecutive;
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 // Free the store: user actions, physics_list and detector_description are
216 // owned and deleted by the run manager, so they should not
217 // be deleted in the main() program !
218
219 delete visManager;
220 delete runManager;
221
222 return 0;
223}
Initialization of user actions.

Applications | User Support | Publications | Collaboration