gtree
Loading...
Searching...
No Matches
gtree_example.cc
Go to the documentation of this file.
1
24// geant4
25#include "G4VisExecutive.hh"
26#include "G4RunManagerFactory.hh"
27#include "QBBC.hh"
28
29// gtree
30#include "gtree.h"
31#include "gtree_options.h"
32
33// gemc
35
36// qt
37#include <QApplication>
38#include <QMainWindow>
39#include <QTimer>
40
41
61int main(int argc, char* argv[]) {
62 // Initialize options and logging
63 auto gopts = std::make_shared<GOptions>(argc, argv, gtree::defineOptions());
64 auto log = std::make_shared<GLogger>(gopts, SFUNCTION_NAME, GTREE_LOGGER);
65 auto timeout = gopts->getScalarDouble("tt");
66
67 log->info(0, "Starting gtree example...");
68
69 // Optional GUI setup (only if --gui is passed)
70 QApplication* app = nullptr;
71 QMainWindow* window = nullptr;
72
73 // Geant4: create a default run manager and register a reference physics list.
74 auto runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::Default);
75 auto physicsList = new QBBC;
76 runManager->SetUserInitialization(physicsList);
77
78 // Geant4: visualization manager used by geometry UI commands invoked by the widget.
79 auto visManager = new G4VisExecutive;
80 visManager->Initialize();
81
82 if (gopts->getSwitch("gui")) {
83 log->info(0, "gtree", "Running in GUI mode...");
84 app = new QApplication(argc, argv);
85 window = new QMainWindow();
86 window->setWindowTitle(QString::fromUtf8("gtree example"));
87 }
88
89 // Build detector and initialize the run manager so geometry exists.
90 auto gdetector = new GDetectorConstruction(gopts);
91 runManager->SetUserInitialization(gdetector);
92 runManager->Initialize();
93
94 // Retrieve volume map used by GTree to build the system/volume hierarchy.
95 auto g4vmap = gdetector->get_g4volumes_map();
96
97 log->info(0, "gtree", "Detector construction successful with ", g4vmap.size(), " volumes.");
98
99 if (gopts->getSwitch("gui")) {
100
101 auto gtree = new GTree(gopts, g4vmap, window);
102
103 window->setCentralWidget(gtree);
104 window->show();
105
106 // Quit after the configured delay (milliseconds) to make the example self-terminating.
107 QTimer::singleShot(timeout, app, &QCoreApplication::quit);
108
109 int appResult = QApplication::exec();
110
111 // Clean up GUI resources
112 delete gtree;
113 delete window;
114 delete app;
115
116 // Clean up Geant4 and custom logic
117 delete visManager;
118
119 return appResult;
120 }
121
122
123 // CLI mode
124 log->info(0, "Running gtree in command line mode...");
125
126 return EXIT_SUCCESS;
127}
Qt widget that displays the geometry hierarchy and allows interactive style edits.
Definition gtree.h:229
#define SFUNCTION_NAME
Option-set definition entry point for the GTree module.
constexpr const char * GTREE_LOGGER
GOptions defineOptions()
Build and return the option set required by the GTree module.
int main(int argc, char *argv[])