Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-05 09:00:12

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 //
0027 /// \file field/field06/field06.cc
0028 /// \brief Main program of the field/field06 example
0029 //
0030 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0031 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0032 
0033 #ifndef WIN32
0034 #  include <unistd.h>
0035 #endif
0036 
0037 #include "F06ActionInitialization.hh"
0038 #include "F06DetectorConstruction.hh"
0039 #include "F06PhysicsList.hh"
0040 
0041 #include "G4RunManagerFactory.hh"
0042 #include "G4Transportation.hh"
0043 #include "G4Types.hh"
0044 #include "G4UIExecutive.hh"
0045 #include "G4UIcommand.hh"
0046 #include "G4UImanager.hh"
0047 #include "G4VisExecutive.hh"
0048 #include "Randomize.hh"
0049 
0050 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0051 namespace
0052 {
0053 void PrintUsage()
0054 {
0055   G4cerr << " Usage: " << G4endl;
0056   G4cerr << " field06 [-m macro ] [-u UIsession] [-t nThreads] [-r randomSeed] " << G4endl;
0057   G4cerr << "   note: -t option is available only for multi-threaded mode." << G4endl;
0058 }
0059 }  // namespace
0060 
0061 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0062 
0063 int main(int argc, char** argv)
0064 {
0065   // Evaluate arguments
0066   //
0067   if (argc > 9) {
0068     PrintUsage();
0069     return 1;
0070   }
0071 
0072   G4String macro;
0073   G4String session;
0074   G4int nThreads = 0;
0075 
0076   G4long randomSeed = 1234;
0077   for (G4int i = 1; i < argc; i = i + 2) {
0078     if (G4String(argv[i]) == "-m")
0079       macro = argv[i + 1];
0080     else if (G4String(argv[i]) == "-u")
0081       session = argv[i + 1];
0082     else if (G4String(argv[i]) == "-r")
0083       randomSeed = atoi(argv[i + 1]);
0084     else if (G4String(argv[i]) == "-t") {
0085       nThreads = G4UIcommand::ConvertToInt(argv[i + 1]);
0086     }
0087     else {
0088       PrintUsage();
0089       return 1;
0090     }
0091   }
0092 
0093   // Instantiate G4UIExecutive for interactive mode
0094   G4UIExecutive* ui = nullptr;
0095   if (macro.size() == 0) {
0096     ui = new G4UIExecutive(argc, argv, session);
0097   }
0098 
0099   // Construct the default run manager
0100   //
0101   auto* runManager = G4RunManagerFactory::CreateRunManager();
0102   if (nThreads > 0) runManager->SetNumberOfThreads(nThreads);
0103 
0104   // Seed the random number generator manually
0105   G4Random::setTheSeed(randomSeed);
0106 
0107   // Set mandatory initialization classes
0108   //
0109   // Detector construction
0110   runManager->SetUserInitialization(new F06DetectorConstruction());
0111   // Physics list
0112   runManager->SetUserInitialization(new F06PhysicsList());
0113 
0114   // Ensure that Transportation considers gravity fields.
0115   G4Transportation::EnableGravity(true);
0116 
0117   // User action initialization
0118   runManager->SetUserInitialization(new F06ActionInitialization());
0119 
0120   // Initialize visualization
0121   //
0122   G4VisManager* visManager = new G4VisExecutive;
0123   // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
0124   // G4VisManager* visManager = new G4VisExecutive("Quiet");
0125   visManager->Initialize();
0126 
0127   // Get the pointer to the User Interface manager
0128   //
0129   G4UImanager* UImanager = G4UImanager::GetUIpointer();
0130 
0131   if (!ui) {
0132     // batch mode
0133     G4String command = "/control/execute ";
0134     UImanager->ApplyCommand(command + macro);
0135   }
0136   else {
0137     UImanager->ApplyCommand("/control/execute init_vis.mac");
0138     if (ui->IsGUI()) UImanager->ApplyCommand("/control/execute gui.mac");
0139     ui->SessionStart();
0140     delete ui;
0141   }
0142 
0143   // Job termination
0144   // Free the store: user actions, physics_list and detector_description are
0145   //                 owned and deleted by the run manager, so they should not
0146   //                 be deleted in the main() program !
0147 
0148   delete visManager;
0149   delete runManager;
0150 
0151   return 0;
0152 }
0153 
0154 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......