13 #include "G4Colour.hh"
14 #include "G4GeometryManager.hh"
15 #include "G4LogicalVolume.hh"
16 #include "G4LogicalVolumeStore.hh"
17 #include "G4Material.hh"
18 #include "G4PVPlacement.hh"
19 #include "G4PVReplica.hh"
20 #include "G4PhysicalVolumeStore.hh"
21 #include "G4SolidStore.hh"
22 #include "G4VisAttributes.hh"
24 #include "G4GDMLParser.hh"
26 #include "G4RunManager.hh"
27 #include "G4TransportationManager.hh"
31 #include "Geant4GM/volumes/Factory.h"
32 #include "RootGM/volumes/Factory.h"
33 #include "TGeoManager.h"
37 #include "GGSVersion.h"
42 namespace GGSWolowitz {
43 G4String outputFile =
"GGSGeometry";
44 G4String geoDataCard =
"";
45 G4String geometryFile =
"";
47 const G4String defaultOutputType =
"g4.gdml";
49 const G4String defaultOutputType =
"tgeo.root";
51 G4String outputType = defaultOutputType;
52 G4String schemaLocation =
"http://service-spi.web.cern.ch/service-spi/app/releases/GDML/schema/gdml.xsd";
53 G4String detectorFlag =
"";
57 std::cout <<
"This program is used to convert GGS detector geometry into other geometry formats.\n";
58 std::cout <<
"Built with support for "
73 std::cout <<
"\nUsage: GGSWolowitz [options] \n";
74 std::cout <<
"\nOptions:\n";
75 std::cout <<
" -o, --output-file FILE output filename [default: output.gdml]\n";
76 std::cout <<
" -g, --geometry FILE full path and name of the geometry .so file\n";
77 std::cout <<
" -gd, --geo-data-card FILE data card filename for geometry configuration [default: not set]\n";
78 std::cout <<
" -t, --output-type TYPE output type (possible values: "
89 << GGSWolowitz::defaultOutputType <<
")\n";
90 std::cout <<
" -u, --gdml-schema-location url of schema location [default: http://service-spi.web.cern.ch/service-spi/app/releases/GDML/schema/gdml.xsd]\n";
91 std::cout <<
" -v, --verbose be verbose [default: false]\n";
92 std::cout <<
" -V, --version displays software version and exit\n";
93 std::cout <<
" -h, --help display this help and exit\n";
98 std::cout <<
"GGSWolowitz geometry software\n";
99 std::cout <<
"Using GGS " << GGSVERSION << std::endl;
102 using namespace GGSWolowitz;
104 int HandleInputPar(
int argc,
const char **argv) {
105 static const std::string routineName(
"HandleInputPar");
107 GGSSmartLog::verboseLevel = GGSSmartLog::WARNING;
108 int vLevel = GGSSmartLog::INFO;
112 if (!strcmp(argv[i],
"-h") || !strcmp(argv[i],
"--help")) {
117 if (!strcmp(argv[i],
"-V") || !strcmp(argv[i],
"--version")) {
122 else if (!strcmp(argv[i],
"-v") || !strcmp(argv[i],
"--verbose")) {
123 std::string vLevStr(argv[++i]);
124 if (vLevStr ==
"error")
125 vLevel = GGSSmartLog::ERROR;
126 else if (vLevStr ==
"warning")
127 vLevel = GGSSmartLog::WARNING;
128 else if (vLevStr ==
"normal" || vLevStr ==
"info")
129 vLevel = GGSSmartLog::INFO;
130 else if (vLevStr ==
"debug")
131 vLevel = GGSSmartLog::DEBUG;
132 else if (vLevStr ==
"deepdeb")
133 vLevel = GGSSmartLog::DEEPDEB;
135 GGSCOUT(WARNING) <<
"Unrecognized verbosity level: " << vLevStr <<
". Ignoring." <<
GGSENDL;
139 else if (!strcmp(argv[i],
"-o") || !strcmp(argv[i],
"--output-file")) {
144 outputFile = argv[i];
147 else if (!strcmp(argv[i],
"-t") || !strcmp(argv[i],
"--output-type")) {
152 if (strcmp(argv[i],
"g4.gdml") && strcmp(argv[i],
"tgeo.root") && strcmp(argv[i],
"tgeo.gdml")) {
153 GGSCOUT(ERROR) <<
"Unknown output type: " << argv[i] <<
GGSENDL;
157 if (!strcmp(argv[i],
"g4.gdml")) {
158 GGSCOUT(ERROR) <<
"Converting to gdml requires Geant4 version compiled with Xerces-C" <<
GGSENDL;
163 if (!strcmp(argv[i],
"tgeo.root")) {
164 GGSCOUT(ERROR) <<
"Converting to TGeo requires Virtual Geometry Model" <<
GGSENDL;
169 if (!strcmp(argv[i],
"tgeo.gdml")) {
171 <<
"Converting to gdml via TGeo requires Virtual Geometry Model and Root > 6.22.06 compiled with "
178 outputType = argv[i];
181 else if (!strcmp(argv[i],
"-g") || !strcmp(argv[i],
"--geometry")) {
186 geometryFile = argv[i];
189 else if (!strcmp(argv[i],
"-gd") || !strcmp(argv[i],
"--geo-data-card")) {
194 geoDataCard = argv[i];
197 else if (!strcmp(argv[i],
"-u") || !strcmp(argv[i],
"--gdml-schema-location")) {
202 schemaLocation = argv[i];
206 GGSCOUT(WARNING) <<
"Unidentified input argument \"" << argv[i] <<
"\". Ignoring." <<
GGSENDL;
212 GGSSmartLog::verboseLevel = vLevel;
216 int main(
int argc,
const char **argv) {
217 static const std::string routineName(
"GGSWolowitz");
219 if (HandleInputPar(argc, argv))
224 GGSCOUT(DEBUG) <<
"Start run manager " <<
GGSENDL;
225 G4RunManager *runManager =
new G4RunManager();
228 GGSCOUT(ERROR) <<
"Impossible to load geometry library " << geometryFile <<
". Exit." <<
GGSENDL;
235 GGSCOUT(ERROR) <<
"Can't create the geometry. Exit." <<
GGSENDL;
241 GGSCOUT(DEBUG) <<
"Construct the geometry." <<
GGSENDL;
244 G4VPhysicalVolume *physVolume = geometry->
Construct();
247 if (GGSWolowitz::outputType ==
"g4.gdml") {
248 GGSCOUT(DEBUG) <<
"Write the GDML file using G4GDMLParser." <<
GGSENDL;
250 parser.SetAddPointerToName(
true);
251 if (outputFile.length() < 6 || outputFile.substr(outputFile.length() - 8) !=
".g4.gdml") {
252 GGSCOUT(DEBUG) <<
"Append .g4.gdml extension to output file name" <<
GGSENDL;
253 outputFile.append(
".g4.gdml");
255 parser.Write(outputFile, physVolume,
true, schemaLocation);
258 #if defined(USE_TGEOROOT) || defined(USE_TGEOGDML)
259 if (GGSWolowitz::outputType ==
"tgeo.root" || GGSWolowitz::outputType ==
"tgeo.gdml") {
260 GGSCOUT(DEBUG) <<
"Write the " << (GGSWolowitz::outputType ==
"tgeo.root" ?
"VGM" :
"TGEO GDML") <<
" file."
262 Geant4GM::Factory *g4Factory =
new Geant4GM::Factory();
263 if (GGSSmartLog::verboseLevel >= GGSSmartLog::DEBUG)
264 g4Factory->SetDebug(1);
265 g4Factory->Import(physVolume);
268 RootGM::Factory *rtFactory =
new RootGM::Factory();
269 if (GGSSmartLog::verboseLevel >= GGSSmartLog::DEBUG)
270 rtFactory->SetDebug(1);
271 g4Factory->Export(rtFactory);
272 gGeoManager->CloseGeometry();
275 if (GGSWolowitz::outputType ==
"tgeo.root") {
276 if (outputFile.length() < 6 || outputFile.substr(outputFile.length() - 10) !=
".tgeo.root") {
277 GGSCOUT(DEBUG) <<
"Append .tgeo.root extension to output file name" <<
GGSENDL;
278 outputFile.append(
".tgeo.root");
283 if (GGSWolowitz::outputType ==
"tgeo.gdml") {
284 if (outputFile.length() < 11 || outputFile.substr(outputFile.length() - 10) !=
".tgeo.gdml") {
285 GGSCOUT(DEBUG) <<
"Append .tgeo.gdml extension to output file name" <<
GGSENDL;
286 outputFile.append(
".tgeo.gdml");
288 TGeoManager::LockDefaultUnits(kFALSE);
289 TGeoManager::SetDefaultUnits(TGeoManager::EDefaultUnits::kRootUnits);
293 gGeoManager->Export(outputFile.data());
Abstract class needed to load GGS geometry.
static GGSGeoPluginManager & GetInstance()
Get the singleton instance.
virtual G4VPhysicalVolume * Construct()=0
Construct the detector - virtual method.
GGSVGeometryConstruction * GetGeoConstruction()
Returns the geometry construction object.
void SetGeoDataCard(const G4String &dataCard)
Sets the geometry configuration datacard.