From d86e5e970e32e158ce2c575df3238416510274ba Mon Sep 17 00:00:00 2001 From: Markus FRANK <Markus.Frank@cern.ch> Date: Sat, 31 Oct 2020 01:17:51 +0100 Subject: [PATCH] Try to fix reflections for volumes and assemblies --- DDCore/include/DD4hep/DetectorImp.h | 3 --- DDCore/include/DD4hep/Volumes.h | 22 +++++++++++++++++++ DDCore/src/DetectorImp.cpp | 21 ------------------ DDCore/src/Volumes.cpp | 22 +++++++++++++++++++ DDCore/src/plugins/Compact2Objects.cpp | 11 ++++++++++ .../ClientTests/eve/NestedBoxReflection.xml | 19 ++++++++++++++++ 6 files changed, 74 insertions(+), 24 deletions(-) create mode 100644 examples/ClientTests/eve/NestedBoxReflection.xml diff --git a/DDCore/include/DD4hep/DetectorImp.h b/DDCore/include/DD4hep/DetectorImp.h index c7c2f6e97..ca3d4f16c 100644 --- a/DDCore/include/DD4hep/DetectorImp.h +++ b/DDCore/include/DD4hep/DetectorImp.h @@ -92,9 +92,6 @@ namespace dd4hep { /// Local method (no interface): Load volume manager. void imp_loadVolumeManager(); - - /// Build reflections the ROOT way. To be called once the geometry is closed - void buildReflections(); /// Default constructor used by ROOT I/O DetectorImp(); diff --git a/DDCore/include/DD4hep/Volumes.h b/DDCore/include/DD4hep/Volumes.h index 4aaa34c93..f15d17500 100644 --- a/DDCore/include/DD4hep/Volumes.h +++ b/DDCore/include/DD4hep/Volumes.h @@ -44,6 +44,28 @@ namespace dd4hep { class Volume; class PlacedVolume; + /// Scan geometry and create reflected volumes + /** + * Build reflections the ROOT way. To be called once the geometry is closed. + * + * For any further documentation please see the following ROOT documentation: + * \see http://root.cern.ch/root/html/TGeoManager.html + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_CORE + */ + class ReflectionBuilder { + Detector& detector; + public: + /// Initializing constructor + ReflectionBuilder(Detector& desc) : detector(desc) {} + /// Default descructor + ~ReflectionBuilder() = default; + /// Perform scan + void execute() const; + }; + /// Implementation class extending the ROOT placed volume /** * For any further documentation please see the following ROOT documentation: diff --git a/DDCore/src/DetectorImp.cpp b/DDCore/src/DetectorImp.cpp index 60306c36d..0d49b27aa 100644 --- a/DDCore/src/DetectorImp.cpp +++ b/DDCore/src/DetectorImp.cpp @@ -652,27 +652,6 @@ namespace { }; } -/// Build reflections the ROOT way. To be called once the geometry is closed -void DetectorImp::buildReflections() { - TGeoIterator next(manager().GetTopVolume()); - TGeoNode *node; - while ((node=next())) { - TGeoMatrix* m = node->GetMatrix(); - if (m->IsReflection()) { - Volume vol(node->GetVolume()); - TGeoMatrix* mclone = new TGeoCombiTrans(*m); - mclone->RegisterYourself(); - // Reflect just the rotation component - mclone->ReflectZ(kFALSE, kTRUE); - TGeoNodeMatrix* nodematrix = (TGeoNodeMatrix*)node; - nodematrix->SetMatrix(mclone); - printout(INFO,"Detector","Reflecting volume: %s ",vol.name()); - Volume refl = vol.reflect(vol.sensitiveDetector()); - node->SetVolume(refl.ptr()); - } - } -} - /// Finalize/close the geometry void DetectorImp::endDocument(bool close_geometry) { TGeoManager* mgr = m_manager; diff --git a/DDCore/src/Volumes.cpp b/DDCore/src/Volumes.cpp index 454abad2a..69f246aba 100644 --- a/DDCore/src/Volumes.cpp +++ b/DDCore/src/Volumes.cpp @@ -275,6 +275,28 @@ namespace { } + +/// Perform scan +void ReflectionBuilder::execute() const { + TGeoIterator next(detector.manager().GetTopVolume()); + TGeoNode *node; + while ( (node=next()) ) { + TGeoMatrix* m = node->GetMatrix(); + if (m->IsReflection()) { + Volume vol(node->GetVolume()); + TGeoMatrix* mclone = new TGeoCombiTrans(*m); + mclone->RegisterYourself(); + // Reflect just the rotation component + mclone->ReflectZ(kFALSE, kTRUE); + TGeoNodeMatrix* nodematrix = (TGeoNodeMatrix*)node; + nodematrix->SetMatrix(mclone); + printout(INFO,"Detector","Reflecting volume: %s ",vol.name()); + Volume refl = vol.reflect(vol.sensitiveDetector()); + node->SetVolume(refl.ptr()); + } + } +} + /// Default constructor PlacedVolume::Processor::Processor() { } diff --git a/DDCore/src/plugins/Compact2Objects.cpp b/DDCore/src/plugins/Compact2Objects.cpp index ac8d6948c..f5044b1c5 100644 --- a/DDCore/src/plugins/Compact2Objects.cpp +++ b/DDCore/src/plugins/Compact2Objects.cpp @@ -1463,6 +1463,7 @@ template <> void Converter<Compact>::operator()(xml_h element) const { bool open_geometry = true; bool close_document = true; bool close_geometry = true; + bool build_reflections = false; if (element.hasChild(_U(debug))) (Converter<Debug>(description))(xml_h(compact.child(_U(debug)))); @@ -1554,10 +1555,20 @@ template <> void Converter<Compact>::operator()(xml_h element) const { description.addConstant(Constant("compact_checksum", text)); description.endDocument(close_geometry); } + if ( build_reflections ) { + ReflectionBuilder rb(description); + rb.execute(); + } xml_coll_t(compact, _U(plugins)).for_each(_U(plugin), Converter<Plugin> (description)); } #ifdef _WIN32 + void buildReflections(); + +/// Build reflections the ROOT way. To be called once the geometry is closed +void DetectorImp::buildReflections() { +} + template Converter<Plugin>; template Converter<Constant>; template Converter<Material>; diff --git a/examples/ClientTests/eve/NestedBoxReflection.xml b/examples/ClientTests/eve/NestedBoxReflection.xml new file mode 100644 index 000000000..86b1fa628 --- /dev/null +++ b/examples/ClientTests/eve/NestedBoxReflection.xml @@ -0,0 +1,19 @@ +<ddeve> + <display visLevel="7" loadLevel="3"/> + <collection name="NestedBoxHits" hits="PointSet" color="kMagenta" size="0.3" type="20"/> + <collection name="MCParticles" hits="Particles" size="0.2" width="1" type="kCircle"/> +<!-- + <view name="3D Trackers R-Phi (Global)" type="RhoPhiProjection"> + <detelement name="NestedBox" load_geo="-1" alpha="0.5"/> + </view> + + <view name="3D Trackers R-Phi (Local)" type="RhoPhiProjection"> + <detelement name="NestedBox" load_geo="3" alpha="0.5"/> + </view> + + <view name="3D Trackers" type="View3D"> + <detelement name="NestedBox" load_geo="-1" alpha="0.5"/> + </view> +--> + <include ref="${DD4hepExamplesINSTALL}/examples/ClientTests/compact/NestedBoxReflection.xml"/> +</ddeve> -- GitLab