Loading...
Searching...
No Matches
examplePar04.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//
27//
28//
29// --------------------------------------------------------------
30// GEANT 4 - examplePar04
31// --------------------------------------------------------------
32// Comments
33//
34// Example of a main program demonstrating inference in C++
35// for fast simulation in calorimeters.
36//
37//-------------------------------------------------------------------
38#include "FTFP_BERT.hh" // for FTFP_BERT
39#include "Par04ActionInitialisation.hh" // for Par04ActionInitialisation
40#include "Par04DetectorConstruction.hh" // for Par04DetectorConstruction
43
44#include "G4EmParameters.hh" // for G4EmParameters
45#include "G4FastSimulationPhysics.hh" // for G4FastSimulationPhysics
46#include "G4HadronicProcessStore.hh" // for G4HadronicProcessStore
47#include "G4ParallelWorldPhysics.hh"
48#include "G4RunManagerFactory.hh" // for G4RunManagerFactory, G4RunMa...
49#include "G4Types.hh" // for G4bool, G4int
50#include "G4UIExecutive.hh" // for G4UIExecutive
51#include "G4UImanager.hh" // for G4UImanager
52#include "G4VisExecutive.hh" // for G4VisExecutive
53
54#include "G4Exception.hh" // for G4Exception
55#include "G4ExceptionSeverity.hh" // for FatalErrorInArgument
56#include "G4RunManager.hh" // for G4RunManager
57#include "G4String.hh" // for G4String
58#include "G4VisManager.hh" // for G4VisManager
59#include "G4ios.hh" // for G4cout, G4endl
60#include <ctime> // for time
61#include <sstream> // for char_traits, operator<<, bas...
62#include <string> // for allocator, operator+, operat...
63
64int main(int argc, char** argv)
65{
66 // Macro name from arguments
67 G4String batchMacroName;
68 G4bool useInteractiveMode = false;
69 G4int numOfThreadsOrTasks = 8;
70 G4int runManagerTypeInt = 0;
71 G4RunManagerType runManagerType = G4RunManagerType::Serial;
72 G4String helpMsg(
73 "Usage: " + G4String(argv[0]) +
74 " [option(s)] \n You need to specify the mode and the macro file.\nOptions:"
75 "\n\t-h\t\tdisplay this help message\n\t-m MACRO\ttriggers a batch mode "
76 "executing MACRO\n\t-i\t\truns interactive mode, use it together with <-m vis*mac> macros"
77 "\n\t-r\t\trun manager type (0=serial,1=MT,2=tasking)"
78 "\n\t-t\t\tnumber of threads for MT mode (no change for other modes)."
79 );
80 if(argc < 2 ) {
81 G4Exception("main", "No arguments", FatalErrorInArgument,
82 ("No arguments passed to " + G4String(argv[0]) + "\n" + helpMsg)
83 .c_str());
84 }
85 for(G4int i = 1; i < argc; ++i)
86 {
87 G4String argument(argv[i]);
88 if(argument == "-h" || argument == "--help")
89 {
90 G4cout << helpMsg << G4endl;
91 return 0;
92 }
93 else if(argument == "-m")
94 {
95 batchMacroName = G4String(argv[i + 1]);
96 ++i;
97 }
98 else if(argument == "-i")
99 {
100 useInteractiveMode = true;
101 }
102 else if(argument == "-r")
103 {
104 G4int tmp = atoi(argv[i + 1]);
105 ++i;
106 switch (tmp) {
107 case 0:
108 runManagerTypeInt = tmp;
109 runManagerType = G4RunManagerType::Serial;
110 break;
111 case 1:
112 runManagerTypeInt = tmp;
113 runManagerType = G4RunManagerType::MTOnly;
114 break;
115 case 2:
116 runManagerTypeInt = tmp;
117 runManagerType = G4RunManagerType::Tasking;
118 break;
119 default:
120 G4Exception("main", "Wrong Run Manager type", FatalErrorInArgument,
121 "Choose 0 (serial, default), 1 (MT), 2 (tasking)");
122 break;
123 }
124 }
125 else if(argument == "-t")
126 {
127 numOfThreadsOrTasks = atoi(argv[i + 1]);
128 ++i;
129 }
130 else
131 {
132 G4Exception("main", "Unknown argument", FatalErrorInArgument,
133 ("Unknown argument passed to " + G4String(argv[0]) + " : " +
134 argument + "\n" + helpMsg)
135 .c_str());
136 }
137 }
138
139 //choose the Random engine
140 CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine());
141 //set random seed with system time
142 G4long seed = time(NULL);
143 CLHEP::HepRandom::setTheSeed(seed);
144
145 // Instantiate G4UIExecutive if interactive mode
146 G4UIExecutive* ui = nullptr;
147
148 if(useInteractiveMode)
149 {
150 ui = new G4UIExecutive(argc, argv);
151 runManagerType = G4RunManagerType::Serial;
152 }
153
154 // Initialization of default Run manager
155 auto* runManager =
156 G4RunManagerFactory::CreateRunManager(runManagerType);
157 if(runManagerTypeInt == 1)
158 runManager->SetNumberOfThreads(numOfThreadsOrTasks);
159 // Detector geometry:
160 auto detector = new Par04DetectorConstruction();
161 auto parallelWorldFull = new Par04ParallelFullWorld("parallelWorldFullSim", detector);
162 auto parallelWorldFast = new Par04ParallelFastWorld("parallelWorldFastSim", detector,
163 parallelWorldFull);
164 detector->RegisterParallelWorld(parallelWorldFull);
165 detector->RegisterParallelWorld(parallelWorldFast);
166 runManager->SetUserInitialization(detector);
167
168 // Physics list
169 auto physicsList = new FTFP_BERT();
170 // Add fast simulation physics
171 auto fastSimulationPhysics = new G4FastSimulationPhysics();
172 fastSimulationPhysics->BeVerbose();
173 fastSimulationPhysics->ActivateFastSimulation("e-");
174 fastSimulationPhysics->ActivateFastSimulation("e+");
175 fastSimulationPhysics->ActivateFastSimulation("gamma");
176 physicsList->RegisterPhysics(fastSimulationPhysics);
177 // Add parallel world for readout
178 physicsList->RegisterPhysics( new G4ParallelWorldPhysics("parallelWorldFullSim") );
179 physicsList->RegisterPhysics( new G4ParallelWorldPhysics("parallelWorldFastSim") );
180 // reduce verbosity of physics lists
181 G4EmParameters::Instance()->SetVerbose(0);
182 runManager->SetUserInitialization(physicsList);
183
184 //-------------------------------
185 // UserAction classes
186 //-------------------------------
187 runManager->SetUserInitialization(new Par04ActionInitialisation(detector, parallelWorldFull));
188 //----------------
189 // Visualization:
190 //----------------
191 G4cout << "Instantiating Visualization Manager......." << G4endl;
192 G4VisManager* visManager = new G4VisExecutive;
193 visManager->Initialize();
194 G4UImanager* UImanager = G4UImanager::GetUIpointer();
195
196 if(useInteractiveMode)
197 {
198 if(batchMacroName.empty())
199 {
200 G4Exception("main", "Unknown macro name", FatalErrorInArgument,
201 ("No macro name passed to " + G4String(argv[0]))
202 .c_str());
203 }
204 G4String command = "/control/execute ";
205 UImanager->ApplyCommand(command + batchMacroName);
206 ui->SessionStart();
207 delete ui;
208 }
209 else
210 {
211 G4String command = "/control/execute ";
212 UImanager->ApplyCommand(command + batchMacroName);
213 }
214
215 // Free the store: user actions, physics_list and detector_description are
216 // owned and deleted by the run manager, so they should not
217 // be deleted in the main() program !
218
219 delete visManager;
220 delete runManager;
221
222 return 0;
223}
Initialization of user actions.
int main()
Definition testCommon.cc:47

Applications | User Support | Publications | Collaboration