Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:21:48

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