Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
Hadr01.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 //
28 //
29 //
30 // $Id: Hadr01.cc 109185 2018-04-03 07:20:46Z gcosmo $
31 //
32 // -------------------------------------------------------------
33 // GEANT4 Hadr01
34 //
35 // Application demonstrating Geant4 hadronic physics:
36 // beam interaction with a target
37 //
38 // Authors: A.Bagulya, I.Gudowska, V.Ivanchenko, N.Starkov
39 //
40 // Modified:
41 // 29.12.2009 V.Ivanchenko introduced access to reference PhysLists
42 //
43 // -------------------------------------------------------------
44 //
45 //
46 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
47 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
48 
49 #include "G4RunManager.hh"
50 #include "G4UImanager.hh"
51 #include "Randomize.hh"
52 
53 #include "DetectorConstruction.hh"
54 #include "PhysicsList.hh"
55 #include "G4PhysListFactory.hh"
56 #include "G4VModularPhysicsList.hh"
57 #include "PrimaryGeneratorAction.hh"
58 #include "PhysicsListMessenger.hh"
59 
60 #include "RunAction.hh"
61 #include "EventAction.hh"
62 #include "StackingAction.hh"
63 
64 #include "G4UIExecutive.hh"
65 #include "G4VisExecutive.hh"
66 
67 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
68 
69 int main(int argc,char** argv) {
70 
71  //detect interactive mode (if no arguments) and define UI session
72  G4UIExecutive* ui = nullptr;
73  if (argc == 1) { ui = new G4UIExecutive(argc,argv); }
74 
75  //Construct the default run manager
76  G4RunManager * runManager = new G4RunManager();
77 
78  //set mandatory initialization classes
80 
81  G4PhysListFactory factory;
82  G4VModularPhysicsList* phys = nullptr;
83  PhysicsListMessenger* mess = nullptr;
84  G4String physName = "";
85 
86  //Physics List name defined via 3nd argument
87  if (argc==3) { physName = argv[2]; }
88 
89  // Physics List name defined via environment variable
90  if("" == physName) {
91  char* path = getenv("PHYSLIST");
92  if (path) { physName = G4String(path); }
93  }
94 
95  //reference PhysicsList via its name
96  if ("" != physName && factory.IsReferencePhysList(physName)) {
97  phys = factory.GetReferencePhysList(physName);
98 
99  // instantiated messenger
100  mess = new PhysicsListMessenger();
101  }
102 
103  //local Physics List
104  if(!phys) { phys = new PhysicsList(); }
105 
106  // define physics
107  runManager->SetUserInitialization(phys);
108  runManager->SetUserAction(new PrimaryGeneratorAction());
109 
110  //set user action classes
111  runManager->SetUserAction(new RunAction());
112  runManager->SetUserAction(new EventAction());
113  runManager->SetUserAction(new StackingAction());
114 
115  //initialize visualization
116  G4VisManager* visManager = nullptr;
117 
118  //get the pointer to the User Interface manager
119  G4UImanager* UImanager = G4UImanager::GetUIpointer();
120 
121  if (ui) {
122  //interactive mode
123  visManager = new G4VisExecutive;
124  visManager->Initialize();
125  ui->SessionStart();
126  delete ui;
127  } else {
128  //batch mode
129  G4String command = "/control/execute ";
130  G4String fileName = argv[1];
131  UImanager->ApplyCommand(command+fileName);
132  }
133 
134  //job termination
135  delete mess;
136  delete visManager;
137  delete runManager;
138 }
139 
140 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:466
virtual void SetUserAction(G4UserRunAction *userAction)
G4bool IsReferencePhysList(const G4String &)
G4VModularPhysicsList * GetReferencePhysList(const G4String &)
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:73
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
The primary generator action class with particle gun.
int main(int argc, char **argv)
Definition: genwindef.cc:359
void Initialize()
Simple detector construction with a box volume placed in a world.