LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
examplePar01.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 //
28 //
29 //
30 //
31 //
32 // --------------------------------------------------------------
33 // Geant4 - examplePar01
34 // --------------------------------------------------------------
35 // Comments
36 //
37 // Example of a main program making use of parameterisation
38 // i.e. "Fast Simulation"
39 //-------------------------------------------------------------------
40 
41 #include "G4Types.hh"
42 
43 //---------------
44 // -- Geometries:
45 //---------------
46 #include "Par01DetectorConstruction.hh"
47 #include "Par01ParallelWorldForPion.hh"
48 
49 //---------------------------------------------------------------------
50 // -- Physics list, and tool to modify it and activate fast simulation:
51 //---------------------------------------------------------------------
52 #include "FTFP_BERT.hh"
53 #include "G4FastSimulationPhysics.hh"
54 
55 #include "G4UImanager.hh"
56 #ifdef G4MULTITHREADED
57 #include "G4MTRunManager.hh"
58 #else
59 #include "G4RunManager.hh"
60 #endif
61 
62 // ----------------------------------------------------------------
63 // -- Action initialization (includes the primary generator action:
64 // ----------------------------------------------------------------
65 #include "Par01ActionInitialization.hh"
66 
67 #include "G4VisExecutive.hh"
68 #include "G4UIExecutive.hh"
69 
70 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
71 
72 int main(int argc, char** argv)
73 {
74  // Instantiate G4UIExecutive if interactive mode
75  G4UIExecutive* ui = nullptr;
76  if ( argc == 1 ) {
77  ui = new G4UIExecutive(argc, argv);
78  }
79 
80  //-------------------------------
81  // Initialization of Run manager
82  //-------------------------------
83 #ifdef G4MULTITHREADED
84  G4MTRunManager * runManager = new G4MTRunManager;
85  runManager->SetNumberOfThreads(4);
86  G4cout<<"+-------------------------------------------------------+"<<G4endl;
87  G4cout<<"| Constructing MT run manager |"<<G4endl;
88  G4cout<<"+-------------------------------------------------------+"<<G4endl;
89 #else
90  G4RunManager * runManager = new G4RunManager;
91  G4cout<<"+-------------------------------------------------------+"<<G4endl;
92  G4cout<<"| Constructing sequential run manager |"<<G4endl;
93  G4cout<<"+-------------------------------------------------------+"<<G4endl;
94 #endif
95 
96  // -----------------------------------------------------
97  // -- Detector/mass geometry and parallel geometry(ies):
98  // -----------------------------------------------------
99  // -- Mass geometry (ie : standard geometry):
100  G4VUserDetectorConstruction* detector = new Par01DetectorConstruction();
101  // -- Parallel geometry for pion parameterisation
102  detector->RegisterParallelWorld(new Par01ParallelWorldForPion("pionGhostWorld"));
103  // -- Passed to the run manager:
104  runManager->SetUserInitialization(detector);
105 
106  // ----------------------------------------------
107  // -- PhysicsList and fast simulation activation:
108  // ----------------------------------------------
109  // -- Create a physics list (note : FTFP_BERT is a G4VModularPhysicsList
110  // -- which allows to use the subsequent G4FastSimulationPhysics tool to
111  // -- activate the fast simulation):
112  FTFP_BERT* physicsList = new FTFP_BERT;
113  // -- Create helper tool, used to activate the fast simulation:
114  G4FastSimulationPhysics* fastSimulationPhysics = new G4FastSimulationPhysics();
115  fastSimulationPhysics->BeVerbose();
116  // -- activation of fast simulation for particles having fast simulation models
117  // -- attached in the mass geometry:
118  fastSimulationPhysics->ActivateFastSimulation("e-");
119  fastSimulationPhysics->ActivateFastSimulation("e+");
120  fastSimulationPhysics->ActivateFastSimulation("gamma");
121  // -- activation of fast simulation for particles having fast simulation models
122  // -- attached in the parallel geometry:
123  fastSimulationPhysics->ActivateFastSimulation("pi+","pionGhostWorld");
124  fastSimulationPhysics->ActivateFastSimulation("pi-","pionGhostWorld");
125  // -- Attach the fast simulation physics constructor to the physics list:
126  physicsList->RegisterPhysics( fastSimulationPhysics );
127  // -- Finally passes the physics list to the run manager:
128  runManager->SetUserInitialization(physicsList);
129 
130  //-------------------------------
131  // UserAction classes
132  //-------------------------------
133  runManager->SetUserInitialization( new Par01ActionInitialization );
134 
135  // Initialize Run manager
136  runManager->Initialize();
137 
138  //----------------
139  // Visualization:
140  //----------------
141  G4cout << "Instantiating Visualization Manager......." << G4endl;
142  G4VisManager* visManager = new G4VisExecutive;
143  visManager -> Initialize ();
144 
145  if(ui)
146  {
147  //--------------------------
148  // Define (G)UI
149  //--------------------------
150  ui->SessionStart();
151  delete ui;
152  }
153  else
154  {
155  G4String command = "/control/execute ";
156  G4String fileName = argv[1];
157  G4UImanager * UImanager = G4UImanager::GetUIpointer();
158  UImanager->ApplyCommand(command+fileName);
159  }
160 
161  // Free the store: user actions, physics_list and detector_description are
162  // owned and deleted by the run manager, so they should not
163  // be deleted in the main() program !
164 
165  delete visManager;
166  delete runManager;
167 
168  return 0;
169 }
void Initialize()
Definition: errprop.cc:100
int main(int argc, char **argv)
Definition: examplePar01.cc:72