From 18cf4e38c1ff7774804d491620862420c9e5b1a8 Mon Sep 17 00:00:00 2001 From: Christian Tacke <58549698+ChristianTackeGSI@users.noreply.github.com> Date: Thu, 13 Jun 2024 12:55:40 +0200 Subject: [PATCH] refactor(Base): Part of FairDetector::Initialize to FairRunSim A part of FairDetector::Initialize updates the sensitive volumes related to that Detector(Module). Instead of handling this inline, move the code to a new member function on FairRunSim. --- fairroot/base/sim/FairDetector.cxx | 20 +------------------- fairroot/base/steer/FairRunSim.cxx | 22 ++++++++++++++++++++++ fairroot/base/steer/FairRunSim.h | 5 +++++ 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/fairroot/base/sim/FairDetector.cxx b/fairroot/base/sim/FairDetector.cxx index b4444d9806..ca0629df2a 100644 --- a/fairroot/base/sim/FairDetector.cxx +++ b/fairroot/base/sim/FairDetector.cxx @@ -94,25 +94,7 @@ void FairDetector::Initialize() DefineSensitiveVolumes(); } - Int_t fMCid; - FairGeoNode* fN; - TString cutName; - TString copysign = "#"; - for (auto aVol : GetRunSim().RangeAllSensitiveVolumes()) { - cutName = aVol->GetName(); - Ssiz_t pos = cutName.Index(copysign, 1); - if (pos > 1) { - cutName.Resize(pos); - } - if (aVol->getModId() == GetModId()) { - fMCid = TVirtualMC::GetMC()->VolId(cutName.Data()); - aVol->setMCid(fMCid); - fN = aVol->getGeoNode(); - if (fN) { - fN->setMCid(fMCid); - } - } - } + GetRunSim().UpdateSensitiveVolumesForModule(*this); // Initialize cached pointer to MC (on master in sequential mode) fMC = TVirtualMC::GetMC(); diff --git a/fairroot/base/steer/FairRunSim.cxx b/fairroot/base/steer/FairRunSim.cxx index c5cd15913c..e75309bdaa 100644 --- a/fairroot/base/steer/FairRunSim.cxx +++ b/fairroot/base/steer/FairRunSim.cxx @@ -28,6 +28,7 @@ #include "FairRunIdGenerator.h" // for FairRunIdGenerator #include "FairRuntimeDb.h" // for FairRuntimeDb #include "FairTask.h" // for FairTask +#include "FairVolume.h" #include // for TIter #include // for gGeoManager @@ -431,3 +432,24 @@ void FairRunSim::ls(Option_t* option) const } TMCThreadLocal FairRunSim* FairRunSim::fginstance = nullptr; + +void FairRunSim::UpdateSensitiveVolumesForModule(FairModule& mod) +{ + TString copysign = "#"; + for (auto aVol : fAllSensitiveVolumes) { + if (aVol->getModId() != mod.GetModId()) { + continue; + } + TString cutName{aVol->GetName()}; + Ssiz_t pos = cutName.Index(copysign, 1); + if (pos > 1) { + cutName.Resize(pos); + } + Int_t mcid = TVirtualMC::GetMC()->VolId(cutName.Data()); + aVol->setMCid(mcid); + FairGeoNode* node = aVol->getGeoNode(); + if (node) { + node->setMCid(mcid); + } + } +} diff --git a/fairroot/base/steer/FairRunSim.h b/fairroot/base/steer/FairRunSim.h index e6f8fe87d4..adba4d78a4 100644 --- a/fairroot/base/steer/FairRunSim.h +++ b/fairroot/base/steer/FairRunSim.h @@ -234,6 +234,11 @@ class FairRunSim : public FairRun */ auto const& RangeAllSensitiveVolumes() const { return fAllSensitiveVolumes; } + /** + * \brief Internal helper for FairDetector + */ + void UpdateSensitiveVolumesForModule(FairModule& mod); + private: FairRunSim(const FairRunSim& M); FairRunSim& operator=(const FairRunSim&) { return *this; }