No data filled to H3 when using MT mode

I am currently working on scoring energy deposition in 3D histograms. When I use G4RunManager in non-multithreading (sequential) mode, the results appear correctly. However, after switching to multi-threading mode,G4MTRunManager, the scoring results always show zero.

Could you please advise what might be causing this issue, or suggest any points I should check when implementing scorers in MT mode?

Thanks!
Masai

//this is my runaction.cc
void RunAction::BeginOfRunAction(const G4Run* run)
{
    G4AccumulableManager* accumMgr = G4AccumulableManager::Instance();
    accumMgr->Reset();

    auto analysisManager = G4AnalysisManager::Instance();
    analysisManager->SetNtupleMerging(true);    
		analysisManager->Reset();  
       // if (IsMaster()) {
            analysisManager->OpenFile("SWG_Target_Edep3D");
     //   }
        // 0
        analysisManager->CreateH3("Edep3D_MeV", "Energy Deposition (MeV)",
            fBinX, -fMeshX, fMeshX,
            fBinY, -fMeshY, fMeshY,
            fBinZ, -fMeshZ * 2, 0.0,
            "mm", "mm", "mm");
        //1
        analysisManager->CreateH3("Edep3D_joule", "Energy Deposition (joule)",
            fBinX, -fMeshX, fMeshX,
            fBinY, -fMeshY, fMeshY,
            fBinZ, -fMeshZ * 2, 0.0,
            "mm", "mm", "mm");
  // }
}

void RunAction::EndOfRunAction(const G4Run* run)
{
    G4AccumulableManager::Instance()->Merge();
        auto analysisManager = G4AnalysisManager::Instance();
        analysisManager->Write();
        analysisManager->CloseFile(false);
    }
}
void SteppingAction::UserSteppingAction(const G4Step* step)
{
    G4double nonIonEdep = step->GetNonIonizingEnergyDeposit();
    G4double totalEdep = step->GetTotalEnergyDeposit();

    G4StepPoint* preStep = step->GetPreStepPoint();
    G4ThreeVector pos = preStep->GetPosition();

    if (totalEdep <= 0.) return;

    G4VPhysicalVolume* volume =
        step->GetPreStepPoint()->GetTouchableHandle()->GetVolume();

    G4String volumeName = volume->GetName();
        if (volumeName == "Target") {

            auto analysis = G4AnalysisManager::Instance();
			G4int Edep3D_MeV_id = analysis->GetH3Id("Edep3D_MeV");

            //G4cout
            //    << "User messager: [Thread " << G4Threading::G4GetThreadId()
            //    << "] Filling at " << pos
            //    << " edep(MeV)=" << totalEdep / MeV
            //    << G4endl;

            analysis->FillH3(0, pos.x(), pos.y(), pos.z(), totalEdep / joule);
            analysis->FillH3(Edep3D_MeV_id, pos.x(), pos.y(), pos.z(), totalEdep / MeV);
        }
}

_Geant4 Version:_11.3
_Operating System:_Ubuntu 24.04.01 LTS
_Compiler/Version:_13.3.0
_CMake Version:_3.28.3


Hello,

Can you confirm that you create your RunAction both on master and workers ? (It should be done in both ActionInialization::Build() and ActionInialization::BuildForMaster() functions.)

Also, histograms should be created only once per program execution, so it is better to move the code, where you create them, from BeginOfRunAction to the RunAction() (constructor).

Best regards,