Back to home page

EIC code displayed by LXR

 
 

    


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

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