diff --git a/DDCore/src/gdml/GdmlPlugins.cpp b/DDCore/src/gdml/GdmlPlugins.cpp index 49cb0d9b981ff708bf6074ee69c7ffb0008dccbb..e55b156c0181c0b6b3972731558b6adb37efbd83 100644 --- a/DDCore/src/gdml/GdmlPlugins.cpp +++ b/DDCore/src/gdml/GdmlPlugins.cpp @@ -12,23 +12,23 @@ //========================================================================== // Framework include files -#include "DD4hep/Detector.h" -#include "DD4hep/Memory.h" -#include "DD4hep/DD4hepUI.h" -#include "DD4hep/Factories.h" -#include "DD4hep/Printout.h" -#include "DD4hep/DetectorTools.h" -#include "DD4hep/DetFactoryHelper.h" -#include "XML/DocumentHandler.h" -#include "XML/Utilities.h" +#include <DD4hep/Detector.h> +#include <DD4hep/Memory.h> +#include <DD4hep/DD4hepUI.h> +#include <DD4hep/Factories.h> +#include <DD4hep/Printout.h> +#include <DD4hep/DetectorTools.h> +#include <DD4hep/DetFactoryHelper.h> +#include <XML/DocumentHandler.h> +#include <XML/Utilities.h> // ROOT includes -#include "TInterpreter.h" -#include "TGeoElement.h" -#include "TGeoManager.h" -#include "TGDMLParse.h" -#include "TGDMLWrite.h" -#include "TUri.h" +#include <TInterpreter.h> +#include <TGeoElement.h> +#include <TGeoManager.h> +#include <TGDMLParse.h> +#include <TGDMLWrite.h> +#include <TUri.h> using namespace std; using namespace dd4hep; @@ -145,10 +145,11 @@ static long gdml_extract(Detector& description, int argc, char** argv) { if ( argc > 0 ) { bool detector = true, volpath = false; string output, path; + int precision = 12; for(int i = 0; i < argc && argv[i]; ++i) { if ( 0 == ::strncmp("-output",argv[i],2) ) output = argv[++i]; - else if ( 0 == ::strncmp("-path", argv[i],2) ) + else if ( 0 == ::strncmp("-path", argv[i],4) ) path = argv[++i]; else if ( 0 == ::strncmp("-volpath", argv[i],7) ) volpath = true, detector = false; @@ -156,6 +157,8 @@ static long gdml_extract(Detector& description, int argc, char** argv) { volpath = false, detector = false; else if ( 0 == ::strncmp("-detector", argv[i],8) ) volpath = false, detector = true; + else if ( 0 == ::strncmp("-precision", argv[i],5) ) + precision = ::atol(argv[++i]); } if ( output.empty() || path.empty() ) { cout << @@ -165,8 +168,9 @@ static long gdml_extract(Detector& description, int argc, char** argv) { " -path <string> Path to parent detector element to extract \n" " top volume to GDML file. \n" " -detector Indicate that the path is a DetElement path \n" - " -volpath Indicate that the path is a volume path \n" + " -volpath Indicate that the path is a volume path \n" " -volname Indicate that the path is a volume name prefix \n" + " -precision <number> GDML output floating point precision \n" "\tArguments given: " << arguments(argc,argv) << endl << flush; ::exit(EINVAL); } @@ -177,7 +181,12 @@ static long gdml_extract(Detector& description, int argc, char** argv) { if ( de.isValid() ) { TGDMLWrite extract; TUri uri(output.c_str()); -#if ROOT_VERSION_CODE >= ROOT_VERSION(6,20,0) + extract.SetFltPrecision(precision); +#if ROOT_VERSION_CODE >= ROOT_VERSION(6,27,1) + extract.SetIgnoreDummyMaterial(true); + extract.SetNamingSpeed(TGDMLWrite::kfastButUglySufix); + extract.WriteGDMLfile(&description.manager(), de.placement().ptr(), uri.GetRelativePart()); +#elif ROOT_VERSION_CODE >= ROOT_VERSION(6,20,0) extract.WriteGDMLfile(&description.manager(), de.placement().ptr(), uri.GetRelativePart()); #else extract.WriteGDMLfile(&description.manager(), de.volume().ptr(), uri.GetRelativePart()); @@ -225,7 +234,12 @@ static long gdml_extract(Detector& description, int argc, char** argv) { if ( a._node ) { TGDMLWrite extract; TUri uri(output.c_str()); -#if ROOT_VERSION_CODE >= ROOT_VERSION(6,20,0) + extract.SetFltPrecision(precision); +#if ROOT_VERSION_CODE >= ROOT_VERSION(6,27,1) + extract.SetIgnoreDummyMaterial(true); + extract.SetNamingSpeed(TGDMLWrite::kfastButUglySufix); + extract.WriteGDMLfile(&description.manager(), a._node, uri.GetRelativePart()); +#elif ROOT_VERSION_CODE >= ROOT_VERSION(6,20,0) extract.WriteGDMLfile(&description.manager(), a._node, uri.GetRelativePart()); #else extract.WriteGDMLfile(&description.manager(), a._node->GetVolume(), uri.GetRelativePart()); diff --git a/DDG4/src/Geant4Converter.cpp b/DDG4/src/Geant4Converter.cpp index d2c8782e14a07e4eaa549f642bde920d57a1335a..4e77b1546519c72c39c9f2e1b4a14865e6a66059 100644 --- a/DDG4/src/Geant4Converter.cpp +++ b/DDG4/src/Geant4Converter.cpp @@ -92,6 +92,13 @@ static constexpr const char* GEANT4_TAG_ENE_PER_ION_PAIR = "MeanEnergyPerIonPair namespace { static string indent = ""; + + string make_NCName(const string& in) { + string res = detail::str_replace(in, "/", "_"); + res = detail::str_replace(res, "#", "_"); + return res; + } + bool is_left_handed(const TGeoMatrix* m) { const Double_t* r = m->GetRotationMatrix(); if ( r ) { @@ -373,24 +380,24 @@ void* Geant4Converter::handleMaterial(const string& name, Material medium) const TNamed* named = (TNamed*)obj; TGDMLMatrix* matrix = info.manager->GetGDMLMatrix(named->GetTitle()); const char* cptr = ::strstr(matrix->GetName(), GEANT4_TAG_IGNORE); - if ( 0 != cptr ) { + if ( nullptr != cptr ) { printout(INFO,name,"++ Ignore property %s [%s]. Not Suitable for Geant4.", matrix->GetName(), matrix->GetTitle()); continue; } cptr = ::strstr(matrix->GetTitle(), GEANT4_TAG_IGNORE); - if ( 0 != cptr ) { + if ( nullptr != cptr ) { printout(INFO,name,"++ Ignore property %s [%s]. Not Suitable for Geant4.", matrix->GetName(), matrix->GetTitle()); continue; } Geant4GeometryInfo::PropertyVector* v = (Geant4GeometryInfo::PropertyVector*)handleMaterialProperties(matrix); - if ( 0 == v ) { + if ( nullptr == v ) { except("Geant4Converter", "++ FAILED to create G4 material %s [Cannot convert property:%s]", material->GetName(), named->GetName()); } - if ( 0 == tab ) { + if ( nullptr == tab ) { tab = new G4MaterialPropertiesTable(); mat->SetMaterialPropertiesTable(tab); } @@ -435,40 +442,40 @@ void* Geant4Converter::handleMaterial(const string& name, Material medium) const TNamed* named = (TNamed*)obj; const char* cptr = ::strstr(named->GetName(), GEANT4_TAG_IGNORE); - if ( 0 != cptr ) { + if ( nullptr != cptr ) { printout(INFO, name, "++ Ignore CONST property %s [%s].", named->GetName(), named->GetTitle()); continue; } cptr = ::strstr(named->GetTitle(), GEANT4_TAG_IGNORE); - if ( 0 != cptr ) { + if ( nullptr != cptr ) { printout(INFO, name,"++ Ignore CONST property %s [%s].", named->GetName(), named->GetTitle()); continue; } cptr = ::strstr(named->GetName(), GEANT4_TAG_PLUGIN); - if ( 0 != cptr ) { + if ( nullptr != cptr ) { printout(INFO, name, "++ Ignore CONST property %s [%s] --> Plugin.", named->GetName(), named->GetTitle()); plugin_name = named->GetTitle(); continue; } cptr = ::strstr(named->GetName(), GEANT4_TAG_BIRKSCONSTANT); - if ( 0 != cptr ) { + if ( nullptr != cptr ) { err = kFALSE; value = material->GetConstProperty(GEANT4_TAG_BIRKSCONSTANT,&err); if ( err == kFALSE ) ionisation_birks_constant = value * (CLHEP::mm/CLHEP::MeV)/(units::mm/units::MeV); continue; } cptr = ::strstr(named->GetName(), GEANT4_TAG_MEE); - if ( 0 != cptr ) { + if ( nullptr != cptr ) { err = kFALSE; value = material->GetConstProperty(GEANT4_TAG_MEE,&err); if ( err == kFALSE ) ionisation_mee = value * (CLHEP::MeV/units::MeV); continue; } cptr = ::strstr(named->GetName(), GEANT4_TAG_ENE_PER_ION_PAIR); - if ( 0 != cptr ) { + if ( nullptr != cptr ) { err = kFALSE; value = material->GetConstProperty(GEANT4_TAG_ENE_PER_ION_PAIR,&err); if ( err == kFALSE ) ionisation_ene_per_ion_pair = value * (CLHEP::MeV/units::MeV); @@ -482,7 +489,7 @@ void* Geant4Converter::handleMaterial(const string& name, Material medium) const "++ FAILED to create G4 material %s [Cannot convert const property: %s]", material->GetName(), named->GetName()); } - if ( 0 == tab ) { + if ( nullptr == tab ) { tab = new G4MaterialPropertiesTable(); mat->SetMaterialPropertiesTable(tab); } @@ -884,7 +891,7 @@ void* Geant4Converter::handlePlacement(const string& name, const TGeoNode* node) "++ Attempt to handle placement without transformation:%p %s of type %s vol:%p", node, node->GetName(), node->IsA()->GetName(), vol); } - else if (0 == vol) { + else if (nullptr == vol) { except("Geant4Converter", "++ Unknown G4 volume:%p %s of type %s ptr:%p", node, node->GetName(), node->IsA()->GetName(), vol); } @@ -1210,13 +1217,13 @@ void* Geant4Converter::handleMaterialProperties(TObject* mtx) const { const char* cptr = ::strstr(matrix->GetName(), GEANT4_TAG_IGNORE); Geant4GeometryInfo::PropertyVector* g4 = info.g4OpticalProperties[matrix]; - if ( 0 != cptr ) { // Check if the property should not be passed to Geant4 + if ( nullptr != cptr ) { // Check if the property should not be passed to Geant4 printout(INFO,"Geant4MaterialProperties","++ Ignore property %s [%s].", matrix->GetName(), matrix->GetTitle()); return nullptr; } cptr = ::strstr(matrix->GetTitle(), GEANT4_TAG_IGNORE); - if ( 0 != cptr ) { // Check if the property should not be passed to Geant4 + if ( nullptr != cptr ) { // Check if the property should not be passed to Geant4 printout(INFO,"Geant4MaterialProperties","++ Ignore property %s [%s].", matrix->GetName(), matrix->GetTitle()); return nullptr; @@ -1341,7 +1348,8 @@ void* Geant4Converter::handleOpticalSurface(TObject* surface) const { G4SurfaceType type = geant4_surface_type(optSurf->GetType()); G4OpticalSurfaceModel model = geant4_surface_model(optSurf->GetModel()); G4OpticalSurfaceFinish finish = geant4_surface_finish(optSurf->GetFinish()); - g4 = new G4OpticalSurface(optSurf->GetName(), model, finish, type, optSurf->GetValue()); + string name = make_NCName(optSurf->GetName()); + g4 = new G4OpticalSurface(name, model, finish, type, optSurf->GetValue()); g4->SetSigmaAlpha(optSurf->GetSigmaAlpha()); // not implemented: g4->SetPolish(s->GetPolish()); printout(debugSurfaces ? ALWAYS : DEBUG, "Geant4Converter", @@ -1350,17 +1358,17 @@ void* Geant4Converter::handleOpticalSurface(TObject* surface) const { TGeoOpticalSurface::TypeToString(optSurf->GetType()), TGeoOpticalSurface::ModelToString(optSurf->GetModel()), TGeoOpticalSurface::FinishToString(optSurf->GetFinish())); - G4MaterialPropertiesTable* tab = 0; + G4MaterialPropertiesTable* tab = nullptr; TListIter it(&optSurf->GetProperties()); for(TObject* obj = it.Next(); obj; obj = it.Next()) { string exc_str; TNamed* named = (TNamed*)obj; TGDMLMatrix* matrix = info.manager->GetGDMLMatrix(named->GetTitle()); const char* cptr = ::strstr(matrix->GetName(), GEANT4_TAG_IGNORE); - if ( 0 != cptr ) // Check if the property should not be passed to Geant4 + if ( nullptr != cptr ) // Check if the property should not be passed to Geant4 continue; - if ( 0 == tab ) { + if ( nullptr == tab ) { tab = new G4MaterialPropertiesTable(); g4->SetMaterialPropertiesTable(tab); } @@ -1417,7 +1425,8 @@ void* Geant4Converter::handleSkinSurface(TObject* surface) const { if ( !g4 ) { G4OpticalSurface* optSurf = info.g4OpticalSurfaces[OpticalSurface(surf->GetSurface())]; G4LogicalVolume* v = info.g4Volumes[surf->GetVolume()]; - g4 = new G4LogicalSkinSurface(surf->GetName(), v, optSurf); + string name = make_NCName(surf->GetName()); + g4 = new G4LogicalSkinSurface(name, v, optSurf); printout(debugSurfaces ? ALWAYS : DEBUG, "Geant4Converter", "++ Created SkinSurface: %-18s optical:%s", surf->GetName(), surf->GetSurface()->GetName()); @@ -1435,7 +1444,8 @@ void* Geant4Converter::handleBorderSurface(TObject* surface) const { G4OpticalSurface* optSurf = info.g4OpticalSurfaces[OpticalSurface(surf->GetSurface())]; G4VPhysicalVolume* n1 = info.g4Placements[surf->GetNode1()]; G4VPhysicalVolume* n2 = info.g4Placements[surf->GetNode2()]; - g4 = new G4LogicalBorderSurface(surf->GetName(), n1, n2, optSurf); + string name = make_NCName(surf->GetName()); + g4 = new G4LogicalBorderSurface(name, n1, n2, optSurf); printout(debugSurfaces ? ALWAYS : DEBUG, "Geant4Converter", "++ Created BorderSurface: %-18s optical:%s", surf->GetName(), surf->GetSurface()->GetName()); diff --git a/DDG4/src/Geant4Exec.cpp b/DDG4/src/Geant4Exec.cpp index 1a7ac3b34f33cfce61a7710ddb9ccf5a49714293..1c7ef026038419de3b03ada5862c2c30346f40ad 100644 --- a/DDG4/src/Geant4Exec.cpp +++ b/DDG4/src/Geant4Exec.cpp @@ -425,7 +425,7 @@ namespace dd4hep { G4AutoLock protection_lock(&action_mutex); updateContext(m_sequence->context()); m_sequence->constructGeo(&m_ctxt); - if ( 0 == m_ctxt.world ) { + if ( nullptr == m_ctxt.world ) { m_sequence->except("+++ Executing G4 detector construction did not result in a valid world volume!"); } m_sequence->context()->kernel().setWorld(m_ctxt.world); @@ -573,10 +573,10 @@ int Geant4Exec::configure(Geant4Kernel& kernel) { /// Get the detector constructed Geant4DetectorConstructionSequence* user_det = kernel.detectorConstruction(false); - if ( 0 == user_det && kernel.isMultiThreaded() ) { + if ( nullptr == user_det && kernel.isMultiThreaded() ) { throw runtime_error("Panic! No valid detector construction sequencer present. [Mandatory MT]"); } - if ( 0 == user_det && !kernel.isMultiThreaded() ) { + if ( nullptr == user_det && !kernel.isMultiThreaded() ) { user_det = Geant4Compatibility().buildDefaultDetectorConstruction(kernel); } Geant4UserDetectorConstruction* det_seq = new Geant4UserDetectorConstruction(ctx,user_det); @@ -584,13 +584,13 @@ int Geant4Exec::configure(Geant4Kernel& kernel) { /// Get the physics list constructed Geant4PhysicsListActionSequence* phys_seq = kernel.physicsList(false); - if ( 0 == phys_seq ) { + if ( nullptr == phys_seq ) { string phys_model = "QGSP_BERT"; phys_seq = kernel.physicsList(true); phys_seq->property("extends").set(phys_model); } G4VUserPhysicsList* physics = phys_seq->extensionList(); - if (0 == physics) { + if (nullptr == physics) { throw runtime_error("Panic! No valid user physics list present!"); } #if 0 @@ -605,10 +605,10 @@ int Geant4Exec::configure(Geant4Kernel& kernel) { /// Construct the remaining user initialization in multi-threaded mode Geant4UserInitializationSequence* user_init = kernel.userInitialization(false); - if ( 0 == user_init && kernel.isMultiThreaded() ) { + if ( nullptr == user_init && kernel.isMultiThreaded() ) { throw runtime_error("Panic! No valid user initialization sequencer present. [Mandatory MT]"); } - else if ( 0 == user_init && !kernel.isMultiThreaded() ) { + else if ( nullptr == user_init && !kernel.isMultiThreaded() ) { /// Use default actions registered to the default kernel. Will do the right thing... user_init = kernel.userInitialization(true); }