Skip to content
Snippets Groups Projects
Simulation.cc 4.82 KiB
Newer Older
Unknown's avatar
Unknown committed
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include "G4RunManager.hh"
matta's avatar
matta committed
#include "G4PhysListFactory.hh"
Unknown's avatar
Unknown committed
// UI
#include "G4UImanager.hh"
#include "G4UIterminal.hh"
#include "G4UItcsh.hh"
matta's avatar
matta committed
#ifdef G4VIS_USE
#include "G4VisExecutive.hh"
#endif

#ifdef G4UI_USE
#include "G4UIExecutive.hh"
#endif
Unknown's avatar
Unknown committed
// G4 local source
#include "DetectorConstruction.hh"
#include "PhysicsList.hh"
#include "PrimaryGeneratorAction.hh"
Unknown's avatar
Unknown committed
// G4 General Source
#include "SteppingVerbose.hh"
matta's avatar
matta committed
// NPS headers
Unknown's avatar
Unknown committed
#include "EventAction.hh"
#include "VDetector.hh"
matta's avatar
matta committed
//NPL headers
#include "NPOptionManager.h"
Unknown's avatar
Unknown committed
#include "RootOutput.h"

matta's avatar
matta committed
int main(int argc, char** argv){
  // Initialize NPOptionManager object
  NPOptionManager* OptionManager  = NPOptionManager::getInstance(argc, argv);
  // Test if input files are found. If not, exit
  if (OptionManager->IsDefault("EventGenerator"))
    OptionManager->SendErrorAndExit("EventGenerator");
  if (OptionManager->IsDefault("DetectorConfiguration"))
    OptionManager->SendErrorAndExit("DetectorConfiguration");
matta's avatar
matta committed
  // case when input files are here
  G4String EventGeneratorFileName = OptionManager->GetReactionFile();
  G4String DetectorFileName       = OptionManager->GetDetectorFile();
  
  // 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* physicsList   = new PhysicsList();
  runManager->SetUserInitialization(physicsList);
  
  // Test for Built in physics list
  // G4PhysListFactory *physListFactory = new G4PhysListFactory();
  //G4VUserPhysicsList *physicsList =
  //physListFactory->GetReferencePhysList("QGSP_BERT");
  
  runManager->SetUserInitialization(physicsList);
  
  
  PrimaryGeneratorAction* primary = new PrimaryGeneratorAction(detector);
  
  // Initialize Geant4 kernel
  runManager->Initialize();
  physicsList->MyOwnConstruction();
  
  ///////////////////////////////////////////////////////////////
  ///////////////// Initializing the Root Output ////////////////
  ///////////////////////////////////////////////////////////////
  RootOutput::getInstance("Simulation/" + OptionManager->GetOutputFile());
  
  ///////////////////////////////////////////////////////////////
  ////////////// 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 ///////////
  ///////////////////////////////////////////////////////////////
deserevi's avatar
deserevi committed
#ifdef G4VIS_USE
matta's avatar
matta committed
  G4VisManager* visManager = new G4VisExecutive("Quiet");
  visManager->Initialize();
deserevi's avatar
deserevi committed
#endif
matta's avatar
matta committed
  
  /*   G4UIsession* session = 0;
   
   #ifdef G4UI_USE_TCSH
deserevi's avatar
deserevi committed
   session = new G4UIterminal(new G4UItcsh);
matta's avatar
matta committed
   #else
deserevi's avatar
deserevi committed
   session = new G4UIterminal();
matta's avatar
matta committed
   #endif
   
deserevi's avatar
deserevi committed
   UI->ApplyCommand("/control/execute vis.mac");
   session->SessionStart();
   delete session;
matta's avatar
matta committed
  // interactive mode : define UI session
  // Get the pointer to the User Interface manager
  G4UImanager* UImanager = G4UImanager::GetUIpointer();
#ifdef G4UI_USE
  G4UIExecutive* ui = new G4UIExecutive(argc, argv);
#ifdef G4VIS_USE
  UImanager->ApplyCommand("/control/execute vis.mac");
#endif
  if (ui->IsGUI())
    UImanager->ApplyCommand("/control/execute gui.mac");
  ui->SessionStart();
  delete ui;
#endif
matta's avatar
matta committed
  
deserevi's avatar
deserevi committed
#ifdef G4VIS_USE
matta's avatar
matta committed
  delete visManager;
deserevi's avatar
deserevi committed
#endif
matta's avatar
matta committed
  
  ///////////////////////////////////////////////////////////////
  ////////////////////// Job termination ////////////////////////
  ///////////////////////////////////////////////////////////////
  // delete primary; delete detector;
  
  delete runManager;
  NPOptionManager::getInstance()->Destroy();
  RootOutput::getInstance()->Destroy();
  return 0;