Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-03-31 07:50:07

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 field04.cc
0027 /// \brief Main program of the field/field04 example
0028 
0029 #ifndef WIN32
0030 #  include <unistd.h>
0031 #endif
0032 
0033 #include "G4Types.hh"
0034 
0035 #include "G4RunManagerFactory.hh"
0036 #include "F04SteppingVerbose.hh"
0037 
0038 #include "F04ActionInitialization.hh"
0039 #include "F04DetectorConstruction.hh"
0040 #include "F04PhysicsList.hh"
0041 
0042 #include "G4UIExecutive.hh"
0043 #include "G4UImanager.hh"
0044 #include "G4VisExecutive.hh"
0045 #include "Randomize.hh"
0046 
0047 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0048 
0049 namespace
0050 {
0051 void PrintUsage()
0052 {
0053   G4cerr << " Usage: " << G4endl;
0054   G4cerr << " field04 [-m macro ] [-p physicsList] [-r randomSeed] [-s preinit|idle]" << G4endl;
0055 }
0056 }  // namespace
0057 
0058 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0059 
0060 int main(int argc, char** argv)
0061 {
0062   // Evaluate arguments
0063   // argc holds the number of arguments (including the name) on the command line
0064   // -> it is ONE when only the name is  given !!!
0065   // argv[0] is always the name of the program
0066   // argv[1] points to the first argument, and so on
0067   //
0068   if (argc > 7) {
0069     PrintUsage();
0070     return 1;
0071   }
0072 
0073   G4String macro;
0074   G4String physicsList = "QGSP_BERT";
0075   G4int randomSeed = 1234;
0076   G4String startPhase = "idle";
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]) == "-r")
0081       randomSeed = atoi(argv[i + 1]);
0082     else if (G4String(argv[i]) == "-p")
0083       physicsList = argv[i + 1];
0084     else if (G4String(argv[i]) == "-s")
0085       startPhase = argv[i + 1];
0086     else {
0087       PrintUsage();
0088       return 1;
0089     }
0090   }
0091 
0092   // Instantiate G4UIExecutive if there are no arguments (interactive mode)
0093   //
0094   G4UIExecutive* ui = nullptr;
0095   if (!macro.size()) {
0096     ui = new G4UIExecutive(argc, argv);
0097   }
0098 
0099   // Setting the application-specific SteppingVerbose
0100   //
0101   auto verbosity = new F04SteppingVerbose;
0102 
0103   // Construct the default run manager
0104   //
0105   auto runManager = G4RunManagerFactory::CreateRunManager();
0106 
0107   G4Random::setTheSeed(randomSeed);
0108 
0109   // Set mandatory initialization classes
0110   //
0111   // Detector construction
0112   auto detector = new F04DetectorConstruction();
0113   runManager->SetUserInitialization(detector);
0114   // Physics list
0115   runManager->SetUserInitialization(new F04PhysicsList(physicsList));
0116   // User action initialization
0117   runManager->SetUserInitialization(new F04ActionInitialization(detector));
0118 
0119   // Initialize G4 kernel
0120   //
0121   // runManager->Initialize();
0122 
0123   // Initialize visualization
0124   //
0125   G4VisManager* visManager = new G4VisExecutive;
0126   // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
0127   // G4VisManager* visManager = new G4VisExecutive("Quiet");
0128   visManager->Initialize();
0129 
0130   // Get the pointer to the User Interface manager
0131   //
0132   G4UImanager* UImanager = G4UImanager::GetUIpointer();
0133 
0134   // Process macro or start UI session
0135   //
0136   if (macro.size()) {
0137     // batch mode
0138     G4String command = "/control/execute ";
0139     UImanager->ApplyCommand(command + macro);
0140   }
0141   else {
0142     // interactive mode : define UI session
0143     if (startPhase == "preinit") {
0144       // start in PreInit> phase if requested
0145       G4cout << "At the prompt, issue commands to set up detector & field, then:" << G4endl;
0146       G4cout << "/run/initialize" << G4endl;
0147       G4cout << "Then if you want a viewer:" << G4endl;
0148       G4cout << "/control/execute vis.mac" << G4endl;
0149       G4cout << "Then: " << G4endl;
0150       G4cout << "/run/beamOn … etc." << G4endl;
0151     }
0152     else {
0153       // perform initialization and draw geometry
0154       UImanager->ApplyCommand("/control/execute init_vis.mac");
0155     }
0156     if (ui->IsGUI()) {
0157       UImanager->ApplyCommand("/control/execute gui.mac");
0158     }
0159     ui->SessionStart();
0160     delete ui;
0161   }
0162 
0163   // Job termination
0164   // Free the store: user actions, physics_list and detector_description are
0165   //                 owned and deleted by the run manager, so they should not
0166   //                 be deleted in the main() program !
0167 
0168   delete verbosity;
0169   delete visManager;
0170   delete runManager;
0171 
0172   return 0;
0173 }
0174 
0175 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......