43 #include "G4RunManager.hh" 44 #include "G4UImanager.hh" 45 #include "G4UIterminal.hh" 46 #include "G4VisExecutive.hh" 47 #include "G4PhysListFactory.hh" 48 #include "G4VModularPhysicsList.hh" 49 #include "G4PropagatorInField.hh" 50 #include "G4TransportationManager.hh" 57 #include <QApplication> 58 #include <QSplashScreen> 113 int get_pid(){
return 0;}
118 int main(
int argc,
char **argv )
122 gemcOpt.
Set(argc, argv);
123 string hd_msg = gemcOpt.
args[
"LOG_MSG"].args +
" Init: >> " ;
125 cout << endl << hd_msg <<
" Geant4 MonteCarlo" << endl;
126 double use_qt = gemcOpt.
args[
"USE_QT"].arg;
129 QApplication gemc_gui( argc, argv, (
bool) use_qt );
131 string guistyle = gemcOpt.
args[
"QTSTYLE"].args;
132 if(guistyle ==
"QPlastiqueStyle") gemc_gui.setStyle(
new QPlastiqueStyle);
133 if(guistyle ==
"QCleanlooksStyle") gemc_gui.setStyle(
new QCleanlooksStyle);
134 if(guistyle ==
"QWindowsStyle") gemc_gui.setStyle(
new QWindowsStyle);
135 if(guistyle ==
"QMotifStyle") gemc_gui.setStyle(
new QMotifStyle);
137 QPixmap *splash_i = NULL;
138 QSplashScreen *splash = NULL;
146 QDir dir(QApplication::applicationDirPath());
149 QStringList dir_list(QLibraryInfo::location(QLibraryInfo::PluginsPath));
150 dir_list.append(dir.absolutePath());
151 QApplication::setLibraryPaths(dir_list);
163 splash_i =
new QPixmap(CLAS12_cad);
164 splash =
new QSplashScreen(*splash_i);
166 gemc_gui.processEvents();
172 msg =
" Setting CLHEP Random Engine...";
173 if(use_qt) splash->showMessage(msg.c_str()); gemc_gui.processEvents(); cout << hd_msg << msg << endl;
175 CLHEP::HepRandom::setTheEngine(
new CLHEP::MTwistEngine);
176 string RAND = gemcOpt.
args[
"RANDOM"].args;
181 msg =
" Initializing CLHEP Random Engine from time, cpu clock and process id...";
182 seed = time(NULL)-clock()-getpid() ;
186 seed = atoi(RAND.c_str());
187 msg =
" Initializing CLHEP Random Engine from user seed...";
189 if(use_qt) splash->showMessage(msg.c_str()); gemc_gui.processEvents(); cout << hd_msg << msg << endl;
191 sprintf(seeds,
"%d", seed);
192 msg =
" Random Seed Initialized to: " ;
195 CLHEP::HepRandom::setTheSeed(seed);
197 if(use_qt) splash->showMessage(msg.c_str()); gemc_gui.processEvents(); cout << hd_msg << msg << endl;
200 if(gemcOpt.
args[
"gcard"].args !=
"no")
202 msg =
" Opening GCARD file " + gemcOpt.
args[
"gcard"].args +
"...";
203 if(use_qt) splash->showMessage(msg.c_str()); gemc_gui.processEvents(); cout << hd_msg << msg << endl;
209 map<string, string> sim_condition;
211 for(map<string, opts>::iterator it = gemcOpt.
args.begin(); it != gemcOpt.
args.end(); it++)
213 string key =
"option: " + it->first;
214 if(it->second.type == 0) sim_condition[key] =
stringify(it->second.arg);
215 else sim_condition[key] = it->second.args;
218 for(
unsigned int i=0; i<RunConditions.
gTab_Vec.size(); i++)
220 string key =
"detector: " + RunConditions.
gTab_Vec[i];
221 sim_condition[key] =
"is present";
224 for(map<string, gcard_detector>::iterator it = RunConditions.
gDet_Map.begin(); it != RunConditions.
gDet_Map.end(); it++)
226 if(it->second.get_position().mag2() != 0)
228 string key =
"local shift for " + it->first;
229 sim_condition[key] =
"(" +
stringify(it->second.get_position().x()/mm) +
", " 230 +
stringify(it->second.get_position().y()/mm) +
", " 231 +
stringify(it->second.get_position().z()/mm) +
")mm";
234 if(it->second.get_vrotation().mag2() != 0)
236 string key =
"local rotation for " + it->first;
237 sim_condition[key] =
"(" +
stringify(it->second.get_vrotation().x()/degree) +
", " 238 +
stringify(it->second.get_vrotation().y()/degree) +
", " 239 +
stringify(it->second.get_vrotation().z()/degree) +
")deg";
244 msg =
" Instantiating Run Manager...";
245 if(use_qt) splash->showMessage(msg.c_str()); gemc_gui.processEvents(); cout << hd_msg << msg << endl;
246 G4RunManager *runManager =
new G4RunManager;
250 msg =
" Retrieving gemc Detector Map...";
251 if(use_qt) splash->showMessage(msg.c_str()); gemc_gui.processEvents(); cout << hd_msg << msg << endl;
252 map<string, detector> Hall_Map =
read_detector(gemcOpt, RunConditions);
255 msg =
" Material factory selected: " + gemcOpt.
args[
"MATERIALSDB"].args;
256 if(use_qt) splash->showMessage(msg.c_str()); gemc_gui.processEvents(); cout << hd_msg << msg << endl;
259 map<string, G4Material*> mats = materialSelectedFactory->
initMaterials(RunConditions, gemcOpt);
262 msg =
" Parameter factory selected: " + gemcOpt.
args[
"PARAMETERSDB"].args;
263 if(use_qt) splash->showMessage(msg.c_str()); gemc_gui.processEvents(); cout << hd_msg << msg << endl;
266 map<string, double> gParameters = parameterSelectedFactory->
initParameters(RunConditions, gemcOpt);
268 for(map<string, double>::iterator it = gParameters.begin(); it != gParameters.end(); it++)
270 string key =
"parameter: " + it->first;
271 sim_condition[key] =
stringify(it->second);
275 msg =
" Building gemc Process Hit Factory...";
276 if(use_qt) splash->showMessage(msg.c_str()); gemc_gui.processEvents(); cout << hd_msg << msg << endl;
277 map<string, MPHB_Factory> MProcessHit_Map =
HitProcess_Map(gemcOpt.
args[
"HIT_PROCESS_LIST"].args);
280 msg =
" Retrieving gemc Banks Map...";
281 if(use_qt) splash->showMessage(msg.c_str()); gemc_gui.processEvents(); cout << hd_msg << msg << endl;
282 map<string, MBank> MBank_Map =
read_banks(gemcOpt, MProcessHit_Map);
285 msg =
" Retrieving gemc Magnetic Fields Map...";
286 if(use_qt) splash->showMessage(msg.c_str()); gemc_gui.processEvents(); cout << hd_msg << msg << endl;
294 ExpHall->
mats = &mats;
296 runManager->SetUserInitialization(ExpHall);
300 string phys_list = gemcOpt.
args[
"USE_PHYSICSL"].args ;
301 msg =
" Initializing Physics List " + phys_list +
"...";
302 if(use_qt) splash->showMessage(msg.c_str()); gemc_gui.processEvents(); cout << hd_msg << msg << endl;
304 G4VUserPhysicsList* physics = NULL;
306 G4PhysListFactory factory;
308 if(phys_list ==
"gemc")
311 runManager->SetUserInitialization(physics);
315 if(factory.IsReferencePhysList(phys_list))
316 phys = factory.GetReferencePhysList(phys_list);
318 if(!phys) phys = factory.ReferencePhysList();
320 runManager->SetUserInitialization(phys);
328 double max_step = gemcOpt.
args[
"MAX_FIELD_STEP"].arg;
330 G4TransportationManager::GetTransportationManager()->GetPropagatorInField()->SetLargestAcceptableStep(max_step);
333 msg =
" Initializing Primary Generator Action...";
334 if(use_qt) splash->showMessage(msg.c_str()); gemc_gui.processEvents(); cout << hd_msg << msg << endl;
336 runManager->SetUserAction(gen_action);
340 msg =
" Initializing Event Action...";
341 if(use_qt) splash->showMessage(msg.c_str()); gemc_gui.processEvents(); cout << hd_msg << msg << endl;
344 runManager->SetUserAction(event_action);
348 msg =
" Initializing Stepping Action...";
349 if(use_qt) splash->showMessage(msg.c_str()); gemc_gui.processEvents(); cout << hd_msg << msg << endl;
351 runManager->SetUserAction(SteppingAction);
355 msg =
" Initializing User Interface...";
356 if(use_qt) splash->showMessage(msg.c_str()); gemc_gui.processEvents(); cout << hd_msg << msg << endl;
357 G4UIsession *session = NULL;
359 session =
new G4UIQt(argc,argv);
362 G4VisManager *visManager = NULL;
365 visManager =
new G4VisExecutive;
366 visManager->Initialize();
370 msg =
" Initializing Run Manager...\n";
371 if(use_qt) splash->showMessage(msg.c_str()); gemc_gui.processEvents(); cout << hd_msg << msg << endl;
372 runManager->Initialize();
375 G4UImanager* UImanager = G4UImanager::GetUIpointer();
376 UImanager->SetCoutDestination(NULL);
380 msg =
" Initializing Output Action...";
382 map<string, MOutput_Factory> MProcessOutput_Map =
Output_Map();
389 delete ProcessOutput;
392 event_action->
MOut = &MOutput;
393 event_action->
Out = &MProcessOutput_Map;
400 map<string, MSensitiveDetector*>::iterator it;
402 it->second->MProcessHit_Map = &MProcessHit_Map;
405 msg =
" Executing initial directives...\n";
406 if(use_qt) splash->showMessage(msg.c_str()); gemc_gui.processEvents(); cout << hd_msg << msg << endl;
407 vector<string> init_commands =
init_dmesg(gemcOpt);
408 for(
unsigned int i=0; i<init_commands.size(); i++)
409 UImanager->ApplyCommand(init_commands[i].c_str());
411 string exec_macro =
"/control/execute " + gemcOpt.
args[
"EXEC_MACRO"].args;
416 splash->showMessage(
"Starting GUI...");
417 gemc_gui.processEvents();
424 gemcW.setWindowTitle(
" gemc" );
427 splash->finish(&gemcW);
429 msg =
" Executing initial visual directives...\n";
430 splash->showMessage(msg.c_str()); gemc_gui.processEvents(); cout << hd_msg << msg << endl;
431 vector<string> init_vcommands =
init_dvmesg(gemcOpt, visManager);
432 for(
unsigned int i=0; i<init_vcommands.size(); i++)
434 cout <<
" >> Now executing: " << init_vcommands[i].c_str() << endl;
435 UImanager->ApplyCommand(init_vcommands[i].c_str());
438 if(exec_macro !=
"/control/execute no") UImanager->ApplyCommand(exec_macro.c_str());
439 if(gemcOpt.
args[
"N"].arg>0)
442 sprintf(command,
"/run/beamOn %d", (
int) gemcOpt.
args[
"N"].arg);
443 UImanager->ApplyCommand(command);
446 return gemc_gui.exec();
450 cout <<
" >> Exiting gemc qApp." << endl;
452 if(session != NULL)
delete session;
456 if(gemcOpt.
args[
"N"].arg>0)
459 sprintf(command,
"/run/beamOn %d", (
int) gemcOpt.
args[
"N"].arg);
460 UImanager->ApplyCommand(command);
462 if(exec_macro !=
"/control/execute no") UImanager->ApplyCommand(exec_macro.c_str());
vector< string > init_dmesg(gemc_opts gemcOpt)
General Initialization Routine.
vector< string > init_dvmesg(gemc_opts gemcOpt, G4VisManager *VM)
Initialization Routine for Visualization.
void SetEvtNumber(int N)
Sets Event Number.
materials * getMaterialFactory(map< string, materialFactory > *factory, string materialsMethod)
parameters * getParameterFactory(map< string, parameterFactory > *factory, string parametersMethod)
vector< string > gTab_Vec
Vector of SQL tables names.
map< string, MOutput_Factory > Output_Map()
map< string, MagneticField > get_magnetic_Fields(gemc_opts Opt)
Fills magnetic field maps from Database.
map< string, MBank > read_banks(gemc_opts gemcOpt, map< string, MPHB_Factory > Map)
Fills bank maps according to Hit Process Map.
map< string, MSensitiveDetector * > SeDe_Map
Sensitive detector Map.
map< string, materialFactory > registerMaterialFactories()
map< string, MagneticField > * FieldMap
map< string, G4Material * > * mats
map< string, detector > read_detector(gemc_opts, run_conditions)
Reads detector map from database.
map< string, G4Material * > * mats
Materials Map.
MPrimaryGeneratorAction * gen_action
Generator Action.
map< string, gcard_detector > gDet_Map
Map of gcard_detector. Map Key = detector name.
map< string, MBank > * MBank_Map
Bank Map.
string stringify(double x)
MOutputBaseClass * GetMOutputClass(map< string, MOutput_Factory > *MProcessOutput_Map, string outputType)
Instantiates MOutputBaseClass.
map< string, MOutput_Factory > * Out
MOutput_Factory map.
virtual void SaveSimConditions(MOutputs *, map< string, string >)=0
Pure Virtual Method to save the simulation conditions on the file.
MOutputs * MOut
MOutputs class - contains the output format.
virtual map< string, G4Material * > initMaterials(run_conditions, gemc_opts)=0
map< string, opts > args
Options map.
map< string, detector > * Hall_Map
Detectors Map.
map< string, MSensitiveDetector * > SeDe_Map
Sensitive detector Map.
virtual map< string, double > initParameters(run_conditions, gemc_opts)=0
map< string, detector > * Hall_Map
map< string, parameterFactory > registerParameterFactories()
map< string, MSensitiveDetector * > SeDe_Map
int main(int argc, char **argv)
Main Program
map< string, MPHB_Factory > HitProcess_Map(string experiments)
< Hit in Converter
map< string, MPHB_Factory > * MProcessHit_Map
Hit Process Routine Factory Map.
int Set(int argc, char **args)
Sets map from command line arguments.