Back to home page

EIC code displayed by LXR

 
 

    


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

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