Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
field04.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 // $Id: field04.cc 110170 2018-05-17 07:28:42Z gcosmo $
27 //
30 //
31 //
32 // --------------------------------------------------------------
33 //
34 // GEANT 4 - Example F04
35 //
36 // --------------------------------------------------------------
37 // Comments
38 //
39 //
40 // --------------------------------------------------------------
41 
42 #ifndef WIN32
43 #include <unistd.h>
44 #endif
45 
46 #include "G4Types.hh"
47 
48 #ifdef G4MULTITHREADED
49 #include "G4MTRunManager.hh"
50 #else
51 #include "F04SteppingVerbose.hh"
52 #include "G4RunManager.hh"
53 #endif
54 
55 #include "F04PhysicsList.hh"
57 
59 
60 #include "G4UImanager.hh"
61 
62 #include "Randomize.hh"
63 
64 #include "G4VisExecutive.hh"
65 #include "G4UIExecutive.hh"
66 
67 // argc holds the number of arguments (including the name) on the command line
68 // -> it is ONE when only the name is given !!!
69 // argv[0] is always the name of the program
70 // argv[1] points to the first argument, and so on
71 
72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
73 
74 int main(int argc,char** argv)
75 {
76  // Instantiate G4UIExecutive if there are no arguments (interactive mode)
77  G4UIExecutive* ui = nullptr;
78  if ( argc == 1 ) {
79  ui = new G4UIExecutive(argc, argv);
80  }
81 
82  // Choose the Random engine
83  //
84  G4Random::setTheEngine(new CLHEP::RanecuEngine);
85 
86  G4int myseed = 1234;
87  if (argc > 2) myseed = atoi(argv[argc-1]);
88 
89  // Construct the default run manager
90  //
91 #ifdef G4MULTITHREADED
92  G4MTRunManager * runManager = new G4MTRunManager;
93 #else
95  G4RunManager * runManager = new G4RunManager;
96 #endif
97 
98  G4Random::setTheSeed(myseed);
99 
100  G4String physicsList = "QGSP_BERT";
101 
102 #ifndef WIN32
103  G4int c = 0;
104  while ((c=getopt(argc,argv,"p")) != -1)
105  {
106  switch (c)
107  {
108  case 'p':
109  physicsList = optarg;
110  G4cout << "Physics List used is " << physicsList << G4endl;
111  break;
112  case ':': /* -p without operand */
113  fprintf(stderr,"Option -%c requires an operand\n", optopt);
114  break;
115  case '?':
116  fprintf(stderr,"Unrecognised option: -%c\n", optopt);
117  }
118  }
119 #endif
120 
121  // Set mandatory initialization classes
122  //
123  // Detector construction
125  runManager->SetUserInitialization(detector);
126  // Physics list
127  runManager->SetUserInitialization(new F04PhysicsList(physicsList));
128  // User action initialization
129  runManager->SetUserInitialization(new F04ActionInitialization(detector));
130 
131  // Initialize G4 kernel
132  //
133  //runManager->Initialize();
134 
135  // Initialize visualization
136  //
137  G4VisManager* visManager = new G4VisExecutive;
138  // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
139  // G4VisManager* visManager = new G4VisExecutive("Quiet");
140  visManager->Initialize();
141 
142  // Get the pointer to the User Interface manager
143  //
144  G4UImanager* UImanager = G4UImanager::GetUIpointer();
145 
146 #ifndef WIN32
147  G4int optmax = argc;
148  if (argc > 2) { optmax = optmax-1; }
149 
150  if (optind < optmax)
151  {
152  G4String command = "/control/execute ";
153  for ( ; optind < optmax; optind++)
154  {
155  G4String macroFilename = argv[optind];
156  UImanager->ApplyCommand(command+macroFilename);
157  }
158  }
159 #else // Simple UI for Windows runs, no possibility of additional arguments
160  if (!ui) // batch mode
161  {
162  G4String command = "/control/execute ";
163  G4String fileName = argv[1];
164  UImanager->ApplyCommand(command+fileName);
165  }
166 #endif
167  else
168  {
169 // UImanager->ApplyCommand("/control/execute vis.mac");
170  G4cout << "At the prompt, issue commands to set up detector & field, then:"
171  << G4endl;
172  G4cout << "/run/initialize" << G4endl;
173  G4cout << "Then if you want a viewer:"<< G4endl;
174  G4cout << "/control/execute vis.mac" << G4endl;
175  G4cout << "Then: " << G4endl;
176  G4cout << "/run/beamOn … etc." << G4endl;
177  if (ui->IsGUI())
178  UImanager->ApplyCommand("/control/execute gui.mac");
179  ui->SessionStart();
180  delete ui;
181  }
182 
183  // Job termination
184  // Free the store: user actions, physics_list and detector_description are
185  // owned and deleted by the run manager, so they should not
186  // be deleted in the main() program !
187 
188  delete visManager;
189  delete runManager;
190 
191  return 0;
192 }
193 
194 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Action initialization class.
Definition of the F04SteppingVerbose class.
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:466
#define G4endl
Definition: G4ios.hh:61
Definition of the F04PhysicsList class.
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:73
Definition of the F04DetectorConstruction class.
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
Definition of the F04ActionInitialization class.
int main(int argc, char **argv)
Definition: genwindef.cc:359
int G4int
Definition: G4Types.hh:78
static void SetInstance(G4VSteppingVerbose *Instance)
G4GLOB_DLL std::ostream G4cout
void Initialize()
G4bool IsGUI() const