Skip to content

Commit

Permalink
refactor(Base): Part of FairDetector::Initialize to FairRunSim
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ChristianTackeGSI committed Aug 26, 2024
1 parent 5afe095 commit 18cf4e3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
20 changes: 1 addition & 19 deletions fairroot/base/sim/FairDetector.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
22 changes: 22 additions & 0 deletions fairroot/base/steer/FairRunSim.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "FairRunIdGenerator.h" // for FairRunIdGenerator
#include "FairRuntimeDb.h" // for FairRuntimeDb
#include "FairTask.h" // for FairTask
#include "FairVolume.h"

#include <TCollection.h> // for TIter
#include <TGeoManager.h> // for gGeoManager
Expand Down Expand Up @@ -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);
}
}
}
5 changes: 5 additions & 0 deletions fairroot/base/steer/FairRunSim.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down

0 comments on commit 18cf4e3

Please sign in to comment.