77 G4UnitDefinition::BuildUnitsTable();
80 B2ERROR(
"No geometry found. => Add the Geometry module to the path before the OverlapChecker module.");
87 G4VExceptionHandler* old = G4StateManager::GetStateManager()->GetExceptionHandler();
89 OverlapHandler handler([&](
const std::string & message) {
handleOverlap(message); });
90 G4StateManager::GetStateManager()->SetExceptionHandler(&handler);
94 G4StateManager::GetStateManager()->SetExceptionHandler(old);
98 B2ERROR(
"Overlaps detected for " << m_overlap);
105 G4VPhysicalVolume* volume =
m_nav.GetTopVolume();
107 B2ERROR(geant4Message);
108 std::regex r(R
"((mother)?\s*local point \(([-+0-9eE.]+),([-+0-9eE.]+),([-+0-9eE.]+)\))");
110 if (std::regex_search(geant4Message, m, r)) {
111 G4ThreeVector posLocal(std::atof(m[2].str().c_str()), std::atof(m[3].str().c_str()), std::atof(m[4].str().c_str()));
112 if (m[1].length() == 0) {
119 G4AffineTransform trans_volume(volume->GetRotation(), volume->GetTranslation());
120 trans_volume.Invert();
122 G4VSolid* solid = volume->GetLogicalVolume()->GetSolid();
124 std::regex nameRegex(
"with (.*) volume's");
125 std::smatch nameMatch;
127 if (std::regex_search(geant4Message, nameMatch, nameRegex)) {
128 const std::string& name = nameMatch[1].str();
130 for (
size_t i = 0; i < volume->GetMotherLogical()->GetNoDaughters(); ++i) {
131 G4VPhysicalVolume* sister = volume->GetMotherLogical()->GetDaughter(i);
133 std::string sisterName{(sister->GetName()).data()};
134 if (name != sisterName)
continue;
136 G4AffineTransform trans_sister(sister->GetRotation(), sister->GetTranslation());
137 G4ThreeVector posMother = trans_sister.TransformPoint(posLocal);
138 G4ThreeVector posSister = trans_volume.TransformPoint(posMother);
140 if (solid->Inside(posSister) != kOutside) {
142 B2INFO(
"Found intersecting volume " << sister->GetName() <<
"." << sister->GetCopyNo());
144 G4AffineTransform t =
m_nav.GetTopTransform().Inverse();
145 G4ThreeVector global = t.TransformPoint(posMother);
146 m_displayData->addPoint(geant4Message, ROOT::Math::XYZVector(global[0], global[1], global[2]) *
Unit::mm);
150 B2ERROR(
"Could not find name of intersecting volume");
154 G4AffineTransform t =
m_nav.GetTopTransform().Inverse();
155 G4ThreeVector global = t.TransformPoint(posLocal);
156 m_displayData->addPoint(geant4Message, ROOT::Math::XYZVector(global[0], global[1], global[2]) *
Unit::mm);
159 m_nav.NewLevel(volume);
167 m_nav.NewLevel(volume);
169 std::string volumePath = path +
"/" + volume->GetName();
180 G4LogicalVolume* logicalVolume = volume->GetLogicalVolume();
181 for (
size_t iDaughter = 0; iDaughter < logicalVolume->GetNoDaughters(); iDaughter++) {
182 G4VPhysicalVolume* daughter = logicalVolume->GetDaughter(iDaughter);
184 auto it =
m_seen.insert(daughter);
185 if (!it.second)
continue;
186 result |=
checkVolume(daughter, volumePath, depth + 1);
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.