Saving vector output to ntuples

Hello,

my plan is to save the number of hits in a detector and energy for each hit in a root tree. I am following the example B5.
In my run action starts with:

ExTGRunAction::ExTGRunAction(ExTGTrackerSD* np)
: fnp(np)
{ G4RunManager::GetRunManager()->SetPrintProgress(1);

  auto analysisManager = G4AnalysisManager::Instance();

  analysisManager->SetVerboseLevel(1);
  analysisManager->SetNtupleMerging(true);

  analysisManager->CreateNtuple("MC", "MCtree");
  analysisManager->CreateNtupleDColumn("nhits");
  analysisManager->CreateNtupleDColumn("energyhit",fnp->GetEnergyHitVec());
  analysisManager->FinishNtuple();

In my Tracker, I do:

void ExTGTrackerSD::EndOfEvent(G4HCofThisEvent*)
{ 
   G4int NbHits = fTrackerCollection->entries();
  
   auto analysisManager = G4AnalysisManager::Instance();
  analysisManager->FillNtupleDColumn(0,NbHits);
  for (G4int i=0;i<NbHits;i++)
   {
     (*fTrackerCollection)[i]->Print();
     fEnergyHit=(*fTrackerCollection)[i]->GetEdep();
     EnergyHitVec.push_back(fEnergyHit);
} 

analysisManager->AddNtupleRow();
}

The function GetEnergyHitVec() in the header of the tracker looks like this:

std::vector<G4double>& GetEnergyHitVec(){return EnergyHitVec; }

Now, my output root file contains the number of hits, this works fine, but “energyhit”, which should contain the vectors is empty. I already checked that the run action can call the function by having a print statement in there.

Can I please get some help on what to do?

Best regards,
Janina

_Geant4 Version:_Geant4.11.2
_Operating System:_Linux cluster
_Compiler/Version:_11.4.1
_CMake Version:_3.20.2