Skip to content

Commit

Permalink
chore: Refactor part of FairDetector::Initialize
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 Jun 10, 2024
1 parent 1d4a1e4 commit 050b6a4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 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 : FairRunSim::Instance()->fAllSensitiveVolumes) {
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);
}
}
}
FairRunSim::Instance()->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 @@ -422,3 +423,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);
}
}
}
6 changes: 5 additions & 1 deletion fairroot/base/steer/FairRunSim.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class FairVolume;
class FairRunSim : public FairRun
{
friend class FairModule;
friend class FairDetector;
friend class FairMCApplication;

public:
Expand Down Expand Up @@ -222,6 +221,11 @@ class FairRunSim : public FairRun

void ls(Option_t* option = "") const override;

/**
* \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 050b6a4

Please sign in to comment.