Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ml2.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 // The code was written by :
27 // ^Claudio Andenna claudio.andenna@ispesl.it, claudio.andenna@iss.infn.it
28 // *Barbara Caccia barbara.caccia@iss.it
29 // with the support of Pablo Cirrone (LNS, INFN Catania Italy)
30 // with the contribute of Alessandro Occhigrossi*
31 //
32 // ^INAIL DIPIA - ex ISPESL and INFN Roma, gruppo collegato Sanità , Italy
33 // *Istituto Superiore di Sanità and INFN Roma, gruppo collegato Sanità , Italy
34 // Viale Regina Elena 299, 00161 Roma (Italy)
35 // tel (39) 06 49902246
36 // fax (39) 06 49387075
37 //
38 // more information:
39 // http://g4advancedexamples.lngs.infn.it/Examples/medical-linac
40 //
41 //*******************************************************//
42 
43 
44 #include "ML2Main.hh"
45 
47 #include "ML2WorldConstruction.hh"
48 #include "ML2PhysicsList.hh"
49 #include "ML2SteppingAction.hh"
50 #include "ML2EventAction.hh"
51 #include "ML2TrackingAction.hh"
52 
53 #include "G4UImanager.hh"
54 #include "G4Timer.hh"
55 
56 
57 #ifdef G4VIS_USE
58  #include "G4VisExecutive.hh"
59 #endif
60 #ifdef G4UI_USE
61  #include "G4UIExecutive.hh"
62 #endif
63 
64 
65 
66 #ifdef G4VIS_USE
67 void visio(int argc, char* argv[])
68 {
69  G4VisManager *visManager=new G4VisExecutive;
70  visManager->Initialize();
71 #ifdef G4UI_USE
72  G4UIExecutive *ui = new G4UIExecutive(argc, argv);
74  UImanager->ApplyCommand("/control/execute vis.mac");
75  ui->SessionStart();
76  delete ui;
77 #endif
78  delete visManager;
79 }
80 #endif
81 
82 int main(int argc, char* argv[])
83 {
84  // instantiate the world class
86 
87  G4RunManager *runManager=new G4RunManager();
88  ML2PhysicsList *physics=new ML2PhysicsList();
89  runManager->SetUserInitialization(physics);
90 
91  // build the primary generator
94 
95  // build the main messenger class for the input data
96  CML2CInputData *myInputData;
97  myInputData=new CML2CInputData();
98 
99  // initialize the primary generator variables
100  gun->inizialize(&myInputData->inputData.primaryParticleData);
101 
102  // according to the number of the launching line
103  if (argc==1)
104  {
105  myInputData->inputData.generalData.seed=1;
106  myInputData->inputData.generalData.StartFileInputData="ml2.mac";
107  }
108  if (argc==2)
109  {
110  myInputData->inputData.generalData.seed=1;
111  myInputData->inputData.generalData.StartFileInputData=(G4String)argv[1];
112  }
113  if (argc==3)
114  {
115  sscanf(argv[2],"%d", &myInputData->inputData.generalData.seed);
116  myInputData->inputData.generalData.StartFileInputData=(G4String)argv[1];
117  }
118 
119  // read the main mac file and execute the commands
120  G4UImanager* UImanager = G4UImanager::GetUIpointer();
121  G4String command = "/control/execute ";
122  UImanager->ApplyCommand(command+myInputData->inputData.generalData.StartFileInputData);
123 
124 
125  // set and initialize the random generator
128 
129  // create the world class
130  if (!myWorld->create(&myInputData->inputData, myInputData->getbOnlyVisio()))
131  {
132  return 1; // if it fails to create the world
133  }
134  else
135  {
136  // initialize the primary generator according to the choosen particle source
138  }
139 
140  // instantiate the convergence control class and assign it to myStepAction
142 
143 
144  // build the ML2RunAction to assign the single phantom name at each run
145  CML2RunAction *myRunAction=new CML2RunAction(convergence, myInputData->inputData.generalData.nBeam, myInputData->bOnlyVisio);
146 
147  CML2SteppingAction *myStepAction=new CML2SteppingAction(convergence);
148  CML2EventAction *ML2EventAction = new CML2EventAction();
149 
150  runManager->SetUserInitialization(myWorld);
151  runManager->SetUserAction(myRunAction);
152  runManager->SetUserAction(gun);
153  runManager->SetUserAction(myStepAction);
154  runManager->SetUserAction(ML2EventAction);
155  runManager->SetUserAction(new CML2TrackingAction);
156  runManager->Initialize();
157 
158  // performances info
159  int nLoop=0;
160  G4Timer MyFullTime;
161  G4double loopElapsedTime;
162  G4bool bStopRun=false;
163  G4bool bNewGeometry=true;
164  if (myInputData->bOnlyVisio)
165  {
166 #ifdef G4VIS_USE
167  // visualization
168  myWorld->newGeometry();
169  convergence->setNewGeometry();
170  visio(argc, argv);
171 #endif
172  }
173  else
174  {
175  MyFullTime.Start();
176  // compute
177  while (bNewGeometry)
178  {
179  bNewGeometry=myWorld->newGeometry();
180  convergence->setNewGeometry();
181  if (bNewGeometry)
182  {
183  if (CML2PhantomConstruction::GetInstance()->getPhantomName()!="Dicom1")
185  std::cout<<"################ START NEW GEOMETRY ########################"<<'\n';
186  myRunAction->setActualLoop(nLoop);
187  while (!bStopRun)
188  {
189  runManager->BeamOn(myInputData->inputData.generalData.nBeam);
190  // check if the run has to be reapeted
191  bStopRun=convergence->stopRun();
192  }
193  nLoop=0;
194  std::cout<<"################ END NEW GEOMETRY ########################"<<'\n';
195  }
196  bStopRun=false;
197  }
198  MyFullTime.Stop();
199  loopElapsedTime=MyFullTime.GetUserElapsed();
200  std::cout << "loop elapsed time [s] : "<< loopElapsedTime << '\n';
201  std::cout <<'\n';
202  }
203  delete runManager;
204  return 0;
205 }
206 
G4String fileExperimentalData
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
bool create(SInputData *inputData, bool bOnlyVisio)
CML2AcceleratorConstruction * getCML2AcceleratorConstruction()
virtual void BeamOn(G4int n_event, const char *macroFile=0, G4int n_select=-1)
static CML2WorldConstruction * GetInstance(void)
G4bool bCompareExp
G4String StartFileInputData
static void setTheSeed(long seed, int lux=3)
Definition: Random.cc:131
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
void design(G4double accTargetZPosition)
void inizialize(SPrimaryParticle *primaryParticleData)
G4int maxNumberOfEvents
bool G4bool
Definition: G4Types.hh:79
G4double GetUserElapsed() const
Definition: G4Timer.cc:130
int main(int argc, char *argv[])
Definition: ml2.cc:82
int saving_in_Selected_Voxels_every_events
void Initialize()
SPrimaryParticle primaryParticleData
SGeneralData generalData
G4bool getbOnlyVisio()
void Stop()
SInputData inputData
virtual void Initialize()
static CML2PrimaryGenerationAction * GetInstance(void)
static void setTheEngine(HepRandomEngine *theNewEngine)
Definition: Random.cc:170
void Start()
double G4double
Definition: G4Types.hh:76
G4String fileExperimentalDataOut
static CML2PhantomConstruction * GetInstance(void)
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:419
virtual void SetUserAction(G4UserRunAction *userAction)