WCSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
WCSim.cc
Go to the documentation of this file.
1 #include "G4ios.hh"
2 #include "G4RunManager.hh"
3 #include "G4UImanager.hh"
4 #include "G4UIterminal.hh"
5 #include "G4UItcsh.hh"
10 #include "WCSimTuningMessenger.hh"
12 #include "WCSimEventAction.hh"
13 #include "WCSimRunAction.hh"
14 #include "WCSimStackingAction.hh"
15 #include "WCSimTrackingAction.hh"
16 #include "WCSimSteppingAction.hh"
17 #include "WCSimVisManager.hh"
18 #include "WCSimRandomParameters.hh"
19 
20 
21 #ifdef G4UI_USE
22 #include "G4UIExecutive.hh"
23 #endif
24 
25 void file_exists(const char * filename) {
26  bool exists = access(filename, F_OK) != -1;
27  if(!exists) {
28  G4cerr << filename << " not found or inaccessible. Exiting" << G4endl;
29  exit(-1);
30  }
31 }
32 
33 int main(int argc,char** argv)
34 {
35  // Construct the default run manager
36  G4RunManager* runManager = new G4RunManager;
37 
38  // get the pointer to the UI manager
39  G4UImanager* UI = G4UImanager::GetUIpointer();
40 
41  // Set up the tuning parameters that need to be read before the detector
42  // construction is done
43  WCSimTuningParameters* tuningpars = new WCSimTuningParameters();
44 
45  // Get the tuning parameters
46  file_exists("macros/tuning_parameters.mac");
47  UI->ApplyCommand("/control/execute macros/tuning_parameters.mac");
48 
49  // define random number generator parameters
50  WCSimRandomParameters *randomparameters = new WCSimRandomParameters();
51 
52  // UserInitialization classes (mandatory)
53  enum DetConfiguration {wfm=1,fwm=2};
54  G4int WCSimConfiguration = fwm;
55 
56  WCSimDetectorConstruction* WCSimdetector = new
57  WCSimDetectorConstruction(WCSimConfiguration,tuningpars);
58 
59  runManager->SetUserInitialization(WCSimdetector);
60 
61  // Added selectable physics lists 2010-07 by DMW
62  // Set up the messenger hooks here, initialize the actual list after loading jobOptions.mac
64 
65  // Currently, default physics list is set to FTFP_BERT
66  // The custom WCSim physics list option is removed in versions later than WCSim1.6.0
67  file_exists("macros/jobOptions.mac");
68  UI->ApplyCommand("/control/execute macros/jobOptions.mac");
69 
70  // Initialize the physics factory to register the selected physics.
71  physFactory->InitializeList();
72  runManager->SetUserInitialization(physFactory);
73 
74  // Visualization
75  G4VisManager* visManager = new WCSimVisManager;
76  visManager->Initialize();
77 
78  // Set user action classes
79  WCSimPrimaryGeneratorAction* myGeneratorAction = new
80  WCSimPrimaryGeneratorAction(WCSimdetector);
81  runManager->SetUserAction(myGeneratorAction);
82 
83 
84  WCSimRunAction* myRunAction = new WCSimRunAction(WCSimdetector, randomparameters);
85 
86  //save all the options from WCSimTuningParameters & WCSimPhysicsListFactory
87  //(set in tuning_parameters.mac & jobOptions*.mac)
88  tuningpars->SaveOptionsToOutput(myRunAction->GetRootOptions());
89  physFactory->SaveOptionsToOutput(myRunAction->GetRootOptions());
90 
91  runManager->SetUserAction(myRunAction);
92 
93  runManager->SetUserAction(new WCSimEventAction(myRunAction, WCSimdetector,
94  myGeneratorAction));
95  runManager->SetUserAction(new WCSimTrackingAction);
96 
97  runManager->SetUserAction(new WCSimStackingAction(WCSimdetector));
98 
99  runManager->SetUserAction(new WCSimSteppingAction);
100 
101 
102  // Initialize G4 kernel
103  runManager->Initialize();
104 
105  if (argc==1) // Define UI terminal for interactive mode
106  {
107 
108  // Start UI Session
109  // G4UIsession* session = new G4UIterminal(new G4UItcsh);
110 
111  //using working example N04 for Qt UI Compatible code
112 #ifdef G4UI_USE
113  G4UIExecutive * ui = new G4UIExecutive(argc,argv);
114 #ifdef G4VIS_USE
115  // Visualization Macro
116  UI->ApplyCommand("/control/execute WCSim.mac");
117 #endif
118  ui->SessionStart();
119  delete ui;
120 #endif
121 
122  // Start Interactive Mode
123  //session->SessionStart();
124 
125  //delete session;
126  }
127  else // Batch mode
128  {
129  G4String command = "/control/execute ";
130  G4String fileName = argv[1];
131  file_exists(fileName);
132  if(fileName == "vis.mac"){
133  G4cout << "ERROR: Execute without arg for interactive mode" << G4endl;
134  //return -1;
135  }
136 
137  UI->ApplyCommand(command+fileName);
138  }
139 
140  delete visManager;
141 
142  delete runManager;
143  return 0;
144 }
145 
146 
void file_exists(const char *filename)
Definition: WCSim.cc:25
int main(int argc, char **argv)
Definition: WCSim.cc:33
void SaveOptionsToOutput(WCSimRootOptions *wcopt)
string filename
Definition: MakeKin.py:209
void SaveOptionsToOutput(WCSimRootOptions *wcopt)
WCSimRootOptions * GetRootOptions()