LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
monopole.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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32 
33 #include "G4Types.hh"
34 
35 #ifdef G4MULTITHREADED
36 #include "G4MTRunManager.hh"
37 #else
38 #include "G4RunManager.hh"
39 #endif
40 
41 #include "G4UImanager.hh"
42 #include "Randomize.hh"
43 
44 #include "G4VisExecutive.hh"
45 #include "G4UIExecutive.hh"
46 
47 #include "DetectorConstruction.hh"
48 #include "G4MonopolePhysics.hh"
49 #include "G4PhysListFactory.hh"
50 #include "G4VModularPhysicsList.hh"
51 #include "ActionInitialization.hh"
52 
53 #include "globals.hh"
54 
55 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
56 
57 namespace {
58  void PrintUsage() {
59  G4cerr
60  << " Usage: " << G4endl
61  << " exampleB4a [-m macro ] [-s setupMonopole] [-t nThreads]" << G4endl
62  << " Note: " << G4endl
63  << " -s should be followed by a composed string, eg. \'1 0 100 GeV\'" << G4endl
64  << " -t option is available only for multi-threaded mode." << G4endl
65  << G4endl;
66  }
67 }
68 
69 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
70 
71 int main(int argc,char** argv)
72 {
73  // Evaluate arguments
74  //
75  if ( argc > 7 ) {
76  PrintUsage();
77  return 1;
78  }
79 
80  G4String macro;
81  G4String setupMonopole;
82 #ifdef G4MULTITHREADED
83  G4int nThreads = 0;
84 #endif
85  for ( G4int i=1; i<argc; i=i+2 ) {
86  if ( G4String(argv[i]) == "-m" ) macro = argv[i+1];
87  else if ( G4String(argv[i]) == "-s" ) setupMonopole = argv[i+1];
88 #ifdef G4MULTITHREADED
89  else if ( G4String(argv[i]) == "-t" ) {
90  nThreads = G4UIcommand::ConvertToInt(argv[i+1]);
91  }
92 #endif
93  else {
94  PrintUsage();
95  return 1;
96  }
97  }
98 
99  // Instantiate G4UIExecutive if interactive mode
100  G4UIExecutive* ui = nullptr;
101  if ( ! macro.size() ) {
102  ui = new G4UIExecutive(argc, argv);
103  }
104 
105  //choose the Random engine
106  CLHEP::HepRandom::setTheEngine(new CLHEP::MixMaxRng);
107 
108  // Construct the default run manager
109 #ifdef G4MULTITHREADED
110  G4MTRunManager* runManager = new G4MTRunManager;
111  if ( nThreads > 0 ) {
112  runManager->SetNumberOfThreads(nThreads);
113  }
114  G4cout << "===== Monopole is started with "
115  << runManager->GetNumberOfThreads() << " threads =====" << G4endl;
116 #else
117  G4RunManager* runManager = new G4RunManager();
118 #endif
119 
120  //create physicsList
121  // Physics List is defined via environment variable PHYSLIST
122  G4PhysListFactory factory;
123  G4VModularPhysicsList* phys = factory.GetReferencePhysList("FTFP_BERT");
124 
125  // monopole physics is added
126  G4MonopolePhysics * theMonopole = new G4MonopolePhysics();
127 
128  //get the pointer to the User Interface manager
129  G4UImanager* UImanager = G4UImanager::GetUIpointer();
130  // Setup monopole
131  if ( setupMonopole.size() ) {
132  UImanager->ApplyCommand("/control/verbose 1");
133  UImanager->ApplyCommand("/monopole/setup " + setupMonopole);
134  }
135 
136  // regsiter monopole physics
137  phys->RegisterPhysics(theMonopole);
138  runManager->SetUserInitialization(phys);
139 
140  // visualization manager
141  G4VisManager* visManager = new G4VisExecutive();
142  visManager->Initialize();
143 
144  // set detector construction
146  runManager->SetUserInitialization(det);
147 
148  // set user action classes
149  runManager->SetUserInitialization(new ActionInitialization(det));
150 
151  // Process macro or start UI session
152  //
153  if ( macro.size() ) {
154  // batch mode
155  G4String command = "/control/execute ";
156  UImanager->ApplyCommand(command+macro);
157  }
158  else {
159  // interactive mode : define UI session
160  UImanager->ApplyCommand("/control/execute init_vis.mac");
161  ui->SessionStart();
162  delete ui;
163  }
164 
165  delete visManager;
166 
167  // job termination
168  delete runManager;
169 
170  return 0;
171 }
172 
173 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void PrintUsage()
int main(int argc, char **argv)
Definition: monopole.cc:71