Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-08 07:53: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 /// \file clGeometry.cc
0027 /// \brief Main program of the g3tog4/clGeometry example
0028 
0029 // package includes
0030 #include "G3toG4ActionInitialization.hh"
0031 #include "G3toG4DetectorConstruction.hh"
0032 
0033 // geant4 includes
0034 #include "FTFP_BERT.hh"
0035 #include "G3VolTable.hh"
0036 
0037 #include "G4RunManagerFactory.hh"
0038 #include "G4UIExecutive.hh"
0039 #include "G4UImanager.hh"
0040 #include "G4VisExecutive.hh"
0041 #include "G4ios.hh"
0042 
0043 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0044 
0045 namespace
0046 {
0047 void PrintUsage()
0048 {
0049   G4cerr << " Usage: " << G4endl;
0050   G4cerr << "clGeometry <call_list_file> [-m macro ] [-u UIsession] [-t nThreads]" << G4endl;
0051   G4cerr << "   note: -t option is relevant only for multi-threaded mode." << G4endl;
0052 }
0053 }  // namespace
0054 
0055 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0056 
0057 int main(int argc, char** argv)
0058 {
0059   // Evaluate arguments
0060   //
0061   G4cout << "argc " << argc << G4endl;
0062   if (argc < 2 || argc > 8) {
0063     PrintUsage();
0064     return 1;
0065   }
0066 
0067   G4String inFile;
0068   G4String macro = "";
0069   G4String session;
0070   G4int nofThreads = 0;
0071 
0072   // First argument is mandatory
0073   inFile = argv[1];
0074   G4cout << "Geometry data file: " << inFile << G4endl;
0075   std::ifstream in(inFile);
0076   if (!in) {
0077     G4cerr << "Cannot open input file \"" << inFile << "\"" << G4endl;
0078     return EXIT_FAILURE;
0079   }
0080 
0081   // Optional arguments
0082   for (G4int i = 2; i < argc; i = i + 2) {
0083     G4cout << "evaluating " << argv[i] << G4endl;
0084     if (G4String(argv[i]) == "-m")
0085       macro = argv[i + 1];
0086     else if (G4String(argv[i]) == "-u")
0087       session = argv[i + 1];
0088     else if (G4String(argv[i]) == "-t") {
0089       nofThreads = G4UIcommand::ConvertToInt(argv[i + 1]);
0090     }
0091     else {
0092       PrintUsage();
0093       return 1;
0094     }
0095   }
0096 
0097   // Detect interactive mode (if no macro provided) and define UI session
0098   //
0099   G4UIExecutive* ui = nullptr;
0100   if (!macro.size()) {
0101     ui = new G4UIExecutive(argc, argv, session);
0102   }
0103 
0104   // Construct the default run manager
0105   auto* runManager = G4RunManagerFactory::CreateRunManager();
0106   if (nofThreads > 0) runManager->SetNumberOfThreads(nofThreads);
0107 
0108   // Set mandatory initialization classes
0109   //
0110   // Detector construction
0111   runManager->SetUserInitialization(new G3toG4DetectorConstruction(inFile));
0112 
0113   // Physics list
0114   runManager->SetUserInitialization(new FTFP_BERT);
0115 
0116   // User action initialization
0117   runManager->SetUserInitialization(new G3toG4ActionInitialization());
0118 
0119   // Initialize visualization
0120   //
0121   auto visManager = new G4VisExecutive;
0122   // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
0123   // G4VisManager* visManager = new G4VisExecutive("Quiet");
0124   visManager->Initialize();
0125 
0126   // Get the pointer to the User Interface manager
0127   auto UImanager = G4UImanager::GetUIpointer();
0128 
0129   // Process macro or start UI session
0130   //
0131   if (macro.size()) {
0132     // batch mode
0133     G4String command = "/control/execute ";
0134     UImanager->ApplyCommand(command + macro);
0135   }
0136   else {
0137     // interactive mode : define UI session
0138     UImanager->ApplyCommand("/control/execute init_vis.mac");
0139     ui->SessionStart();
0140     delete ui;
0141   }
0142 
0143   // Job termination
0144   // Free the store: user actions, physics_list and detector_description are
0145   // owned and deleted by the run manager, so they should not be deleted
0146   // in the main() program !
0147 
0148   delete visManager;
0149   delete runManager;
0150 }