Back to home page

EIC code displayed by LXR

 
 

    


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

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