Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-19 08:38:16

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 pdb4dna.cc
0027 /// \brief Main program of the dna/pdb4dna 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 // Delage et al. PDB4DNA: implementation of DNA geometry from the Protein Data
0034 //                  Bank (PDB) description for Geant4-DNA Monte-Carlo
0035 //                  simulations (submitted to Comput. Phys. Commun.)
0036 // The Geant4-DNA web site is available at http://geant4-dna.org
0037 //
0038 //
0039 
0040 #include "ActionInitialization.hh"
0041 #include "DetectorConstruction.hh"
0042 #include "PhysicsList.hh"
0043 
0044 #ifdef G4MULTITHREADED
0045 #  include "G4MTRunManager.hh"
0046 #else
0047 #  include "G4RunManager.hh"
0048 #endif
0049 
0050 #include "G4UIExecutive.hh"
0051 #include "G4UImanager.hh"
0052 #include "G4VisExecutive.hh"
0053 #include "Randomize.hh"
0054 #ifdef G4UI_USE_QT
0055 #  include "G4UIQt.hh"
0056 #endif
0057 #include "CommandLineParser.hh"
0058 
0059 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0060 
0061 using namespace G4DNAPARSER;
0062 CommandLineParser* parser(0);
0063 
0064 void Parse(int& argc, char** argv);
0065 
0066 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0067 
0068 int main(int argc, char** argv)
0069 {
0070   //////////
0071   // Parse options given in commandLine
0072   //
0073   Parse(argc, argv);
0074 
0075   //////////
0076   // Construct the run manager according to whether MT is activated or not
0077   //
0078   Command* commandLine(0);
0079 
0080 #ifdef G4MULTITHREADED
0081   G4MTRunManager* runManager = new G4MTRunManager;
0082   if ((commandLine = parser->GetCommandIfActive("-mt"))) {
0083     int nThreads = 2;
0084     if (commandLine->GetOption() == "NMAX") {
0085       nThreads = G4Threading::G4GetNumberOfCores();
0086     }
0087     else {
0088       nThreads = G4UIcommand::ConvertToInt(commandLine->GetOption());
0089     }
0090     G4cout << "===== PDB4DNA is started with " << runManager->GetNumberOfThreads()
0091            << " threads =====" << G4endl;
0092 
0093     runManager->SetNumberOfThreads(nThreads);
0094   }
0095 #else
0096   G4RunManager* runManager = new G4RunManager();
0097 #endif
0098 
0099   // Set user classes
0100   //
0101   runManager->SetUserInitialization(new DetectorConstruction());
0102   runManager->SetUserInitialization(new PhysicsList);
0103   runManager->SetUserInitialization(new ActionInitialization());
0104 
0105   // Initialize G4 keRnel
0106   //
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 (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 600x600-0+0");
0133       }
0134       UImanager->ApplyCommand("/control/execute vis.mac");
0135     }
0136     if (ui->IsGUI()) UImanager->ApplyCommand("/control/execute gui.mac");
0137   }
0138   else
0139   // to be use visualization file (= store the visualization into
0140   // an external file:
0141   // ASCIITree ;  DAWNFILE ; HepRepFile ; VRML(1,2)FILE ; gMocrenFile ...
0142   {
0143     if ((commandLine = parser->GetCommandIfActive("-vis"))) {
0144       UImanager->ApplyCommand(G4String("/vis/open ") + commandLine->GetOption());
0145       UImanager->ApplyCommand("/control/execute vis.mac");
0146     }
0147   }
0148 
0149   if ((commandLine = parser->GetCommandIfActive("-mac"))) {
0150     G4String command = "/control/execute ";
0151     UImanager->ApplyCommand(command + commandLine->GetOption());
0152   }
0153   else {
0154     UImanager->ApplyCommand("/control/execute init.mac");
0155   }
0156 
0157   if ((commandLine = parser->GetCommandIfActive("-gui"))) {
0158 #ifdef G4UI_USE_QT
0159     G4UIQt* UIQt = static_cast<G4UIQt*>(UImanager->GetG4UIWindow());
0160     if (UIQt) {
0161       UIQt->AddViewerTabFromFile("README", "README from " + G4String(argv[0]));
0162     }
0163 #endif
0164     ui->SessionStart();
0165     delete ui;
0166   }
0167 
0168   // Job termination
0169   delete visManager;
0170   delete runManager;
0171 
0172   return 0;
0173 }
0174 
0175 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
0176 
0177 void Parse(int& argc, char** argv)
0178 {
0179   //////////
0180   // Parse options given in commandLine
0181   //
0182   parser = CommandLineParser::GetParser();
0183 
0184   parser->AddCommand("-gui", Command::OptionNotCompulsory,
0185                      "Select geant4 UI or just launch a geant4 terminal session", "qt");
0186 
0187   parser->AddCommand("-mac", Command::WithOption, "Give a mac file to execute", "pdb4dna.in");
0188 
0189   // You cann your own command, as for instance:
0190   //  parser->AddCommand("-seed",
0191   //                     Command::WithOption,
0192   //                     "Give a seed value in argument to be tested", "seed");
0193   // it is then up to you to manage this option
0194 
0195 #ifdef G4MULTITHREADED
0196   parser->AddCommand("-mt", Command::WithOption, "Launch in MT mode (events computed in parallel)",
0197                      "2");
0198 #endif
0199 
0200   parser->AddCommand("-vis", Command::WithOption, "Select a visualization driver",
0201                      "OGL 600x600-0+0");
0202 
0203   parser->AddCommand("-novis", Command::WithoutOption, "Deactivate visualization when using GUI");
0204 
0205   //////////
0206   // If -h or --help is given in option : print help and exit
0207   //
0208   if (parser->Parse(argc, argv) != 0)  // help is being printed
0209   {
0210     // if you are using ROOT, create a TApplication in this condition in order
0211     // to print the help from ROOT as well
0212     CommandLineParser::DeleteInstance();
0213     std::exit(0);
0214   }
0215 
0216   ///////////
0217   // Kill application if wrong argument in command line
0218   //
0219   if (parser->CheckIfNotHandledOptionsExists(argc, argv)) {
0220     // if you are using ROOT, you should initialise your TApplication
0221     // before this condition
0222     abort();
0223   }
0224 }