How do I store energy values in a histogram?

Following an example I have the following working at the moment:

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);

||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);

but how do I get the energy information of the particles?
I hope this code is sufficient to comprehend my doing? Otherwise I’ll add more code.

Thanks a lot in advance!

Hi @BenjaminW ,
To store the variable , you can use codes like

man->FillNtupleIColumn(0, 0, evt);
man->FillNtupleDColumn(0,1, posDetector[0]);

To get the energy information, you can use G4StepPoint class to get total energy or the deposited energy.

G4StepPoint *preStepPoint = aStep->GetPreStepPoint();
G4double totalEnergy=preStepPoint->GetTotalEnergy();
man->FillNtupleDColumn(0,4, totalEnergy);

Best

1 Like

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