Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-02 08:06:54

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 wholeNuclearDNA.cc
0027 /// \brief Main program of the dna/wholeNuclearDNA 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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0037 #include "G4RunManagerFactory.hh"
0038 #include "G4Types.hh"
0039 #include "G4UIExecutive.hh"
0040 #include "G4UImanager.hh"
0041 #include "G4UItcsh.hh"
0042 #include "G4UIterminal.hh"
0043 #include "G4VisExecutive.hh"
0044 #ifdef G4UI_USE_QT
0045 #  include "G4UIQt.hh"
0046 #endif
0047 
0048 #include "ActionInitialization.hh"
0049 #include "CommandLineParser.hh"
0050 #include "DetectorConstruction.hh"
0051 #include "PhysicsList.hh"
0052 
0053 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0054 
0055 using namespace G4DNAPARSER;
0056 CommandLineParser* parser(0);
0057 
0058 void Parse(int& argc, char** argv);
0059 
0060 int main(int argc, char** argv)
0061 {
0062   //////////
0063   // Parse options given in commandLine
0064   //
0065   Parse(argc, argv);
0066 
0067   //////////
0068   // Construct the run manager according to whether MT is activated or not
0069   //
0070   Command* commandLine(0);
0071 
0072   auto* runManager = G4RunManagerFactory::CreateRunManager();
0073   if ((commandLine = parser->GetCommandIfActive("-mt"))) {
0074     int nThreads = 2;
0075     if (commandLine->GetOption() == "NMAX") {
0076       nThreads = G4Threading::G4GetNumberOfCores();
0077     }
0078     else {
0079       nThreads = G4UIcommand::ConvertToInt(commandLine->GetOption());
0080     }
0081 
0082     runManager->SetNumberOfThreads(nThreads);
0083 
0084     G4cout << "===== WholeNuclearDNA is started with " << runManager->GetNumberOfThreads()
0085            << " threads =====" << G4endl;
0086   }
0087 
0088   // Set mandatory user initialization classes
0089   DetectorConstruction* detector = new DetectorConstruction;
0090   runManager->SetUserInitialization(detector);
0091   runManager->SetUserInitialization(new PhysicsList);
0092   runManager->SetUserInitialization(new ActionInitialization());
0093 
0094   // Initialize G4 kernel
0095   runManager->Initialize();
0096 
0097   // Initialize visualization
0098   G4VisManager* visManager = new G4VisExecutive;
0099   // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
0100   // G4VisManager* visManager = new G4VisExecutive("Quiet");
0101   visManager->Initialize();
0102 
0103   // Get the pointer to the User Interface manager
0104   G4UImanager* UImanager = G4UImanager::GetUIpointer();
0105   G4UIExecutive* ui(0);
0106 
0107   // interactive mode : define UI session
0108   if ((commandLine = parser->GetCommandIfActive("-gui"))) {
0109     ui = new G4UIExecutive(argc, argv, commandLine->GetOption());
0110 
0111     if (ui->IsGUI()) UImanager->ApplyCommand("/control/execute gui.mac");
0112 
0113     if (parser->GetCommandIfActive("-novis") == 0)
0114     // visualization is used by default
0115     {
0116       if ((commandLine = parser->GetCommandIfActive("-vis")))
0117       // select a visualization driver if needed (e.g. HepFile)
0118       {
0119         UImanager->ApplyCommand(G4String("/vis/open ") + commandLine->GetOption());
0120       }
0121       else
0122       // by default OGL is used
0123       {
0124         UImanager->ApplyCommand("/vis/open OGL 800x600-0+0");
0125       }
0126       UImanager->ApplyCommand("/control/execute vis.mac");
0127     }
0128   }
0129   else
0130   // to be use visualization file (= store the visualization into
0131   // an external file:
0132   // ASCIITree ;  DAWNFILE ; HepRepFile ; VRML(1,2)FILE ; gMocrenFile ...
0133   {
0134     if ((commandLine = parser->GetCommandIfActive("-vis"))) {
0135       UImanager->ApplyCommand(G4String("/vis/open ") + commandLine->GetOption());
0136       UImanager->ApplyCommand("/control/execute vis.mac");
0137     }
0138   }
0139 
0140   if ((commandLine = parser->GetCommandIfActive("-mac"))) {
0141     G4String command = "/control/execute ";
0142     UImanager->ApplyCommand(command + commandLine->GetOption());
0143   }
0144   else {
0145     UImanager->ApplyCommand("/control/execute wholeNuclearDNA.in");
0146   }
0147 
0148   if ((commandLine = parser->GetCommandIfActive("-gui"))) {
0149 #ifdef G4UI_USE_QT
0150     G4UIQt* UIQt = static_cast<G4UIQt*>(UImanager->GetG4UIWindow());
0151     if (UIQt) {
0152       UIQt->AddViewerTabFromFile("README", "README from " + G4String(argv[0]));
0153     }
0154 #endif
0155     ui->SessionStart();
0156     delete ui;
0157   }
0158 
0159   delete visManager;
0160   delete runManager;
0161 
0162   return 0;
0163 }
0164 
0165 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0166 
0167 void GetNameAndPathOfExecutable(char** argv, G4String& executable, G4String& path)
0168 {
0169   // Get the last position of '/'
0170   std::string aux(argv[0]);
0171 
0172   // get '/' or '\\' depending on unix/mac or windows.
0173 #if defined(_WIN32) || defined(WIN32)
0174   int pos = aux.rfind('\\');
0175 #else
0176   int pos = aux.rfind('/');
0177 #endif
0178 
0179   // Get the path and the name
0180   path = aux.substr(0, pos + 1);
0181   executable = aux.substr(pos + 1);
0182 }
0183 
0184 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0185 
0186 void Parse(int& argc, char** argv)
0187 {
0188   //////////
0189   // Parse options given in commandLine
0190   //
0191   parser = CommandLineParser::GetParser();
0192 
0193   parser->AddCommand("-gui", Command::OptionNotCompulsory,
0194                      "Select geant4 UI or just launch a geant4 terminal session", "qt");
0195 
0196   parser->AddCommand("-mac", Command::WithOption, "Give a mac file to execute", "macFile.mac");
0197 
0198   // You cann your own command, as for instance:
0199   //  parser->AddCommand("-seed",
0200   //                     Command::WithOption,
0201   //                     "Give a seed value in argument to be tested", "seed");
0202   // it is then up to you to manage this option
0203 
0204   parser->AddCommand("-mt", Command::WithOption, "Launch in MT mode (events computed in parallel)",
0205                      "2");
0206 
0207   parser->AddCommand("-vis", Command::WithOption, "Select a visualization driver",
0208                      "OGL 600x600-0+0");
0209 
0210   parser->AddCommand("-novis", Command::WithoutOption, "Deactivate visualization when using GUI");
0211 
0212   G4String exec;
0213   G4String path;
0214   GetNameAndPathOfExecutable(argv, exec, path);
0215 
0216   parser->AddCommand("-out", Command::OptionNotCompulsory, "Output files (ROOT is used by default)",
0217                      exec);
0218 
0219   //////////
0220   // If -h or --help is given in option : print help and exit
0221   //
0222   if (parser->Parse(argc, argv) != 0)  // help is being printed
0223   {
0224     // if you are using ROOT, create a TApplication in this condition in order
0225     // to print the help from ROOT as well
0226     CommandLineParser::DeleteInstance();
0227     std::exit(0);
0228   }
0229 
0230   ///////////
0231   // Kill application if wrong argument in command line
0232   //
0233   if (parser->CheckIfNotHandledOptionsExists(argc, argv)) {
0234     // if you are using ROOT, you should initialise your TApplication
0235     // before this condition
0236     abort();
0237   }
0238 }