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->OpenFile("output.root");
man->CreateNtuple("Hits", "Hits");
man->CreateNtupleIColumn("fEvent");
man->CreateNtupleDColumn("fX");
man->CreateNtupleDColumn("fY");
man->CreateNtupleDColumn("fZ");
man->FinishNtuple(0);
}
void MyRunAction::EndOfRunAction(const G4Run*)
{
G4AnalysisManager *man = G4AnalysisManager::Instance();
man->Write();
man->CloseFile();
}
and in detector.cc:
G4bool MySensitiveDetector::ProcessHits(G4Step *aStep, G4TouchableHistory *ROHist)
{
G4Track *track = aStep->GetTrack();
track->SetTrackStatus(fStopAndKill);
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]);
man->AddNtupleRow(0);
}
I am using Geant4 version 10.06, on ubuntu terminal, gcc version 8.5.0, cmake version 3.20.2.
Thank you