Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-19 08:37:32

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 monopole.cc
0027 /// \brief Main program of the exoticphysics/monopole example
0028 
0029 #include "ActionInitialization.hh"
0030 #include "DetectorConstruction.hh"
0031 
0032 #include "G4MonopolePhysics.hh"
0033 #include "G4PhysListFactory.hh"
0034 #include "G4RunManagerFactory.hh"
0035 #include "G4Types.hh"
0036 #include "G4UIExecutive.hh"
0037 #include "G4UImanager.hh"
0038 #include "G4VModularPhysicsList.hh"
0039 #include "G4VisExecutive.hh"
0040 #include "Randomize.hh"
0041 #include "globals.hh"
0042 
0043 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0044 
0045 namespace
0046 {
0047 void PrintUsage()
0048 {
0049   G4cerr << " Usage: " << G4endl << " monopole [-m macro ] [-s setupMonopole] [-t nThreads]"
0050          << G4endl << "   Note: " << G4endl
0051          << "    -s should be followed by a composed string, eg. \'1 0 100 GeV\'" << G4endl
0052          << "    -t option is for multi-threaded mode." << G4endl << G4endl;
0053 }
0054 }  // namespace
0055 
0056 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0057 
0058 int main(int argc, char** argv)
0059 {
0060   // Evaluate arguments
0061   //
0062   if (argc > 7) {
0063     PrintUsage();
0064     return 1;
0065   }
0066 
0067   G4String macro;
0068   G4String setupMonopole;
0069   G4int nThreads = 1;
0070   for (G4int i = 1; i < argc; i = i + 2) {
0071     if (G4String(argv[i]) == "-m")
0072       macro = argv[i + 1];
0073     else if (G4String(argv[i]) == "-s")
0074       setupMonopole = argv[i + 1];
0075     else if (G4String(argv[i]) == "-t") {
0076       nThreads = G4UIcommand::ConvertToInt(argv[i + 1]);
0077     }
0078     else {
0079       PrintUsage();
0080       return 1;
0081     }
0082   }
0083 
0084   // Construct the default run manager
0085   auto* runManager = G4RunManagerFactory::CreateRunManager();
0086   if (nThreads > 0) {
0087     runManager->SetNumberOfThreads(nThreads);
0088   }
0089   G4cout << "===== Example is started with " << runManager->GetNumberOfThreads()
0090          << " threads =====" << G4endl;
0091 
0092   // Instantiate G4UIExecutive if interactive
0093   G4UIExecutive* ui = nullptr;
0094   if (macro.empty()) {
0095     ui = new G4UIExecutive(argc, argv);
0096   }
0097 
0098   // get the pointer to the User Interface manager
0099   G4UImanager* UImanager = G4UImanager::GetUIpointer();
0100 
0101   // create physicsList
0102   //  Physics List is defined via environment variable PHYSLIST
0103   G4PhysListFactory factory;
0104   G4VModularPhysicsList* phys = factory.GetReferencePhysList("FTFP_BERT");
0105 
0106   // monopole physics is added
0107   G4MonopolePhysics* theMonopole = new G4MonopolePhysics();
0108 
0109   // Setup monopole
0110   if (setupMonopole.size()) {
0111     UImanager->ApplyCommand("/control/verbose 1");
0112     UImanager->ApplyCommand("/monopole/setup " + setupMonopole);
0113   }
0114 
0115   // regsiter monopole physics
0116   phys->RegisterPhysics(theMonopole);
0117 
0118   runManager->SetUserInitialization(phys);
0119 
0120   // visualization manager
0121   G4VisManager* visManager = nullptr;
0122 
0123   // set detector construction
0124   DetectorConstruction* det = new DetectorConstruction();
0125   runManager->SetUserInitialization(det);
0126 
0127   // set user action classes
0128   runManager->SetUserInitialization(new ActionInitialization(det));
0129 
0130   // Process macro or start UI session
0131   //
0132   if (macro.size()) {
0133     // batch mode
0134     G4String command = "/control/execute ";
0135     UImanager->ApplyCommand(command + macro);
0136   }
0137   else {
0138     // interactive mode : define UI session
0139     visManager = new G4VisExecutive();
0140     visManager->Initialize();
0141     UImanager->ApplyCommand("/control/execute init_vis.mac");
0142     ui->SessionStart();
0143     delete ui;
0144   }
0145 
0146   delete visManager;
0147 
0148   // job termination
0149   delete runManager;
0150 
0151   return 0;
0152 }
0153 
0154 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......