diff --git a/GeoModelCore/GeoModelHelpers/GeoModelHelpers/defineWorld.h b/GeoModelCore/GeoModelHelpers/GeoModelHelpers/defineWorld.h index fbfe4779d63c9672a6e73795a2e146ec3e0f9118..3a9625c0b16df622e4761e6e6cf9a65a7ea2a5ee 100644 --- a/GeoModelCore/GeoModelHelpers/GeoModelHelpers/defineWorld.h +++ b/GeoModelCore/GeoModelHelpers/GeoModelHelpers/defineWorld.h @@ -21,5 +21,6 @@ GeoIntrusivePtr<GeoPhysVol> createGeoWorld(const double worldBoxX = GeoWorldDim: const double worldBoxZ = GeoWorldDim::worldBoxZ); /// Resize the world volume to be the needed size -GeoIntrusivePtr<GeoPhysVol> resizeGeoWorld(GeoIntrusivePtr<GeoPhysVol> world); +GeoIntrusivePtr<GeoPhysVol> resizeGeoWorld(GeoIntrusivePtr<GeoPhysVol> world, + bool cloneNodes = false); #endif diff --git a/GeoModelCore/GeoModelHelpers/src/defineWorld.cxx b/GeoModelCore/GeoModelHelpers/src/defineWorld.cxx index ebf851eaffd7f0fc4e5229094280c474ee5c1e00..2dcff72d1690e5c67dafe31725c7c706174eaa63 100644 --- a/GeoModelCore/GeoModelHelpers/src/defineWorld.cxx +++ b/GeoModelCore/GeoModelHelpers/src/defineWorld.cxx @@ -43,7 +43,8 @@ GeoIntrusivePtr<GeoPhysVol> createGeoWorld(const double worldBoxX, return world; } -GeoIntrusivePtr<GeoPhysVol> resizeGeoWorld(GeoIntrusivePtr<GeoPhysVol> world) { +GeoIntrusivePtr<GeoPhysVol> resizeGeoWorld(GeoIntrusivePtr<GeoPhysVol> world, + bool cloneVolumes) { if (!world) return world; //resize the world volume to the real needed volume @@ -57,31 +58,19 @@ GeoIntrusivePtr<GeoPhysVol> resizeGeoWorld(GeoIntrusivePtr<GeoPhysVol> world) { // loop over all children volumes for (unsigned int i=0; i<nChild; i++) { - PVConstLink nodeLink = world->getChildVol(i); - if ( dynamic_cast<const GeoVPhysVol*>( &(*( nodeLink ))) ) - { - const GeoVPhysVol *childVolV = &(*( nodeLink )); - - if ( dynamic_cast<const GeoPhysVol*>(childVolV) ) { - const GeoPhysVol* childVol = dynamic_cast<const GeoPhysVol*>(childVolV); - childVol->getLogVol()->getShape()->extent(xmin, ymin, zmin, xmax, ymax, zmax); - } - else if ( dynamic_cast<const GeoFullPhysVol*>(childVolV) ) { - const GeoFullPhysVol* childVol = dynamic_cast<const GeoFullPhysVol*>(childVolV); - childVol->getLogVol()->getShape()->extent(xmin, ymin, zmin, xmax, ymax, zmax); - - } - xworld=std::max({xworld,std::abs(xmin),std::abs(xmax)}); - yworld=std::max({yworld,std::abs(ymin),std::abs(ymax)}); - zworld=std::max({zworld,std::abs(zmin),std::abs(zmax)}); - } + PVConstLink childVol = world->getChildVol(i); + childVol->getLogVol()->getShape()->extent(xmin, ymin, zmin, xmax, ymax, zmax); + + xworld=std::max({xworld,std::abs(xmin),std::abs(xmax)}); + yworld=std::max({yworld,std::abs(ymin),std::abs(ymax)}); + zworld=std::max({zworld,std::abs(zmin),std::abs(zmax)}); } GeoIntrusivePtr<GeoPhysVol> resizedWorld{createGeoWorld(xworld, yworld, zworld)}; for (unsigned int ch = 0; ch < world->getNChildNodes(); ++ch) { const GeoGraphNode * node = *(world->getChildNode(ch)); - if (typeid(*node) == typeid(GeoFullPhysVol) || - typeid(*node) == typeid(GeoPhysVol)) { + if (cloneVolumes && (typeid(*node) == typeid(GeoFullPhysVol) || + typeid(*node) == typeid(GeoPhysVol))) { const GeoVPhysVol* subVol{dynamic_cast<const GeoVPhysVol*>(node)}; GeoVPhysVol* nonConstVol{const_cast<GeoVPhysVol*>(subVol)}; resizedWorld->add(cloneVolume(nonConstVol));