Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:22:30

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 parallel/ThreadsafeScorers/ts_scorers.cc
0027 /// \brief Main of the ThreadsafeScorers example
0028 //
0029 //
0030 //
0031 //
0032 /// ts_scorers example shows how to use global scorers. The benefit of using
0033 ///     global scorers in memory-savings for problems with very large amounts
0034 ///     of scoring volumes. Additionally, the global scorers are more precise
0035 ///     w.r.t. the serial solution because of the lack of compounding
0036 ///     round-off error from multiple threads
0037 ///
0038 /// In this example, the global scorers are implemented as static member
0039 ///     variables in TSRun because TSRun is thread-local. The G4atomic
0040 ///     class is the core of the thread-safe scorers and can be uses
0041 //
0042 //
0043 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0044 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0045 
0046 #include "G4RunManagerFactory.hh"
0047 #include "G4Threading.hh"
0048 #include "G4Types.hh"
0049 #include "Randomize.hh"
0050 
0051 // User Defined Classes
0052 #include "TSActionInitialization.hh"
0053 #include "TSDetectorConstruction.hh"
0054 #include "TSPhysicsList.hh"
0055 
0056 #include "G4Step.hh"
0057 #include "G4Track.hh"
0058 #include "G4UIExecutive.hh"
0059 #include "G4UImanager.hh"
0060 #include "G4VisExecutive.hh"
0061 
0062 // for std::system(const char*)
0063 #include <cstdlib>
0064 
0065 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0066 
0067 void message(G4RunManager* runmanager)
0068 {
0069   G4MTRunManager* man = dynamic_cast<G4MTRunManager*>(runmanager);
0070   if (man) {
0071     man->SetNumberOfThreads(G4Threading::G4GetNumberOfCores());
0072     G4cout << "\n\n\t--> Running in multithreaded mode with " << man->GetNumberOfThreads()
0073            << " threads\n\n"
0074            << G4endl;
0075   }
0076   else {
0077     G4cout << "\n\n\t--> Running in serial mode\n\n" << G4endl;
0078   }
0079 }
0080 
0081 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0082 
0083 int main(int argc, char** argv)
0084 {
0085   G4String macro;
0086   if (argc > 1) macro = argv[argc - 1];
0087 
0088   // Detect interactive mode (if no arguments) and define UI session
0089   //
0090   G4UIExecutive* ui = 0;
0091   if (macro.empty()) ui = new G4UIExecutive(argc, argv);
0092 
0093   // Set the random seed
0094   CLHEP::HepRandom::setTheSeed(1245214UL);
0095 
0096   G4RunManager* runmanager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::Tasking);
0097 
0098   message(runmanager);
0099 
0100   runmanager->SetUserInitialization(new TSDetectorConstruction);
0101 
0102   runmanager->SetUserInitialization(new TSPhysicsList);
0103 
0104   runmanager->SetUserInitialization(new TSActionInitialization);
0105 
0106   runmanager->Initialize();
0107 
0108   // Initialize visualization
0109   //
0110   G4VisManager* visManager = new G4VisExecutive;
0111   // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
0112   // G4VisManager* visManager = new G4VisExecutive("Quiet");
0113   visManager->Initialize();
0114 
0115   // Get the pointer to the User Interface manager
0116   G4UImanager* UImanager = G4UImanager::GetUIpointer();
0117 
0118   // Process macro or start UI session
0119   //
0120   if (!ui) {
0121     // batch mode
0122     G4String command = "/control/execute ";
0123     UImanager->ApplyCommand(command + macro);
0124   }
0125   else {
0126     ui->SessionStart();
0127   }
0128 
0129   // Job termination
0130   // Free the store: user actions, physics_list and detector_description are
0131   // owned and deleted by the run manager, so they should not be deleted
0132   // in the main() program !
0133   delete visManager;
0134   delete runmanager;
0135 
0136   return 0;
0137 }