Back to home page

EIC code displayed by LXR

 
 

    


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

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