Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-01 08:26:47

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 // -------------------------------------------------------------
0028 //      GEANT4 FF_Neutron_HP
0029 //
0030 //  Command line options:
0031 //      -i ARG      : run in batch mode from script file ARG
0032 //      -o ARG      : write output to file ARG
0033 //                    (defaults to FF_Neutron_HP.out)
0034 //      -n ARG      : multithreading with ARG number of threads
0035 //                    (only works if Geant4 was compiled with
0036 //                    multithreading enables)
0037 //
0038 //  =============== Begin Documentation Comments ===============
0039 //!
0040 //! \file       FissionFragment.cc
0041 //! \author     B. Wendt (brycen.linn.wendt@cern.ch)
0042 //! \date       June 06, 2014
0043 //!
0044 //! \brief      Main program of the FissionFragment example
0045 //!
0046 //! \details    Application demonstrating the Fission Fragment model as used
0047 //!                 within the neutron_hp model. It demostrates the capability
0048 //!                 for fission product containment by the cladding in a water
0049 //!                 moderated sub-critical assembly.
0050 //!             It could also be further extended to calculate the effective
0051 //!                 multiplication factor of the subcritical assembly for
0052 //!                 various loading schemes.
0053 //!
0054 //  ================ End Documentation Comments ================
0055 //
0056 //  Modified:
0057 //
0058 //  05-08-20                                              ARibon
0059 //  Replaced deprecated HP environmental variables with UI commands
0060 //  23-06-14                                              BWendt
0061 //  Added check for NeutronHP fission generator environment variable
0062 //
0063 // -------------------------------------------------------------
0064 
0065 #include "FFActionInitialization.hh"
0066 #include "FFDetectorConstruction.hh"
0067 #include "QGSP_BIC_HP.hh"
0068 
0069 #include "G4ParticleHPManager.hh"
0070 #include "G4RunManagerFactory.hh"
0071 #include "G4UIExecutive.hh"
0072 #include "G4UImanager.hh"
0073 #include "G4VisExecutive.hh"
0074 #include "Randomize.hh"
0075 #include "globals.hh"
0076 
0077 // Entry point
0078 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0079 int main(int argc, char* argv[])
0080 {
0081   int result;
0082   unsigned int numberOfThreads = 1;
0083 
0084   G4String scriptFileName = "";
0085   G4String outputFileName = "FF_Neutron_HP.out";
0086   G4UImanager* UIManager = NULL;
0087 
0088   // Activate production of fission fragments in neutronHP
0089   G4ParticleHPManager::GetInstance()->SetProduceFissionFragments(true);
0090 
0091   char Force[] = "G4FORCENUMBEROFTHREADS";
0092   if (std::getenv(Force) != NULL) {
0093     char doNotForce[] = "G4FORCENUMBEROFTHREADS=1";
0094     putenv(doNotForce);
0095   }
0096 
0097   // Indicate the example is starting
0098   G4cout << "####   Starting: " << argv[0] << "    ####" << G4endl;
0099 
0100   //  Parse the command line arguments, if any
0101   for (int i = 1; i < argc; i += 2) {
0102     // Ensure that this is actually a command
0103     if (argv[i][0] != '-') {
0104       G4cerr << G4endl << "!!!!" << G4endl;
0105       G4cerr << "!!!! Error in argument " << i + 1 << G4endl;
0106       G4cerr << "!!!! A command-line option was expected, but \"" << argv[i] << "\" was found"
0107              << G4endl;
0108       G4cerr << "!!!! " << argv[0] << " will now terminate" << G4endl;
0109       G4cerr << "!!!!" << G4endl << G4endl;
0110 
0111       return EXIT_FAILURE;
0112     }
0113 
0114     // Ensure that the command-line option has an associated argument
0115     if (!(i + 1 < argc)) {
0116       G4cerr << G4endl << "!!!!" << G4endl;
0117       G4cerr << "!!!! Error in argument " << i + 2 << G4endl;
0118       G4cerr << "!!!! An argument was expected, but \"" << argv[i + 1] << "\" was found" << G4endl;
0119       G4cerr << "!!!! Ensure that a space is used to separate the "
0120                 "option and argument"
0121              << G4endl;
0122       G4cerr << "!!!! " << argv[0] << " will now terminate" << G4endl;
0123       G4cerr << "!!!!" << G4endl << G4endl;
0124 
0125       return EXIT_FAILURE;
0126     }
0127 
0128     switch (argv[i][1]) {
0129       case 'i':
0130         scriptFileName = "/control/execute ";
0131         scriptFileName.append(argv[i + 1]);
0132         break;
0133 
0134       case 'o':
0135         outputFileName = argv[i + 1];
0136         break;
0137 
0138       case 'n':
0139         result = sscanf(argv[i + 1], "%u", &numberOfThreads);
0140         if (result != 1) {
0141           G4cerr << G4endl << "!!!!" << G4endl;
0142           G4cerr << "!!!! Error in argument " << i + 2 << G4endl;
0143           G4cerr << "!!!! An positive number was expected, but \"" << argv[i + 1] << "\" was found"
0144                  << G4endl;
0145           G4cerr << "!!!! " << argv[0] << " will now terminate" << G4endl;
0146           G4cerr << "!!!!" << G4endl << G4endl;
0147 
0148           return EXIT_FAILURE;
0149         }
0150         break;
0151 
0152       default:
0153         G4cout << G4endl << "!!!!" << G4endl;
0154         G4cout << "!!!! Warning for command " << i + 1 << G4endl;
0155         G4cout << "!!!! \"" << argv[i] << "\" is not a valid command" << G4endl;
0156         G4cout << "!!!! " << argv[0] << " will ignore \"" << argv[i] << "\" and \"" << argv[i + 1]
0157                << "\"" << G4endl;
0158         G4cout << "!!!!" << G4endl << G4endl;
0159     }
0160   }
0161 
0162   // Instantiate G4UIExecutive if interactive mode
0163   G4UIExecutive* ui = nullptr;
0164   if (scriptFileName.length() == 0) {
0165     ui = new G4UIExecutive(argc, argv);
0166   }
0167 
0168   // Set the Random engine
0169   // A seed of 62737819 produced a maximum number of 67 events on the
0170   // author's system before timing out the nightly test
0171   const G4long seed = 62737819;
0172 #ifndef NDEBUG
0173   G4cout << "MT RNG Seed: " << seed << G4endl;
0174 #endif  // NDEBUG
0175   G4Random::setTheEngine(new CLHEP::MTwistEngine(seed));
0176 
0177   // Initialize the multithreaded run manager
0178   auto* runManager = G4RunManagerFactory::CreateRunManager();
0179   runManager->SetNumberOfThreads(numberOfThreads);
0180   G4cout << "    Threads requested:    " << numberOfThreads << G4endl;
0181   G4cout << "    Threads started:      " << runManager->GetNumberOfThreads() << G4endl;
0182 
0183   // Set mandatory initialization classes
0184   runManager->SetUserInitialization(new FFDetectorConstruction());
0185   runManager->SetUserInitialization(new QGSP_BIC_HP());
0186   runManager->SetUserInitialization(new FFActionInitialization());
0187 
0188   // Initialize the Geant4 kernel
0189   runManager->Initialize();
0190 
0191   // Initialize visualization
0192   G4VisManager* visManager = new G4VisExecutive();
0193   visManager->Initialize();
0194 
0195   // Get the pointer to the User Interface manager
0196   UIManager = G4UImanager::GetUIpointer();
0197 
0198   if (!ui) {
0199     // Batch mode
0200     UIManager->ApplyCommand(scriptFileName);
0201   }
0202   else {
0203     // Interactive mode
0204     ui->SessionStart();
0205     delete ui;
0206   }
0207 
0208   // Job termination
0209   // Free the store: user actions, physics_list and detector_description are
0210   // owned and deleted by the run manager, so they should not be deleted
0211   // in the main() program !
0212   delete visManager;
0213   delete runManager;
0214 
0215   return 0;
0216 }