LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
Hadr01.cc File Reference

Main program of the hadronic/Hadr01 example. More...

#include "G4RunManager.hh"
#include "G4UImanager.hh"
#include "Randomize.hh"
#include "DetectorConstruction.hh"
#include "PhysicsList.hh"
#include "G4PhysListFactory.hh"
#include "G4VModularPhysicsList.hh"
#include "PrimaryGeneratorAction.hh"
#include "PhysicsListMessenger.hh"
#include "RunAction.hh"
#include "EventAction.hh"
#include "StackingAction.hh"
#include "G4UIExecutive.hh"
#include "G4VisExecutive.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Main program of the hadronic/Hadr01 example.

Definition in file Hadr01.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 68 of file Hadr01.cc.

68  {
69 
70  //detect interactive mode (if no arguments) and define UI session
71  G4UIExecutive* ui = nullptr;
72  if (argc == 1) { ui = new G4UIExecutive(argc,argv); }
73 
74  //Construct the default run manager
75  G4RunManager * runManager = new G4RunManager();
76 
77  //set mandatory initialization classes
78  runManager->SetUserInitialization(new DetectorConstruction());
79 
80  G4PhysListFactory factory;
81  G4VModularPhysicsList* phys = nullptr;
82  PhysicsListMessenger* mess = nullptr;
83  G4String physName = "";
84 
85  //Physics List name defined via 3nd argument
86  if (argc==3) { physName = argv[2]; }
87 
88  // Physics List name defined via environment variable
89  if("" == physName) {
90  char* path = std::getenv("PHYSLIST");
91  if (path) { physName = G4String(path); }
92  }
93 
94  //reference PhysicsList via its name
95  if ("" != physName && factory.IsReferencePhysList(physName)) {
96  phys = factory.GetReferencePhysList(physName);
97 
98  // instantiated messenger
99  mess = new PhysicsListMessenger();
100  }
101 
102  //local Physics List
103  if(!phys) { phys = new PhysicsList(); }
104 
105  // define physics
106  runManager->SetUserInitialization(phys);
107  runManager->SetUserAction(new PrimaryGeneratorAction());
108 
109  //set user action classes
110  runManager->SetUserAction(new RunAction());
111  runManager->SetUserAction(new EventAction());
112  runManager->SetUserAction(new StackingAction());
113 
114  //initialize visualization
115  G4VisManager* visManager = nullptr;
116 
117  //get the pointer to the User Interface manager
118  G4UImanager* UImanager = G4UImanager::GetUIpointer();
119 
120  if (ui) {
121  //interactive mode
122  visManager = new G4VisExecutive;
123  visManager->Initialize();
124  ui->SessionStart();
125  delete ui;
126  } else {
127  //batch mode
128  G4String command = "/control/execute ";
129  G4String fileName = argv[1];
130  UImanager->ApplyCommand(command+fileName);
131  }
132 
133  //job termination
134  delete mess;
135  delete visManager;
136  delete runManager;
137 }
TConfigurablePhysicsList< ModularPhysicsList > PhysicsList
Definition: PhysicsList.h:83