Back to home page

EIC code displayed by LXR

 
 

    


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

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 exoticphysics/ucn/ExUCN.cc
0028 /// \brief Main program of the exoticphysics/ucn example
0029 //
0030 //
0031 //
0032 //
0033 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0034 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0035 
0036 #ifndef WIN32
0037 #  include <unistd.h>
0038 #endif
0039 
0040 #include "ExUCNActionInitialization.hh"
0041 #include "ExUCNDetectorConstruction.hh"
0042 #include "ExUCNPhysicsList.hh"
0043 
0044 #include "G4RunManagerFactory.hh"
0045 #include "G4Types.hh"
0046 #include "G4UIExecutive.hh"
0047 #include "G4UIcommand.hh"
0048 #include "G4UImanager.hh"
0049 #include "G4VisExecutive.hh"
0050 #include "Randomize.hh"
0051 
0052 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0053 
0054 namespace
0055 {
0056 void PrintUsage()
0057 {
0058   G4cerr << " Usage: " << G4endl;
0059   G4cerr << " ExUCN [-m macro ] [-u UIsession] [-t nThreads] [-r seed] " << G4endl;
0060   G4cerr << "   note: -t option is available only for multi-threaded mode." << G4endl;
0061 }
0062 }  // namespace
0063 
0064 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0065 
0066 int main(int argc, char** argv)
0067 {
0068   // Evaluate arguments
0069   //
0070   if (argc > 9) {
0071     PrintUsage();
0072     return 1;
0073   }
0074 
0075   G4String macro;
0076   G4String session;
0077   G4int nThreads = 0;
0078 
0079   G4long myseed = 1234;
0080   for (G4int i = 1; i < argc; i = i + 2) {
0081     if (G4String(argv[i]) == "-m")
0082       macro = argv[i + 1];
0083     else if (G4String(argv[i]) == "-u")
0084       session = argv[i + 1];
0085     else if (G4String(argv[i]) == "-r")
0086       myseed = atoi(argv[i + 1]);
0087     else if (G4String(argv[i]) == "-t") {
0088       nThreads = G4UIcommand::ConvertToInt(argv[i + 1]);
0089     }
0090     else {
0091       PrintUsage();
0092       return 1;
0093     }
0094   }
0095 
0096   // Instantiate G4UIExecutive if interactive mode
0097   G4UIExecutive* ui = nullptr;
0098   if (argc == 1) {
0099     ui = new G4UIExecutive(argc, argv);
0100   }
0101 
0102   // Choose the Random engine
0103   //
0104   G4Random::setTheEngine(new CLHEP::RanecuEngine);
0105 
0106   // Construct the default run manager
0107   //
0108   auto* runManager = G4RunManagerFactory::CreateRunManager();
0109   if (nThreads > 0) runManager->SetNumberOfThreads(nThreads);
0110 
0111   // Seed the random number generator manually
0112   G4Random::setTheSeed(myseed);
0113 
0114   // Set mandatory initialization classes
0115   //
0116   // Detector construction
0117   runManager->SetUserInitialization(new ExUCNDetectorConstruction());
0118   // Physics list
0119   runManager->SetUserInitialization(new ExUCNPhysicsList());
0120   // User action initialization
0121   runManager->SetUserInitialization(new ExUCNActionInitialization());
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   if (macro.size()) {
0139     // batch mode
0140     G4String command = "/control/execute ";
0141     UImanager->ApplyCommand(command + macro);
0142   }
0143   else {  // interactive mode : define UI session
0144     UImanager->ApplyCommand("/control/execute vis.mac");
0145     if (ui->IsGUI()) UImanager->ApplyCommand("/control/execute gui.mac");
0146     ui->SessionStart();
0147     delete ui;
0148   }
0149 
0150   // Job termination
0151   // Free the store: user actions, physics_list and detector_description are
0152   //                 owned and deleted by the run manager, so they should not
0153   //                 be deleted in the main() program !
0154 
0155   delete visManager;
0156   delete runManager;
0157 
0158   return 0;
0159 }
0160 
0161 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......