diff --git a/Detectors/Base/include/DetectorsBase/Aligner.h b/Detectors/Base/include/DetectorsBase/Aligner.h index 0b378dcfa33cb..12eb7dfee003c 100644 --- a/Detectors/Base/include/DetectorsBase/Aligner.h +++ b/Detectors/Base/include/DetectorsBase/Aligner.h @@ -33,7 +33,7 @@ class Aligner : public o2::conf::ConfigurableParamHelper o2::detectors::DetID::mask_t getDetectorsMask() const; bool isAlignmentRequested() const { return getDetectorsMask().any(); } - void applyAlignment(long timestamp = 0, o2::detectors::DetID::mask_t addMask = o2::detectors::DetID::FullMask) const; + void applyAlignment(long timestamp = 0, o2::detectors::DetID::mask_t addMask = o2::detectors::DetID::FullMask, bool keepPhysicalNodes = true) const; private: std::string mDetectors = "all"; // comma-separated list of modules to align, "all" or "none" diff --git a/Detectors/Base/include/DetectorsBase/GeometryManager.h b/Detectors/Base/include/DetectorsBase/GeometryManager.h index f918c278dcf33..6c771aa4bc936 100644 --- a/Detectors/Base/include/DetectorsBase/GeometryManager.h +++ b/Detectors/Base/include/DetectorsBase/GeometryManager.h @@ -84,7 +84,8 @@ class GeometryManager : public TObject ~GeometryManager() override = default; /// misalign geometry with alignment objects from the array, optionaly check overlaps - static bool applyAlignment(const std::vector& algPars); + /// with keepPhysicalNodes false, each physical node is deleted after its alignment (no original matrices are kept) + static bool applyAlignment(const std::vector& algPars, bool keepPhysicalNodes = true); static bool applyAlignment(const std::vector*> algPars); struct MatBudgetExt { diff --git a/Detectors/Base/src/Aligner.cxx b/Detectors/Base/src/Aligner.cxx index a82f48942d2be..70f5f9f96a453 100644 --- a/Detectors/Base/src/Aligner.cxx +++ b/Detectors/Base/src/Aligner.cxx @@ -27,7 +27,7 @@ DetID::mask_t Aligner::getDetectorsMask() const return DetID::getMask(mDetectors) & (~DetID::getMask(DetID::CTP)); } -void Aligner::applyAlignment(long timestamp, DetID::mask_t addMask) const +void Aligner::applyAlignment(long timestamp, DetID::mask_t addMask, bool keepPhysicalNodes) const { DetID::mask_t msk = getDetectorsMask() & addMask; if (msk.none()) { @@ -59,7 +59,7 @@ void Aligner::applyAlignment(long timestamp, DetID::mask_t addMask) const } if (!algV->empty()) { done.set(id); - o2::base::GeometryManager::applyAlignment(*algV); + o2::base::GeometryManager::applyAlignment(*algV, keepPhysicalNodes); } else { skipped.set(id); } diff --git a/Detectors/Base/src/GeometryManager.cxx b/Detectors/Base/src/GeometryManager.cxx index f0ea0d41e7d04..ecc279dab1db2 100644 --- a/Detectors/Base/src/GeometryManager.cxx +++ b/Detectors/Base/src/GeometryManager.cxx @@ -277,7 +277,7 @@ bool GeometryManager::applyAlignment(const std::vector& algPars) +bool GeometryManager::applyAlignment(const std::vector& algPars, bool keepPhysicalNodes) { /// misalign geometry with alignment objects from the array, optionaly check overlaps int nvols = algPars.size(); @@ -286,11 +286,23 @@ bool GeometryManager::applyAlignment(const std::vectorGetListOfPhysicalNodes(); for (int i = 0; i < nvols; i++) { + int npn = pns->GetEntriesFast(); if (!algPars[ord[i]].applyToGeometry(GeometryManagerParam::Instance().printLevel)) { res = false; LOG(error) << "Error applying alignment object for volume" << algPars[ord[i]].getSymName(); } + if (!keepPhysicalNodes) { // delete the nodes this alignment created, so their memory is reused by the next one + for (int k = pns->GetEntriesFast() - 1; k >= npn; k--) { + auto pn = static_cast(pns->RemoveAt(k)); + if (auto pne = gGeoManager->GetAlignableEntry(algPars[ord[i]].getSymName().c_str()); pne && pne->GetPhysicalNode() == pn) { + pne->SetPhysicalNode(nullptr); + } + delete pn; + } + pns->Compress(); + } } return res; } diff --git a/Steer/src/O2MCApplication.cxx b/Steer/src/O2MCApplication.cxx index b3bbe0e59223e..e79264744d3ac 100644 --- a/Steer/src/O2MCApplication.cxx +++ b/Steer/src/O2MCApplication.cxx @@ -330,7 +330,8 @@ bool O2MCApplicationBase::MisalignGeometry() // apply alignment for included detectors AFTER exporting ideal geometry auto& aligner = o2::base::Aligner::Instance(); - aligner.applyAlignment(confref.getTimestamp()); + // the simulation needs no original matrices, so the physical nodes are not kept + aligner.applyAlignment(confref.getTimestamp(), o2::detectors::DetID::FullMask, false); // export aligned geometry into different file auto alignedgeomfile = o2::base::NameConf::getAlignedGeomFileName(confref.getOutPrefix());