gtree
Loading...
Searching...
No Matches
gtree_example.cc
Go to the documentation of this file.
1
23
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->getRequiredScalarDouble("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 auto gvmap = gdetector->get_gvolumes_flat_map();
97 auto gmmap = gdetector->get_gmirrors_flat_map();
98
99 log->info(0, "gtree", "Detector construction successful with ", g4vmap.size(), " volumes.");
100
101 if (gopts->getSwitch("gui")) {
102
103 auto gtree = new GTree(gopts, g4vmap, gvmap, window, gmmap);
104
105 window->setCentralWidget(gtree);
106 window->show();
107
108 // Quit after the configured delay (milliseconds) to make the example self-terminating.
109 QTimer::singleShot(timeout, app, &QCoreApplication::quit);
110
111 int appResult = QApplication::exec();
112
113 // Clean up GUI resources
114 delete gtree;
115 delete window;
116 delete app;
117
118 // Clean up Geant4 and custom logic
119 delete visManager;
120
121 return appResult;
122 }
123
124
125 // CLI mode
126 log->info(0, "Running gtree in command line mode...");
127
128 return EXIT_SUCCESS;
129}
Qt widget that displays the geometry hierarchy and allows interactive style edits.
Definition gtree.h:297
#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[])