Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-03-30 07:51:00

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 OpNovice.cc
0027 /// \brief Main program of the optical/OpNovice example
0028 
0029 // Description: Test of Continuous Process G4Cerenkov
0030 //              and RestDiscrete Process G4Scintillation
0031 //              -- Generation Cerenkov Photons --
0032 //              -- Generation Scintillation Photons --
0033 //              -- Transport of optical Photons --
0034 // Version:     5.0
0035 // Created:     1996-04-30
0036 // Author:      Juliet Armstrong
0037 //
0038 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0039 
0040 #include "OpNoviceDetectorConstruction.hh"
0041 #ifdef GEANT4_USE_GDML
0042 #  include "OpNoviceGDMLDetectorConstruction.hh"
0043 #endif
0044 #include "FTFP_BERT.hh"
0045 #include "OpNoviceActionInitialization.hh"
0046 
0047 #include "G4EmStandardPhysics_option4.hh"
0048 #include "G4OpticalPhysics.hh"
0049 #include "G4RunManagerFactory.hh"
0050 #include "G4Types.hh"
0051 #include "G4UIExecutive.hh"
0052 #include "G4UImanager.hh"
0053 #include "G4VisExecutive.hh"
0054 
0055 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0056 namespace
0057 {
0058 void PrintUsage()
0059 {
0060   G4cerr << " Usage: " << G4endl;
0061 #ifdef GEANT4_USE_GDML
0062   G4cerr << " OpNovice [-g gdmlfile] [-m macro ] [-u UIsession] [-t "
0063             "nThreads] [-r seed] "
0064          << G4endl;
0065 #else
0066   G4cerr << " OpNovice  [-m macro ] [-u UIsession] [-t nThreads] [-r seed] " << G4endl;
0067 #endif
0068   G4cerr << "   note: -t option is available only for multi-threaded mode." << G4endl;
0069 }
0070 }  // namespace
0071 
0072 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0073 
0074 int main(int argc, char** argv)
0075 {
0076   // Evaluate arguments
0077   //
0078   if (argc > 9) {
0079     PrintUsage();
0080     return 1;
0081   }
0082   G4String gdmlfile;
0083   G4String macro;
0084   G4String session;
0085 #ifdef G4MULTITHREADED
0086   G4int nThreads = 0;
0087 #endif
0088 
0089   G4long myseed = 345354;
0090   for (G4int i = 1; i < argc; i = i + 2) {
0091     if (G4String(argv[i]) == "-g")
0092       gdmlfile = argv[i + 1];
0093     else if (G4String(argv[i]) == "-m")
0094       macro = argv[i + 1];
0095     else if (G4String(argv[i]) == "-u")
0096       session = argv[i + 1];
0097     else if (G4String(argv[i]) == "-r")
0098       myseed = atoi(argv[i + 1]);
0099 #ifdef G4MULTITHREADED
0100     else if (G4String(argv[i]) == "-t") {
0101       nThreads = G4UIcommand::ConvertToInt(argv[i + 1]);
0102     }
0103 #endif
0104     else {
0105       PrintUsage();
0106       return 1;
0107     }
0108   }
0109 
0110   // Instantiate G4UIExecutive if interactive mode
0111   G4UIExecutive* ui = nullptr;
0112   if (macro.size() == 0) {
0113     ui = new G4UIExecutive(argc, argv);
0114   }
0115 
0116   // Construct the default run manager
0117   auto runManager = G4RunManagerFactory::CreateRunManager();
0118 #ifdef G4MULTITHREADED
0119   if (nThreads > 0) runManager->SetNumberOfThreads(nThreads);
0120 #endif
0121 
0122   // Seed the random number generator manually
0123   G4Random::setTheSeed(myseed);
0124 
0125   // Set mandatory initialization classes
0126   //
0127   // Detector construction
0128   if (gdmlfile != "") {
0129 #ifdef GEANT4_USE_GDML
0130     runManager->SetUserInitialization(new OpNoviceGDMLDetectorConstruction(gdmlfile));
0131 #else
0132     G4cout << "Error! Input gdml file specified, but Geant4 wasn't" << G4endl
0133            << "built with gdml support." << G4endl;
0134     return 1;
0135 #endif
0136   }
0137   else {
0138     runManager->SetUserInitialization(new OpNoviceDetectorConstruction());
0139   }
0140   // Physics list
0141   G4VModularPhysicsList* physicsList = new FTFP_BERT;
0142   physicsList->ReplacePhysics(new G4EmStandardPhysics_option4());
0143   auto opticalPhysics = new G4OpticalPhysics();
0144   physicsList->RegisterPhysics(opticalPhysics);
0145   runManager->SetUserInitialization(physicsList);
0146 
0147   runManager->SetUserInitialization(new OpNoviceActionInitialization());
0148 
0149   G4VisManager* visManager = new G4VisExecutive("Quiet");
0150   visManager->Initialize();
0151 
0152   G4UImanager* UImanager = G4UImanager::GetUIpointer();
0153 
0154   if (macro.size()) {
0155     G4String command = "/control/execute ";
0156     UImanager->ApplyCommand(command + macro);
0157   }
0158   else  // Define UI session for interactive mode
0159   {
0160     UImanager->ApplyCommand("/control/execute vis.mac");
0161     if (ui->IsGUI()) UImanager->ApplyCommand("/control/execute gui.mac");
0162     ui->SessionStart();
0163     delete ui;
0164   }
0165 
0166   delete visManager;
0167   delete runManager;
0168 
0169   return 0;
0170 }
0171 
0172 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......