Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-29 08:00:25

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