Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:17:16

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 exampleB4c.cc
0028 /// \brief Main program of the B4c example
0029 
0030 #include "ActionInitialization.hh"
0031 #include "DetectorConstruction.hh"
0032 #include "FTFP_BERT.hh"
0033 
0034 #include "G4RunManagerFactory.hh"
0035 #include "G4SteppingVerbose.hh"
0036 #include "G4UIExecutive.hh"
0037 #include "G4UIcommand.hh"
0038 #include "G4UImanager.hh"
0039 #include "G4VisExecutive.hh"
0040 // #include "Randomize.hh"
0041 
0042 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0043 
0044 namespace
0045 {
0046 void PrintUsage()
0047 {
0048   G4cerr << " Usage: " << G4endl;
0049   G4cerr << " exampleB4c [-m macro ] [-u UIsession] [-t nThreads] [-vDefault]" << G4endl;
0050   G4cerr << "   note: -t option is available only for multi-threaded mode." << G4endl;
0051 }
0052 }  // namespace
0053 
0054 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0055 
0056 int main(int argc, char** argv)
0057 {
0058   // Evaluate arguments
0059   //
0060   if (argc > 7) {
0061     PrintUsage();
0062     return 1;
0063   }
0064 
0065   G4String macro;
0066   G4String session;
0067   G4bool verboseBestUnits = true;
0068 #ifdef G4MULTITHREADED
0069   G4int nThreads = 0;
0070 #endif
0071   for (G4int i = 1; i < argc; i = i + 2) {
0072     if (G4String(argv[i]) == "-m")
0073       macro = argv[i + 1];
0074     else if (G4String(argv[i]) == "-u")
0075       session = argv[i + 1];
0076 #ifdef G4MULTITHREADED
0077     else if (G4String(argv[i]) == "-t") {
0078       nThreads = G4UIcommand::ConvertToInt(argv[i + 1]);
0079     }
0080 #endif
0081     else if (G4String(argv[i]) == "-vDefault") {
0082       verboseBestUnits = false;
0083       --i;  // this option is not followed with a parameter
0084     }
0085     else {
0086       PrintUsage();
0087       return 1;
0088     }
0089   }
0090 
0091   // Detect interactive mode (if no macro provided) and define UI session
0092   //
0093   G4UIExecutive* ui = nullptr;
0094   if (!macro.size()) {
0095     ui = new G4UIExecutive(argc, argv, session);
0096   }
0097 
0098   // Optionally: choose a different Random engine...
0099   // G4Random::setTheEngine(new CLHEP::MTwistEngine);
0100 
0101   // Use G4SteppingVerboseWithUnits
0102   if (verboseBestUnits) {
0103     G4int precision = 4;
0104     G4SteppingVerbose::UseBestUnit(precision);
0105   }
0106 
0107   // Construct the default run manager
0108   //
0109   auto runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::Default);
0110 #ifdef G4MULTITHREADED
0111   if (nThreads > 0) {
0112     runManager->SetNumberOfThreads(nThreads);
0113   }
0114 #endif
0115 
0116   // Set mandatory initialization classes
0117   //
0118   auto detConstruction = new B4c::DetectorConstruction();
0119   runManager->SetUserInitialization(detConstruction);
0120 
0121   auto physicsList = new FTFP_BERT;
0122   runManager->SetUserInitialization(physicsList);
0123 
0124   auto actionInitialization = new B4c::ActionInitialization();
0125   runManager->SetUserInitialization(actionInitialization);
0126 
0127   // Initialize visualization
0128   auto visManager = new G4VisExecutive;
0129   // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
0130   // auto visManager = new G4VisExecutive("Quiet");
0131   visManager->Initialize();
0132 
0133   // Get the pointer to the User Interface manager
0134   auto UImanager = G4UImanager::GetUIpointer();
0135 
0136   // Process macro or start UI session
0137   //
0138   if (macro.size()) {
0139     // batch mode
0140     G4String command = "/control/execute ";
0141     UImanager->ApplyCommand(command + macro);
0142   }
0143   else {
0144     // interactive mode : define UI session
0145     UImanager->ApplyCommand("/control/execute init_vis.mac");
0146     if (ui->IsGUI()) {
0147       UImanager->ApplyCommand("/control/execute gui.mac");
0148     }
0149     ui->SessionStart();
0150     delete ui;
0151   }
0152 
0153   // Job termination
0154   // Free the store: user actions, physics_list and detector_description are
0155   // owned and deleted by the run manager, so they should not be deleted
0156   // in the main() program !
0157 
0158   delete visManager;
0159   delete runManager;
0160 }
0161 
0162 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....