Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-27 07:34:09

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 factory.cc
0027 /// \brief Main program of the physicslists/factory example
0028 
0029 // -------------------------------------------------------------
0030 //      factory
0031 //
0032 //  Application demonstrating the usage of G4PhysListFactory
0033 //  to build the concrete physics list
0034 //
0035 //  Modified from hadronic/Hadr00/Hadr00.cc
0036 //     Author: V.Ivanchenko 20 June 2008
0037 // -------------------------------------------------------------
0038 //
0039 //
0040 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0041 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0042 
0043 #include "ActionInitialization.hh"
0044 #include "DetectorConstruction.hh"
0045 #include "PrimaryGeneratorAction.hh"
0046 
0047 #include "G4PhysListFactory.hh"
0048 #include "G4RunManagerFactory.hh"
0049 #include "G4UIExecutive.hh"
0050 #include "G4UImanager.hh"
0051 #include "G4VModularPhysicsList.hh"
0052 #include "G4VisExecutive.hh"
0053 #include "Randomize.hh"
0054 
0055 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0056 
0057 namespace
0058 {
0059 void PrintUsage()
0060 {
0061   G4cerr << " Usage: " << G4endl;
0062   G4cerr << " factory [-m macro ] [-p physList ] [-u UIsession] [-t nThreads]" << G4endl;
0063   G4cerr << "   note: -t option is available only for multi-threaded mode." << G4endl;
0064   G4cerr << G4endl;
0065 }
0066 }  // namespace
0067 
0068 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0069 
0070 int main(int argc, char** argv)
0071 {
0072   // Evaluate arguments
0073   //
0074   if (argc > 9) {
0075     PrintUsage();
0076     return 1;
0077   }
0078 
0079   G4String macro;
0080   G4String session;
0081   G4String physListName;
0082   G4String gdmlFileName;
0083 #ifdef G4MULTITHREADED
0084   G4int nofThreads = 0;
0085 #endif
0086   for (G4int i = 1; i < argc; i = i + 2) {
0087     if (G4String(argv[i]) == "-m")
0088       macro = argv[i + 1];
0089     else if (G4String(argv[i]) == "-u")
0090       session = argv[i + 1];
0091     else if (G4String(argv[i]) == "-p")
0092       physListName = argv[i + 1];
0093 #ifdef G4MULTITHREADED
0094     else if (G4String(argv[i]) == "-t") {
0095       nofThreads = G4UIcommand::ConvertToInt(argv[i + 1]);
0096     }
0097 #endif
0098     else {
0099       PrintUsage();
0100       return 1;
0101     }
0102   }
0103 
0104   // Detect interactive mode (if no arguments) and define UI session
0105   //
0106   G4UIExecutive* ui = nullptr;
0107   if (!macro.size()) {
0108     ui = new G4UIExecutive(argc, argv, session);
0109   }
0110 
0111   // Choose the Random engine  //choose the Random engine
0112   G4Random::setTheEngine(new CLHEP::RanecuEngine());
0113 
0114   // Construct the run manager
0115   auto* runManager = G4RunManagerFactory::CreateRunManager();
0116 #ifdef G4MULTITHREADED
0117   if (nofThreads > 0) {
0118     runManager->SetNumberOfThreads(nofThreads);
0119   }
0120 #endif
0121 
0122   // Physics list factory
0123   G4PhysListFactory factory;
0124   G4VModularPhysicsList* physList = nullptr;
0125 
0126   // Get physics list name
0127   if (!physListName.size()) {
0128     // Physics List is defined via environment variable PHYSLIST
0129     char* physListNameEnv = std::getenv("PHYSLIST");
0130     if (physListNameEnv) {
0131       physListName = G4String(physListNameEnv);
0132     }
0133   }
0134 
0135   // Check if the name is known to the factory
0136   if (physListName.size() && (!factory.IsReferencePhysList(physListName))) {
0137     G4cerr << "Physics list " << physListName << " is not available in PhysListFactory." << G4endl;
0138     physListName.clear();
0139   }
0140 
0141   // If name is not defined use FTFP_BERT
0142   if (!physListName.size()) {
0143     physListName = "FTFP_BERT";
0144   }
0145 
0146   // Reference PhysicsList via its name
0147   physList = factory.GetReferencePhysList(physListName);
0148 
0149   // Set mandatory initialization classes
0150   runManager->SetUserInitialization(new DetectorConstruction());
0151   runManager->SetUserInitialization(physList);
0152 
0153   // set user action classes
0154   runManager->SetUserInitialization(new ActionInitialization("factory"));
0155 
0156   // Initialize visualization
0157   G4VisManager* visManager = new G4VisExecutive;
0158   // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
0159   // G4VisManager* visManager = new G4VisExecutive("Quiet");
0160   visManager->Initialize();
0161 
0162   // Get the pointer to the User Interface manager
0163   G4UImanager* UImanager = G4UImanager::GetUIpointer();
0164 
0165   if (macro.size()) {
0166     // batch mode
0167     G4String command = "/control/execute ";
0168     UImanager->ApplyCommand(command + macro);
0169   }
0170   else {
0171     // interactive mode : define UI session
0172     UImanager->ApplyCommand("/control/execute init_vis.mac");
0173     ui->SessionStart();
0174     delete ui;
0175   }
0176 
0177   // Job termination
0178   // Free the store: user actions, physics_list and detector_description are
0179   // owned and deleted by the run manager, so they should not be deleted
0180   // in the main() program !
0181 
0182   delete visManager;
0183   delete runManager;
0184 }
0185 
0186 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......