Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-03-28 07:50:45

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 neuron.cc
0027 /// \brief Main program of the dna/neuron 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 // and papers
0034 // M. Batmunkh et al. J Radiat Res Appl Sci 8 (2015) 498-507
0035 // O. Belov et al. Physica Medica 32 (2016) 1510-1520
0036 // The Geant4-DNA web site is available at http://geant4-dna.org
0037 //
0038 // -------------------------------------------------------------------
0039 // November 2016
0040 // -------------------------------------------------------------------
0041 //
0042 //
0043 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0044 #include "ActionInitialization.hh"
0045 #include "CommandLineParser.hh"
0046 #include "DetectorConstruction.hh"
0047 #include "PhysicsList.hh"
0048 
0049 #include "G4DNAChemistryManager.hh"
0050 #include "G4RunManagerFactory.hh"
0051 #include "G4Timer.hh"
0052 #include "G4Types.hh"
0053 #include "G4UIExecutive.hh"
0054 #include "G4UImanager.hh"
0055 #include "G4VisExecutive.hh"
0056 
0057 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0058 
0059 using namespace std;
0060 using namespace G4DNAPARSER;
0061 
0062 CommandLineParser* parser(0);
0063 
0064 void Parse(int& argc, char** argv);
0065 
0066 int main(int argc, char** argv)
0067 {
0068   // run time in Geant4
0069   G4Timer* timer = new G4Timer();
0070   timer->Start();
0071 
0072   //////////
0073   // Parse options given in commandLine
0074   //
0075   Parse(argc, argv);
0076 
0077   //////////
0078   // Construct the run manager according to whether MT is activated or not
0079   //
0080   Command* commandLine(0);
0081 
0082   auto* runManager = G4RunManagerFactory::CreateRunManager();
0083 
0084   if ((commandLine = parser->GetCommandIfActive("-mt"))) {
0085     G4int nThreads = 2;
0086 
0087     if (commandLine->GetOption() == "NMAX") {
0088       nThreads = G4Threading::G4GetNumberOfCores();
0089     }
0090     else {
0091       nThreads = G4UIcommand::ConvertToInt(commandLine->GetOption());
0092     }
0093     runManager->SetNumberOfThreads(nThreads);
0094 
0095     G4cout << "===== neuron is started with " << runManager->GetNumberOfThreads()
0096            << " threads of MT MODE =====" << G4endl;
0097   }
0098 
0099   // Set mandatory user initialization classes
0100   DetectorConstruction* detector = new DetectorConstruction;
0101   runManager->SetUserInitialization(detector);
0102   runManager->SetUserInitialization(new PhysicsList);
0103 
0104   // User action initialization
0105   runManager->SetUserInitialization(new ActionInitialization(detector));
0106 
0107   // Initialize visualization
0108   G4VisManager* visManager = new G4VisExecutive;
0109   visManager->Initialize();
0110 
0111   // Get the pointer to the User Interface manager
0112   G4UImanager* UImanager = G4UImanager::GetUIpointer();
0113   G4UIExecutive* ui(0);
0114 
0115   // interactive mode : define UI session
0116   if ((commandLine = parser->GetCommandIfActive("-gui"))) {
0117     ui = new G4UIExecutive(argc, argv, commandLine->GetOption());
0118 
0119     if (ui->IsGUI()) UImanager->ApplyCommand("/control/execute gui.mac");
0120 
0121     if (parser->GetCommandIfActive("-novis") == 0)
0122     // visualization is used by default
0123     {
0124       if ((commandLine = parser->GetCommandIfActive("-vis")))
0125       // select a visualization driver if needed (e.g. HepFile)
0126       {
0127         UImanager->ApplyCommand(G4String("/vis/open ") + commandLine->GetOption());
0128       }
0129       else
0130       // by default OGL is used
0131       {
0132         UImanager->ApplyCommand("/vis/open OGL 800x600-0+0");
0133       }
0134       UImanager->ApplyCommand("/control/execute vis.mac");
0135     }
0136   }
0137   else
0138   // to be use visualization file (= store the visualization into
0139   // an external file:
0140   // ASCIITree ;  DAWNFILE ; HepRepFile ; VRML(1,2)FILE ; gMocrenFile ...
0141   {
0142     if ((commandLine = parser->GetCommandIfActive("-vis"))) {
0143       UImanager->ApplyCommand(G4String("/vis/open ") + commandLine->GetOption());
0144       UImanager->ApplyCommand("/control/execute vis.mac");
0145     }
0146   }
0147 
0148   if ((commandLine = parser->GetCommandIfActive("-mac"))) {
0149     G4String command = "/control/execute ";
0150     UImanager->ApplyCommand(command + commandLine->GetOption());
0151   }
0152   else {
0153     UImanager->ApplyCommand("/control/execute ");  // neuron.in
0154   }
0155 
0156   if ((commandLine = parser->GetCommandIfActive("-gui"))) {
0157     ui->SessionStart();
0158     delete ui;
0159   }
0160 
0161   // calculation time
0162   timer->Stop();
0163   G4cout << " Calculation time                      = " << timer->GetRealElapsed() << " s \n"
0164          << G4endl;
0165 
0166   delete visManager;
0167   delete runManager;
0168 
0169   return 0;
0170 }
0171 
0172 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0173 
0174 void GetNameAndPathOfExecutable(char** argv, G4String& executable, G4String& path)
0175 {
0176   // Get the last position of '/'
0177   std::string aux(argv[0]);
0178 
0179   // get '/' or '\\' depending on unix/mac or windows.
0180 #if defined(_WIN32) || defined(WIN32)
0181   int pos = aux.rfind('\\');
0182 #else
0183   int pos = aux.rfind('/');
0184 #endif
0185 
0186   // Get the path and the name
0187   path = aux.substr(0, pos + 1);
0188   executable = aux.substr(pos + 1);
0189 }
0190 
0191 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0192 
0193 void Parse(int& argc, char** argv)
0194 {
0195   //////////
0196   // Parse options given in commandLine
0197   //
0198   parser = CommandLineParser::GetParser();
0199 
0200   parser->AddCommand("-gui", Command::OptionNotCompulsory,
0201                      "Select geant4 UI or just launch a geant4 terminal session", "qt");
0202 
0203   parser->AddCommand("-mac", Command::WithOption, "Give a mac file to execute", "macFile.mac");
0204 
0205   // You cann your own command, as for instance:
0206   //  parser->AddCommand("-seed",
0207   //                     Command::WithOption,
0208   //                     "Give a seed value in argument to be tested", "seed");
0209   // it is then up to you to manage this option
0210 
0211   parser->AddCommand("-mt", Command::WithOption, "Launch in MT mode (events computed in parallel)",
0212                      " NOT RECOMMANDED WITH CHEMISTRY)", "2");
0213 
0214   parser->AddCommand("-sXY", Command::OptionNotCompulsory,
0215                      "Initial beam position uniformly spread on a square!");
0216   parser->AddCommand("-dXY", Command::OptionNotCompulsory,
0217                      "Initial beam position uniformly spread on a disk!");
0218 
0219   parser->AddCommand("-dnaliv", Command::OptionNotCompulsory, "Activate Livermore + DNAPhysics");
0220   parser->AddCommand("-dnachemON", Command::OptionNotCompulsory,
0221                      "Activate Livermore + DNAPhysics + DNAChemistry");
0222   parser->AddCommand("-dnahad", Command::OptionNotCompulsory,
0223                      "Activate Hadronic + Livermore + DNAPhysics");
0224 
0225   parser->AddCommand("-swc", Command::WithOption, "Give a SWC file to simulation", "fileName.swc");
0226 
0227   parser->AddCommand("-network",
0228                      Command::WithOption,  // OptionNotCompulsory,
0229                      "Give a DAT file to simulation", "fileName.dat");
0230 
0231   parser->AddCommand("-vis", Command::WithOption, "Select a visualization driver",
0232                      "OGL 600x600-0+0");
0233 
0234   parser->AddCommand("-novis", Command::WithoutOption, "Deactivate visualization when using GUI");
0235 
0236   G4String exec;
0237   G4String path;
0238   GetNameAndPathOfExecutable(argv, exec, path);
0239 
0240   parser->AddCommand("-out", Command::OptionNotCompulsory, "Output files", exec);
0241 
0242   //////////
0243   // If -h or --help is given in option : print help and exit
0244   //
0245   if (parser->Parse(argc, argv) != 0)  // help is being printed
0246   {
0247     // if you are using ROOT, create a TApplication in this condition in order
0248     // to print the help from ROOT as well
0249     CommandLineParser::DeleteInstance();
0250     std::exit(0);
0251   }
0252   ///////////
0253   // Kill application if wrong argument in command line
0254   //
0255   if (parser->CheckIfNotHandledOptionsExists(argc, argv)) {
0256     // if you are using ROOT, you should initialise your TApplication
0257     // before this condition
0258     abort();
0259   }
0260 }