Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-08 07:53:22

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 Hadr02.cc
0027 /// \brief Main program of the hadronic/Hadr02 example
0028 
0029 // -------------------------------------------------------------
0030 //      GEANT4 Hadr02
0031 //
0032 //  Application demonstrating Geant4 hadronic cross sections
0033 //
0034 //  Author: V.Ivanchenko 20 June 2008
0035 //
0036 //  Modified:
0037 //
0038 // -------------------------------------------------------------
0039 //
0040 //
0041 #include "CRMC_FTFP_BERT.hh"
0042 #include "DetectorConstruction.hh"
0043 #include "EventAction.hh"
0044 #include "HistoManager.hh"
0045 #include "PrimaryGeneratorAction.hh"
0046 #include "RunAction.hh"
0047 #include "StackingAction.hh"
0048 #include "UrQMD.hh"
0049 
0050 #include "G4PhysListFactory.hh"
0051 #include "G4RunManagerFactory.hh"
0052 #include "G4UIExecutive.hh"
0053 #include "G4UImanager.hh"
0054 #include "G4VModularPhysicsList.hh"
0055 #include "G4VisExecutive.hh"
0056 #include "Randomize.hh"
0057 
0058 int main(int argc, char** argv)
0059 {
0060   // detect interactive mode (if no arguments) and define UI session
0061   G4UIExecutive* ui = nullptr;
0062   if (argc == 1) ui = new G4UIExecutive(argc, argv);
0063 
0064   // choose the Random engine
0065   CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine());
0066 
0067   // Construct a serial run manager
0068   auto* runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::SerialOnly);
0069 
0070   // set mandatory initialization classes
0071   runManager->SetUserInitialization(new DetectorConstruction());
0072 
0073   G4PhysListFactory factory;
0074   G4VModularPhysicsList* phys = 0;
0075 
0076   // default Physics List for this example
0077   G4String physName = "QBBC";
0078 
0079   // Physics List name defined via 2nd argument
0080   if (argc == 3) {
0081     physName = argv[2];
0082   }
0083   else {
0084     char* path = std::getenv("PHYSLIST");
0085     if (path) {
0086       physName = G4String(path);
0087     }
0088   }
0089   if (physName == "UrQMD") {
0090     phys = new UrQMD;
0091   }
0092   else if (physName == "CRMC_FTFP_BERT") {
0093     phys = new CRMC_FTFP_BERT;
0094   }
0095   else {
0096     phys = factory.GetReferencePhysList(physName);
0097   }
0098 
0099   // Physics List is defined via environment variable PHYSLIST
0100   if (!phys) {
0101     G4cout << "Hadr02 FATAL ERROR: Physics List is not defined" << G4endl;
0102     return 1;
0103   }
0104   runManager->SetUserInitialization(phys);
0105   HistoManager::GetPointer()->SetPhysicsList(phys);
0106 
0107   runManager->SetUserAction(new PrimaryGeneratorAction());
0108 
0109   // set user action classes
0110   runManager->SetUserAction(new RunAction());
0111   runManager->SetUserAction(new EventAction());
0112   runManager->SetUserAction(new StackingAction());
0113 
0114   // initialize visualization
0115   G4VisManager* visManager = new G4VisExecutive;
0116   visManager->Initialize();
0117 
0118   // get the pointer to the User Interface manager
0119   G4UImanager* UImanager = G4UImanager::GetUIpointer();
0120 
0121   if (ui) {
0122     // interactive mode
0123     ui->SessionStart();
0124     delete ui;
0125   }
0126   else {
0127     // batch mode
0128     G4String command = "/control/execute ";
0129     G4String fileName = argv[1];
0130     UImanager->ApplyCommand(command + fileName);
0131   }
0132 
0133   // job termination
0134   delete visManager;
0135   delete runManager;
0136 }