Back to home page

EIC code displayed by LXR

 
 

    


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

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