Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-17 09:57:14

0001 
0002 #include "G4RunManager.hh"
0003 #include "G4UImanager.hh"
0004 
0005 #include "FTFP_BERT.hh"
0006 #include "G4EmStandardPhysics_option4.hh"
0007 #include "G4OpticalPhysics.hh"
0008 
0009 #define _GEANT_SOURCE_CODE_
0010 #include "RunAction.h"
0011 #include "CherenkovEvent.h"
0012 #include "CherenkovSteppingAction.h"
0013 #include "CherenkovStackingAction.h"
0014 
0015 #include "G4VisExecutive.hh"
0016 #include "G4UIExecutive.hh"
0017 
0018 #include <share.h>
0019 
0020 // This is indeed a cut'n'paste from one of the GEANT examples (as well as 
0021 // quite the rest of the stuff in this file); let it be;
0022 namespace {
0023   void PrintUsage() {
0024     G4cerr << " Usage: " << G4endl;
0025     G4cerr << " pfrich [-m macro ] [-u UIsession] [-r seed] [-s statistics] [-i <input HEPMC3 file>] [-o <output ROOT file>]" << G4endl;
0026   }
0027 }
0028 
0029 #include <TFile.h>
0030 #include <TTree.h>
0031 
0032 #include <CherenkovDetectorCollection.h>
0033 
0034 // -------------------------------------------------------------------------------------
0035 
0036 int main(int argc, char** argv)
0037 {
0038   // At most 1+4*2 command line arguments;
0039   if ( argc > 9 ) {
0040     PrintUsage();
0041     return 1;
0042   } //if
0043 
0044   // Parse them;
0045   G4String macro;
0046   G4String session;
0047 
0048   // Default is to use tuning.h hardcoded values;
0049   const char *infile = 0;
0050   // These two may have default values;
0051   unsigned stat = _STATISTICS_DEFAULT_;
0052   G4String outfile = "pfrich.root";
0053 
0054   G4long myseed = 345354;
0055   for ( G4int i=1; i<argc; i=i+2 ) {
0056     if      ( G4String(argv[i]) == "-m" ) macro   =      argv[i+1];
0057     else if ( G4String(argv[i]) == "-u" ) session =      argv[i+1];
0058 #if defined(HEPMC3) 
0059     else if ( G4String(argv[i]) == "-i" ) infile  =      argv[i+1];
0060 #endif
0061     else if ( G4String(argv[i]) == "-o" ) outfile =      argv[i+1];
0062     else if ( G4String(argv[i]) == "-r" ) myseed  = atoi(argv[i+1]);
0063     else if ( G4String(argv[i]) == "-s" ) stat    = atoi(argv[i+1]);
0064     else {
0065       PrintUsage();
0066       return 1;
0067     } //if
0068   }
0069 
0070   auto outputFile = TFile::Open(outfile, "RECREATE");
0071 
0072   auto geometry = new CherenkovDetectorCollection();
0073   auto event    = new CherenkovEvent();
0074 
0075   auto TT = new TTree("t", "My tree");
0076   TT->Branch("e", "CherenkovEvent", &event, 16000, 2);
0077 
0078   // Choose the Random engine
0079   G4Random::setTheEngine(new CLHEP::RanecuEngine);
0080 
0081   // Construct the default run manager
0082   G4RunManager * runManager = new G4RunManager;
0083 
0084   // Seed the random number generator manually
0085   G4Random::setTheSeed(myseed);
0086 
0087   // Set mandatory initialization classes
0088   //
0089   // Physics list
0090   {
0091     G4VModularPhysicsList* physicsList = new FTFP_BERT;
0092     physicsList->ReplacePhysics(new G4EmStandardPhysics_option4());
0093     G4OpticalPhysics* opticalPhysics = new G4OpticalPhysics();
0094     physicsList->RegisterPhysics(opticalPhysics);
0095     runManager->SetUserInitialization(physicsList);
0096   }
0097 
0098   // Detector construction and user action initialization;
0099   setup(runManager, geometry, infile);
0100   // User action initialization
0101   runManager->SetUserAction(new RunAction());
0102   {
0103     auto stepping = new CherenkovSteppingAction(geometry, event);
0104 #ifdef _DISABLE_SECONDARIES_
0105     stepping->DisableSecondaries();
0106 #endif
0107     runManager->SetUserAction(stepping);
0108   }
0109   runManager->SetUserAction(new CherenkovStackingAction(event, TT));
0110 
0111   // Initialize G4 kernel
0112   runManager->Initialize();
0113 
0114   // Initialize visualization
0115   G4VisManager* visManager = new G4VisExecutive;
0116   visManager->Initialize();
0117 
0118   // Get the pointer to the User Interface manager
0119   //
0120   G4UImanager* UImanager = G4UImanager::GetUIpointer(); 
0121    
0122   // As of 2023/02/22 "-m" is used for interactive mode; in batch mode pfrich.mac
0123   // is ignored; it really makes no sense to hardcode everything in tuning.h, and
0124   // then leave the requested statistics parameter alone in the macro;
0125   if ( macro.size() ) {
0126     // Presumably interactive mode with macro/vis.mac;
0127     G4UIExecutive * ui = new G4UIExecutive(argc,argv,session);
0128     G4String command = "/control/execute ";
0129     UImanager->ApplyCommand(command+macro);
0130 
0131 #ifdef _GEOMETRY_CHECK_
0132      UImanager->ApplyCommand("/geometry/test/run");
0133 #endif
0134 
0135      ui->SessionStart();
0136      delete ui;
0137   } else {
0138     // Batch mode;
0139     TString cmd; cmd.Form("/run/beamOn %d", stat);
0140     UImanager->ApplyCommand(cmd.Data());
0141   }
0142 
0143   // FIXME: sort this out later;
0144   //#ifdef _GENERATE_GDML_OUTPUT_
0145   //construction->ExportGdmlFile();
0146   //#endif
0147 
0148   // Job termination
0149   delete visManager;
0150   delete runManager;
0151 
0152   geometry->Write();
0153   TT->Write();
0154   outputFile->Close();
0155 
0156   return 0;
0157 } // main() 
0158 
0159 // -------------------------------------------------------------------------------------
0160