From dea46ac332090460005aa1605ebe96cbf7935880 Mon Sep 17 00:00:00 2001 From: Frank Gaede <frank.gaede@desy.de> Date: Mon, 23 Mar 2015 15:35:49 +0000 Subject: [PATCH] - added method: Geometry::Volume createPlacedEnvelope( DD4hep::Geometry::LCDD& lcdd, DD4hep::XML::Handle_t e , DD4hep::Geometry::DetElement sdet ) ; --- DDCore/include/XML/Utilities.h | 17 ++++++++ DDCore/src/XML/Utilities.cpp | 78 ++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) diff --git a/DDCore/include/XML/Utilities.h b/DDCore/include/XML/Utilities.h index 788e7df67..ecc8cf941 100644 --- a/DDCore/include/XML/Utilities.h +++ b/DDCore/include/XML/Utilities.h @@ -22,6 +22,23 @@ namespace DD4hep { /// Create a solid shape using the plugin mechanism from the attributes of the XML element Geometry::Solid createShape(Geometry::LCDD& lcdd, const std::string& shape_type, XML::Element element); + + /** Create an envelope volume that is placed into the world volume ( the parent volume of sdet) from an xml + * element <envelope/> with child nodes <shape/> and optionally <position/> and <rotation/>. + * Example: <br> + * <p> + * <envelope vis="ILD_ECALVis"> + * <shape type="PolyhedraRegular" numsides="8" rmin="TPC_outer_radius+Ecal_Tpc_gap" rmax="Ecal_outer_radius" + * dz="2.*TPC_Ecal_Hcal_barrel_halfZ" material = "Air" /> + * <rotation x="0*deg" y="0*deg" z="90*deg-180*deg/8"/> + * </envelope> + * + * @author S.Lu DESY, F. Gaede CERN/DESY + * @version $Id:$ + */ + Geometry::Volume createPlacedEnvelope( DD4hep::Geometry::LCDD& lcdd, DD4hep::XML::Handle_t e , + DD4hep::Geometry::DetElement sdet ) ; + } /* End namespace XML */ } /* End namespace DD4hep */ #endif /* DD4hep_XML_XMLUTILITIES_H */ diff --git a/DDCore/src/XML/Utilities.cpp b/DDCore/src/XML/Utilities.cpp index dfe91e777..6c68bcea4 100644 --- a/DDCore/src/XML/Utilities.cpp +++ b/DDCore/src/XML/Utilities.cpp @@ -11,9 +11,11 @@ #include "DD4hep/Printout.h" #include "DD4hep/Plugins.h" #include "DD4hep/LCDD.h" +#include "DD4hep/DetFactoryHelper.h" using namespace std; using namespace DD4hep; +using namespace DD4hep::Geometry; /// Create a solid shape using the plugin mechanism from the attributes of the XML element Geometry::Solid @@ -29,3 +31,79 @@ DD4hep::XML::createShape(Geometry::LCDD& lcdd, const std::string& shape_type, XM } return solid; } + + + + +Geometry::Volume DD4hep::XML::createPlacedEnvelope( DD4hep::Geometry::LCDD& lcdd, DD4hep::XML::Handle_t e , + DD4hep::Geometry::DetElement sdet ){ + + xml_det_t x_det = e; + string det_name = x_det.nameStr(); + + xml_comp_t x_env = x_det.child( DD4hep::XML::Strng_t("envelope") ) ; + xml_comp_t x_shape = x_env.child( _U(shape) ); + + Material env_mat = lcdd.material( x_shape.materialStr() ); + + + bool useRot = false ; + bool usePos = false ; + Position pos ; + RotationZYX rot ; + + if( x_env.hasChild( _U(position) ) ) { + usePos = true ; + xml_comp_t env_pos = x_env.position(); + pos = Position( env_pos.x(),env_pos.y(),env_pos.z() ); + } + if( x_env.hasChild( _U(rotation) ) ) { + useRot = true ; + xml_comp_t env_rot = x_env.rotation(); + rot = RotationZYX( env_rot.z(),env_rot.y(),env_rot.x() ) ; + } + + + // ---- create a shape from the specified xml element -------- + Box env_solid = xml_comp_t( x_shape ).createShape(); + + if( !env_solid.isValid() ){ + + throw std::runtime_error( std::string(" Cannot create envelope volume : ") + x_shape.typeStr() + + std::string(" for detector " ) + det_name ) ; + } + + Volume envelope ( det_name+"_envelope", env_solid, env_mat ); + + PlacedVolume env_pv ; + + Volume mother = lcdd.pickMotherVolume(sdet); + + + // ---- place the envelope into the mother volume + // only specify transformations given in xml + // to allow for optimization + + if( useRot && usePos ){ + env_pv = mother.placeVolume( envelope , Transform3D( rot, pos ) ) ; + + } else if( useRot ){ + env_pv = mother.placeVolume( envelope , rot ) ; + + } else if( usePos ){ + env_pv = mother.placeVolume( envelope , pos ) ; + + } else { + env_pv = mother.placeVolume( envelope ); + } + + // ---------------------------------------------- + + env_pv.addPhysVolID("system", sdet.id()); + + sdet.setPlacement( env_pv ) ; + + envelope.setAttributes( lcdd,x_det.regionStr(),x_det.limitsStr(),x_env.visStr()); + + return envelope ; +} -- GitLab