From 1e1dcaa8738f3597f29068a49a2f6eaf758b77db Mon Sep 17 00:00:00 2001 From: Markus Frank <Markus.Frank@cern.ch> Date: Wed, 5 Feb 2020 10:03:27 +0100 Subject: [PATCH] Add support of tessellated shapes for ROOT > 6.19.0 --- DDCore/src/ShapeUtilities.cpp | 22 ++++++++++++++++++++-- DDCore/src/Shapes.cpp | 2 ++ DDCore/src/plugins/ShapePlugins.cpp | 4 ++++ DDG4/src/Geant4ShapeConverter.cpp | 26 ++++++++++++++++---------- 4 files changed, 42 insertions(+), 12 deletions(-) diff --git a/DDCore/src/ShapeUtilities.cpp b/DDCore/src/ShapeUtilities.cpp index e6feee8c5..7abc61e2e 100644 --- a/DDCore/src/ShapeUtilities.cpp +++ b/DDCore/src/ShapeUtilities.cpp @@ -77,7 +77,9 @@ namespace dd4hep { template bool isInstance<PolyhedraRegular> (const Handle<TGeoShape>& solid); template bool isInstance<Polyhedra> (const Handle<TGeoShape>& solid); template bool isInstance<ExtrudedPolygon> (const Handle<TGeoShape>& solid); +#if ROOT_VERSION_CODE > ROOT_VERSION(6,19,0) template bool isInstance<TessellatedSolid> (const Handle<TGeoShape>& solid); +#endif template bool isInstance<BooleanSolid> (const Handle<TGeoShape>& solid); template <> bool isInstance<Cone>(const Handle<TGeoShape>& solid) { @@ -149,8 +151,9 @@ namespace dd4hep { template bool isA<ExtrudedPolygon>(const Handle<TGeoShape>& solid); template bool isA<Polycone>(const Handle<TGeoShape>& solid); template bool isA<EightPointSolid>(const Handle<TGeoShape>& solid); +#if ROOT_VERSION_CODE > ROOT_VERSION(6,19,0) template bool isA<TessellatedSolid>(const Handle<TGeoShape>& solid); - +#endif template <> bool isA<TwistedTube>(const Handle<TGeoShape>& solid) { return check_shape_type<TwistedTubeObject>(solid) && ::strcmp(solid->GetTitle(), TWISTEDTUBE_TAG) == 0; @@ -334,6 +337,8 @@ namespace dd4hep { for(auto p : s_pars) pars.push_back(p); return pars; } + +#if ROOT_VERSION_CODE > ROOT_VERSION(6,19,0) template <> vector<double> dimensions<TGeoTessellated>(const TGeoShape* shape) { TGeoTessellated* sh = get_ptr<TGeoTessellated>(shape); int num_facet = sh->GetNfacets(); @@ -358,6 +363,8 @@ namespace dd4hep { } return pars; } +#endif + template <> vector<double> dimensions<TGeoCompositeShape>(const TGeoShape* shape) { const TGeoCompositeShape* sh = get_ptr<TGeoCompositeShape>(shape); const TGeoBoolNode* boolean = sh->GetBoolNode(); @@ -409,7 +416,9 @@ namespace dd4hep { template vector<double> dimensions<Polyhedra> (const Handle<TGeoShape>& shape); template vector<double> dimensions<ExtrudedPolygon> (const Handle<TGeoShape>& shape); template vector<double> dimensions<EightPointSolid> (const Handle<TGeoShape>& shape); +#if ROOT_VERSION_CODE > ROOT_VERSION(6,19,0) template vector<double> dimensions<TessellatedSolid> (const Handle<TGeoShape>& shape); +#endif template vector<double> dimensions<BooleanSolid> (const Handle<TGeoShape>& shape); template vector<double> dimensions<SubtractionSolid> (const Handle<TGeoShape>& shape); template vector<double> dimensions<UnionSolid> (const Handle<TGeoShape>& shape); @@ -502,8 +511,10 @@ namespace dd4hep { return dimensions<TGeoXtru>(shape.ptr()); else if (cl == TGeoScaledShape::Class()) return dimensions<TGeoScaledShape>(shape.ptr()); +#if ROOT_VERSION_CODE > ROOT_VERSION(6,19,0) else if (cl == TGeoTessellated::Class()) return dimensions<TGeoTessellated>(shape.ptr()); +#endif else if (isA<TruncatedTube>(shape.ptr())) return dimensions<TruncatedTube>(shape); else if (isA<PseudoTrap>(shape.ptr())) @@ -733,6 +744,8 @@ namespace dd4hep { auto pars = params; s_sh.access()->SetDimensions(&pars[3]); } + +#if ROOT_VERSION_CODE > ROOT_VERSION(6,19,0) template <> void set_dimensions(TGeoTessellated* sh, const std::vector<double>& params) { int num_vtx = params[0]; int num_facet = params[1]; @@ -765,7 +778,8 @@ namespace dd4hep { } sh->CloseShape(true, true, false); } - +#endif + template <> void set_dimensions(TGeoCompositeShape*, const std::vector<double>&) { // In general TGeoCompositeShape instances have an empty SetDimension call #if 0 @@ -824,8 +838,10 @@ namespace dd4hep { { set_dimensions(shape.ptr(), params); } template <> void set_dimensions(EightPointSolid shape, const std::vector<double>& params) { set_dimensions(shape.ptr(), params); } +#if ROOT_VERSION_CODE > ROOT_VERSION(6,19,0) template <> void set_dimensions(TessellatedSolid shape, const std::vector<double>& params) { set_dimensions(shape.ptr(), params); } +#endif template <> void set_dimensions(BooleanSolid shape, const std::vector<double>& params) { set_dimensions(shape.ptr(), params); } template <> void set_dimensions(SubtractionSolid shape, const std::vector<double>& params) @@ -1026,8 +1042,10 @@ namespace dd4hep { set_dimensions(ExtrudedPolygon(shape), params); else if (cl == TGeoArb8::Class()) set_dimensions(EightPointSolid(shape), params); +#if ROOT_VERSION_CODE > ROOT_VERSION(6,19,0) else if (cl == TGeoTessellated::Class()) set_dimensions(TessellatedSolid(shape), params); +#endif else if (cl == TGeoScaledShape::Class()) { TGeoScaledShape* sh = (TGeoScaledShape*) shape.ptr(); set_dimensions(sh, params); diff --git a/DDCore/src/Shapes.cpp b/DDCore/src/Shapes.cpp index d401c9cb0..9ae8a1efe 100644 --- a/DDCore/src/Shapes.cpp +++ b/DDCore/src/Shapes.cpp @@ -716,6 +716,7 @@ void EightPointSolid::make(const string& nam, double dz, const double* vtx) { _assign(new TGeoArb8(nam.c_str(), dz, (double*)vtx), "", EIGHTPOINTSOLID_TAG, true); } +#if ROOT_VERSION_CODE > ROOT_VERSION(6,19,0) /// Internal helper method to support object construction void TessellatedSolid::make(const std::string& nam, int num_facets) { _assign(new TGeoTessellated(nam.c_str(), num_facets), nam, TESSELLATEDSOLID_TAG, false); @@ -745,6 +746,7 @@ bool TessellatedSolid::addFacet(const int pt0, const int pt1, const int pt2) co bool TessellatedSolid::addFacet(const int pt0, const int pt1, const int pt2, const int pt3) const { return access()->AddFacet(pt0, pt1, pt2, pt3); } +#endif /// Constructor to be used when creating a new object. Position is identity, Rotation is the identity rotation SubtractionSolid::SubtractionSolid(const Solid& shape1, const Solid& shape2) { diff --git a/DDCore/src/plugins/ShapePlugins.cpp b/DDCore/src/plugins/ShapePlugins.cpp index 9ea5bd52f..0c52f1c3f 100644 --- a/DDCore/src/plugins/ShapePlugins.cpp +++ b/DDCore/src/plugins/ShapePlugins.cpp @@ -310,6 +310,7 @@ static Handle<TObject> create_EightPointSolid(Detector&, xml_h element) { } DECLARE_XML_SHAPE(EightPointSolid__shape_constructor,create_EightPointSolid) +#if ROOT_VERSION_CODE > ROOT_VERSION(6,19,0) /// Plugin factory to created tessellated shapes static Handle<TObject> create_TessellatedSolid(Detector&, xml_h element) { xml_dim_t e(element); @@ -336,6 +337,7 @@ static Handle<TObject> create_TessellatedSolid(Detector&, xml_h element) { return solid; } DECLARE_XML_SHAPE(TessellatedSolid__shape_constructor,create_TessellatedSolid) +#endif /** Plugin function for creating a boolean solid from an xml element <shape type=\"BooleanShape\"/>. * Expects exactly two child elements <shape/> and a string attribute 'operation', which is one of @@ -629,8 +631,10 @@ static Ref_t create_shape(Detector& description, xml_h e, Ref_t /* sens */) { instance_test = isInstance<EllipticalTube>(solid); else if ( 0 == strcasecmp(solid->GetTitle(),EXTRUDEDPOLYGON_TAG) ) instance_test = isInstance<ExtrudedPolygon>(solid); +#if ROOT_VERSION_CODE > ROOT_VERSION(6,19,0) else if ( 0 == strcasecmp(solid->GetTitle(),TESSELLATEDSOLID_TAG) ) instance_test = isInstance<TessellatedSolid>(solid); +#endif else if ( 0 == strcasecmp(solid->GetTitle(),POLYCONE_TAG) ) instance_test = isInstance<Polycone>(solid); else if ( 0 == strcasecmp(solid->GetTitle(),TWISTEDTUBE_TAG) ) { diff --git a/DDG4/src/Geant4ShapeConverter.cpp b/DDG4/src/Geant4ShapeConverter.cpp index 8ff8888eb..6b70e1eda 100644 --- a/DDG4/src/Geant4ShapeConverter.cpp +++ b/DDG4/src/Geant4ShapeConverter.cpp @@ -43,10 +43,13 @@ #include "G4GenericTrap.hh" #include "G4ExtrudedSolid.hh" #include "G4EllipticalTube.hh" -#include "G4TessellatedSolid.hh" #include "G4TriangularFacet.hh" #include "G4QuadrangularFacet.hh" +#if ROOT_VERSION_CODE > ROOT_VERSION(6,19,0) +#include "G4TessellatedSolid.hh" +#endif + // C/C++ include files using namespace std; @@ -222,6 +225,16 @@ namespace dd4hep { sh->GetH2() * CM_2_MM, sh->GetBl2() * CM_2_MM, sh->GetTl2() * CM_2_MM, sh->GetAlpha2() * DEGREE_2_RAD); } + template <> G4VSolid* convertShape<G4GenericTrap>(const TGeoShape* shape) { + vector<G4TwoVector> vertices; + TGeoTrap* sh = (TGeoTrap*) shape; + Double_t* vtx_xy = sh->GetVertices(); + for ( size_t i=0; i<8; ++i, vtx_xy +=2 ) + vertices.emplace_back(vtx_xy[0] * CM_2_MM, vtx_xy[1] * CM_2_MM); + return new G4GenericTrap(sh->GetName(), sh->GetDz() * CM_2_MM, vertices); + } + +#if ROOT_VERSION_CODE > ROOT_VERSION(6,19,0) template <> G4VSolid* convertShape<TGeoTessellated>(const TGeoShape* shape) { TGeoTessellated* sh = (TGeoTessellated*) shape; G4TessellatedSolid* g4 = new G4TessellatedSolid(sh->GetName()); @@ -257,14 +270,7 @@ namespace dd4hep { } return g4; } - - template <> G4VSolid* convertShape<G4GenericTrap>(const TGeoShape* shape) { - vector<G4TwoVector> vertices; - TGeoTrap* sh = (TGeoTrap*) shape; - Double_t* vtx_xy = sh->GetVertices(); - for ( size_t i=0; i<8; ++i, vtx_xy +=2 ) - vertices.emplace_back(vtx_xy[0] * CM_2_MM, vtx_xy[1] * CM_2_MM); - return new G4GenericTrap(sh->GetName(), sh->GetDz() * CM_2_MM, vertices); - } +#endif + } // End namespace sim } // End namespace dd4hep -- GitLab