1#include "Framework/Configure/Parameters.h"
3#include "G4GeometryManager.hh"
4#include "G4PhysListFactory.hh"
5#include "G4RunManager.hh"
6#include "G4UIExecutive.hh"
7#include "G4UImanager.hh"
8#include "G4VisExecutive.hh"
9#include "SimCore/DetectorConstruction.h"
10#include "SimCore/Geo/Parser.h"
12static void printUsage() {
13 std::cout <<
"usage: g4-vis {detector.gdml} (macro.mac)" << std::endl;
14 std::cout <<
" {detector.gdml} is the geometry description "
15 "that you wish to visualize."
17 <<
" (macro.mac) is an optional argument to execute"
18 " a macro file immediately after initialization."
20 <<
" The macro file must be in the current directory"
21 " or in a subdirectory of the current directory."
26int main(
int argc,
char* argv[]) {
27 if (argc != 2 && argc != 3) {
29 std::cerr <<
"** Need to be given a single detector description and "
30 "(optionally) a single macro to execute. **"
35 std::string the_arg{argv[1]};
36 std::string the_macro;
37 if (argc == 3) the_macro = std::string(argv[2]);
38 if (the_arg ==
"-h" or the_arg ==
"--help") {
47 parser_parameters.addParameter(
"validate_detector",
true);
48 parser_parameters.addParameter<std::string>(
"detector", the_arg);
51 G4RunManager* run_manager =
new G4RunManager;
54 auto parser{simcore::geo::Parser::Factory::get().make(
55 "gdml", parser_parameters, empty_interface)};
57 std::cerr <<
"Unable to create a 'gdml' parser to read the geometry."
61 auto parser_ptr{parser.value()};
63 parser_ptr, parser_parameters, empty_interface));
64 G4GeometryManager::GetInstance()->OpenGeometry();
66 run_manager->DefineWorldVolume(parser_ptr->getWorldVolume());
69 G4PhysListFactory lists;
70 run_manager->SetUserInitialization(lists.GetReferencePhysList(
"FTFP_BERT"));
72 run_manager->Initialize();
75 G4UIExecutive* ui =
new G4UIExecutive(argc, argv);
76 G4VisManager* vis_manager =
new G4VisExecutive;
77 vis_manager->Initialize();
79 if (!std::fopen(argv[2],
"r")) {
80 std::cerr <<
"Macro file doesn't exist, or the path is incorrect! "
81 "Try using an absolute path or checking your directory."
86 auto* uimanager = G4UImanager::GetUIpointer();
87 G4String command =
"/control/execute " + the_macro;
88 uimanager->ApplyCommand(command);
Base classes for all user event processing components to extend.
Base class for all event processing components.
Class encapsulating parameters for configuring a processor.
Handle to the conditions system, provided at construction to classes which require it.
Implements the Geant4 detector construction.