Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-05 07:50:02

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 /// \file field06.cc
0027 /// \brief Main program of the field/field06 example
0028 
0029 #ifndef WIN32
0030 #  include <unistd.h>
0031 #endif
0032 
0033 #include "F06ActionInitialization.hh"
0034 #include "F06DetectorConstruction.hh"
0035 #include "F06PhysicsList.hh"
0036 
0037 #include "G4RunManagerFactory.hh"
0038 #include "G4Transportation.hh"
0039 #include "G4Types.hh"
0040 #include "G4UIExecutive.hh"
0041 #include "G4UIcommand.hh"
0042 #include "G4UImanager.hh"
0043 #include "G4VisExecutive.hh"
0044 #include "Randomize.hh"
0045 
0046 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0047 namespace
0048 {
0049 void PrintUsage()
0050 {
0051   G4cerr << " Usage: " << G4endl;
0052   G4cerr << " field06 [-m macro ] [-u UIsession] [-t nThreads] [-r randomSeed] " << G4endl;
0053   G4cerr << "   note: -t option is available only for multi-threaded mode." << G4endl;
0054 }
0055 }  // namespace
0056 
0057 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0058 
0059 int main(int argc, char** argv)
0060 {
0061   // Evaluate arguments
0062   //
0063   if (argc > 9) {
0064     PrintUsage();
0065     return 1;
0066   }
0067 
0068   G4String macro;
0069   G4String session;
0070   G4int nThreads = 0;
0071 
0072   G4long randomSeed = 1234;
0073   for (G4int i = 1; i < argc; i = i + 2) {
0074     if (G4String(argv[i]) == "-m")
0075       macro = argv[i + 1];
0076     else if (G4String(argv[i]) == "-u")
0077       session = argv[i + 1];
0078     else if (G4String(argv[i]) == "-r")
0079       randomSeed = atoi(argv[i + 1]);
0080     else if (G4String(argv[i]) == "-t") {
0081       nThreads = G4UIcommand::ConvertToInt(argv[i + 1]);
0082     }
0083     else {
0084       PrintUsage();
0085       return 1;
0086     }
0087   }
0088 
0089   // Instantiate G4UIExecutive for interactive mode
0090   G4UIExecutive* ui = nullptr;
0091   if (macro.size() == 0) {
0092     ui = new G4UIExecutive(argc, argv, session);
0093   }
0094 
0095   // Construct the default run manager
0096   //
0097   auto* runManager = G4RunManagerFactory::CreateRunManager();
0098   if (nThreads > 0) runManager->SetNumberOfThreads(nThreads);
0099 
0100   // Seed the random number generator manually
0101   G4Random::setTheSeed(randomSeed);
0102 
0103   // Set mandatory initialization classes
0104   //
0105   // Detector construction
0106   runManager->SetUserInitialization(new F06DetectorConstruction());
0107   // Physics list
0108   runManager->SetUserInitialization(new F06PhysicsList());
0109 
0110   // Ensure that Transportation considers gravity fields.
0111   G4Transportation::EnableGravity(true);
0112 
0113   // User action initialization
0114   runManager->SetUserInitialization(new F06ActionInitialization());
0115 
0116   // Initialize visualization
0117   //
0118   G4VisManager* visManager = new G4VisExecutive;
0119   // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
0120   // G4VisManager* visManager = new G4VisExecutive("Quiet");
0121   visManager->Initialize();
0122 
0123   // Get the pointer to the User Interface manager
0124   //
0125   G4UImanager* UImanager = G4UImanager::GetUIpointer();
0126 
0127   if (!ui) {
0128     // batch mode
0129     G4String command = "/control/execute ";
0130     UImanager->ApplyCommand(command + macro);
0131   }
0132   else {
0133     UImanager->ApplyCommand("/control/execute init_vis.mac");
0134     if (ui->IsGUI()) UImanager->ApplyCommand("/control/execute gui.mac");
0135     ui->SessionStart();
0136     delete ui;
0137   }
0138 
0139   // Job termination
0140   // Free the store: user actions, physics_list and detector_description are
0141   //                 owned and deleted by the run manager, so they should not
0142   //                 be deleted in the main() program !
0143 
0144   delete visManager;
0145   delete runManager;
0146 
0147   return 0;
0148 }
0149 
0150 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......