Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-15 07:44:25

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 exampleGB07.cc
0027 /// \brief Main program of the biasing/GB07 example
0028 
0029 #include "FTFP_BERT.hh"
0030 #include "GB07ActionInitialization.hh"
0031 #include "GB07DetectorConstruction.hh"
0032 #include "GB07PrimaryGeneratorAction.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 
0041 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0042 
0043 namespace
0044 {
0045 void PrintUsage()
0046 {
0047   G4cerr << " Usage: " << G4endl;
0048   G4cerr << " ./exampleGB07 [-m macro ] "
0049          << " [-b biasing {'on','off'}]"
0050          << "\n or\n ./exampleGB07 [macro.mac]" << G4endl;
0051 }
0052 }  // namespace
0053 
0054 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0055 
0056 int main(int argc, char** argv)
0057 {
0058   // Evaluate arguments
0059   //
0060   if (argc > 5) {
0061     PrintUsage();
0062     return 1;
0063   }
0064 
0065   G4String macro("");
0066   G4String onOffBiasing("");
0067   if (argc == 2)
0068     macro = argv[1];
0069   else {
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]) == "-b")
0074         onOffBiasing = argv[i + 1];
0075       else {
0076         PrintUsage();
0077         return 1;
0078       }
0079     }
0080   }
0081 
0082   if (onOffBiasing == "") onOffBiasing = "on";
0083 
0084   // Instantiate G4UIExecutive if interactive mode
0085   G4UIExecutive* ui = nullptr;
0086   if (macro == "") {
0087     ui = new G4UIExecutive(argc, argv);
0088   }
0089 
0090   // -- Construct the run manager : MT or sequential one
0091   auto* runManager = G4RunManagerFactory::CreateRunManager();
0092   runManager->SetNumberOfThreads(4);
0093 
0094   G4bool biasingFlag = (onOffBiasing == "on");
0095 
0096   // -- Set mandatory initialization classes
0097   auto detector = new GB07DetectorConstruction(biasingFlag);
0098   runManager->SetUserInitialization(detector);
0099   // -- Select a physics list
0100   auto physicsList = new FTFP_BERT;
0101   if (biasingFlag) {
0102     // -- And augment it with biasing facilities:
0103     auto biasingPhysics = new G4GenericBiasingPhysics();
0104     // -- Specify the processes that will be under biasing:
0105     // ---- Decide to apply the technique to hadronic inelastic interactions:
0106     std::vector<G4String> piPlusProcessesToBias, piMinusProcessesToBias, protonProcessesToBias,
0107       antiProtonProcessesToBias, neutronProcessesToBias, antiNeutronProcessesToBias;
0108     piPlusProcessesToBias.push_back("pi+Inelastic");
0109     piMinusProcessesToBias.push_back("pi-Inelastic");
0110     protonProcessesToBias.push_back("protonInelastic");
0111     antiProtonProcessesToBias.push_back("anti_protonInelastic");
0112     neutronProcessesToBias.push_back("neutronInelastic");
0113     neutronProcessesToBias.push_back("nCapture");
0114     antiNeutronProcessesToBias.push_back("anti_neutronInelastic");
0115     biasingPhysics->PhysicsBias("pi+", piPlusProcessesToBias);
0116     biasingPhysics->PhysicsBias("pi-", piMinusProcessesToBias);
0117     biasingPhysics->PhysicsBias("proton", protonProcessesToBias);
0118     biasingPhysics->PhysicsBias("anti_proton", antiProtonProcessesToBias);
0119     biasingPhysics->PhysicsBias("neutron", neutronProcessesToBias);
0120     biasingPhysics->PhysicsBias("anti_neutron", antiNeutronProcessesToBias);
0121     // ---- Apply also the technique to some EM processes (producing at least
0122     // ---- 2 same or 2 particle - anti-particle pairs):
0123     std::vector<G4String> gammaProcessesToBias, electronProcessesToBias, positronProcessesToBias;
0124     gammaProcessesToBias.push_back("conv");
0125     gammaProcessesToBias.push_back("photonNuclear");
0126     electronProcessesToBias.push_back("electronNuclear");
0127     positronProcessesToBias.push_back("annihil");
0128     positronProcessesToBias.push_back("positronNuclear");
0129     biasingPhysics->PhysicsBias("gamma", gammaProcessesToBias);
0130     biasingPhysics->PhysicsBias("e-", electronProcessesToBias);
0131     biasingPhysics->PhysicsBias("e+", positronProcessesToBias);
0132     // ---- And apply it to pi0 decay:
0133     std::vector<G4String> pi0ProcessesToBias;
0134     pi0ProcessesToBias.push_back("Decay");
0135     biasingPhysics->PhysicsBias("pi0", pi0ProcessesToBias);
0136     // --
0137     physicsList->RegisterPhysics(biasingPhysics);
0138     G4cout << "      ********************************************************* " << G4endl;
0139     G4cout << "      ********** processes are wrapped for biasing ************ " << G4endl;
0140     G4cout << "      ********************************************************* " << G4endl;
0141   }
0142   else {
0143     G4cout << "      ************************************************* " << G4endl;
0144     G4cout << "      ********** processes are not wrapped ************ " << G4endl;
0145     G4cout << "      ************************************************* " << G4endl;
0146   }
0147   runManager->SetUserInitialization(physicsList);
0148   // -- Action initialization:
0149   runManager->SetUserInitialization(new GB07ActionInitialization);
0150 
0151   // Initialize G4 kernel
0152   runManager->Initialize();
0153 
0154   // Initialize visualization
0155   auto visManager = new G4VisExecutive;
0156   // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
0157   visManager->Initialize();
0158 
0159   // Get the pointer to the User Interface manager
0160   auto UImanager = G4UImanager::GetUIpointer();
0161 
0162   if (macro != "")  // batch mode
0163   {
0164     G4String command = "/control/execute ";
0165     UImanager->ApplyCommand(command + macro);
0166   }
0167   else {  // interactive mode : define UI session
0168     UImanager->ApplyCommand("/control/execute vis.mac");
0169     //      if (ui->IsGUI())
0170     //        UImanager->ApplyCommand("/control/execute gui.mac");
0171     ui->SessionStart();
0172     delete ui;
0173   }
0174 
0175   delete visManager;
0176   delete runManager;
0177 }
0178 
0179 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....