Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:22:34

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 //
0029 // --------------------------------------------------------------
0030 //      GEANT 4 - examplePar03
0031 // --------------------------------------------------------------
0032 // Comments
0033 //
0034 // Example of a main program demonstrating multiple energy deposition
0035 // from fast simulation model.
0036 //
0037 //-------------------------------------------------------------------
0038 
0039 #include "FTFP_BERT.hh"
0040 #include "Par03ActionInitialisation.hh"
0041 #include "Par03DetectorConstruction.hh"
0042 
0043 #include "G4EmParameters.hh"
0044 #include "G4FastSimulationPhysics.hh"
0045 #include "G4HadronicProcessStore.hh"
0046 #include "G4RunManagerFactory.hh"
0047 #include "G4Types.hh"
0048 #include "G4UIExecutive.hh"
0049 #include "G4UImanager.hh"
0050 #include "G4VisExecutive.hh"
0051 
0052 #include <sstream>
0053 
0054 int main(int argc, char** argv)
0055 {
0056   // Macro name from arguments
0057   G4String batchMacroName;
0058   G4bool useInteractiveMode = true;
0059   G4String helpMsg(
0060     "Usage: " + G4String(argv[0]) +
0061     " [option(s)] \n No additional arguments triggers an interactive mode "
0062     "executing vis.mac macro. \n Options:\n\t-h\t\tdisplay this help "
0063     "message\n\t-m MACRO\ttriggers a batch mode executing MACRO\n");
0064   for (G4int i = 1; i < argc; ++i) {
0065     G4String argument(argv[i]);
0066     if (argument == "-h" || argument == "--help") {
0067       G4cout << helpMsg << G4endl;
0068       return 0;
0069     }
0070     else if (argument == "-m") {
0071       batchMacroName = G4String(argv[i + 1]);
0072       useInteractiveMode = false;
0073       ++i;
0074     }
0075     else {
0076       G4Exception(
0077         "main", "Unknown argument", FatalErrorInArgument,
0078         ("Unknown argument passed to " + G4String(argv[0]) + " : " + argument + "\n" + helpMsg)
0079           .c_str());
0080     }
0081   }
0082 
0083   // Initialization of default Run manager
0084   auto* runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::Default);
0085 
0086   // Detector geometry:
0087   auto detector = new Par03DetectorConstruction();
0088   runManager->SetUserInitialization(detector);
0089 
0090   // Physics list
0091   auto physicsList = new FTFP_BERT();
0092   // Add fast simulation physics
0093   auto fastSimulationPhysics = new G4FastSimulationPhysics();
0094   fastSimulationPhysics->BeVerbose();
0095   fastSimulationPhysics->ActivateFastSimulation("e-");
0096   fastSimulationPhysics->ActivateFastSimulation("e+");
0097   fastSimulationPhysics->ActivateFastSimulation("gamma");
0098   physicsList->RegisterPhysics(fastSimulationPhysics);
0099   // reduce verbosity of physics lists
0100   G4EmParameters::Instance()->SetVerbose(0);
0101   runManager->SetUserInitialization(physicsList);
0102   G4HadronicProcessStore::Instance()->SetVerbose(0);
0103 
0104   //-------------------------------
0105   // UserAction classes
0106   //-------------------------------
0107   runManager->SetUserInitialization(new Par03ActionInitialisation(detector));
0108 
0109   //----------------
0110   // Visualization:
0111   //----------------
0112   G4cout << "Instantiating Visualization Manager......." << G4endl;
0113   G4VisManager* visManager = new G4VisExecutive;
0114   visManager->Initialize();
0115   G4UImanager* UImanager = G4UImanager::GetUIpointer();
0116 
0117   if (useInteractiveMode) {
0118     auto ui = new G4UIExecutive(argc, argv);
0119     UImanager->ApplyCommand("/control/execute vis.mac");
0120     ui->SessionStart();
0121     delete ui;
0122   }
0123   else {
0124     G4String command = "/control/execute ";
0125     UImanager->ApplyCommand(command + batchMacroName);
0126   }
0127 
0128   // Free the store: user actions, physics_list and detector_description are
0129   //                 owned and deleted by the run manager, so they should not
0130   //                 be deleted in the main() program !
0131 
0132   delete visManager;
0133   delete runManager;
0134 
0135   return 0;
0136 }