Empty root output file

Hi Everyone,
I am new to Geant4 and I am learning by following the youtube tutorial by “Physics Matters” in this link.

I have successfully made it to part 8 with a running simulation, but when I try to add the scoring in a root file, the file comes out with empty branches.

The relevant parts of the code are:
In run.cc:

void MyRunAction::BeginOfRunAction(const G4Run*)
    G4AnalysisManager *man = G4AnalysisManager::Instance();

    man->CreateNtuple("Hits", "Hits"); 

void MyRunAction::EndOfRunAction(const G4Run*)
    G4AnalysisManager *man = G4AnalysisManager::Instance();

and in detector.cc:

G4bool MySensitiveDetector::ProcessHits(G4Step *aStep, G4TouchableHistory *ROHist)
    G4Track *track = aStep->GetTrack();

    G4StepPoint *preStepPoint = aStep->GetPreStepPoint();
    G4StepPoint *postStepPoint = aStep->GetPostStepPoint();

    G4ThreeVector posPhoton = preStepPoint->GetPosition();

    //G4cout << "Photon position: " << posPhoton << G4endl;

    const G4VTouchable *touchable = aStep->GetPreStepPoint()->GetTouchable();

    G4int copyNo = touchable->GetCopyNumber();

    //G4cout << "Copy number: " << copyNo << G4endl;

    G4VPhysicalVolume *physVol = touchable->GetVolume();
    G4ThreeVector posDetector = physVol->GetTranslation();

    //G4cout << "Detector position: " << posDetector << G4endl;

    G4int evt = G4RunManager::GetRunManager()->GetCurrentEvent()->GetEventID();

    G4AnalysisManager *man = G4AnalysisManager::Instance();
    man->FillNtupleIColumn(0, evt);
    man->FillNtupleDColumn(1, posDetector[0]);
    man->FillNtupleDColumn(2, posDetector[1]);
    man->FillNtupleDColumn(3, posDetector[2]);

I am using Geant4 version 10.06, on ubuntu terminal, gcc version 8.5.0, cmake version 3.20.2.

Thank you

As far as I can see, that tutorial uses Geant4 10.7, whilst you’re using 10.6. Have you tried with 10.7, or a more recent version and the official examples? If it’s a problem with that tutorial, you should contact its author directly.


I am not familiar with that tutorial, so I can give just general suggestion. Did you check that when you uncomment the lines with G4cout in MySensitiveDetector::ProcessHits, you can see these printings in the output?

Best regards,

Thank you both, it was indeed a problem with the version. I updated to the latest version (11.2.0) and the problem was solved.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.