Back to home page

EIC code displayed by LXR

 
 

    


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

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