Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:19:32

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 //---------------------------------------------------------------------
0027 //*            |\___/|                                                *
0028 //*            )     (                                                *
0029 //*           =\     /=                                               *
0030 //*             )===(                                                 *
0031 //*            /     \     CaTS: Calorimeter and Tracker Simulation   *
0032 //*            |     |     is a flexible and extend-able framework    *
0033 //*           /       \    for the simulation of various detector     *
0034 //*       \       /    systems                                    *
0035 //*            \__  _/     https://github.com/hanswenzel/CaTS         *
0036 //*          ( (                                                  *
0037 //*           ) )                                                 *
0038 //*              (_(                                                  *
0039 //* CaTS also serves as an example that demonstrates how to use       *
0040 //* opticks from within Geant4 for the creation and propagation of    *
0041 //* optical photons.                                                  *
0042 //* see https://bitbucket.org/simoncblyth/opticks.git).               *
0043 //* Ascii Art by Joan Stark: https://www.asciiworld.com/-Cats-2-.html *
0044 //---------------------------------------------------------------------
0045 //
0046 // ********************************************************************
0047 //
0048 //  CaTS (Calorimetry and Tracking Simulation)
0049 //
0050 //  Authors : Hans Wenzel
0051 //            Soon Yung Jun
0052 //            (Fermi National Accelerator Laboratory)
0053 //
0054 // History
0055 //   October 18th, 2021 : first implementation
0056 //
0057 // ********************************************************************
0058 //
0059 /// \file CaTS.cc
0060 /// \brief main driver of CaTS
0061 //
0062 // project headers:
0063 #include "ActionInitialization.hh"
0064 #include "CaTSVersion.hh"
0065 #include "ConfigurationManager.hh"
0066 #include "DetectorConstruction.hh"
0067 #include "PhysicsConfigurator.hh"
0068 // Geant4 headers:
0069 #include "G4RunManager.hh"
0070 #include "G4RunManagerFactory.hh"
0071 #include "G4Timer.hh"
0072 #include "G4UIExecutive.hh"
0073 #include "G4UImanager.hh"
0074 #include "G4VModularPhysicsList.hh"
0075 #include "G4VisExecutive.hh"
0076 #include <G4Threading.hh>
0077 #ifdef WITH_G4OPTICKS
0078 #  include "OPTICKS_LOG.hh"
0079 #endif
0080 #include "TROOT.h"
0081 #include <thread>
0082 
0083 int main(int argc, char** argv)
0084 {
0085 #ifdef G4MULTITHREADED
0086   G4int nThreads = 0;
0087 #endif
0088   G4bool interactive   = false;
0089   G4String physicsconf = "";
0090   G4String gdmlfile    = "";
0091   G4String macrofile   = "";
0092   G4UIExecutive* ui    = nullptr;
0093   for(G4int i = 1; i < argc; i = i + 2)
0094   {
0095     if(G4String(argv[i]) == "-g")
0096     {
0097       gdmlfile = argv[i + 1];
0098     }
0099     else if(G4String(argv[i]) == "-pl")
0100     {
0101       physicsconf = G4String(argv[i + 1]);
0102     }
0103     else if(G4String(argv[i]) == "-m")
0104     {
0105       macrofile = G4String(argv[i + 1]);
0106     }
0107 #ifdef G4MULTITHREADED
0108     else if(G4String(argv[i]) == "-t")
0109     {
0110       nThreads = G4UIcommand::ConvertToInt(argv[i + 1]);
0111     }
0112 #endif
0113   }
0114   if(gdmlfile == "")
0115   {
0116     G4cout << "Error! Mandatory input file is not specified!" << G4endl;
0117     G4cout << G4endl;
0118     G4cout << G4endl;
0119     G4cout << "Usage:  CaTS -g input_gdml_file:mandatory" << G4endl;
0120     G4cout << G4endl;
0121     return -1;
0122   }
0123   G4cout
0124     << G4endl
0125     << "---------------------------------------------------------------------"
0126     << G4endl
0127     << "*            |\\___/|                                                "
0128        "*"
0129     << G4endl
0130     << "*            )     (                                                *"
0131     << G4endl
0132     << "*           =\\     /=                                               "
0133        "*"
0134     << G4endl
0135     << "*             )===(      Welcome to:                                *"
0136     << G4endl
0137     << "*            /     \\     CaTS: Calorimeter and Tracker Simulation   "
0138        "*"
0139     << G4endl
0140     << "*            |     |     a flexible and extend-able framework       *"
0141     << G4endl
0142     << "*           /       \\    for the simulation of various detector     "
0143        "*"
0144     << G4endl
0145     << "*       \\       /    systems                                    *"
0146     << G4endl
0147     << "*            \\__  _/     https://github.com/hanswenzel/CaTS         "
0148        "*"
0149     << G4endl
0150     << "*              ( (                                                  *"
0151     << G4endl << "*         ) )      Version: " << CaTSVersion
0152     << "                          *" << G4endl
0153     << "*              (_(       Date:    " << CaTSDate << "                 *"
0154     << G4endl
0155     << "---------------------------------------------------------------------"
0156     << G4endl << G4endl;
0157   if(physicsconf == "")
0158   {
0159     G4cout << "Warning! no physics configuration specified!" << G4endl;
0160     G4cout << "Using default FTFP_BERT+OPTICAL+STEPLIMIT" << G4endl;
0161     physicsconf = "FTFP_BERT+OPTICAL+STEPLIMIT";
0162     G4cout << "Usage:  CaTS -pl physicsconfiguration" << G4endl;
0163     G4cout << G4endl;
0164   }
0165   if(macrofile == "")
0166   {
0167     G4cout << "Warning! no macro specified!" << G4endl;
0168     G4cout << "assume interactive mode" << G4endl;
0169     interactive = true;
0170     ui          = new G4UIExecutive(argc, argv);
0171     G4cout << G4endl;
0172     G4cout << G4endl;
0173     G4cout << "Usage:  CaTS -m macrofile" << G4endl;
0174     G4cout << G4endl;
0175   }
0176   G4Timer* eventTimer = new G4Timer;
0177   eventTimer->Start();
0178 #ifdef WITH_G4OPTICKS
0179   OPTICKS_LOG(argc, argv);
0180 #endif
0181   G4VModularPhysicsList* phys =
0182     PhysicsConfigurator::getInstance()->Construct(physicsconf);
0183   G4String DumpFilename = gdmlfile + "_G4";
0184   ConfigurationManager::getInstance()->setGDMLFileName(DumpFilename);
0185   DetectorConstruction* dc = new DetectorConstruction(gdmlfile);
0186   // Run manager
0187   auto* rm = G4RunManagerFactory::CreateRunManager(G4RunManagerType::Default);
0188 
0189   // G4RunManagerFactory::CreateRunManager(G4RunManagerType::SerialOnly);
0190 #ifdef G4MULTITHREADED
0191   // number of threads not set so use number of cores
0192   if(nThreads == 0)
0193   {
0194     nThreads = G4Threading::G4GetNumberOfCores();
0195   }
0196   if(nThreads > 0)
0197   {
0198     rm->SetNumberOfThreads(nThreads);
0199   }
0200 #endif
0201   rm->SetUserInitialization(dc);
0202   rm->SetUserInitialization(phys);
0203   ActionInitialization* actionInitialization = new ActionInitialization();
0204   rm->SetUserInitialization(actionInitialization);
0205   G4UImanager* UImanager = G4UImanager::GetUIpointer();
0206   if(interactive)
0207   {
0208     G4VisManager* visManager = new G4VisExecutive;
0209     visManager->Initialize();
0210     UImanager->ApplyCommand("/control/execute init_vis.mac");
0211     ui->SessionStart();
0212     delete ui;
0213     delete visManager;
0214   }
0215   else
0216   {
0217     // batch mode
0218     G4String command = "/control/execute ";
0219     UImanager->ApplyCommand(command + macrofile);
0220     
0221     delete ui;
0222   }
0223   eventTimer->Stop();
0224   double totalCPUTime =
0225     eventTimer->GetUserElapsed() + eventTimer->GetSystemElapsed();
0226   G4int precision_t          = G4cout.precision(3);
0227   std::ios::fmtflags flags_t = G4cout.flags();
0228   G4cout.setf(std::ios::fixed, std::ios::floatfield);
0229   G4cout << "TimeTotal> " << eventTimer->GetRealElapsed() << " " << totalCPUTime
0230          << G4endl;
0231   G4cout.setf(flags_t);
0232   G4cout.precision(precision_t);
0233   delete eventTimer;
0234   delete rm;
0235   return 0;
0236 }