LDMX Software
g4_vis.cxx
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 "G4VisExecutive.hh"
9#include "SimCore/DetectorConstruction.h"
10#include "SimCore/Geo/ParserFactory.h"
11
12static void printUsage() {
13 std::cout << "usage: g4-vis {detector.gdml}" << std::endl;
14 std::cout << " {detector.gdml} is the geometry description "
15 "that you wish to visualize."
16 << std::endl;
17}
18
19int main(int argc, char* argv[]) {
20 if (argc != 2) {
21 printUsage();
22 std::cerr << "** Need to be given a single detector description. **"
23 << std::endl;
24 return 1;
25 }
26
27 std::string the_arg{argv[1]};
28 if (the_arg == "-h" or the_arg == "--help") {
29 // ask for help, let's give it to them.
30 printUsage();
31 return 0;
32 }
33
34 framework::EventProcessor* null_processor{nullptr};
35 simcore::ConditionsInterface empty_interface(null_processor);
36 framework::config::Parameters parser_parameters;
37 parser_parameters.addParameter("validate_detector", true);
38 parser_parameters.addParameter<std::string>("detector", the_arg);
39
40 // RunManager
41 G4RunManager* runManager = new G4RunManager;
42
43 // Detector components
45 "gdml", parser_parameters, empty_interface)};
46 runManager->SetUserInitialization(new simcore::DetectorConstruction(
47 parser, parser_parameters, empty_interface));
48 G4GeometryManager::GetInstance()->OpenGeometry();
49 parser->read();
50 runManager->DefineWorldVolume(parser->GetWorldVolume());
51
52 // required to define a physics list to complete initialization
53 G4PhysListFactory lists;
54 runManager->SetUserInitialization(lists.GetReferencePhysList("FTFP_BERT"));
55
56 runManager->Initialize();
57
58 // Define (G)UI
59 G4UIExecutive* ui = new G4UIExecutive(argc, argv);
60 G4VisManager* visManager = new G4VisExecutive;
61 visManager->Initialize();
62
63 ui->SessionStart();
64
65 delete ui;
66 delete runManager;
67 delete visManager;
68
69 return 0;
70}
Base classes for all user event processing components to extend.
Base class for all event processing components.
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:27
void addParameter(const std::string &name, const T &value)
Add a parameter to the parameter list.
Definition Parameters.h:55
Handle to the conditions system, provided at construction to classes which require it.
Implements the Geant4 detector construction.
Parser * createParser(const std::string &name, framework::config::Parameters &parameters, simcore::ConditionsInterface &ci)
Create an instance of the parser of the given type.
static ParserFactory & getInstance()
Get the instance to this factory.
virtual void read()=0
Parse the detector geometry and read it into memory.