Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix G4 logical volumes assignments to production cuts regions with DD4hep #33164

Merged
merged 3 commits into from Mar 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 19 additions & 1 deletion SimG4Core/Geometry/src/DDG4ProductionCuts.cc
Expand Up @@ -11,6 +11,7 @@
#include "G4RegionStore.hh"
#include "G4Region.hh"
#include "G4LogicalVolume.hh"
#include "G4LogicalVolumeStore.hh"

#include <algorithm>

Expand Down Expand Up @@ -140,9 +141,26 @@ void DDG4ProductionCuts::dd4hepInitialize() {
for (auto const& it : dd4hepVec_) {
auto regName = it.second->strValue(keywordRegion_);
G4Region* region = G4RegionStore::GetInstance()->FindOrCreateRegion({regName.data(), regName.size()});

region->AddRootLogicalVolume(it.first);
edm::LogVerbatim("Geometry") << it.first->GetName() << ": " << it.second->strValue(keywordRegion_);
edm::LogVerbatim("Geometry") << it.first->GetName() << ": " << regName;
edm::LogVerbatim("Geometry") << " MakeRegions: added " << it.first->GetName() << " to region " << region->GetName();

// Also treat reflected volumes
const G4String& nonReflectedG4Name = it.first->GetName();
const G4String& reflectedG4Name = nonReflectedG4Name + "_refl";
const G4LogicalVolumeStore* const allG4LogicalVolumes = G4LogicalVolumeStore::GetInstance();
const auto reflectedG4LogicalVolumeIt = std::find_if(
allG4LogicalVolumes->begin(), allG4LogicalVolumes->end(), [&](const G4LogicalVolume* const aG4LogicalVolume) {
return (aG4LogicalVolume->GetName() == reflectedG4Name);
});
// If G4 Logical volume has a reflected volume, add it to the region as well.
if (reflectedG4LogicalVolumeIt != allG4LogicalVolumes->end()) {
region->AddRootLogicalVolume(*reflectedG4LogicalVolumeIt);
edm::LogVerbatim("Geometry") << " MakeRegions: added " << (*reflectedG4LogicalVolumeIt)->GetName()
<< " to region " << region->GetName();
}

edm::LogVerbatim("Geometry").log([&](auto& log) {
for (auto const& sit : it.second->spars) {
log << sit.first << " = " << sit.second[0] << "\n";
Expand Down