ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ml2.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ml2.cc
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 #include "ML2Main.hh"
27 
29 #include "ML2WorldConstruction.hh"
30 #include "ML2PhysicsList.hh"
31 #include "ML2SteppingAction.hh"
32 #include "ML2EventAction.hh"
33 #include "ML2TrackingAction.hh"
34 
35 #include "G4ios.hh"
36 #include "G4UImanager.hh"
37 #include "G4ScoringManager.hh"
38 #include "G4Timer.hh"
39 
40 #include "G4VisExecutive.hh"
41 #include "G4UIExecutive.hh"
42 
43 
44 void visio(int argc, char* argv[])
45 {
46  G4VisManager *visManager=new G4VisExecutive;
47  visManager -> Initialize();
48  G4UIExecutive *ui = new G4UIExecutive(argc, argv);
50  UImanager -> ApplyCommand("/control/execute macroAndData/macro_files/main/vis.mac");
51  ui -> SessionStart();
52  delete ui;
53  delete visManager;
54 }
55 
56 int main(int argc, char* argv[])
57 {
58  G4RunManager *runManager = new G4RunManager();
59  // instantiate the world class
61 
62  // read the main mac file and execute the commands
64  UImanager->ApplyCommand("/control/verbose 2");
65  UImanager->ApplyCommand("/run/verbose 2");
66 
67  ML2PhysicsList *physics = new ML2PhysicsList();
68  runManager -> SetUserInitialization(physics);
69 
70  // instantiate the scoring manager
72  scoringManager->SetVerboseLevel(1);
73 
74  // build the primary generator
77 
78  // build the main messenger class for the input data
79  CML2CInputData *myInputData = new CML2CInputData();
80 
81  // initialize the primary generator variables
82  gun->inizialize(&myInputData->inputData.primaryParticleData);
83 
84  // according to the number of the launching line
85  if (argc==1)
86  {
87  myInputData->inputData.generalData.seed = 1;
88  myInputData->inputData.generalData.StartFileInputData = "macroAndData/macro_files/main/ml2.mac";
89  }
90  if (argc==2)
91  {
92  myInputData->inputData.generalData.seed = 1;
93  myInputData->inputData.generalData.StartFileInputData = (G4String)argv[1];
94  }
95  if (argc==3)
96  {
97  sscanf(argv[2],"%d", &myInputData->inputData.generalData.seed);
98  myInputData->inputData.generalData.StartFileInputData = (G4String)argv[1];
99  }
100 
101  G4String command = "/control/execute ";
102  UImanager->ApplyCommand(command+myInputData->inputData.generalData.StartFileInputData);
103 
104 
105  // set and initialize the random generator
108  G4cout << "Using seed " << CLHEP::HepRandom::getTheSeed() << G4endl;
109 
110  // create the world class
111  if (!myWorld->create(&myInputData->inputData, myInputData->getbOnlyVisio()))
112  {
113  return 1; // if it fails to create the world
114  }
115  else
116  {
117  // initialize the primary generator according to the chosen particle source
119  }
120 
121  // instantiate the convergence control class and assign it to myStepAction
122  CML2Convergence *convergence = new CML2Convergence(myInputData->inputData.generalData.seed,
126  myInputData->inputData.generalData.bCompareExp,
128  gun->getNrecycling(),
129  myInputData->inputData.generalData.nMaxLoop);
130 
131 
132  // build the ML2RunAction to assign the single phantom name at each run
133  CML2RunAction *myRunAction = new CML2RunAction(convergence, myInputData->inputData.generalData.nBeam,
134  myInputData->bOnlyVisio,
135  myInputData->inputData.voxelSegmentation.nX,
136  myInputData->inputData.voxelSegmentation.nY,
137  myInputData->inputData.voxelSegmentation.nZ );
138 
139  CML2SteppingAction *myStepAction = new CML2SteppingAction(convergence);
140  CML2EventAction *ML2EventAction = new CML2EventAction();
141 
142  runManager -> SetUserInitialization(myWorld);
143  runManager -> SetUserAction(myRunAction);
144  runManager -> SetUserAction(gun);
145  runManager -> SetUserAction(myStepAction);
146  runManager -> SetUserAction(ML2EventAction);
147  runManager -> SetUserAction(new CML2TrackingAction);
148  runManager -> Initialize();
149 
150  // performances info
151  int nLoop = 0;
152  G4Timer MyFullTime;
153  G4double loopElapsedTime;
154  G4bool bStopRun = false;
155  G4bool bNewGeometry = true;
156 
157  if (myInputData->bOnlyVisio)
158  {
159  // visualization
160  myWorld -> newGeometry();
161  convergence -> setNewGeometry();
162  visio(argc, argv);
163  }
164  else
165  {
166  MyFullTime.Start();
167  // compute
168  while (bNewGeometry)
169  {
170  bNewGeometry = myWorld -> newGeometry();
171  convergence -> setNewGeometry();
172 
173  if (bNewGeometry)
174  {
175  runManager -> Initialize();
177 
178  G4cout << "################ START NEW GEOMETRY ########################" << G4endl;
179  myRunAction->setActualLoop(nLoop);
180 
181  while (!bStopRun)
182  {
183  runManager->BeamOn(myInputData->inputData.generalData.nBeam);
184  // check if the run has to be repeated
185  bStopRun = convergence->stopRun();
186  }
187  nLoop = 0;
188  G4cout << "################ END NEW GEOMETRY ########################" << G4endl;
189  }
190  bStopRun = false;
191  }
192  MyFullTime.Stop();
193  loopElapsedTime = MyFullTime.GetUserElapsed();
194  G4cout << "loop elapsed time [s] : "<< loopElapsedTime << '\n' << G4endl;
195  }
196  delete runManager;
197  return 0;
198 }
199