#ifdef G4MULTITHREADED #include "G4MTRunManager.hh" #else #include "G4RunManager.hh" #endif #include "G4UImanager.hh" #include "G4UIterminal.hh" #include "G4UItcsh.hh" #ifdef G4UI_USE_XM #include "G4UIXm.hh" #endif #include "Randomize.hh" #ifdef G4VIS_USE #include "G4VisExecutive.hh" #endif #ifdef G4UI_USE #include "G4UIExecutive.hh" #endif #include "SolidRunAction.hh" #include "Shielding.hh" #include "QGSP_BIC_HP.hh" #include "SolidDetectorConstruction.hh" #include "NemenixDetectorConstruction.hh" #include "SM1DetectorConstruction.hh" #include "Phase1DetectorConstruction.hh" #include "G4VUserDetectorConstruction.hh" #include "SolidPhysicsList.hh" #include "SolidActionInitialization.hh" #include "SolidInputParser.hh" #include "TString.h" #include "TFile.h" void Help() { // Print help message G4cout << "This is the help message" << G4endl; G4cout << "run this program as ./SolidSim inputfile.mac [-option value] or as ./SolidSim [-option value]" << G4endl; G4cout << "\ninputfile.mac is a macro file with the typical G4 and SolidSim macro commands" << G4endl; G4cout << "\nposible options:" << G4endl; G4cout << " -i inputfile.mac : macro file with the typical G4 and SolidSim macro commands" << G4endl; G4cout << " -o outputfile.root : root file with the simulation output, default EventData.root " << G4endl; G4cout << " -f cosmicsfile : input file for cosmics simulations" << G4endl; G4cout << " -n nevents : set the number of events to be simulated, nevents must be an integer number" << G4endl; G4cout << " -s seed : set the initial random seed, seed must be an integer number" << G4endl; G4cout << " -h : see this help message" << G4endl << G4endl; exit(0); } int main(int argc,char** argv) { G4cout << " " << G4endl << " ##### ##### ##### " << G4endl << " # # #### # # ##### # # # # # # # # # " << G4endl << " # # # # # # # # # ## ## # # # " << G4endl << " ##### # # # # # # ##### # # ## # # # ##### " << G4endl << " # # # # # # # # # # # # # # " << G4endl << " # # # # # # # # # # # # # # # # " << G4endl << " ##### #### ###### # ##### ##### # # # ## ####### " << G4endl << " " << G4endl << "============================================================================="<< G4endl << G4endl << G4endl; G4String exe_macro="vis.mac"; G4String output_filename="EventData.root"; G4String generator_filename=""; G4int verbosityLevel=1; G4long seed = -1; // If user doesn't specify seed, CPU clock will be used for seed in SolidRunAction G4int nEvents = 0; SolidInputParser input(argc, argv); if (input.cmdOptionExists("-h") ){ Help(); } const std::string &macfilename = input.getCmdOption("-i"); if (!macfilename.empty()){ exe_macro=macfilename; } else if (argc>1) { exe_macro = argv[1]; } else { G4cout << "No input macro defined, using default and entering to interactive mode!!" << G4endl; } const std::string &filename = input.getCmdOption("-f"); if (!filename.empty()){ generator_filename = filename; } const std::string &outputfilename = input.getCmdOption("-o"); if (!outputfilename.empty()){ output_filename = outputfilename; } const std::string &vseed = input.getCmdOption("-s"); if (!vseed.empty()){ seed = std::stoi(vseed); } const std::string &vn = input.getCmdOption("-n"); if (!vn.empty()) nEvents = std::stoi(vn); bool FindSolidBeamOn = false; bool FindRunBeamOn = false; //Print running conditions G4cout << "Execution macro=" << exe_macro << "\nOutput file name=" << output_filename << G4endl; if (generator_filename != "") G4cout << "Generator input file: " << generator_filename << G4endl; if (nEvents > 0) G4cout << "Number of events to be simulated: " << nEvents << G4endl; if (exe_macro != "vis.mac"){ FindSolidBeamOn = input.FindBeamOn(exe_macro, "/Solid/beamOn"); FindRunBeamOn = input.FindBeamOn(exe_macro, "/run/beamOn"); if ((nEvents > 0 || FindSolidBeamOn) && FindRunBeamOn){ G4cerr << G4endl << " ERROR: Use of /run/beamOn in the input_macro not allowed in combination with \"-n\" and \"/Solid/beamOn\"" << G4endl; G4cerr << " Please modify your macro and use /Solid/beamOn" << G4endl << G4endl; return 0; } } TFile *outp = new TFile(output_filename,"RECREATE"); // choose the Random engine //G4Random::setTheEngine(new CLHEP::RanecuEngine); G4Random::setTheEngine(new CLHEP::Ranlux64Engine);//RanecuEngine); if (seed>-1) CLHEP::HepRandom:: setTheSeed(seed); // Construct the run manager //#ifdef G4MULTITHREADED // G4MTRunManager* runManager = new G4MTRunManager; //runManager->SetNumberOfThreads(2); //#else G4RunManager* runManager = new G4RunManager; //#endif #ifdef G4VIS_USE // visualization manager G4VisManager* visManager = new G4VisExecutive; visManager->Initialize(); #endif //#ifdef G4MULTITHREADED // G4MTRunManager* runManager = new G4MTRunManager; // G4int nThreads = G4Threading::G4GetNumberOfCores(); /// if (argc==3) nThreads = G4UIcommand::ConvertToInt(argv[2]); // G4cout << "number of threads: " << nThreads << G4endl; // runManager->SetNumberOfThreads(nThreads); //#else //// my Verbose output class // G4VSteppingVerbose::SetInstance(new SteppingVerbose); // G4RunManager* runManager = new G4RunManager; //#endif // set mandatory initialization classes // Use Nemenix detector // SolidDetectorConstruction* detector = new NemenixDetectorConstruction; // Use SM1 detector // SolidDetectorConstruction* detector = new SM1DetectorConstruction(verbosityLevel); // Use Phase1 detector SolidDetectorConstruction* detector = new Phase1DetectorConstruction(verbosityLevel); // SoLid standard G4VModularPhysicsList* physicsList = new SolidPhysicsList(verbosityLevel); // old lists used for cosmic-ray: not to be used anymore (see docDB 902-v1) // G4VModularPhysicsList* physicsList = new QGSP_BIC_HP(verbosityLevel); // G4VModularPhysicsList* physicsList = new Shielding(verbosityLevel); runManager->SetUserInitialization(detector); runManager->SetUserInitialization(physicsList); runManager->SetUserInitialization(new SolidActionInitialization(detector, outp, seed, generator_filename)); runManager->Initialize(); G4UImanager* UImanager = G4UImanager::GetUIpointer(); // Define UI session for interactive mode. if(argc == 1) { #ifdef G4UI_USE G4UIExecutive* ui = new G4UIExecutive(argc, argv); #ifdef G4VIS_USE UImanager->ApplyCommand("/control/execute vis.mac"); #endif ui->SessionStart(); delete ui; #endif } // Batch mode else { G4String command = "/control/execute "; G4String fileName = exe_macro; UImanager->ApplyCommand(command+fileName); SolidRunAction *runac = (SolidRunAction*)(G4RunManager::GetRunManager()->GetUserRunAction()); if (nEvents == 0) nEvents = runac->GetNevt(); if (nEvents > 0) { G4cout << "Running: " << nEvents << " events " << G4endl; runManager->BeamOn(nEvents); } else G4cerr << G4endl << " ERROR : nEvents = 0. Set Nevents in the macro (/Solid/beamOn ) or as input parameters (-n ) " << G4endl << " exiting... " << G4endl; } #ifdef G4VIS_USE if(visManager) delete visManager; #endif delete runManager; return 0; }