diff --git a/DDCAD/src/ASSIMPReader.cpp b/DDCAD/src/ASSIMPReader.cpp index 8f9dfc673134c6d77e3d694a4c2262697bb5e1e4..5accbd731785ff7aa1ddd1403ca84ad38d9f19f8 100644 --- a/DDCAD/src/ASSIMPReader.cpp +++ b/DDCAD/src/ASSIMPReader.cpp @@ -14,6 +14,7 @@ /// Framework include files #include <DD4hep/Printout.h> #include <DD4hep/Detector.h> +#include <DD4hep/ShapeTags.h> #include <DDCAD/ASSIMPReader.h> /// Open Asset Importer Library @@ -67,6 +68,7 @@ ASSIMPReader::readShapes(const std::string& source, double unit_length) const i, str.str().c_str()); } } + shape->SetTitle(TESSELLATEDSOLID_TAG); result.emplace_back(std::unique_ptr<TGeoTessellated>(shape.ptr())); continue; } diff --git a/DDCore/src/XML/Utilities.cpp b/DDCore/src/XML/Utilities.cpp index cc82701070f68691506e67666daf5fb6734a1026..32c6f95f03ec013bce1173c4cb7168c5f8561afd 100644 --- a/DDCore/src/XML/Utilities.cpp +++ b/DDCore/src/XML/Utilities.cpp @@ -246,10 +246,10 @@ void dd4hep::xml::setDetectorTypeFlag( dd4hep::xml::Handle_t e, dd4hep::DetElem namespace { template <typename TYPE> std::size_t _propagate(bool debug, - bool apply_to_children, - Volume vol, - TYPE item, - const Volume& (Volume::*apply)(const TYPE&) const) { + bool apply_to_children, + Volume vol, + TYPE item, + const Volume& (Volume::*apply)(const TYPE&) const) { std::size_t count = 0; if ( !vol->IsAssembly() ) { printout(debug ? ALWAYS : DEBUG,"VolumeConfig", "++ Volume: %s apply setting %s", vol.name(), item.name()); @@ -259,11 +259,11 @@ namespace { if ( apply_to_children ) { std::set<Volume> handled; for (Int_t idau = 0, ndau = vol->GetNdaughters(); idau < ndau; ++idau) { - Volume v = vol->GetNode(idau)->GetVolume(); - if ( handled.find(v) == handled.end() ) { - handled.insert(v); - count += _propagate(debug, apply_to_children, v, item, apply); - } + Volume v = vol->GetNode(idau)->GetVolume(); + if ( handled.find(v) == handled.end() ) { + handled.insert(v); + count += _propagate(debug, apply_to_children, v, item, apply); + } } } return count; @@ -273,10 +273,10 @@ namespace { /// Configure volume properties from XML element std::size_t dd4hep::xml::configVolume( dd4hep::Detector& detector, - dd4hep::xml::Handle_t element, - dd4hep::Volume vol, - bool propagate, - bool ignore_unknown) + dd4hep::xml::Handle_t element, + dd4hep::Volume vol, + bool propagate, + bool ignore_unknown) { std::size_t count = 0; if ( element ) { @@ -288,28 +288,28 @@ std::size_t dd4hep::xml::configVolume( dd4hep::Detector& detector, std::string nam = itm.nameStr("UN-NAMED"); if ( itm.tag() == TAG_REGIONREF ) { - Region region = detector.region(nam); - count += _propagate(debug, propagate, vol.ptr(), region, &Volume::setRegion); - printout(lvl, "VolumeConfig", "++ %-12s: %-10s REGIONs named '%s'", - vol.name(), region.isValid() ? "Set" : "Invalidate", nam.c_str()); + Region region = detector.region(nam); + count += _propagate(debug, propagate, vol.ptr(), region, &Volume::setRegion); + printout(lvl, "VolumeConfig", "++ %-12s: %-10s REGIONs named '%s'", + vol.name(), region.isValid() ? "Set" : "Invalidate", nam.c_str()); } else if ( itm.tag() == TAG_LIMITSETREF ) { - LimitSet limitset = detector.limitSet(nam); - count += _propagate(debug, propagate, vol.ptr(), limitset, &Volume::setLimitSet); - printout(lvl, "VolumeConfig", "++ %-12s: %-10s LIMITSETs named '%s'", - vol.name(), limitset.isValid() ? "Set" : "Invalidate", nam.c_str()); + LimitSet limitset = detector.limitSet(nam); + count += _propagate(debug, propagate, vol.ptr(), limitset, &Volume::setLimitSet); + printout(lvl, "VolumeConfig", "++ %-12s: %-10s LIMITSETs named '%s'", + vol.name(), limitset.isValid() ? "Set" : "Invalidate", nam.c_str()); } else if ( itm.tag() == TAG_VISREF ) { - VisAttr attrs = detector.visAttributes(nam); - count += _propagate(debug, propagate, vol.ptr(), attrs, &Volume::setVisAttributes); - printout(lvl, "VolumeConfig", "++ %-12s: %-10s VISATTRs named '%s'", - vol.name(), attrs.isValid() ? "Set" : "Invalidate", nam.c_str()); + VisAttr attrs = detector.visAttributes(nam); + count += _propagate(debug, propagate, vol.ptr(), attrs, &Volume::setVisAttributes); + printout(lvl, "VolumeConfig", "++ %-12s: %-10s VISATTRs named '%s'", + vol.name(), attrs.isValid() ? "Set" : "Invalidate", nam.c_str()); } else if ( !ignore_unknown ) { - except("VolumeConfig", "++ Unknown Volume property: %s [Ignored]", itm.tag().c_str()); + except("VolumeConfig", "++ Unknown Volume property: %s [Ignored]", itm.tag().c_str()); } else { - printout(DEBUG, "VolumeConfig", "++ Unknown Volume property: %s [Ignored]", itm.tag().c_str()); + printout(DEBUG, "VolumeConfig", "++ Unknown Volume property: %s [Ignored]", itm.tag().c_str()); } } return count; @@ -320,8 +320,8 @@ std::size_t dd4hep::xml::configVolume( dd4hep::Detector& detector, /// Configure sensitive detector from XML element std::size_t dd4hep::xml::configSensitiveDetector( dd4hep::Detector& /* detector */, - dd4hep::SensitiveDetector sensitive, - dd4hep::xml::Handle_t element) + dd4hep::SensitiveDetector sensitive, + dd4hep::xml::Handle_t element) { std::size_t count = 0; if ( sensitive.isValid() && element ) { @@ -332,49 +332,49 @@ std::size_t dd4hep::xml::configSensitiveDetector( dd4hep::Detector& /* de for( xml_coll_t coll(element, "*"); coll; coll++ ) { xml_dim_t itm = coll; if ( itm.tag() == TAG_COMBINE_HITS ) { - bool value = itm.attr<bool>(_U(value)); - sensitive.setCombineHits(value); - ++count; - printout(lvl, "SensDetConfig", "++ %s Set property 'combine_hits' to %s", - sensitive.name(), true_false(value)); + bool value = itm.attr<bool>(_U(value)); + sensitive.setCombineHits(value); + ++count; + printout(lvl, "SensDetConfig", "++ %s Set property 'combine_hits' to %s", + sensitive.name(), true_false(value)); } else if ( itm.tag() == TAG_VERBOSE ) { - bool value = itm.attr<bool>(_U(value)); - sensitive.setVerbose(value); - ++count; - printout(lvl, "SensDetConfig", "++ %s Set property 'verbose' to %s", - sensitive.name(), true_false(value)); + bool value = itm.attr<bool>(_U(value)); + sensitive.setVerbose(value); + ++count; + printout(lvl, "SensDetConfig", "++ %s Set property 'verbose' to %s", + sensitive.name(), true_false(value)); } else if ( itm.tag() == TAG_TYPE ) { - std::string value = itm.valueStr(); - sensitive.setType(value); - ++count; - printout(lvl, "SensDetConfig", "++ %s Set property 'type' to %s", - sensitive.name(), value.c_str()); + std::string value = itm.valueStr(); + sensitive.setType(value); + ++count; + printout(lvl, "SensDetConfig", "++ %s Set property 'type' to %s", + sensitive.name(), value.c_str()); } else if ( itm.tag() == TAG_ECUT ) { - double value = itm.attr<double>(_U(value)); - sensitive.setEnergyCutoff(value); - ++count; - printout(lvl, "SensDetConfig", "++ %s Set property 'ecut' to %f", - sensitive.name(), value); + double value = itm.attr<double>(_U(value)); + sensitive.setEnergyCutoff(value); + ++count; + printout(lvl, "SensDetConfig", "++ %s Set property 'ecut' to %f", + sensitive.name(), value); } else if ( itm.tag() == TAG_HITS_COLLECTION ) { - sensitive.setHitsCollection(itm.valueStr()); - ++count; - printout(lvl, "SensDetConfig", "++ %s Set property 'hits_collection' to %s", - sensitive.name(), itm.valueStr().c_str()); + sensitive.setHitsCollection(itm.valueStr()); + ++count; + printout(lvl, "SensDetConfig", "++ %s Set property 'hits_collection' to %s", + sensitive.name(), itm.valueStr().c_str()); } else { - except("SensDetConfig", - "++ Unknown Sensitive Detector property: %s [Failure]", - itm.tag().c_str()); + except("SensDetConfig", + "++ Unknown Sensitive Detector property: %s [Failure]", + itm.tag().c_str()); } } return count; } except("SensDetConfig", - "FAILED: No valid sensitive detector. Configuration could not be applied!"); + "FAILED: No valid sensitive detector. Configuration could not be applied!"); return count; } diff --git a/DDCore/src/plugins/ShapePlugins.cpp b/DDCore/src/plugins/ShapePlugins.cpp index fd88d6a9951130bd99d7df7cf02394ee268ccc20..5487c170f312ce818b4be384d39e1159cb217bd6 100644 --- a/DDCore/src/plugins/ShapePlugins.cpp +++ b/DDCore/src/plugins/ShapePlugins.cpp @@ -945,7 +945,6 @@ static Ref_t create_shape(Detector& description, xml_h e, SensitiveDetector sens xml_det_t x_det = e; string name = x_det.nameStr(); xml_dim_t x_reflect = x_det.child(_U(reflect), false); - xml_comp_t x_test = x_det.child(xml_tag_t("test"), false); DetElement det (name,x_det.id()); Material mat = description.air(); Assembly assembly (name); @@ -981,7 +980,7 @@ static Ref_t create_shape(Detector& description, xml_h e, SensitiveDetector sens string sens_type = x_det.child(_U(sensitive)).attr<string>(_U(type)); volume.setSensitiveDetector(sens); sens.setType(sens_type); - printout(INFO,"TestShape","+++ Sensitive type is %s", sens_type.c_str()); + printout(INFO,"TestShape","+++ Sensitive type is %s", sens_type.c_str()); } volume.setVisAttributes(description, x_check.visStr()); solid->SetName(shape_type.c_str()); @@ -1023,7 +1022,11 @@ static Ref_t create_shape(Detector& description, xml_h e, SensitiveDetector sens shape_type.c_str(), nam ? '[' : ' ', nam ? nam : "" ,nam ? ']' : ' '); bool instance_test = false; - if ( 0 == strcasecmp(solid->GetTitle(),BOX_TAG) ) + if ( shape_type == "CAD_Assembly" || shape_type == "CAD_MultiVolume" ) { + solid->SetTitle(shape_type.c_str()); + instance_test = true; + } + else if ( 0 == strcasecmp(solid->GetTitle(),BOX_TAG) ) instance_test = isInstance<Box>(solid); else if ( 0 == strcasecmp(solid->GetTitle(),TUBE_TAG) ) instance_test = isInstance<Tube>(solid); @@ -1170,8 +1173,9 @@ static Ref_t create_shape(Detector& description, xml_h e, SensitiveDetector sens pv.addPhysVolID("system", x_det.id()); det.setPlacement(pv); } - - if ( x_test.ptr() ) { + /// Execute test plugin(s) on the placed volume if desired + for ( xml_coll_t itm(e, xml_tag_t("test")); itm; ++itm, ++count ) { + xml_comp_t x_test = itm; string typ = x_test.typeStr(); const void* argv[] = { &e, &pv, 0}; Ref_t result = (NamedObject*)PluginService::Create<void*>(typ, &description, 2, (char**)argv); diff --git a/examples/DDCAD/CMakeLists.txt b/examples/DDCAD/CMakeLists.txt index 08abeb0c17ef91467fcfe42070ad2bafddf7c6e3..29ba5888f7b9769209a35296ebd7ea6ce9441ece 100644 --- a/examples/DDCAD/CMakeLists.txt +++ b/examples/DDCAD/CMakeLists.txt @@ -32,7 +32,7 @@ dd4hep_set_compiler_flags() #========================================================================== # set(DDCAD_INSTALL ${CMAKE_INSTALL_PREFIX}/examples/DDCAD) -dd4hep_install_dir( compact models ref DESTINATION ${DDCAD_INSTALL} ) +dd4hep_install_dir( compact models scripts ref DESTINATION ${DDCAD_INSTALL} ) #-------------------------------------------------------------------------- find_package(assimp QUIET) MESSAGE(STATUS "ASSIMP VERSION IS ${assimp_VERSION}") @@ -144,4 +144,40 @@ dd4hep_add_test_reg( DDCAD_import_FCC_machine REGEX_FAIL "Exception" ) # - +# Geometry loading the CAD file from Armin Ilg's example +dd4hep_add_test_reg( DDCAD_Issue1134_geometry_load + COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_DDCAD.sh" + EXEC_ARGS geoDisplay ${DDCADEx_INSTALL}/compact/DD4hep_Issue_1134.xml -load -destroy + REGEX_PASS "Created successfull shape of type: CAD_MultiVolume \\[CAD_MultiVolume\\]" + REGEX_FAIL "Exception;ERROR;FAILED" +) +# +# ROOT based Overlap check of Armin Ilg's example +dd4hep_add_test_reg( DDCAD_Issue1134_overlap_check + COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_DDCAD.sh" + EXEC_ARGS checkOverlaps --compact=file:${DDCADEx_INSTALL}/compact/DD4hep_Issue_1134.xml + --print=1 --tolerance 0.000001 + REGEX_PASS "Number of illegal overlaps/extrusions : 0" + REGEX_FAIL "Exception;ERROR;FAILED" +) +# +# Overlap check of Armin Ilg's example +dd4hep_add_test_reg( DDCAD_Issue1134_g4overlap_check + COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_DDCAD.sh" + EXEC_ARGS ddsim --compactFile ${DDCADEx_INSTALL}/compact/DD4hep_Issue_1134.xml + --enableG4Gun --runType run + --macroFile ${DDCADEx_INSTALL}/scripts/overlap.mac + REGEX_PASS "Checking overlaps for volume AV_2.Shape_STL_0.0.tessellated_0_0.0 .G4TessellatedSolid. ... OK" + REGEX_FAIL "EXCEPTION;ERROR;Error;FAILED" +) +# +# Geometry scan of Armin Ilg's example +dd4hep_add_test_reg( DDCAD_Issue1134_g4geometry_scan + COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_DDCAD.sh" + EXEC_ARGS g4GeometryScan + --compact=file:${DDCADEx_INSTALL}/compact/DD4hep_Issue_1134.xml + --position=-35,-35,-300 --direction=7,7,60 + REGEX_PASS ". -1.29, -1.29, -11.06. Path:./world/AV_2.Shape_STL_0.0.tessellated_0_0.0. Shape:G4TessellatedSolid Mat:Gold" + REGEX_FAIL "EXCEPTION;ERROR;Error;FAILED" +) +# diff --git a/examples/DDCAD/compact/DD4hep_Issue_1134.xml b/examples/DDCAD/compact/DD4hep_Issue_1134.xml index 9f9ec8e6b5261d8ab70bc5df053b6e033cb2976b..914be8dce2fc74e15d0eeeed3b213c3cce230d70 100644 --- a/examples/DDCAD/compact/DD4hep_Issue_1134.xml +++ b/examples/DDCAD/compact/DD4hep_Issue_1134.xml @@ -12,23 +12,66 @@ --> + <info name= "DDCAD_test" + title= "Checking issue 1134" + author= "Markus Frank" + url= "http://www.cern.ch/lhcb" + status= "development" + version="1.0"> + <comment>CAD Shape tester</comment> + </info> + <includes> - <gdmlFile ref="../../ClientTests/compact/CheckShape.xml"/> + <gdmlFile ref="${DD4hepINSTALL}/DDDetectors/compact/elements.xml"/> + <gdmlFile ref="${DD4hepINSTALL}/DDDetectors/compact/materials.xml"/> </includes> + + <materials> + <material name="DefaultMaterial"> + <D value="7.85" unit="g/cm3"/> + <fraction n="0.998" ref="Fe"/> + <fraction n=".002" ref="C"/> + </material> + <material name="Material01"> + <D value="7.85" unit="g/cm3"/> + <fraction n="1.0" ref="Fe"/> + </material> + </materials> + <define> - <constant name="tracker_region_zmax" value="10*m"/> + <constant name="world_side" value="15*m"/> + <constant name="world_x" value="world_side"/> + <constant name="world_y" value="world_side"/> + <constant name="world_z" value="world_side"/> + <constant name="unit_length" value="1*10"/> + <constant name="unit_pos" value="unit_length/10"/> + <constant name="CheckShape_create" value="0"/> + <constant name="tracker_region_zmax" value="15*m"/> <constant name="tracker_region_rmax" value="5*m"/> </define> + <display> + <vis name="InvisibleNoDaughters" showDaughters="false" visible="false"/> + <vis name="InvisibleWithDaughters" showDaughters="true" visible="false"/> + <vis name="Shape1_vis_20" alpha="0.2" r="0.9" g="0.8" b="0.8" showDaughters="true" visible="true"/> + <vis name="ShapeGray_vis_50" alpha="0.5" r="0.9" g="0.8" b="0.8" showDaughters="true" visible="true"/> + <vis name="Shape0_vis" alpha="1.0" r="0" g="1" b="1" showDaughters="true" visible="true"/> + <vis name="Shape1_vis" alpha="1.0" r="1" g="0" b="0" showDaughters="true" visible="true"/> + <vis name="Shape2_vis" alpha="1.0" r="0" g="1" b="0" showDaughters="true" visible="true"/> + <vis name="Shape3_vis" alpha="1.0" r="0" g="0" b="1" showDaughters="true" visible="true"/> + <vis name="Shape_grey" alpha="0.5" r="0.0" g="0.4" b="0.4" showDaughters="true" visible="true"/> + </display> + <detectors> <detector id="1" name="Shape_STL" type="DD4hep_TestShape_Creator"> <check> <shape type="CAD_MultiVolume" ref="${DD4hepExamplesINSTALL}/examples/DDCAD/models/STL/DD4hep_Issue_1134.stl" - unit="cm" - material="Iron"> + unit="cm"> <volume id="0" name="s1" vis="Shape3_vis" material="Gold"/> + <position x="1050*mm" y="-28*mm" z="-338*mm"/> + <rotation x="0*pi/8*rad" y="-4*pi/8*rad" z="0*rad"/> </shape> </check> diff --git a/examples/DDCAD/scripts/overlap.mac b/examples/DDCAD/scripts/overlap.mac new file mode 100644 index 0000000000000000000000000000000000000000..b09cfe9281e0860b6ea14e39adbbfba47cb340da --- /dev/null +++ b/examples/DDCAD/scripts/overlap.mac @@ -0,0 +1,2 @@ +/geometry/test/run +exit