Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-12 08:07:57

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 exampleGB03.cc
0027 /// \brief Main program of the biasing/GB03 example
0028 
0029 #include "FTFP_BERT.hh"
0030 #include "GB03ActionInitialization.hh"
0031 #include "GB03DetectorConstruction.hh"
0032 #include "GB03PrimaryGeneratorAction.hh"
0033 
0034 #include "G4GenericBiasingPhysics.hh"
0035 #include "G4RunManagerFactory.hh"
0036 #include "G4Types.hh"
0037 #include "G4UIExecutive.hh"
0038 #include "G4UImanager.hh"
0039 #include "G4VisExecutive.hh"
0040 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0041 
0042 namespace
0043 {
0044 void PrintUsage()
0045 {
0046   G4cerr << " Usage: " << G4endl;
0047   G4cerr << " ./exampleGB04 [-m macro ] "
0048          << " [-b biasing {'on','off'}]"
0049          << "\n or\n ./exampleGB04 [macro.mac]" << G4endl;
0050 }
0051 }  // namespace
0052 
0053 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0054 
0055 int main(int argc, char** argv)
0056 {
0057   // Evaluate arguments
0058   //
0059   if (argc > 5) {
0060     PrintUsage();
0061     return 1;
0062   }
0063 
0064   G4String macro("");
0065   G4String onOffBiasing("");
0066   if (argc == 2)
0067     macro = argv[1];
0068   else {
0069     for (G4int i = 1; i < argc; i = i + 2) {
0070       if (G4String(argv[i]) == "-m")
0071         macro = argv[i + 1];
0072       else if (G4String(argv[i]) == "-b")
0073         onOffBiasing = argv[i + 1];
0074       else {
0075         PrintUsage();
0076         return 1;
0077       }
0078     }
0079   }
0080 
0081   if (onOffBiasing == "") onOffBiasing = "on";
0082 
0083   // Instantiate G4UIExecutive if interactive mode
0084   G4UIExecutive* ui = nullptr;
0085   if (macro == "") {
0086     ui = new G4UIExecutive(argc, argv);
0087   }
0088 
0089   // -- Construct the run manager : MT or sequential one
0090   auto* runManager = G4RunManagerFactory::CreateRunManager();
0091   runManager->SetNumberOfThreads(4);
0092 
0093   G4bool biasingFlag = (onOffBiasing == "on");
0094 
0095   // -- Set mandatory initialization classes
0096   G4VUserDetectorConstruction* detector = new GB03DetectorConstruction(biasingFlag);
0097   runManager->SetUserInitialization(detector);
0098   G4VModularPhysicsList* physicsList = new FTFP_BERT;
0099   // -- Setup biasing for neutron only. As will not bias any
0100   // -- physics process, require the G4GenericBiasingPhysics()
0101   // -- to modify the physics list just for "non-physics" biasing:
0102   if (biasingFlag) {
0103     auto biasingPhysics = new G4GenericBiasingPhysics();
0104     biasingPhysics->NonPhysicsBias("neutron");
0105     physicsList->RegisterPhysics(biasingPhysics);
0106     G4cout << "      ********************************************************* " << G4endl;
0107     G4cout << "      ********** processes are wrapped for biasing ************ " << G4endl;
0108     G4cout << "      ********************************************************* " << G4endl;
0109   }
0110   else {
0111     G4cout << "      ************************************************* " << G4endl;
0112     G4cout << "      ********** processes are not wrapped ************ " << G4endl;
0113     G4cout << "      ************************************************* " << G4endl;
0114   }
0115   runManager->SetUserInitialization(physicsList);
0116 
0117   // -- Set user action initialization class
0118   G4VUserActionInitialization* actions = new GB03ActionInitialization;
0119   runManager->SetUserInitialization(actions);
0120 
0121   // Visualization manager
0122   //
0123   auto visManager = new G4VisExecutive;
0124   visManager->Initialize();
0125 
0126   // Initialize G4 kernel
0127   //
0128   runManager->Initialize();
0129 
0130   // Get the pointer to the User Interface manager
0131   //
0132   auto UImanager = G4UImanager::GetUIpointer();
0133 
0134   if (ui)  // Define UI session for interactive mode
0135   {
0136     UImanager->ApplyCommand("/control/execute vis.mac");
0137     ui->SessionStart();
0138     delete ui;
0139   }
0140   else  // Batch mode
0141   {
0142     G4String command = "/control/execute ";
0143     UImanager->ApplyCommand(command + macro);
0144   }
0145 
0146   delete visManager;
0147   delete runManager;
0148 
0149   return 0;
0150 }