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 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  1 //
  2 // ********************************************************************
  3 // * License and Disclaimer                                           *
  4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.                             *
 10 // *                                                                  *
 11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                                                  *
 18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // ********************************************************************
 25 //
 26 //---------------------------------------------------------------------
 27 //*            |\___/|                                                *
 28 //*            )     (                                                *
 29 //*           =\     /=                                               *
 30 //*             )===(                                                 *
 31 //*            /     \     CaTS: Calorimeter and Tracker Simulation   *
 32 //*            |     |     is a flexible and extend-able framework    *
 33 //*           /       \    for the simulation of various detector     *
 34 //*       \       /    systems                                    *
 35 //*            \__  _/     https://github.com/hanswenzel/CaTS         *
 36 //*          ( (                                                  *
 37 //*           ) )                                                 *
 38 //*              (_(                                                  *
 39 //* CaTS also serves as an example that demonstrates how to use       *
 40 //* opticks from within Geant4 for the creation and propagation of    *
 41 //* optical photons.                                                  *
 42 //* see https://bitbucket.org/simoncblyth/opticks.git).               *
 43 //* Ascii Art by Joan Stark: https://www.asciiworld.com/-Cats-2-.html *
 44 //---------------------------------------------------------------------
 45 //
 46 // ********************************************************************
 47 //
 48 //  CaTS (Calorimetry and Tracking Simulation)
 49 //
 50 //  Authors : Hans Wenzel
 51 //            Soon Yung Jun
 52 //            (Fermi National Accelerator Laboratory)
 53 //
 54 // History
 55 //   October 18th, 2021 : first implementation
 56 //
 57 // ********************************************************************
 58 //
 59 /// \file CaTS.cc
 60 /// \brief main driver of CaTS
 61 //
 62 // project headers:
 63 #include "ActionInitialization.hh"
 64 #include "CaTSVersion.hh"
 65 #include "ConfigurationManager.hh"
 66 #include "DetectorConstruction.hh"
 67 #include "PhysicsConfigurator.hh"
 68 // Geant4 headers:
 69 #include "G4RunManager.hh"
 70 #include "G4RunManagerFactory.hh"
 71 #include "G4Timer.hh"
 72 #include "G4UIExecutive.hh"
 73 #include "G4UImanager.hh"
 74 #include "G4VModularPhysicsList.hh"
 75 #include "G4VisExecutive.hh"
 76 #include <G4Threading.hh>
 77 #ifdef WITH_G4OPTICKS
 78 #  include "OPTICKS_LOG.hh"
 79 #endif
 80 #include "TROOT.h"
 81 #include <thread>
 82 
 83 int main(int argc, char** argv)
 84 {
 85 #ifdef G4MULTITHREADED
 86   G4int nThreads = 0;
 87 #endif
 88   G4bool interactive   = false;
 89   G4String physicsconf = "";
 90   G4String gdmlfile    = "";
 91   G4String macrofile   = "";
 92   G4UIExecutive* ui    = nullptr;
 93   for(G4int i = 1; i < argc; i = i + 2)
 94   {
 95     if(G4String(argv[i]) == "-g")
 96     {
 97       gdmlfile = argv[i + 1];
 98     }
 99     else if(G4String(argv[i]) == "-pl")
100     {
101       physicsconf = G4String(argv[i + 1]);
102     }
103     else if(G4String(argv[i]) == "-m")
104     {
105       macrofile = G4String(argv[i + 1]);
106     }
107 #ifdef G4MULTITHREADED
108     else if(G4String(argv[i]) == "-t")
109     {
110       nThreads = G4UIcommand::ConvertToInt(argv[i + 1]);
111     }
112 #endif
113   }
114   if(gdmlfile == "")
115   {
116     G4cout << "Error! Mandatory input file is not specified!" << G4endl;
117     G4cout << G4endl;
118     G4cout << G4endl;
119     G4cout << "Usage:  CaTS -g input_gdml_file:mandatory" << G4endl;
120     G4cout << G4endl;
121     return -1;
122   }
123   G4cout
124     << G4endl
125     << "---------------------------------------------------------------------"
126     << G4endl
127     << "*            |\\___/|                                                "
128        "*"
129     << G4endl
130     << "*            )     (                                                *"
131     << G4endl
132     << "*           =\\     /=                                               "
133        "*"
134     << G4endl
135     << "*             )===(      Welcome to:                                *"
136     << G4endl
137     << "*            /     \\     CaTS: Calorimeter and Tracker Simulation   "
138        "*"
139     << G4endl
140     << "*            |     |     a flexible and extend-able framework       *"
141     << G4endl
142     << "*           /       \\    for the simulation of various detector     "
143        "*"
144     << G4endl
145     << "*     \\       /    systems                                    *"
146     << G4endl
147     << "*            \\__  _/     https://github.com/hanswenzel/CaTS         "
148        "*"
149     << G4endl
150     << "*              ( (                                                  *"
151     << G4endl << "*         ) )      Version: " << CaTSVersion
152     << "                          *" << G4endl
153     << "*              (_(       Date:    " << CaTSDate << "                 *"
154     << G4endl
155     << "---------------------------------------------------------------------"
156     << G4endl << G4endl;
157   if(physicsconf == "")
158   {
159     G4cout << "Warning! no physics configuration specified!" << G4endl;
160     G4cout << "Using default FTFP_BERT+OPTICAL+STEPLIMIT" << G4endl;
161     physicsconf = "FTFP_BERT+OPTICAL+STEPLIMIT";
162     G4cout << "Usage:  CaTS -pl physicsconfiguration" << G4endl;
163     G4cout << G4endl;
164   }
165   if(macrofile == "")
166   {
167     G4cout << "Warning! no macro specified!" << G4endl;
168     G4cout << "assume interactive mode" << G4endl;
169     interactive = true;
170     ui          = new G4UIExecutive(argc, argv);
171     G4cout << G4endl;
172     G4cout << G4endl;
173     G4cout << "Usage:  CaTS -m macrofile" << G4endl;
174     G4cout << G4endl;
175   }
176   G4Timer* eventTimer = new G4Timer;
177   eventTimer->Start();
178 #ifdef WITH_G4OPTICKS
179   OPTICKS_LOG(argc, argv);
180 #endif
181   G4VModularPhysicsList* phys =
182     PhysicsConfigurator::getInstance()->Construct(physicsconf);
183   G4String DumpFilename = gdmlfile + "_G4";
184   ConfigurationManager::getInstance()->setGDMLFileName(DumpFilename);
185   DetectorConstruction* dc = new DetectorConstruction(gdmlfile);
186   // Run manager
187   auto* rm = G4RunManagerFactory::CreateRunManager(G4RunManagerType::Default);
188 
189   // G4RunManagerFactory::CreateRunManager(G4RunManagerType::SerialOnly);
190 #ifdef G4MULTITHREADED
191   // number of threads not set so use number of cores
192   if(nThreads == 0)
193   {
194     nThreads = G4Threading::G4GetNumberOfCores();
195   }
196   if(nThreads > 0)
197   {
198     rm->SetNumberOfThreads(nThreads);
199   }
200 #endif
201   rm->SetUserInitialization(dc);
202   rm->SetUserInitialization(phys);
203   ActionInitialization* actionInitialization = new ActionInitialization();
204   rm->SetUserInitialization(actionInitialization);
205   G4UImanager* UImanager = G4UImanager::GetUIpointer();
206   if(interactive)
207   {
208     G4VisManager* visManager = new G4VisExecutive;
209     visManager->Initialize();
210     UImanager->ApplyCommand("/control/execute init_vis.mac");
211     ui->SessionStart();
212     delete ui;
213     delete visManager;
214   }
215   else
216   {
217     // batch mode
218     G4String command = "/control/execute ";
219     UImanager->ApplyCommand(command + macrofile);
220     
221     delete ui;
222   }
223   eventTimer->Stop();
224   double totalCPUTime =
225     eventTimer->GetUserElapsed() + eventTimer->GetSystemElapsed();
226   G4int precision_t          = G4cout.precision(3);
227   std::ios::fmtflags flags_t = G4cout.flags();
228   G4cout.setf(std::ios::fixed, std::ios::floatfield);
229   G4cout << "TimeTotal> " << eventTimer->GetRealElapsed() << " " << totalCPUTime
230          << G4endl;
231   G4cout.setf(flags_t);
232   G4cout.precision(precision_t);
233   delete eventTimer;
234   delete rm;
235   return 0;
236 }
237