LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
hadrontherapy.cc File Reference
#include "G4RunManager.hh"
#include "G4UImanager.hh"
#include "G4PhysListFactory.hh"
#include "G4VModularPhysicsList.hh"
#include "HadrontherapyEventAction.hh"
#include "HadrontherapyPhysicsList.hh"
#include "HadrontherapyDetectorSD.hh"
#include "HadrontherapyPrimaryGeneratorAction.hh"
#include "HadrontherapyRunAction.hh"
#include "HadrontherapyMatrix.hh"
#include "Randomize.hh"
#include "G4UImessenger.hh"
#include "globals.hh"
#include "HadrontherapySteppingAction.hh"
#include "HadrontherapyGeometryController.hh"
#include "HadrontherapyGeometryMessenger.hh"
#include "HadrontherapyInteractionParameters.hh"
#include "HadrontherapyLet.hh"
#include "G4ScoringManager.hh"
#include "G4ParallelWorldPhysics.hh"
#include <time.h>
#include "G4Timer.hh"
#include "HadrontherapyActionInitialization.hh"
#include "G4VisExecutive.hh"
#include "G4UIExecutive.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 105 of file hadrontherapy.cc.

References Initialize(), and seed.

106 {
107  G4UIExecutive* ui = 0;
108  if ( argc == 1 ) {
109  ui = new G4UIExecutive(argc, argv);
110  }
111 
112  //Instantiate the G4Timer object, to monitor the CPU time spent for
113  //the entire execution
114  G4Timer* theTimer = new G4Timer();
115  //Start the benchmark
116  theTimer->Start();
117 
118  // Set the Random engine
119  // The following guarantees random generation also for different runs
120  // in multithread
121  CLHEP::RanluxEngine defaultEngine( 1234567, 4 );
122  G4Random::setTheEngine( &defaultEngine );
123  G4int seed = time( NULL );
124  G4Random::setTheSeed( seed );
125 
126 #ifdef G4MULTITHREADED
127 
128  G4MTRunManager* runManager = new G4MTRunManager;
129 #else
130  G4RunManager* runManager = new G4RunManager;
131 #endif
132 
133  // Geometry controller is responsible for instantiating the
134  // geometries. All geometry specific m tasks are now in class
135  // HadrontherapyGeometryController.
136  HadrontherapyGeometryController *geometryController = new HadrontherapyGeometryController();
137 
138  // Connect the geometry controller to the G4 user interface
139  HadrontherapyGeometryMessenger *geometryMessenger = new HadrontherapyGeometryMessenger(geometryController);
140 
141  G4ScoringManager *scoringManager = G4ScoringManager::GetScoringManager();
142  scoringManager->SetVerboseLevel(1);
143 
144  // Initialize the default Hadrontherapy geometry
145  geometryController->SetGeometry("default");
146 
147  // Initialize the physics
148  G4PhysListFactory factory;
149  G4VModularPhysicsList* phys = 0;
150  G4String physName = "";
151 
152  // Physics List name defined via environment variable
153  char* path = std::getenv("PHYSLIST");
154  if (path) { physName = G4String(path); }
155 
156  if(physName != "" && factory.IsReferencePhysList(physName))
157  {
158  phys = factory.GetReferencePhysList(physName);
159  }
160  if (phys)
161  {
162  G4cout << "Going to register G4ParallelWorldPhysics" << G4endl;
163  phys->RegisterPhysics(new G4ParallelWorldPhysics("DetectorROGeometry"));
164  }
165  else
166  {
167  G4cout << "Using HadrontherapyPhysicsList()" << G4endl;
168  phys = new HadrontherapyPhysicsList();
169  }
170 
171  // Initialisations of physics
172  runManager->SetUserInitialization(phys);
173 
174  // Initialisation of the Actions
175  runManager->SetUserInitialization(new HadrontherapyActionInitialization);
176 
177  // Initialize command based scoring
178  G4ScoringManager::GetScoringManager();
179 
180  // Interaction data: stopping powers
181  HadrontherapyInteractionParameters* pInteraction = new HadrontherapyInteractionParameters(true);
182 
183  // Initialize analysis
184  HadrontherapyAnalysis* analysis = HadrontherapyAnalysis::GetInstance();
185 
186 
187 
188 // Initialise the Visualisation
189  G4VisManager* visManager = new G4VisExecutive;
190  visManager -> Initialize();
191 
192  //** Get the pointer to the User Interface manager
193  G4UImanager* UImanager = G4UImanager::GetUIpointer();
194 
195  if ( !ui ) {
196  // batch mode
197  G4String command = "/control/execute ";
198  G4String fileName = argv[1];
199  UImanager->ApplyCommand(command+fileName);
200 
201  }
202 
203  else {
204 
205  UImanager -> ApplyCommand("/control/execute macro/defaultMacro.mac");
206  ui -> SessionStart();
207  delete ui;
208  }
209  delete visManager;
210 
211  //Stop the benchmark here
212  theTimer->Stop();
213 
214  G4cout << "The simulation took: " << theTimer->GetRealElapsed() << " s to run (real time)"
215  << G4endl;
216 
217  // Job termination
218  // Free the store: user actions, physics_list and detector_description are
219  // owned and deleted by the run manager, so they should not be deleted
220  // in the main() program !
221 
222 
223  if ( HadrontherapyMatrix * pMatrix = HadrontherapyMatrix::GetInstance() )
224  {
225  // pMatrix -> TotalEnergyDeposit();
226  pMatrix -> StoreDoseFluenceAscii();
227 
228  }
229 
230  if (HadrontherapyLet *let = HadrontherapyLet::GetInstance())
231  if(let -> doCalculation)
232  {
233  let -> LetOutput(); // Calculate let
234  let -> StoreLetAscii(); // Store it
235  }
236 
237  delete geometryMessenger;
238  delete geometryController;
239  delete pInteraction;
240  delete runManager;
241  delete analysis;
242  return 0;
243 
244 }
void Initialize()
Definition: errprop.cc:100
long seed
Definition: chem4.cc:67