Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-17 08:31:46

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 clustering.cc
0027 /// \brief Main program of the dna/clustering example
0028 
0029 // This example is provided by the Geant4-DNA collaboration
0030 // Any report or published results obtained using the Geant4-DNA software
0031 // shall cite the following Geant4-DNA collaboration publication:
0032 // Med. Phys. 37 (2010) 4692-4708
0033 // The Geant4-DNA web site is available at http://geant4-dna.org
0034 //
0035 //
0036 
0037 #include "ActionInitialization.hh"
0038 #include "CommandLineParser.hh"
0039 #include "DetectorConstruction.hh"
0040 #include "PhysicsList.hh"
0041 
0042 #include "G4DNAChemistryManager.hh"
0043 #include "G4RunManagerFactory.hh"
0044 #include "G4UIExecutive.hh"
0045 #include "G4UImanager.hh"
0046 #include "G4VisExecutive.hh"
0047 
0048 using namespace G4DNAPARSER;
0049 CommandLineParser* parser(0);
0050 
0051 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0052 
0053 void Parse(int& argc, char** argv);
0054 
0055 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0056 
0057 int main(int argc, char** argv)
0058 {
0059   //////////
0060   // Parse options given in commandLine
0061   //
0062   Parse(argc, argv);
0063 
0064   //////////
0065   // Construct the run manager according to whether MT is activated or not
0066   //
0067   Command* commandLine(0);
0068 
0069   auto* runManager = G4RunManagerFactory::CreateRunManager();
0070   if ((commandLine = parser->GetCommandIfActive("-mt"))) {
0071     int nThreads = 2;
0072     if (commandLine->GetOption() == "NMAX") {
0073       nThreads = G4Threading::G4GetNumberOfCores();
0074     }
0075     else {
0076       nThreads = G4UIcommand::ConvertToInt(commandLine->GetOption());
0077     }
0078     runManager->SetNumberOfThreads(nThreads);
0079 
0080     G4cout << "===== clustering is started with " << runManager->GetNumberOfThreads()
0081            << " threads =====" << G4endl;
0082   }
0083 
0084   //////////
0085   // Set mandatory user initialization classes
0086   //
0087   DetectorConstruction* detector = new DetectorConstruction;
0088   runManager->SetUserInitialization(new PhysicsList);
0089   runManager->SetUserInitialization(detector);
0090   runManager->SetUserInitialization(new ActionInitialization());
0091 
0092   // Initialize G4 kernel
0093   runManager->Initialize();
0094 
0095   // Initialize visualization
0096   G4VisManager* visManager = new G4VisExecutive;
0097   visManager->Initialize();
0098 
0099   // Get the pointer to the User Interface manager
0100   G4UImanager* UImanager = G4UImanager::GetUIpointer();
0101   G4UIExecutive* ui(0);
0102 
0103   // interactive mode : define UI session
0104   if ((commandLine = parser->GetCommandIfActive("-gui"))) {
0105     ui = new G4UIExecutive(argc, argv, commandLine->GetOption());
0106 
0107     if (ui->IsGUI()) UImanager->ApplyCommand("/control/execute gui.mac");
0108 
0109     if (parser->GetCommandIfActive("-novis") == 0)
0110     // visualization is used by default
0111     {
0112       if ((commandLine = parser->GetCommandIfActive("-vis")))
0113       // select a visualization driver if needed (e.g. HepFile)
0114       {
0115         UImanager->ApplyCommand(G4String("/vis/open ") + commandLine->GetOption());
0116       }
0117       else
0118       // by default OGL is used
0119       {
0120         UImanager->ApplyCommand("/vis/open OGL 800x600-0+0");
0121       }
0122       UImanager->ApplyCommand("/control/execute vis.mac");
0123     }
0124   }
0125   else
0126   // to be use visualization file (= store the visualization into
0127   // an external file:
0128   // ASCIITree ;  DAWNFILE ; HepRepFile ; VRML(1,2)FILE ; gMocrenFile ...
0129   {
0130     if ((commandLine = parser->GetCommandIfActive("-vis"))) {
0131       UImanager->ApplyCommand(G4String("/vis/open ") + commandLine->GetOption());
0132       UImanager->ApplyCommand("/control/execute vis.mac");
0133     }
0134   }
0135 
0136   if ((commandLine = parser->GetCommandIfActive("-mac"))) {
0137     G4String command = "/control/execute ";
0138     UImanager->ApplyCommand(command + commandLine->GetOption());
0139   }
0140   else {
0141     UImanager->ApplyCommand("/control/execute run.in");
0142   }
0143 
0144   if ((commandLine = parser->GetCommandIfActive("-gui"))) {
0145     ui->SessionStart();
0146     delete ui;
0147   }
0148 
0149   // Job termination
0150   // Free the store: user actions, physics_list and detector_description are
0151   // owned and deleted by the run manager, so they should not be deleted
0152   // in the main() program !
0153 
0154   delete visManager;
0155   delete runManager;
0156 
0157   CommandLineParser::DeleteInstance();
0158 
0159   return 0;
0160 }
0161 
0162 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0163 
0164 void Parse(int& argc, char** argv)
0165 {
0166   //////////
0167   // Parse options given in commandLine
0168   //
0169   parser = CommandLineParser::GetParser();
0170 
0171   parser->AddCommand("-gui", Command::OptionNotCompulsory,
0172                      "Select geant4 UI or just launch a geant4 terminal session", "qt");
0173 
0174   parser->AddCommand("-mac", Command::WithOption, "Give a mac file to execute", "macFile.mac");
0175 
0176   // You cann your own command, as for instance:
0177   //  parser->AddCommand("-seed",
0178   //                     Command::WithOption,
0179   //                     "Give a seed value in argument to be tested", "seed");
0180   // it is then up to you to manage this option
0181 
0182   parser->AddCommand("-mt", Command::WithOption,
0183                      "Launch in MT mode (events computed in parallel,"
0184                      " NOT RECOMMENDED WITH CHEMISTRY)",
0185                      "2");
0186 
0187   parser->AddCommand("-vis", Command::WithOption, "Select a visualization driver",
0188                      "OGL 600x600-0+0");
0189 
0190   parser->AddCommand("-novis", Command::WithoutOption, "Deactivate visualization when using GUI");
0191 
0192   //////////
0193   // If -h or --help is given in option : print help and exit
0194   //
0195   if (parser->Parse(argc, argv) != 0)  // help is being printed
0196   {
0197     // if you are using ROOT, create a TApplication in this condition in order
0198     // to print the help from ROOT as well
0199     CommandLineParser::DeleteInstance();
0200     // Exit is kept
0201     std::exit(0);
0202   }
0203 
0204   ///////////
0205   // Kill application if wrong argument in command line
0206   //
0207   if (parser->CheckIfNotHandledOptionsExists(argc, argv)) {
0208     // if you are using ROOT, you should initialise your TApplication
0209     // before this condition
0210     abort();
0211   }
0212 }