File indexing completed on 2025-01-18 09:14:30
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
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
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
0084 run->Initialize();
0085
0086
0087 G4VisManager* vis = new G4VisExecutive;
0088 vis->Initialize();
0089
0090
0091 G4UImanager* uiman = G4UImanager::GetUIpointer();
0092 G4UIExecutive* ui = new G4UIExecutive(1,(char**)args);
0093 uiman->ApplyCommand("/control/execute "+setup);
0094 ui->SessionStart();
0095
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 }