17 #include "G4PhysListFactory.hh"
18 #include "G4UImanager.hh"
19 #include "G4Version.hh"
20 #include "Randomize.hh"
23 #include "G4VisExecutive.hh"
27 #include "G4UIExecutive.hh"
31 #include "GGSVersion.h"
34 #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";
56 <<
"If both options are specified, the datacard will be processed before entering the interactive mode.\n\n";
57 std::cout <<
"Configuration options\n";
58 std::cout <<
"---------------------\n";
59 std::cout <<
" -g, --geometry FILE full path and name of the geometry; can be a .so or a .gdml.\n";
60 std::cout <<
" -gd, --geo-data-card FILE data card filename for geometry configuration [default: not set]\n\n";
61 std::cout <<
" -pl, --physics-list NAME physics list (standard list name or full path of physics list .so "
62 "library) [default: QGSP_BERT]\n\n";
64 <<
" -pd, --physlist-data-card FILE data card filename for physics list configuration [default: not set]\n\n";
65 std::cout <<
" -ap, --action-plugin FILE full path and name of the plugin user and generator action library\n";
66 std::cout <<
" May be repeated to load many libraries: -ap libUserAction.so -ap "
67 "libGeneratorAction.so\n\n";
68 std::cout <<
" -ro, --root-output-file FILE default ROOT output filename (may be overridden in datacard for each "
70 std::cout <<
" -os, --output-suffix SUFFIX output file suffix [default: "
72 std::cout <<
" --seed1 INT first random seed [default: 1]\n\n";
73 std::cout <<
" --seed2 INT second random seed [default: 2]\n\n";
74 std::cout <<
" -s, --input-seed-file FILE file containing input random seeds [default: not set]\n\n";
75 std::cout <<
"Configuration options can either be given as command line parameters or placed in an input file.\n";
76 std::cout <<
"File syntax is the same as the above specified commands, one command per line. Set the input file via "
77 "command line as:\n\n";
78 std::cout <<
" -i, --input-file FILE file containing input arguments [default: not set]\n\n";
79 std::cout <<
"Miscellaneous\n";
80 std::cout <<
"-------------\n";
81 std::cout <<
" -v, --verbose be verbose [default: false]\n\n";
82 std::cout <<
" -V, --version displays software version and exit\n\n";
83 std::cout <<
" -h, --help display this help and exit\n\n";
84 std::cout <<
"\nTo run GGSPenny either the -d (data card) or the -X (interactive) option MUST be set!\n";
85 std::cout <<
"Report bugs to: mori@fi.infn.it \n";
88 void GGSPennyVersion() {
89 std::cout <<
"GGSPenny simulation software\n";
90 std::cout <<
"Using GGS " << GGSVERSION << std::endl;
95 G4String rootOutputFile =
"";
96 G4String outputSuffix =
"";
97 G4String dataCard =
"";
98 G4String geoDataCard =
"";
99 G4String physListDataCard =
"";
100 G4String inputFile =
"";
101 G4String inputSeedFile =
"";
102 G4String geometry =
"";
103 G4String physicsListName =
"FTFP_BERT";
104 std::vector<G4String> actionPluginFiles;
105 G4bool interactiveMode =
false;
109 using namespace GGSPenny;
112 std::cout <<
"==============> MonteCarlo globals used for this run <===============" << std::endl;
113 std::cout <<
"dataCard : " << dataCard.c_str() << std::endl;
114 std::cout <<
"geometry : " << geometry.c_str() << std::endl;
115 std::cout <<
"geoDataCard : " << geoDataCard.c_str() << std::endl;
116 std::cout <<
"physicsListName : " << physicsListName.c_str() << std::endl;
117 std::cout <<
"physListDataCard: " << physListDataCard.c_str() << std::endl;
118 std::cout <<
"rootOutputFile : " << rootOutputFile.c_str() << std::endl;
119 std::cout <<
"outputSuffix : " << outputSuffix.c_str() << std::endl;
120 std::cout <<
"inputSeedFile : " << inputSeedFile.c_str() << std::endl;
121 std::cout <<
"seed1 : " << seed1 << std::endl;
122 std::cout <<
"seed2 : " << seed2 << std::endl;
123 std::cout <<
"inputFile : " << inputFile.c_str() << std::endl;
124 std::cout <<
"interactiveMode : " << interactiveMode << std::endl;
125 std::cout <<
"======================================================================" << std::endl;
128 int HandleInputPar(
int argc,
char **argv) {
129 static const std::string routineName(
"HandleInputPar");
131 GGSSmartLog::verboseLevel = GGSSmartLog::WARNING;
132 int vLevel = GGSSmartLog::INFO;
136 if (!strcmp(argv[i],
"-h") || !strcmp(argv[i],
"--help")) {
141 if (!strcmp(argv[i],
"-V") || !strcmp(argv[i],
"--version")) {
146 if (!strcmp(argv[i],
"--")) {
150 else if (!strcmp(argv[i],
"-d") || !strcmp(argv[i],
"--data-card")) {
158 else if (!strcmp(argv[i],
"-gd") || !strcmp(argv[i],
"--geo-data-card")) {
163 geoDataCard = argv[i];
166 else if (!strcmp(argv[i],
"-g") || !strcmp(argv[i],
"--geometry")) {
174 else if (!strcmp(argv[i],
"-pl") || !strcmp(argv[i],
"--physics-list")) {
179 physicsListName = argv[i];
182 else if (!strcmp(argv[i],
"-pd") || !strcmp(argv[i],
"--physlist-data-card")) {
187 physListDataCard = argv[i];
190 else if (!strcmp(argv[i],
"-ap") || !strcmp(argv[i],
"--action-plugin")) {
195 actionPluginFiles.push_back(G4String(argv[i]));
198 else if (!strcmp(argv[i],
"-X") || !strcmp(argv[i],
"--interactive")) {
199 interactiveMode =
true;
202 else if (!strcmp(argv[i],
"-ro") || !strcmp(argv[i],
"--root-output-file")) {
207 rootOutputFile = argv[i];
210 else if (!strcmp(argv[i],
"-os") || !strcmp(argv[i],
"--output-suffix")) {
215 outputSuffix = argv[i];
218 else if (!strcmp(argv[i],
"-i") || !strcmp(argv[i],
"--input-file")) {
226 else if (!strcmp(argv[i],
"-s") || !strcmp(argv[i],
"--input-seed-file")) {
231 inputSeedFile = argv[i];
234 else if (!strcmp(argv[i],
"--seed1")) {
239 seed1 = atoi(argv[i]);
242 else if (!strcmp(argv[i],
"--seed2")) {
247 seed2 = atoi(argv[i]);
250 else if (!strcmp(argv[i],
"-v") || !strcmp(argv[i],
"--verbose")) {
251 std::string vLevStr(argv[++i]);
252 if (vLevStr ==
"error")
253 vLevel = GGSSmartLog::ERROR;
254 else if (vLevStr ==
"warning")
255 vLevel = GGSSmartLog::WARNING;
256 else if (vLevStr ==
"normal" || vLevStr ==
"info")
257 vLevel = GGSSmartLog::INFO;
258 else if (vLevStr ==
"debug")
259 vLevel = GGSSmartLog::DEBUG;
260 else if (vLevStr ==
"deepdeb")
261 vLevel = GGSSmartLog::DEEPDEB;
263 COUT(WARNING) <<
"Unrecognized verbosity level: " << vLevStr <<
". Ignoring." <<
ENDL;
268 COUT(WARNING) <<
"Unidentified input argument \"" << argv[i] <<
"\". Ignoring." << std::endl;
276 GGSSmartLog::verboseLevel = vLevel;
280 int main(
int argc,
char **argv) {
282 static const std::string routineName(
"GGSPenny");
284 if (HandleInputPar(argc, argv))
290 char *cfileArgv[1000];
291 if (strcmp(inputFile.c_str(),
"")) {
292 std::string mych[1000];
296 while (i < nPar - 1) {
297 cfileArgv[i] =
new char[(mych[i]).length()];
298 strcpy(cfileArgv[i], (mych[i]).c_str());
301 if (HandleInputPar(nPar - 1, cfileArgv))
309 cfileArgv[i] =
new char[1000];
310 cfileArgv[i] = (argv[i]);
315 if (!strcmp(dataCard.c_str(),
"") && !interactiveMode) {
320 if (geometry ==
"") {
321 COUT(ERROR) <<
"No geometry provided. Exit." <<
ENDL;
328 if (dataCard !=
"" && stat(dataCard.c_str(), &st) != 0) {
329 COUT(ERROR) <<
"Datacard " << dataCard <<
" not found." <<
ENDL;
332 if (geoDataCard !=
"" && stat(geoDataCard.c_str(), &st) != 0) {
333 COUT(ERROR) <<
"Geometry datacard " << geoDataCard <<
" not found." <<
ENDL;
336 if (physListDataCard !=
"" && stat(physListDataCard.c_str(), &st) != 0) {
337 COUT(ERROR) <<
"Physics list datacard " << physListDataCard <<
" not found." <<
ENDL;
347 COUT(DEBUG) <<
"Create the run manager." <<
ENDL;
351 COUT(DEBUG) <<
"Create the detector." <<
ENDL;
353 if (geometry.length() > 4 && geometry.substr(geometry.length() - 5) ==
".gdml") {
358 runManager->SetUserInitialization(detector);
360 G4VUserPhysicsList *physicsList =
nullptr;
362 G4PhysListFactory *physListFactory =
new G4PhysListFactory;
363 if (physListFactory->IsReferencePhysList(physicsListName)) {
364 physicsList = physListFactory->GetReferencePhysList(physicsListName);
367 if (physicsList ==
nullptr) {
369 if (physicsListName ==
"GGSCRMC") {
375 if (physicsList ==
nullptr) {
378 if (physicsList == NULL) {
379 COUT(WARNING) <<
"User physics list has NOT been loaded. Fall back to standard list." <<
ENDL;
383 if (physicsList == NULL) {
384 COUT(INFO) <<
"Load standard physics list: FTFP_BERT." <<
ENDL;
385 physicsListName =
"FTFP_BERT";
386 physicsList = physListFactory->GetReferencePhysList(physicsListName);
390 G4UImanager *UImanager = G4UImanager::GetUIpointer();
393 if (physListDataCard !=
"") {
394 COUT(DEBUG) <<
"Execute physics list data card" <<
ENDL;
395 G4String command =
"/control/execute ";
396 if (UImanager->ApplyCommand(command + physListDataCard) != 0) {
397 COUT(ERROR) <<
"Error in executing physics list datacard " << physListDataCard <<
ENDL;
402 runManager->SetUserInitialization(physicsList);
405 GGSGeneratorActionsManager::GetInstance();
408 COUT(DEBUG) <<
"Initialize the user actions manager." <<
ENDL;
410 runManager->SetUserAction((G4UserSteppingAction *)actionsManager);
411 runManager->SetUserAction((G4UserTrackingAction *)actionsManager);
412 runManager->SetUserAction((G4UserEventAction *)actionsManager);
413 runManager->SetUserAction((G4UserRunAction *)actionsManager);
414 runManager->SetUserAction((G4UserStackingAction *)actionsManager);
420 for (
unsigned int i = 0; i < actionPluginFiles.size(); i++)
424 COUT(DEBUG) <<
"Initialize output." <<
ENDL;
425 if (rootOutputFile !=
"")
430 simInfo.SetName(
"GGSSimInfo");
437 simInfo.
seed1 = seed1;
438 simInfo.
seed2 = seed2;
442 COUT(DEBUG) <<
"Initialize run manager." <<
ENDL;
444 runManager->Initialize();
445 }
catch (std::runtime_error &exc) {
446 COUT(ERROR) <<
"Error while building the geometry: " << exc.what() <<
ENDL;
448 delete physListFactory;
451 COUT(ERROR) <<
"Impossible to set up the geometry due to an unknown exception. Exit." <<
ENDL;
453 delete physListFactory;
461 gROOT->GetInterpreter();
464 G4VisManager *visManager =
new G4VisExecutive;
465 visManager->Initialize();
468 COUT(DEBUG) <<
"Initialize random generator." <<
ENDL;
470 CLHEP::HepRandom::setTheEngine(
new CLHEP::RanecuEngine);
471 G4long seeds[2] = {seed1, seed2};
472 CLHEP::HepRandom::setTheSeeds(seeds, 0);
473 if (strcmp(inputSeedFile.c_str(),
"")) {
474 G4String command =
"/random/resetEngineFrom ";
475 UImanager->ApplyCommand(command + inputSeedFile);
477 CLHEP::HepRandom::showEngineStatus();
479 if (dataCard !=
"") {
480 if (!interactiveMode) {
481 COUT(DEBUG) <<
"Start batch mode." <<
ENDL;
483 G4String command =
"/control/execute ";
484 if (UImanager->ApplyCommand(command + dataCard) != 0) {
485 COUT(ERROR) <<
"Error in executing datacard " << dataCard <<
ENDL;
489 if (interactiveMode) {
490 if (dataCard !=
"") {
491 COUT(DEBUG) <<
"Start configured interactive mode." <<
ENDL;
493 COUT(DEBUG) <<
"Start interactive mode." <<
ENDL;
497 G4UIExecutive *ui =
new G4UIExecutive(nPar, cfileArgv);
500 if (stat(
"vis.mac", &st) == 0) {
501 if (UImanager->ApplyCommand(
"/control/execute vis.mac") != 0) {
502 COUT(ERROR) <<
"Error in executing vis.mac visualization macro." <<
ENDL;
508 if (stat(
"visTutor/gui.mac", &st) == 0) {
509 if (UImanager->ApplyCommand(
"/control/execute visTutor/gui.mac") != 0) {
510 COUT(ERROR) <<
"Error in executing visTutor/gui.mac visualization macro." <<
ENDL;
520 COUT(DEBUG) <<
"Job termination." <<
ENDL;
531 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.