From 716512bdba75f0745cbf326b734b12af0c0cb8ca Mon Sep 17 00:00:00 2001 From: matta <matta@npt> Date: Wed, 17 Nov 2010 16:18:11 +0000 Subject: [PATCH] * Add NPOption Manager to NPS --- NPSimulation/Simulation.cc | 179 ++++++++++++++++++------------------- 1 file changed, 88 insertions(+), 91 deletions(-) diff --git a/NPSimulation/Simulation.cc b/NPSimulation/Simulation.cc index 1c4d652cb..0a49c6b35 100644 --- a/NPSimulation/Simulation.cc +++ b/NPSimulation/Simulation.cc @@ -13,103 +13,100 @@ #ifdef G4VIS_USE #include "G4VisExecutive.hh" #endif -// NPS Source +// NPS headers #include "EventAction.hh" #include "VDetector.hh" +//NPL headers +#include "NPOptionManager.h" #include "RootOutput.h" -// ROOT Source +// ROOT headers #include "TTree.h" #include "TFile.h" // STL #include <vector> int main(int argc, char** argv) -{ - - if (argc != 3) { - cout << "you need to specify both a Reaction file and a Detector file such as : Simulation myReaction.reaction myDetector.detector" << endl ; - return 0; - } - - // Getting arguments - G4String EventGeneratorFileName = argv[1]; - G4String DetectorFileName = argv[2]; - - //my Verbose output class - G4VSteppingVerbose::SetInstance(new SteppingVerbose); - - //Construct the default run manager - G4RunManager* runManager = new G4RunManager; - - //set mandatory initialization classes - DetectorConstruction* detector = new DetectorConstruction(); - runManager->SetUserInitialization(detector); - - PhysicsList* physics = new PhysicsList(); - runManager->SetUserInitialization(physics); - PrimaryGeneratorAction* primary = new PrimaryGeneratorAction(detector); - - //Initialize Geant4 kernel - runManager->Initialize(); - physics->MyOwnConstruction(); - - /////////////////////////////////////////////////////////////// - ///////////////// Initializing the Root Output //////////////// - /////////////////////////////////////////////////////////////// - RootOutput::getInstance("Simulation/mySimul"); - - /////////////////////////////////////////////////////////////// - ////////////// Reading Detector Configuration ///////////////// - /////////////////////////////////////////////////////////////// - detector->ReadConfigurationFile(DetectorFileName); - - /////////////////////////////////////////////////////////////// - ////////////////////// Reading Reaction /////////////////////// - /////////////////////////////////////////////////////////////// - primary->ReadEventGeneratorFile(EventGeneratorFileName); - runManager->SetUserAction(primary); - - /////////////////////////////////////////////////////////////// - ////////////////// Starting the Event Action ////////////////// - /////////////////////////////////////////////////////////////// - EventAction* event_action = new EventAction() ; - event_action->SetDetector(detector) ; - runManager->SetUserAction(event_action) ; - - /////////////////////////////////////////////////////////////// - /////// Get the pointer to the User Interface manager //////// - /////////////////////////////////////////////////////////////// - G4UImanager* UI = G4UImanager::GetUIpointer(); - - /////////////////////////////////////////////////////////////// - /////////// Define UI terminal for interactive mode /////////// - /////////////////////////////////////////////////////////////// -#ifdef G4VIS_USE - G4VisManager* visManager = new G4VisExecutive; - visManager->Initialize(); -#endif - - G4UIsession* session = 0; - -#ifdef G4UI_USE_TCSH - session = new G4UIterminal(new G4UItcsh); -#else - session = new G4UIterminal(); -#endif - - UI->ApplyCommand("/control/execute vis.mac"); - session->SessionStart(); - delete session; - -#ifdef G4VIS_USE - delete visManager; -#endif - - /////////////////////////////////////////////////////////////// - ////////////////////// Job termination //////////////////////// - /////////////////////////////////////////////////////////////// - RootOutput::getInstance()->Destroy(); - - delete runManager; - return 0; -} + { + NPOptionManager* OptionManager = NPOptionManager::getInstance(argc,argv); + G4String EventGeneratorFileName = OptionManager->GetReactionFilePath(); + G4String DetectorFileName = OptionManager->GetDetectorFilePath(); + + + //my Verbose output class + G4VSteppingVerbose::SetInstance(new SteppingVerbose); + + //Construct the default run manager + G4RunManager* runManager = new G4RunManager; + + //set mandatory initialization classes + DetectorConstruction* detector = new DetectorConstruction(); + runManager->SetUserInitialization(detector); + + PhysicsList* physics = new PhysicsList(); + runManager->SetUserInitialization(physics); + PrimaryGeneratorAction* primary = new PrimaryGeneratorAction(detector); + + //Initialize Geant4 kernel + runManager->Initialize(); + physics->MyOwnConstruction(); + + /////////////////////////////////////////////////////////////// + ///////////////// Initializing the Root Output //////////////// + /////////////////////////////////////////////////////////////// + RootOutput::getInstance("Simulation/"+OptionManager->GetOutputFilePath()); + + /////////////////////////////////////////////////////////////// + ////////////// Reading Detector Configuration ///////////////// + /////////////////////////////////////////////////////////////// + detector->ReadConfigurationFile(DetectorFileName); + + /////////////////////////////////////////////////////////////// + ////////////////////// Reading Reaction /////////////////////// + /////////////////////////////////////////////////////////////// + primary->ReadEventGeneratorFile(EventGeneratorFileName); + runManager->SetUserAction(primary); + + /////////////////////////////////////////////////////////////// + ////////////////// Starting the Event Action ////////////////// + /////////////////////////////////////////////////////////////// + EventAction* event_action = new EventAction() ; + event_action->SetDetector(detector) ; + runManager->SetUserAction(event_action) ; + + /////////////////////////////////////////////////////////////// + /////// Get the pointer to the User Interface manager //////// + /////////////////////////////////////////////////////////////// + G4UImanager* UI = G4UImanager::GetUIpointer(); + + /////////////////////////////////////////////////////////////// + /////////// Define UI terminal for interactive mode /////////// + /////////////////////////////////////////////////////////////// + #ifdef G4VIS_USE + G4VisManager* visManager = new G4VisExecutive; + visManager->Initialize(); + #endif + + G4UIsession* session = 0; + + #ifdef G4UI_USE_TCSH + session = new G4UIterminal(new G4UItcsh); + #else + session = new G4UIterminal(); + #endif + + UI->ApplyCommand("/control/execute vis.mac"); + session->SessionStart(); + delete session; + + #ifdef G4VIS_USE + delete visManager; + #endif + + /////////////////////////////////////////////////////////////// + ////////////////////// Job termination //////////////////////// + /////////////////////////////////////////////////////////////// + RootOutput::getInstance()->Destroy(); + + delete runManager; + return 0; + } -- GitLab