Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:14:30

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 //#define G4UI_USE
0014 //#define G4VIS_USE
0015 //#define G4INTY_USE_XT
0016 //#define G4VIS_USE_OPENGL
0017 //#define G4UI_USE_TCSH
0018 
0019 #include <G4PVPlacement.hh>
0020 #include <G4RunManager.hh>
0021 #include <G4UImanager.hh>
0022 #include <G4UIsession.hh>
0023 #include <Randomize.hh>
0024 
0025 #ifdef G4VIS_USE_OPENGLX
0026 #include <G4OpenGLImmediateX.hh>
0027 #include <G4OpenGLStoredX.hh>
0028 #endif
0029 
0030 #include <G4VisManager.hh>
0031 #include <G4VisExecutive.hh>
0032 #include <G4UIExecutive.hh>
0033 #include <G4VUserPhysicsList.hh>
0034 #include <G4ParticleTypes.hh>
0035 #include <globals.hh>
0036 
0037 #include <DDG4/Geant4GDMLDetector.h>
0038 #include <cerrno>
0039 #include <stdexcept>
0040 
0041 using namespace std;
0042 using namespace dd4hep::sim;
0043 
0044 namespace {
0045   class EmptyPhysicsList: public G4VUserPhysicsList  {
0046   public:
0047     EmptyPhysicsList()       {                                       }
0048     ~EmptyPhysicsList()      {                                       }
0049     // Construct particle and physics process
0050     void ConstructParticle() {    G4Geantino::GeantinoDefinition();  }
0051     void ConstructProcess()  {    AddTransportation();               }
0052     void SetCuts()           {    SetCutsWithDefault();              }
0053   };
0054 }
0055 
0056 static const char* get_arg(int argc, char**  argv,int which)  {
0057   if ( which>0 && which < argc ) return argv[which];
0058   throw runtime_error("Invalid argument sequence");
0059 }
0060 
0061 int main_wrapper(int argc, char** argv)   {
0062   string gdml = argv[1];
0063   string setup = argv[2];
0064   const char* args[] = {"cmd"};
0065   for(int i=1; i<argc;++i)   {
0066     if ( argv[i][0]=='-' )     {
0067       string n = argv[i]+1;
0068       if ( ::strncmp(n.c_str(),"gdml",4) == 0 )
0069         gdml = get_arg(argc,argv,++i);
0070       else if ( ::strncmp(n.c_str(),"guisetup",3) == 0 )
0071         setup = get_arg(argc,argv,++i);
0072     }
0073   }
0074   if ( gdml.empty() || setup.empty() )  {
0075     cout << " usage: g4gdmlDisplay -gdml <file-name> -guisetup <g4 macro>" << endl;
0076     return EINVAL;
0077   }
0078 
0079   G4RunManager * run = new G4RunManager;
0080   run->SetUserInitialization(new Geant4GDMLDetector(gdml));
0081   run->SetUserInitialization(new EmptyPhysicsList());
0082   //
0083   // Initialize G4 kernel
0084   run->Initialize();
0085   //
0086   // Initialize visualization
0087   G4VisManager* vis = new G4VisExecutive;
0088   vis->Initialize();
0089   //
0090   // Get the pointer to the User Interface manager
0091   G4UImanager* uiman = G4UImanager::GetUIpointer();
0092   G4UIExecutive* ui = new G4UIExecutive(1,(char**)args);
0093   uiman->ApplyCommand("/control/execute "+setup);
0094   ui->SessionStart();
0095   // end ...
0096   delete ui;
0097   delete vis;
0098   delete run;
0099   return 0;
0100 }
0101 
0102 //______________________________________________________________________________
0103 int main(int argc, char** argv)  {
0104   try {
0105     return main_wrapper(argc,argv);
0106   }
0107   catch(const exception& e)  {
0108     cout << "Got uncaught exception: " << e.what() << endl;
0109   }
0110   catch (...)  {
0111     cout << "Got UNKNOWN uncaught exception." << endl;
0112   }
0113   return EINVAL;    
0114 }