Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:17:16

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 //
0027 /// \file exampleB4d.cc
0028 /// \brief Main program of the B4d example
0029 
0030 #include "ActionInitialization.hh"
0031 #include "DetectorConstruction.hh"
0032 #include "FTFP_BERT.hh"
0033 
0034 #include "G4AnalysisManager.hh"
0035 #include "G4RunManagerFactory.hh"
0036 #include "G4SteppingVerbose.hh"
0037 #include "G4TScoreNtupleWriter.hh"
0038 #include "G4UIExecutive.hh"
0039 #include "G4UIcommand.hh"
0040 #include "G4UImanager.hh"
0041 #include "G4VisExecutive.hh"
0042 // #include "Randomize.hh"
0043 
0044 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0045 
0046 namespace
0047 {
0048 void PrintUsage()
0049 {
0050   G4cerr << " Usage: " << G4endl;
0051   G4cerr << " exampleB4d [-m macro ] [-u UIsession] [-t nThreads] [-vDefault]" << G4endl;
0052   G4cerr << "   note: -t option is available only for multi-threaded mode." << 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 session;
0069   G4bool verboseBestUnits = true;
0070 #ifdef G4MULTITHREADED
0071   G4int nThreads = 0;
0072 #endif
0073   for (G4int i = 1; i < argc; i = i + 2) {
0074     if (G4String(argv[i]) == "-m")
0075       macro = argv[i + 1];
0076     else if (G4String(argv[i]) == "-u")
0077       session = argv[i + 1];
0078 #ifdef G4MULTITHREADED
0079     else if (G4String(argv[i]) == "-t") {
0080       nThreads = G4UIcommand::ConvertToInt(argv[i + 1]);
0081     }
0082 #endif
0083     else if (G4String(argv[i]) == "-vDefault") {
0084       verboseBestUnits = false;
0085       --i;  // this option is not followed with a parameter
0086     }
0087     else {
0088       PrintUsage();
0089       return 1;
0090     }
0091   }
0092 
0093   // Detect interactive mode (if no macro provided) and define UI session
0094   //
0095   G4UIExecutive* ui = nullptr;
0096   if (!macro.size()) {
0097     ui = new G4UIExecutive(argc, argv, session);
0098   }
0099 
0100   // Optionally: choose a different Random engine...
0101   // G4Random::setTheEngine(new CLHEP::MTwistEngine);
0102 
0103   // Use G4SteppingVerboseWithUnits
0104   if (verboseBestUnits) {
0105     G4int precision = 4;
0106     G4SteppingVerbose::UseBestUnit(precision);
0107   }
0108 
0109   // Construct the default run manager
0110   //
0111   auto runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::Default);
0112 #ifdef G4MULTITHREADED
0113   if (nThreads > 0) {
0114     runManager->SetNumberOfThreads(nThreads);
0115   }
0116 #endif
0117 
0118   // Set mandatory initialization classes
0119   //
0120   auto detConstruction = new B4d::DetectorConstruction();
0121   runManager->SetUserInitialization(detConstruction);
0122 
0123   auto physicsList = new FTFP_BERT;
0124   runManager->SetUserInitialization(physicsList);
0125 
0126   auto actionInitialization = new B4d::ActionInitialization();
0127   runManager->SetUserInitialization(actionInitialization);
0128 
0129   // Initialize visualization
0130   auto visManager = new G4VisExecutive;
0131   // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
0132   // auto visManager = new G4VisExecutive("Quiet");
0133   visManager->Initialize();
0134 
0135   // Get the pointer to the User Interface manager
0136   auto UImanager = G4UImanager::GetUIpointer();
0137 
0138   // Activate score ntuple writer
0139   // The verbose level can be also set via UI commands
0140   // /score/ntuple/writerVerbose level
0141   // The default file type ("root") can be changed in xml, csv, hdf5
0142   // scoreNtupleWriter.SetDefaultFileType("xml");
0143   G4TScoreNtupleWriter<G4AnalysisManager> scoreNtupleWriter;
0144   scoreNtupleWriter.SetVerboseLevel(1);
0145   scoreNtupleWriter.SetNtupleMerging(true);
0146   // Note: merging ntuples is available only with Root output
0147   // (the default in G4TScoreNtupleWriter)
0148 
0149   // Process macro or start UI session
0150   //
0151   if (macro.size()) {
0152     // batch mode
0153     G4String command = "/control/execute ";
0154     UImanager->ApplyCommand(command + macro);
0155   }
0156   else {
0157     // interactive mode : define UI session
0158     UImanager->ApplyCommand("/control/execute init_vis.mac");
0159     if (ui->IsGUI()) {
0160       UImanager->ApplyCommand("/control/execute gui.mac");
0161     }
0162     ui->SessionStart();
0163     delete ui;
0164   }
0165 
0166   // Job termination
0167   // Free the store: user actions, physics_list and detector_description are
0168   // owned and deleted by the run manager, so they should not be deleted
0169   // in the main() program !
0170 
0171   delete visManager;
0172   delete runManager;
0173 }
0174 
0175 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....