Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:22:39

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