Back to home page

EIC code displayed by LXR

 
 

    


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

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