From bbb099311bb9e26efa433019cb5681439cd6c24e Mon Sep 17 00:00:00 2001 From: Markus Frank <Markus.Frank@cern.ch> Date: Fri, 23 Oct 2020 22:29:21 +0200 Subject: [PATCH] Fix shape check examples --- DDCore/src/DetectorImp.cpp | 1 + DDCore/src/Volumes.cpp | 20 +++------ DDCore/src/plugins/ShapePlugins.cpp | 41 ++++++++----------- examples/ClientTests/compact/CheckShape.xml | 2 +- .../compact/Check_Shape_TruncatedTube.xml | 9 +--- .../compact/Check_Shape_Collada_duck.xml | 2 +- 6 files changed, 28 insertions(+), 47 deletions(-) diff --git a/DDCore/src/DetectorImp.cpp b/DDCore/src/DetectorImp.cpp index 939895064..107c60c06 100644 --- a/DDCore/src/DetectorImp.cpp +++ b/DDCore/src/DetectorImp.cpp @@ -668,6 +668,7 @@ void DetectorImp::endDocument(bool close_geometry) { m_trackingVol.setVisAttributes(trackingVis); add(trackingVis); #endif + m_worldVol.solid()->ComputeBBox(); /// Since we allow now for anonymous shapes, /// we will rename them to use the name of the volume they are assigned to mgr->CloseGeometry(); diff --git a/DDCore/src/Volumes.cpp b/DDCore/src/Volumes.cpp index 84adb2d7d..bbc1e42dd 100644 --- a/DDCore/src/Volumes.cpp +++ b/DDCore/src/Volumes.cpp @@ -579,31 +579,22 @@ PlacedVolume _addNode(TGeoVolume* par, TGeoVolume* daughter, int id, TGeoMatrix* if ( !parent ) { except("dd4hep","Volume: Attempt to assign daughters to an invalid physical parent volume."); } - if ( !daughter ) { + else if ( !daughter ) { except("dd4hep","Volume: Attempt to assign an invalid physical daughter volume."); } - if ( !transform ) { + else if ( !transform ) { except("dd4hep","Volume: Attempt to place volume without placement matrix."); } if ( transform != detail::matrix::_identity() ) { string nam = string(daughter->GetName()) + "_placement"; transform->SetName(nam.c_str()); } -#if 0 - if ( transform->IsTranslation() ) { - cout << daughter->GetName() << ": Translation: " << transform->GetTranslation()[2] << endl; - } -#endif TGeoShape* shape = daughter->GetShape(); // Need to fix the daughter's BBox of assemblies, if the BBox was not calculated.... if ( shape->IsA() == TGeoShapeAssembly::Class() ) { TGeoShapeAssembly* as = (TGeoShapeAssembly*)shape; - if ( std::fabs(as->GetDX()) < numeric_limits<double>::epsilon() && - std::fabs(as->GetDY()) < numeric_limits<double>::epsilon() && - std::fabs(as->GetDZ()) < numeric_limits<double>::epsilon() ) { - as->NeedsBBoxRecompute(); - as->ComputeBBox(); - } + as->NeedsBBoxRecompute(); + as->ComputeBBox(); } const Double_t* r = transform->GetRotationMatrix(); if ( r ) { @@ -614,8 +605,7 @@ PlacedVolume _addNode(TGeoVolume* par, TGeoVolume* daughter, int id, TGeoMatrix* transform->SetBit(TGeoMatrix::kGeoRotation); if ( transform->IsRotation() ) { - TGeoRotation* rot = static_cast<TGeoRotation*>(transform); - Double_t det = + Double_t det = r[0]*r[4]*r[8] + r[3]*r[7]*r[2] + r[6]*r[1]*r[5] - r[2]*r[4]*r[6] - r[5]*r[7]*r[0] - r[8]*r[1]*r[3]; diff --git a/DDCore/src/plugins/ShapePlugins.cpp b/DDCore/src/plugins/ShapePlugins.cpp index aaa8a5ebc..fe5564822 100644 --- a/DDCore/src/plugins/ShapePlugins.cpp +++ b/DDCore/src/plugins/ShapePlugins.cpp @@ -633,39 +633,34 @@ static Ref_t create_shape(Detector& description, xml_h e, Ref_t /* sens */) { volume.setVisAttributes(description, x_check.visStr()); solid->SetName(shape_type.c_str()); + Transform3D tr; if ( pos.ptr() && rot.ptr() ) { Rotation3D rot3D(RotationZYX(rot.z(0),rot.y(0),rot.x(0))); Position pos3D(pos.x(0),pos.y(0),pos.z(0)); - Transform3D tr(rot3D, pos3D); - if ( reflect ) { - rot3D = Rotation3D(1., 0., 0., 0., 1., 0., 0., 0., -1.) * rot3D; - tr = Transform3D(rot3D, pos3D); - } - else if ( reflectX ) { - tr = Transform3D(rot3D, pos3D) * Rotation3D(-1.,0.,0.,0.,1.,0.,0.,0.,1.); - } - else if ( reflectY ) { - tr = Transform3D(rot3D, pos3D) * Rotation3D(1.,0.,0.,0.,-1.,0.,0.,0.,1.); - } - else if ( reflectZ ) { - tr = Transform3D(rot3D, pos3D) * Rotation3D(1.,0.,0.,0.,1.,0.,0.,0.,-1.); - } - pv = assembly.placeVolume(volume,tr); + tr = Transform3D(rot3D, pos3D); } -#if 0 else if ( pos.ptr() ) { - pv = assembly.placeVolume(volume,Position(pos.x(0),pos.y(0),pos.z(0))); + tr = Transform3D(Rotation3D(),Position(pos.x(0),pos.y(0),pos.z(0))); } else if ( rot.ptr() ) { Rotation3D rot3D(RotationZYX(rot.z(0),rot.y(0),rot.x(0))); - if ( reflect ) - rot3D = Rotation3D(1., 0., 0., 0., 1., 0., 0., 0., -1.) * rot3D; - pv = assembly.placeVolume(volume,rot3D); + tr = Transform3D(rot3D,Position()); + } + + if ( reflect ) { + tr = tr * Rotation3D(1., 0., 0., 0., 1., 0., 0., 0., -1.); } - else { - pv = assembly.placeVolume(volume); + if ( reflectX ) { + tr = tr * Rotation3D(-1.,0.,0.,0.,1.,0.,0.,0.,1.); } -#endif + if ( reflectY ) { + tr = tr * Rotation3D(1.,0.,0.,0.,-1.,0.,0.,0.,1.); + } + if ( reflectZ ) { + tr = tr * Rotation3D(1.,0.,0.,0.,1.,0.,0.,0.,-1.); + } + pv = assembly.placeVolume(volume,tr); + if ( x_check.hasAttr(_U(id)) ) { pv.addPhysVolID("check",x_check.id()); } diff --git a/examples/ClientTests/compact/CheckShape.xml b/examples/ClientTests/compact/CheckShape.xml index a4d208d5f..12a6d2db9 100644 --- a/examples/ClientTests/compact/CheckShape.xml +++ b/examples/ClientTests/compact/CheckShape.xml @@ -16,7 +16,7 @@ </includes> <define> - <constant name="world_side" value="3000*cm"/> + <constant name="world_side" value="300*cm"/> <constant name="world_x" value="world_side"/> <constant name="world_y" value="world_side"/> <constant name="world_z" value="world_side"/> diff --git a/examples/ClientTests/compact/Check_Shape_TruncatedTube.xml b/examples/ClientTests/compact/Check_Shape_TruncatedTube.xml index f89db3fc1..362b5c049 100644 --- a/examples/ClientTests/compact/Check_Shape_TruncatedTube.xml +++ b/examples/ClientTests/compact/Check_Shape_TruncatedTube.xml @@ -5,11 +5,6 @@ <detectors> <detector id="1" name="Shape_TruncatedTube" type="DD4hep_TestShape_Creator"> - <check vis="Shape1_vis"> - <shape type="Box" dx="30*cm" dy="20*cm" dz="10*cm"/> - <position x="30" y="30" z="30"/> - <rotation x="0" y="0" z="0"/> - </check> <check vis="Shape1_vis"> <shape type="TruncatedTube" dz="50*cm" rmin="20*cm" rmax="40*cm" startphi="0*deg" deltaphi="90*deg" @@ -43,8 +38,8 @@ </check> --> - <test type="DD4hep_Mesh_Verifier" ref="${DD4hepExamplesINSTALL}/examples/ClientTests/ref/Ref_TruncatedTube.txt" create="CheckShape_create"/> - <ntest type="DD4hep_Mesh_Verifier" ref="${DD4hepExamplesINSTALL}/examples/ClientTests/ref/Ref_TruncatedTube.txt" create="1"/> + <ntest type="DD4hep_Mesh_Verifier" ref="${DD4hepExamplesINSTALL}/examples/ClientTests/ref/Ref_TruncatedTube.txt" create="CheckShape_create"/> + <test type="DD4hep_Mesh_Verifier" ref="${DD4hepExamplesINSTALL}/examples/ClientTests/ref/Ref_TruncatedTube.txt" create="1"/> </detector> </detectors> </lccdd> diff --git a/examples/DDCAD/compact/Check_Shape_Collada_duck.xml b/examples/DDCAD/compact/Check_Shape_Collada_duck.xml index b1a1aa8bd..ad9f18d62 100644 --- a/examples/DDCAD/compact/Check_Shape_Collada_duck.xml +++ b/examples/DDCAD/compact/Check_Shape_Collada_duck.xml @@ -8,7 +8,7 @@ <check vis="Shape1_vis"> <shape type="CAD_Shape" ref="${DD4hepExamplesINSTALL}/examples/DDCAD/models/Collada/duck.dae" mesh="0"/> </check> - <test type="DD4hep_Mesh_Verifier" ref="${DD4hepExamplesINSTALL}/examples/DDCAD/ref/Ref_Collada_duck.txt" create="CheckShape_create"/> + <btest type="DD4hep_Mesh_Verifier" ref="${DD4hepExamplesINSTALL}/examples/DDCAD/ref/Ref_Collada_duck.txt" create="CheckShape_create"/> </detector> </detectors> </lccdd> -- GitLab