G4OCCT 0.1.0
Geant4 interface to Open CASCADE Technology (OCCT) geometry definitions
Loading...
Searching...
No Matches
exampleB1.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
41
42#include "ActionInitialization.hh"
43#include "DetectorConstruction.hh"
44
45#include <G4RunManagerFactory.hh>
46#include <G4UImanager.hh>
47#include <QBBC.hh>
48
49#include <cerrno>
50#include <cstdlib>
51#include <iostream>
52
53int main(int argc, char** argv) {
54 // ── Run manager ───────────────────────────────────────────────────────────
55
56 auto* runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::Default);
57
58 // ── User initializations ──────────────────────────────────────────────────
59
60 runManager->SetUserInitialization(new B1::DetectorConstruction());
61 runManager->SetUserInitialization(new QBBC(0)); // 0: suppress physics-list verbosity
62 runManager->SetUserInitialization(new ActionInitialization());
63
64 // ── UI manager ────────────────────────────────────────────────────────────
65
66 G4UImanager* UImanager = G4UImanager::GetUIpointer();
67
68 // Optional second argument: number of worker threads (must be set before
69 // /run/initialize, which is the first command in the macro).
70 if (argc > 2) {
71 char* endptr = nullptr;
72 errno = 0;
73 long nthreads = std::strtol(argv[2], &endptr, 10);
74 if (errno != 0 || endptr == argv[2] || *endptr != '\0' || nthreads <= 0) {
75 std::cerr << "exampleB1: invalid nthreads argument '" << argv[2]
76 << "' (must be a positive integer)\n";
77 return 1;
78 }
79 int rc = UImanager->ApplyCommand(G4String("/run/numberOfThreads ") + G4String(argv[2]));
80 if (rc != 0) {
81 std::cerr << "exampleB1: /run/numberOfThreads command failed (code " << rc << ")\n";
82 return 1;
83 }
84 }
85
86 int exitCode = 0;
87 if (argc > 1) {
88 // Batch mode: execute the supplied macro file.
89 G4String command = "/control/execute ";
90 G4String fileName = argv[1];
91 exitCode = UImanager->ApplyCommand(command + fileName);
92 } else {
93 // Minimal headless default: initialise and exit without running any events.
94 exitCode = UImanager->ApplyCommand("/run/initialize");
95 }
96
97 delete runManager;
98 return exitCode != 0 ? 1 : 0;
99}
Initializes all user action classes for the B1 example.
Detector construction class to define materials and geometry.
int main(int argc, char **argv)
Definition exampleB1.cc:53