Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:21:19

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