Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-20 08:30:29

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