Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-14 07:53:23

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 Hadr01.cc
0027 /// \brief Main program of the hadronic/Hadr01 example
0028 
0029 // -------------------------------------------------------------
0030 //      GEANT4 Hadr01
0031 //
0032 //  Application demonstrating Geant4 hadronic physics:
0033 //  beam interaction with a target
0034 //
0035 //  Authors: A.Bagulya, I.Gudowska, V.Ivanchenko, N.Starkov
0036 //
0037 //  Modified:
0038 //  29.12.2009 V.Ivanchenko introduced access to reference PhysLists
0039 //
0040 // -------------------------------------------------------------
0041 //
0042 //
0043 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0044 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0045 
0046 #include "DetectorConstruction.hh"
0047 #include "EventAction.hh"
0048 #include "PhysicsList.hh"
0049 #include "PrimaryGeneratorAction.hh"
0050 #include "RunAction.hh"
0051 #include "StackingAction.hh"
0052 
0053 #include "G4HadronicParameters.hh"
0054 #include "G4PhysListFactory.hh"
0055 #include "G4RunManagerFactory.hh"
0056 #include "G4UIExecutive.hh"
0057 #include "G4UImanager.hh"
0058 #include "G4VModularPhysicsList.hh"
0059 #include "G4VisExecutive.hh"
0060 
0061 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0062 
0063 int main(int argc, char** argv)
0064 {
0065   // detect interactive mode (if no arguments) and define UI session
0066   G4UIExecutive* ui = nullptr;
0067   if (argc == 1) {
0068     ui = new G4UIExecutive(argc, argv);
0069   }
0070 
0071   // Construct a serial run manager
0072   auto* runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::SerialOnly);
0073 
0074   // set mandatory initialization classes
0075   runManager->SetUserInitialization(new DetectorConstruction());
0076 
0077   G4PhysListFactory factory;
0078   G4VModularPhysicsList* phys = nullptr;
0079   G4String physName = "";
0080 
0081   // Physics List name defined via 3nd argument
0082   if (argc >= 3) {
0083     physName = argv[2];
0084   }
0085 
0086   // Physics List name defined via environment variable
0087   if ("" == physName) {
0088     char* path = std::getenv("PHYSLIST");
0089     if (nullptr != path) {
0090       physName = G4String(path);
0091     }
0092   }
0093 
0094   G4cout << "PhysicsList: " << physName << G4endl;
0095 
0096   // reference PhysicsList via its name
0097   if ("" != physName && factory.IsReferencePhysList(physName)) {
0098     phys = factory.GetReferencePhysList(physName);
0099   }
0100 
0101   // local Physics List
0102   if (nullptr == phys) {
0103     phys = new PhysicsList();
0104   }
0105 
0106   // optional change of overlap cascade/string
0107   if (argc >= 5) {
0108     auto param = G4HadronicParameters::Instance();
0109     G4double e1 = CLHEP::GeV * std::strtod(argv[3], 0);
0110     G4double e2 = CLHEP::GeV * std::strtod(argv[4], 0);
0111     G4cout << "### Bertini/FTFP limits: e1(GeV)=" << e1 / CLHEP::GeV
0112            << "  e2(GeV)=" << e2 / CLHEP::GeV << G4endl;
0113     param->SetMinEnergyTransitionFTF_Cascade(e1);
0114     param->SetMaxEnergyTransitionFTF_Cascade(e2);
0115   }
0116 
0117   if (argc >= 6) {
0118     auto param = G4HadronicParameters::Instance();
0119     param->SetEnableNUDEX(true);
0120   }
0121 
0122   // define physics
0123   runManager->SetUserInitialization(phys);
0124   runManager->SetUserAction(new PrimaryGeneratorAction());
0125 
0126   // set user action classes
0127   runManager->SetUserAction(new RunAction());
0128   runManager->SetUserAction(new EventAction());
0129   runManager->SetUserAction(new StackingAction());
0130 
0131   // initialize visualization
0132   G4VisManager* visManager = nullptr;
0133 
0134   // get the pointer to the User Interface manager
0135   G4UImanager* UImanager = G4UImanager::GetUIpointer();
0136 
0137   if (ui) {
0138     // interactive mode
0139     visManager = new G4VisExecutive;
0140     visManager->Initialize();
0141     ui->SessionStart();
0142     delete ui;
0143   }
0144   else {
0145     // batch mode
0146     G4String command = "/control/execute ";
0147     G4String fileName = argv[1];
0148     UImanager->ApplyCommand(command + fileName);
0149   }
0150 
0151   // job termination
0152   delete visManager;
0153   delete runManager;
0154 }
0155 
0156 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......