17 #include "G4Version.hh"
18 #include "G4UImanager.hh"
19 #include "Randomize.hh"
20 #include "G4PhysListFactory.hh"
23 #include "G4VisExecutive.hh"
27 #include "G4UIExecutive.hh"
31 #include "GGSVersion.h"
40 #include "montecarlo/generators/manager/GGSGeneratorActionsManager.h"
42 #include "montecarlo/physicslists/GGSCRMCPhysicsList.h"
48 std::cout <<
"Usage: GGSPenny [options] \n";
49 std::cout <<
"This is the GGS main MonteCarlo program\n\n";
50 std::cout <<
"Run type selection\n";
51 std::cout <<
"------------------\n";
52 std::cout <<
" -X, --interactive interactive mode [default: false]\n\n";
53 std::cout <<
" -d, --data-card FILE data card filename [default: not set]\n\n";
54 std::cout <<
"If only -d is specified the program will run in batch mode.\n";
55 std::cout <<
"If both options are specified, the datacard will be processed before entering the interactive mode.\n\n";
56 std::cout <<
"Configuration options\n";
57 std::cout <<
"---------------------\n";
58 std::cout <<
" -g, --geometry FILE full path and name of the geometry; can be a .so or a .gdml.\n";
59 std::cout <<
" -gd, --geo-data-card FILE data card filename for geometry configuration [default: not set]\n\n";
60 std::cout <<
" -pl, --physics-list NAME physics list (standard list name or full path of physics list .so library) [default: QGSP_BERT]\n\n";
61 std::cout <<
" -pd, --physlist-data-card FILE data card filename for physics list configuration [default: not set]\n\n";
62 std::cout <<
" -ap, --action-plugin FILE full path and name of the plugin user and generator action library\n";
63 std::cout <<
" May be repeated to load many libraries: -ap libUserAction.so -ap libGeneratorAction.so\n\n";
64 std::cout <<
" -ro, --root-output-file FILE default ROOT output filename (may be overridden in datacard for each action)\n\n";
65 std::cout <<
" -os, --output-suffix SUFFIX output file suffix [default: " "]\n\n";
66 std::cout <<
" --seed1 INT first random seed [default: 1]\n\n";
67 std::cout <<
" --seed2 INT second random seed [default: 2]\n\n";
68 std::cout <<
" -s, --input-seed-file FILE file containing input random seeds [default: not set]\n\n";
69 std::cout <<
"Configuration options can either be given as command line parameters or placed in an input file.\n";
70 std::cout <<
"File syntax is the same as the above specified commands, one command per line. Set the input file via command line as:\n\n";
71 std::cout <<
" -i, --input-file FILE file containing input arguments [default: not set]\n\n";
72 std::cout <<
"Miscellaneous\n";
73 std::cout <<
"-------------\n";
74 std::cout <<
" -v, --verbose be verbose [default: false]\n\n";
75 std::cout <<
" -V, --version displays software version and exit\n\n";
76 std::cout <<
" -h, --help display this help and exit\n\n";
77 std::cout <<
"\nTo run GGSPenny either the -d (data card) or the -X (interactive) option MUST be set!\n";
78 std::cout <<
"Report bugs to: mori@fi.infn.it \n";
81 void GGSPennyVersion() {
82 std::cout <<
"GGSPenny simulation software\n";
83 std::cout <<
"Using GGS " << GGSVERSION << std::endl;
88 G4String rootOutputFile =
"";
89 G4String outputSuffix =
"";
90 G4String dataCard =
"";
91 G4String geoDataCard =
"";
92 G4String physListDataCard =
"";
93 G4String inputFile =
"";
94 G4String inputSeedFile =
"";
95 G4String geometry =
"";
96 G4String physicsListName =
"FTFP_BERT";
97 std::vector<G4String> actionPluginFiles;
98 G4bool interactiveMode =
false;
102 using namespace GGSPenny;
105 std::cout <<
"==============> MonteCarlo globals used for this run <===============" << std::endl;
106 std::cout <<
"dataCard : " << dataCard.c_str() << std::endl;
107 std::cout <<
"geometry : " << geometry.c_str() << std::endl;
108 std::cout <<
"geoDataCard : " << geoDataCard.c_str() << std::endl;
109 std::cout <<
"physicsListName : " << physicsListName.c_str() << std::endl;
110 std::cout <<
"physListDataCard: " << physListDataCard.c_str() << std::endl;
111 std::cout <<
"rootOutputFile : " << rootOutputFile.c_str() << std::endl;
112 std::cout <<
"outputSuffix : " << outputSuffix.c_str() << std::endl;
113 std::cout <<
"inputSeedFile : " << inputSeedFile.c_str() << std::endl;
114 std::cout <<
"seed1 : " << seed1 << std::endl;
115 std::cout <<
"seed2 : " << seed2 << std::endl;
116 std::cout <<
"inputFile : " << inputFile.c_str() << std::endl;
117 std::cout <<
"interactiveMode : " << interactiveMode << std::endl;
118 std::cout <<
"======================================================================" << std::endl;
121 int HandleInputPar(
int argc,
char **argv) {
122 static const std::string routineName(
"HandleInputPar");
124 GGSSmartLog::verboseLevel = GGSSmartLog::WARNING;
125 int vLevel = GGSSmartLog::INFO;
129 if (!strcmp(argv[i],
"-h") || !strcmp(argv[i],
"--help")) {
134 if (!strcmp(argv[i],
"-V") || !strcmp(argv[i],
"--version")) {
139 if (!strcmp(argv[i],
"--")) {
143 else if (!strcmp(argv[i],
"-d") || !strcmp(argv[i],
"--data-card")) {
151 else if (!strcmp(argv[i],
"-gd") || !strcmp(argv[i],
"--geo-data-card")) {
156 geoDataCard = argv[i];
159 else if (!strcmp(argv[i],
"-g") || !strcmp(argv[i],
"--geometry")) {
167 else if (!strcmp(argv[i],
"-pl") || !strcmp(argv[i],
"--physics-list")) {
172 physicsListName = argv[i];
175 else if (!strcmp(argv[i],
"-pd") || !strcmp(argv[i],
"--physlist-data-card")) {
180 physListDataCard = argv[i];
183 else if (!strcmp(argv[i],
"-ap") || !strcmp(argv[i],
"--action-plugin")) {
188 actionPluginFiles.push_back(G4String(argv[i]));
191 else if (!strcmp(argv[i],
"-X") || !strcmp(argv[i],
"--interactive")) {
192 interactiveMode =
true;
195 else if (!strcmp(argv[i],
"-ro") || !strcmp(argv[i],
"--root-output-file")) {
200 rootOutputFile = argv[i];
203 else if (!strcmp(argv[i],
"-os") || !strcmp(argv[i],
"--output-suffix")) {
208 outputSuffix = argv[i];
211 else if (!strcmp(argv[i],
"-i") || !strcmp(argv[i],
"--input-file")) {
219 else if (!strcmp(argv[i],
"-s") || !strcmp(argv[i],
"--input-seed-file")) {
224 inputSeedFile = argv[i];
227 else if (!strcmp(argv[i],
"--seed1")) {
232 seed1 = atoi(argv[i]);
235 else if (!strcmp(argv[i],
"--seed2")) {
240 seed2 = atoi(argv[i]);
243 else if (!strcmp(argv[i],
"-v") || !strcmp(argv[i],
"--verbose")) {
244 std::string vLevStr(argv[++i]);
245 if (vLevStr ==
"error")
246 vLevel = GGSSmartLog::ERROR;
247 else if (vLevStr ==
"warning")
248 vLevel = GGSSmartLog::WARNING;
249 else if (vLevStr ==
"normal" || vLevStr ==
"info")
250 vLevel = GGSSmartLog::INFO;
251 else if (vLevStr ==
"debug")
252 vLevel = GGSSmartLog::DEBUG;
253 else if (vLevStr ==
"deepdeb")
254 vLevel = GGSSmartLog::DEEPDEB;
256 COUT(WARNING) <<
"Unrecognized verbosity level: " << vLevStr <<
". Ignoring." <<
ENDL;
261 COUT(WARNING)<<
"Unidentified input argument \"" << argv[i] <<
"\". Ignoring." << std::endl;
270 GGSSmartLog::verboseLevel = vLevel;
274 int main(
int argc,
char** argv) {
276 static const std::string routineName(
"GGSPenny");
278 if (HandleInputPar(argc, argv))
284 char *cfileArgv[1000];
285 if (strcmp(inputFile.c_str(),
"")) {
286 std::string mych[1000];
290 while (i < nPar - 1) {
291 cfileArgv[i] =
new char[(mych[i]).length()];
292 strcpy(cfileArgv[i], (mych[i]).c_str());
295 if (HandleInputPar(nPar - 1, cfileArgv))
304 cfileArgv[i] =
new char[1000];
305 cfileArgv[i] = (argv[i]);
310 if (!strcmp(dataCard.c_str(),
"") && !interactiveMode) {
315 if (geometry ==
"") {
316 COUT(ERROR) <<
"No geometry provided. Exit." <<
ENDL;
325 COUT(DEBUG) <<
"Create the run manager." <<
ENDL;
329 COUT(DEBUG) <<
"Create the detector." <<
ENDL;
331 if (geometry.length() > 4 && geometry.substr(geometry.length() - 5) ==
".gdml") {
337 runManager->SetUserInitialization(detector);
339 G4VUserPhysicsList *physicsList =
nullptr;
341 G4PhysListFactory *physListFactory =
new G4PhysListFactory;
342 if (physListFactory->IsReferencePhysList(physicsListName)) {
343 physicsList = physListFactory->GetReferencePhysList(physicsListName);
346 if (physicsList ==
nullptr) {
348 if (physicsListName ==
"GGSCRMC") {
354 if (physicsList ==
nullptr) {
357 if (physicsList == NULL) {
358 COUT(WARNING) <<
"User physics list has NOT been loaded. Fall back to standard list." <<
ENDL;
362 if (physicsList == NULL) {
363 COUT(INFO) <<
"Load standard physics list: FTFP_BERT." <<
ENDL;
364 physicsListName =
"FTFP_BERT";
365 physicsList = physListFactory->GetReferencePhysList(physicsListName);
368 runManager->SetUserInitialization(physicsList);
371 GGSGeneratorActionsManager::GetInstance();
374 COUT(DEBUG) <<
"Initialize the user actions manager." <<
ENDL;
376 runManager->SetUserAction((G4UserSteppingAction*) actionsManager);
377 runManager->SetUserAction((G4UserTrackingAction*) actionsManager);
378 runManager->SetUserAction((G4UserEventAction*) actionsManager);
379 runManager->SetUserAction((G4UserRunAction*) actionsManager);
380 runManager->SetUserAction((G4UserStackingAction*) actionsManager);
386 for (
unsigned int i = 0; i < actionPluginFiles.size(); i++)
390 COUT(DEBUG) <<
"Initialize output." <<
ENDL;
391 if (rootOutputFile !=
"")
396 simInfo.SetName(
"GGSSimInfo");
403 simInfo.
seed1 = seed1;
404 simInfo.
seed2 = seed2;
408 G4UImanager* UImanager = G4UImanager::GetUIpointer();
411 if (physListDataCard !=
"") {
412 COUT(DEBUG) <<
"Execute physics list data card" <<
ENDL;
413 std::ifstream fileChecker(physListDataCard);
414 if (!fileChecker.good()) {
416 <<
"Physics list data card file " << physListDataCard <<
" not found." <<
ENDL;
419 UImanager->ExecuteMacroFile(physListDataCard);
423 COUT(DEBUG) <<
"Initialize run manager." <<
ENDL;
425 runManager->Initialize();
426 }
catch (std::runtime_error&) {
427 COUT(ERROR) <<
"Impossible to set up the geometry. Exit." <<
ENDL;
429 delete physListFactory;
437 gROOT->GetInterpreter();
440 G4VisManager* visManager =
new G4VisExecutive;
441 visManager->Initialize();
444 COUT(DEBUG) <<
"Initialize random generator." <<
ENDL;
446 CLHEP::HepRandom::setTheEngine(
new CLHEP::RanecuEngine);
447 G4long seeds[2] = { seed1, seed2 };
448 CLHEP::HepRandom::setTheSeeds(seeds, 0);
449 if (strcmp(inputSeedFile.c_str(),
"")) {
450 G4String command =
"/random/resetEngineFrom ";
451 UImanager->ApplyCommand(command + inputSeedFile);
453 CLHEP::HepRandom::showEngineStatus();
455 if (dataCard !=
"") {
456 if (!interactiveMode)
457 COUT(DEBUG) <<
"Start batch mode." <<
ENDL;
458 G4String command =
"/control/execute ";
459 G4String fileName = dataCard;
460 UImanager->ApplyCommand(command + fileName);
462 if (interactiveMode) {
463 if (dataCard !=
"") {
464 COUT(DEBUG) <<
"Start configured interactive mode." <<
ENDL;
467 COUT(DEBUG) <<
"Start interactive mode." <<
ENDL;
471 G4UIExecutive* ui =
new G4UIExecutive(nPar, cfileArgv);
475 if (stat(
"vis.mac", &st) == 0)
476 UImanager->ApplyCommand(
"/control/execute vis.mac");
479 if (stat(
"visTutor/gui.mac", &st) == 0)
480 UImanager->ApplyCommand(
"/control/execute visTutor/gui.mac");
487 COUT(DEBUG) <<
"Job termination." <<
ENDL;
498 delete physListFactory;
TString geometry
The geometry used for the simulation.
void AddAction(GGSUserAction *userAction)
Adds a general user action.
static GGSMCPluginManager & GetInstance()
Get the singleton instance.
#define COUT(level)
Smart log macro. It writes on stdout only if the specified verbosity level is lesser than the maximum...
Class for GGS detector construction.
TString G4Version
Geant 4 version (as defined in G4Version.hh)
bool LoadPlugin(const std::string &libName)
Loads a plugin library.
void SetDefaultFileBase(const path &newFileBase)
Sets the default file name.
TString physicsList
The physics list used for the simulation.
TString geoDataCard
The data card file used for geometry configuration.
The GGS ser actions manager.
Action which dumps the simulation status on standard output.
static GGSRootFileService & GetInstance()
Get reference to GGSRootFileService unique instance.
void SetSuffix(const std::string &suffix)
Sets the suffix for file names.
void SetSimInfo(const GGSTSimInfo &simInfo)
Set the simulation info object to be saved on output files.
UInt_t seed2
Second random generator seed.
UInt_t seed1
First random generator seed.
TString dataCard
The data card file used for the simulation.
A class to store simulation informations.
G4VUserPhysicsList * LoadPhysicsListPlugin(const std::string &libName)
Loads a physics list plugin library.
static GGSUserActionsManager * GetInstance()
Get the singleton instance.
Physics list based on CRMC for high-energy hadron-hadron interactions.
TString GGSVersion
GGS version (as defined by GGSVERSION in Version.h)
A run manager for GGS simulations.