Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-01 07:38:35

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 exampleVecGeomNav.cc
0027 /// \brief Main program of the geometry/vecGeomNavigation example
0028 
0029 //  Author: J. Apostolakis, S. Wenzel,  2018-2021
0030 //
0031 //  Started from FullCMS Geant4 application by Mihaly Novak  (2017)
0032 //---------------------------------------------------------------------
0033 
0034 #include "FTFP_BERT.hh"
0035 #include "VG01ActionInitialization.hh"
0036 #include "VG01DetectorConstruction.hh"
0037 #include "VG01SteppingVerboseWithDir.hh"
0038 
0039 #include "G4RunManager.hh"
0040 #include "G4RunManagerFactory.hh"
0041 #include "G4StepLimiterPhysics.hh"
0042 #include "G4UImanager.hh"
0043 #include "G4UIsession.hh"
0044 #include "G4UIterminal.hh"
0045 #include "G4VModularPhysicsList.hh"
0046 #include "Randomize.hh"
0047 
0048 #include <iomanip>
0049 #include <iostream>
0050 
0051 // For interactivity
0052 #include "G4UIExecutive.hh"
0053 #include "G4VisExecutive.hh"
0054 
0055 static G4bool parUseVecGeom = true;
0056 static G4bool parCompareG4 = false;
0057 static G4bool parInteractive = false;
0058 static std::string parMacroFileName = "";
0059 static std::string parGDMLFile = "TestNTST.gdml";
0060 
0061 void GetInputArguments(int argc, char** argv);
0062 void PrintUsage();
0063 
0064 int main(int argc, char** argv)
0065 {
0066   //
0067   // get input arguments
0068   GetInputArguments(argc, argv);
0069   G4cout << " ========== Running exampleVecGeomNav ================ " << G4endl
0070          << "   GDML geometry file          =  " << parGDMLFile << G4endl
0071          << "   Geant4 macro                =  " << parMacroFileName << G4endl
0072          << "   Use VecGeom (VG) navigation =  " << parUseVecGeom << G4endl
0073          << "   Compare G4 vs VG navigation =  " << parCompareG4 << G4endl
0074          << " ===================================================== " << G4endl;
0075 
0076   // Use custom stepping verbosity
0077   G4VSteppingVerbose::SetInstance(new VG01SteppingVerboseWithDir());
0078 
0079   // Construct the run manager
0080   //
0081   G4RunManager* runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::Serial);
0082   //  or G4RunManagerType::Default to get Task or Multithreading
0083 
0084   // set mandatory initialization classes
0085   //
0086   // 1. Detector construction
0087   //
0088   VG01DetectorConstruction* detector = new VG01DetectorConstruction;
0089   detector->SetGDMLFileName(parGDMLFile);
0090   detector->SetUseVecGeom(parUseVecGeom);
0091   runManager->SetUserInitialization(detector);
0092 
0093   // 2. Physics list
0094   //
0095   G4VModularPhysicsList* physicsList = new FTFP_BERT;
0096   physicsList->RegisterPhysics(new G4StepLimiterPhysics());
0097   runManager->SetUserInitialization(physicsList);
0098 
0099   // 3. User action
0100   //
0101   runManager->SetUserInitialization(new VG01ActionInitialization());
0102 
0103   // 4. Run the simulation in batch mode, except if macroFile == "-"
0104   //
0105   G4UImanager* UImgr = G4UImanager::GetUIpointer();
0106   G4String command = "/control/execute ";
0107   if (parMacroFileName != "-") UImgr->ApplyCommand(command + parMacroFileName);
0108 
0109   // 5. Run the simulation in Interactive mode if requested ( flag: -i )
0110   //
0111   if (parInteractive) {
0112     G4UIExecutive* uiExec = 0;
0113     uiExec = new G4UIExecutive(argc, argv);
0114 
0115     // Initialize visualization
0116     //
0117     G4VisManager* visManager = new G4VisExecutive;
0118     // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
0119     // G4VisManager* visManager = new G4VisExecutive("Quiet");
0120     visManager->Initialize();
0121 
0122     // UImgr->ApplyCommand("/control/execute init_vis.mac");
0123 
0124     // interactive mode
0125     uiExec->SessionStart();
0126 
0127     // Cleanup
0128     delete uiExec;
0129     delete visManager;
0130   }
0131   else {
0132     // Print out the final random number - for batch only runs
0133     G4cout << G4endl
0134            << " ================================================================= " << G4endl
0135            << " Final random number = " << G4UniformRand() << G4endl
0136            << " ================================================================= " << G4endl
0137            << G4endl;
0138   }
0139   //
0140 
0141   // Delete the RunManager
0142   delete runManager;
0143   return 0;
0144 }
0145 
0146 void horizontal_line(char c)
0147 {
0148   std::cout << "\n " << std::setw(100) << std::setfill(c) << "" << std::setfill(' ') << std::endl;
0149 }
0150 
0151 void PrintUsage()
0152 {
0153   horizontal_line('=');
0154   std::cout << "  Geant4 application to demonstrate interface to VecGeom Navigation.    \n"
0155             << std::endl
0156             << "  Two modes: \n\n"
0157             << "   * 1 parameter this is treated as Geant4 macro file \n"
0158             << " \n"
0159             << "   * Multiple Parameters: \n"
0160             << "      at least one of the following: \n"
0161             << "       -m :   the standard Geant4 macro file \n"
0162             << "       -i :   interactive (after batch, if any) \n"
0163             << "      optionally one of the following: \n"
0164             << "       -v :   flag  ==> run using VecGeom navigation (default). \n"
0165             << "       -o :   flag  ==> run using Geant4  navigation. \n"
0166             << "       -c :   flag  ==> compare VecGeom and Geant4 navigation"
0167             << " (and report differences.) \n"
0168             << "      and other(s): \n"
0169             << "       -g :   GDML file with geometry \n"
0170             << "\n"
0171             << std::endl;
0172   horizontal_line('=');
0173 }
0174 
0175 void GetInputArguments(int argc, char** argv)
0176 {
0177   // process arguments
0178   if (argc == 1) {
0179     PrintUsage();
0180     exit(0);
0181   }
0182   if (argc == 2) {
0183     parMacroFileName = argv[1];
0184     G4cout << " argc = 2  -- Filename = " << parMacroFileName << G4endl;
0185     return;
0186   }
0187 
0188   // Adapted from examples/basic/B4/exampleB4a.cc
0189   for (G4int i = 1; i < argc; ++i) {
0190     if (G4String(argv[i]) == "-m") {
0191       if (++i < argc) {
0192         parMacroFileName = argv[i];
0193         G4cout << " arg-parsing:  Macro file name= " << parMacroFileName << G4endl;
0194       }
0195       else {
0196         G4cerr << " Parse Error: '-m' cannot be last argument.  Use it : -m <filename>" << G4endl;
0197         PrintUsage();
0198         exit(1);
0199       }
0200     }
0201     else if (G4String(argv[i]) == "-g") {
0202       if (++i < argc) {
0203         parGDMLFile = argv[i];
0204         G4cout << " arg-parsing:  GDML file name= " << parGDMLFile << G4endl;
0205       }
0206       else {
0207         G4cerr << " Parse Error: '-m' cannot be last argument.  Use it : -m <filename>" << G4endl;
0208         PrintUsage();
0209         exit(1);
0210       }
0211     }
0212     else if (G4String(argv[i]) == "-v") {
0213       parUseVecGeom = true;
0214     }
0215     else if (G4String(argv[i]) == "-o") {
0216       parUseVecGeom = false;
0217     }
0218     else if (G4String(argv[i]) == "-c") {
0219       parCompareG4 = true;
0220       parUseVecGeom = true;
0221     }
0222     else {
0223       G4cerr << "  Unknown argument : " << argv[i] << G4endl;
0224       PrintUsage();
0225       exit(1);
0226     }
0227   }
0228 
0229   // check if mandatory Geant4 macro file was provided
0230   if (parMacroFileName == "" && !parInteractive) {
0231     G4cerr << "  *** ERROR : either interactive mode or a Geant4 macro file is required. "
0232            << G4endl;
0233     PrintUsage();
0234     exit(-1);
0235   }
0236 }