Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-18 07:41:49

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 // gpaterno, October 2025
0027 //
0028 /// \file ch5.cc
0029 /// \brief Main program of the ch5 example
0030 //
0031 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0032 
0033 #include "DetectorConstruction.hh"
0034 #include "ActionInitialization.hh"
0035 
0036 #include "G4RunManagerFactory.hh"
0037 #include "G4SteppingVerbose.hh"
0038 #include "G4UImanager.hh"
0039 #include "G4ScoringManager.hh"
0040 #include "G4AnalysisManager.hh"
0041 #include "G4VisExecutive.hh"
0042 #include "G4UIExecutive.hh"
0043 
0044 #include "FTFP_BERT.hh"
0045 #include "G4FastSimulationPhysics.hh"
0046 #include "G4CoherentPairProductionPhysics.hh"
0047 
0048 #include "Randomize.hh"
0049 #include <ctime>
0050 #include "G4Timer.hh"
0051 
0052 #include "G4ParticleTable.hh"
0053 #include "G4ParticleDefinition.hh"
0054 
0055 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0056 
0057 int main(int argc,char** argv)
0058 {
0059     // Get current time
0060     G4Timer* theTimer = new G4Timer();
0061     theTimer->Start();
0062      
0063     //Set random number generator
0064     CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine);
0065     G4String option_file = "random.in";
0066     std::ifstream fin(option_file);
0067     long random_seed = 0;
0068     if (fin.is_open()) {
0069         fin >> random_seed;
0070         fin.close();
0071     }
0072     random_seed += time(NULL);
0073     G4cout << "Random seed: " << random_seed << G4endl;
0074     CLHEP::HepRandom::setTheSeed(random_seed);
0075  
0076     //Use G4SteppingVerboseWithUnits
0077     G4int precision = 4;
0078     G4SteppingVerbose::UseBestUnit(precision);
0079 
0080     //Construct the run manager
0081     int vNumberOfThreads = 1;
0082     if (argc > 2) {
0083         vNumberOfThreads = atoi(argv[2]);
0084     }
0085     auto* runManager =
0086         G4RunManagerFactory::CreateRunManager(G4RunManagerType::Default);
0087     runManager->SetNumberOfThreads(vNumberOfThreads);
0088     G4cout << "### Using " << vNumberOfThreads << " threads ###" << G4endl;
0089                    
0090     //Activate UI-command based scorer
0091     G4ScoringManager* scManager = G4ScoringManager::GetScoringManager();
0092     scManager->SetVerboseLevel(0);
0093 
0094            
0095     //Set mandatory initialization classes    
0096     //Set the Geometry
0097     runManager->SetUserInitialization(new DetectorConstruction);
0098 
0099     //Physics list
0100     G4VModularPhysicsList* physicsList = new FTFP_BERT;
0101     // -- Create helper tool used to activate the fast simulation
0102     G4FastSimulationPhysics* fastSimulationPhysics = new G4FastSimulationPhysics();
0103     fastSimulationPhysics->BeVerbose();
0104     // -- activation of fast simulation for particles having fast simulation models
0105     // -- attached in the mass geometry
0106     fastSimulationPhysics->ActivateFastSimulation("e-");
0107     fastSimulationPhysics->ActivateFastSimulation("e+");
0108     fastSimulationPhysics->ActivateFastSimulation("pi-");
0109     fastSimulationPhysics->ActivateFastSimulation("pi+");
0110     fastSimulationPhysics->ActivateFastSimulation("mu-");
0111     fastSimulationPhysics->ActivateFastSimulation("mu+");
0112     fastSimulationPhysics->ActivateFastSimulation("proton");
0113     fastSimulationPhysics->ActivateFastSimulation("anti_proton");
0114     fastSimulationPhysics->ActivateFastSimulation("GenericIon");
0115     // -- Attach the fast simulation physics constructor to the physics list
0116     physicsList->RegisterPhysics(fastSimulationPhysics);
0117     /*
0118     //Coherent pair production model
0119     G4CoherentPairProductionPhysics* coherentPairProductionPhysics =
0120         new G4CoherentPairProductionPhysics();
0121     physicsList->RegisterPhysics(coherentPairProductionPhysics);
0122     */
0123     physicsList->SetVerboseLevel(1);
0124     runManager->SetUserInitialization(physicsList);
0125 
0126     //Set user action classes
0127     runManager->SetUserInitialization(new ActionInitialization());
0128 
0129 
0130     //Get the pointer to the User Interface manager
0131     G4UImanager* UImanager = G4UImanager::GetUIpointer();
0132        
0133     if (argc != 1) {
0134         //Batch mode
0135         G4String command = "/control/execute ";
0136         G4String fileName = argv[1];
0137         UImanager->ApplyCommand(command+fileName);
0138     } else {
0139         //Visualization manager
0140         G4VisManager* visManager = new G4VisExecutive;
0141         visManager->Initialize();
0142 
0143         //Define UI session for interactive mode        
0144         G4UIExecutive* ui = new G4UIExecutive(argc,argv);
0145         UImanager->ApplyCommand("/control/execute macros/init_vis.mac");
0146         if (ui->IsGUI()) UImanager->ApplyCommand("/control/execute macros/gui.mac");
0147         ui->SessionStart();
0148         delete ui;
0149 
0150         delete visManager;
0151     }
0152     
0153     //Job termination
0154     delete runManager;
0155 
0156     theTimer->Stop();
0157     G4cout << "Execution terminated" << G4endl;
0158     G4cout << (*theTimer) << G4endl;
0159     delete theTimer;
0160     
0161     return 0;  
0162 }
0163 
0164 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....