1#include "Framework/Configure/Parameters.h"
3#include "G4GDMLParser.hh"
4#include "G4GeometryManager.hh"
5#include "G4PhysListFactory.hh"
6#include "G4RunManager.hh"
7#include "G4UIExecutive.hh"
8#include "G4UImanager.hh"
9#include "G4VisExecutive.hh"
10#include "SimCore/DetectorConstruction.h"
11#include "SimCore/Geo/Parser.h"
13static void printUsage() {
14 std::cout <<
"usage: g4-vis {detector.gdml} (macro.mac)" << std::endl;
15 std::cout <<
" {detector.gdml} is the geometry description "
16 "that you wish to visualize."
18 <<
" (macro.mac) is an optional argument to execute"
19 " a macro file immediately after initialization."
21 <<
" The macro file must be in the current directory"
22 " or in a subdirectory of the current directory."
27int main(
int argc,
char* argv[]) {
28 if (argc != 2 && argc != 3) {
30 std::cerr <<
"** Need to be given a single detector description and "
31 "(optionally) a single macro to execute. **"
36 std::string the_arg{argv[1]};
37 std::string the_macro;
38 if (argc == 3) the_macro = std::string(argv[2]);
39 if (the_arg ==
"-h" or the_arg ==
"--help") {
48 parser_parameters.addParameter(
"validate_detector",
true);
49 parser_parameters.addParameter<std::string>(
"detector", the_arg);
52 G4RunManager* run_manager =
new G4RunManager;
55 auto parser{simcore::geo::Parser::Factory::get().make(
56 "gdml", parser_parameters, empty_interface)};
58 std::cerr <<
"Unable to create a 'gdml' parser to read the geometry."
62 auto parser_ptr{parser.value()};
64 parser_ptr, parser_parameters, empty_interface));
65 G4GeometryManager::GetInstance()->OpenGeometry();
67 run_manager->DefineWorldVolume(parser_ptr->getWorldVolume());
70 G4PhysListFactory lists;
71 run_manager->SetUserInitialization(lists.GetReferencePhysList(
"FTFP_BERT"));
73 run_manager->Initialize();
76 G4UIExecutive* ui =
new G4UIExecutive(argc, argv);
77 G4VisManager* vis_manager =
new G4VisExecutive;
78 vis_manager->Initialize();
80 if (!std::fopen(argv[2],
"r")) {
81 std::cerr <<
"Macro file doesn't exist, or the path is incorrect! "
82 "Try using an absolute path or checking your directory."
87 auto* uimanager = G4UImanager::GetUIpointer();
88 G4String command =
"/control/execute " + the_macro;
89 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.