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