LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
ml2.cc File Reference
#include "ML2Main.hh"
#include "ML2PrimaryGenerationAction.hh"
#include "ML2WorldConstruction.hh"
#include "ML2PhysicsList.hh"
#include "ML2SteppingAction.hh"
#include "ML2EventAction.hh"
#include "ML2TrackingAction.hh"
#include "G4UImanager.hh"
#include "G4Timer.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 82 of file ml2.cc.

83 {
84  // instantiate the world class
85  CML2WorldConstruction *myWorld=CML2WorldConstruction::GetInstance();
86 
87  G4RunManager *runManager=new G4RunManager();
88  ML2PhysicsList *physics=new ML2PhysicsList();
89  runManager->SetUserInitialization(physics);
90 
91  // build the primary generator
92  CML2PrimaryGenerationAction *gun;
93  gun = CML2PrimaryGenerationAction::GetInstance();
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
126  CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine);
127  CLHEP::HepRandom :: setTheSeed(myInputData->inputData.generalData.seed);
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
137  gun->design(myWorld->getCML2AcceleratorConstruction()->getAcceleratorIsoCentre());
138  }
139 
140  // instantiate the convergence control class and assign it to myStepAction
141  CML2Convergence *convergence=new CML2Convergence(myInputData->inputData.generalData.seed, myInputData->inputData.generalData.saving_in_Selected_Voxels_every_events, myInputData->inputData.generalData.fileExperimentalData, myInputData->inputData.generalData.fileExperimentalDataOut, myInputData->inputData.generalData.bCompareExp, myInputData->inputData.generalData.maxNumberOfEvents, gun->getNrecycling(), myInputData->inputData.generalData.nMaxLoop);
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")
184  {CML2WorldConstruction::GetInstance()->checkVolumeOverlap();}
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 }