LArSoft  v09_90_00
Liquid Argon Software toolkit - https://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 "G4ios.hh"
#include "G4UImanager.hh"
#include "G4ScoringManager.hh"
#include "G4Timer.hh"
#include "G4VisExecutive.hh"
#include "G4UIExecutive.hh"

Go to the source code of this file.

Functions

void visio (int argc, char *argv[])
 
int main (int argc, char *argv[])
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 56 of file ml2.cc.

References Initialize(), and visio().

57 {
58  G4RunManager *runManager = new G4RunManager();
59  // instantiate the world class
60  CML2WorldConstruction *myWorld=CML2WorldConstruction::GetInstance();
61 
62  // read the main mac file and execute the commands
63  G4UImanager* UImanager = G4UImanager::GetUIpointer();
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
71  G4ScoringManager* scoringManager = G4ScoringManager::GetScoringManager();
72  scoringManager->SetVerboseLevel(1);
73 
74  // build the primary generator
75  CML2PrimaryGenerationAction *gun;
76  gun = CML2PrimaryGenerationAction::GetInstance();
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
106  CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine);
107  CLHEP::HepRandom::setTheSeed(myInputData->inputData.generalData.seed);
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
118  gun->design(myWorld->getCML2AcceleratorConstruction()->getAcceleratorIsoCentre());
119  }
120 
121  // instantiate the convergence control class and assign it to myStepAction
122  CML2Convergence *convergence = new CML2Convergence(myInputData->inputData.generalData.seed,
123  myInputData->inputData.generalData.saving_in_Selected_Voxels_every_events,
124  myInputData->inputData.generalData.fileExperimentalData,
125  myInputData->inputData.generalData.fileExperimentalDataOut,
126  myInputData->inputData.generalData.bCompareExp,
127  myInputData->inputData.generalData.maxNumberOfEvents,
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();
176  CML2WorldConstruction::GetInstance()->checkVolumeOverlap();
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 }
void visio(int argc, char *argv[])
Definition: ml2.cc:44
void Initialize()
Definition: errprop.cc:100
void visio ( int  argc,
char *  argv[] 
)

Definition at line 44 of file ml2.cc.

References Initialize().

Referenced by main().

45 {
46  G4VisManager *visManager=new G4VisExecutive;
47  visManager -> Initialize();
48  G4UIExecutive *ui = new G4UIExecutive(argc, argv);
49  G4UImanager *UImanager = G4UImanager::GetUIpointer();
50  UImanager -> ApplyCommand("/control/execute macroAndData/macro_files/main/vis.mac");
51  ui -> SessionStart();
52  delete ui;
53  delete visManager;
54 }
void Initialize()
Definition: errprop.cc:100