DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
g4gdmlDisplay.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 //#define G4UI_USE
14 //#define G4VIS_USE
15 //#define G4INTY_USE_XT
16 //#define G4VIS_USE_OPENGL
17 //#define G4UI_USE_TCSH
18 
19 #include <G4PVPlacement.hh>
20 #include <G4RunManager.hh>
21 #include <G4UImanager.hh>
22 #include <G4UIsession.hh>
23 #include <Randomize.hh>
24 
25 #ifdef G4VIS_USE_OPENGLX
26 #include <G4OpenGLImmediateX.hh>
27 #include <G4OpenGLStoredX.hh>
28 #endif
29 
30 #include <G4VisManager.hh>
31 #include <G4VisExecutive.hh>
32 #include <G4UIExecutive.hh>
33 #include <G4VUserPhysicsList.hh>
34 #include <G4ParticleTypes.hh>
35 #include <globals.hh>
36 
38 #include <cerrno>
39 #include <stdexcept>
40 
41 using namespace std;
42 using namespace dd4hep::sim;
43 
44 namespace {
45  class EmptyPhysicsList: public G4VUserPhysicsList {
46  public:
47  EmptyPhysicsList() { }
48  ~EmptyPhysicsList() { }
49  // Construct particle and physics process
50  void ConstructParticle() { G4Geantino::GeantinoDefinition(); }
51  void ConstructProcess() { AddTransportation(); }
52  void SetCuts() { SetCutsWithDefault(); }
53  };
54 }
55 
56 static const char* get_arg(int argc, char** argv,int which) {
57  if ( which>0 && which < argc ) return argv[which];
58  throw runtime_error("Invalid argument sequence");
59 }
60 
61 int main_wrapper(int argc, char** argv) {
62  string gdml = argv[1];
63  string setup = argv[2];
64  const char* args[] = {"cmd"};
65  for(int i=1; i<argc;++i) {
66  if ( argv[i][0]=='-' ) {
67  string n = argv[i]+1;
68  if ( ::strncmp(n.c_str(),"gdml",4) == 0 )
69  gdml = get_arg(argc,argv,++i);
70  else if ( ::strncmp(n.c_str(),"guisetup",3) == 0 )
71  setup = get_arg(argc,argv,++i);
72  }
73  }
74  if ( gdml.empty() || setup.empty() ) {
75  cout << " usage: g4gdmlDisplay -gdml <file-name> -guisetup <g4 macro>" << endl;
76  return EINVAL;
77  }
78 
79  G4RunManager * run = new G4RunManager;
80  run->SetUserInitialization(new Geant4GDMLDetector(gdml));
81  run->SetUserInitialization(new EmptyPhysicsList());
82  //
83  // Initialize G4 kernel
84  run->Initialize();
85  //
86  // Initialize visualization
87  G4VisManager* vis = new G4VisExecutive;
88  vis->Initialize();
89  //
90  // Get the pointer to the User Interface manager
91  G4UImanager* uiman = G4UImanager::GetUIpointer();
92  G4UIExecutive* ui = new G4UIExecutive(1,(char**)args);
93  uiman->ApplyCommand("/control/execute "+setup);
94  ui->SessionStart();
95  // end ...
96  delete ui;
97  delete vis;
98  delete run;
99  return 0;
100 }
101 
102 //______________________________________________________________________________
103 int main(int argc, char** argv) {
104  try {
105  return main_wrapper(argc,argv);
106  }
107  catch(const exception& e) {
108  cout << "Got uncaught exception: " << e.what() << endl;
109  }
110  catch (...) {
111  cout << "Got UNKNOWN uncaught exception." << endl;
112  }
113  return EINVAL;
114 }
dd4hep::exception
void exception(const std::string &src, const std::string &msg)
Definition: RootDictionary.h:69
main_wrapper
int main_wrapper(int argc, char **argv)
Definition: g4gdmlDisplay.cpp:61
main
int main(int argc, char **argv)
Definition: g4gdmlDisplay.cpp:103
Geant4GDMLDetector.h
dd4hep::sim::Geant4GDMLDetector
Class to read Geant4 geometry from GDML file.
Definition: Geant4GDMLDetector.h:32
dd4hep::sim
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
Definition: Geant4Output2EDM4hep.cpp:49
std
Definition: Plugins.h:30