How to get Edep histogram in ROOT?

I made a simulation of Co-60, but I do not know what happen when I try to save the data. What I need is this spectrum
I have these results, but I can not made the gamma spectrum of Co-60:

I made the saving in RunAction:
void runaction::BeginOfRunAction(const G4Run*){
// initializate the run manager to store the hits
G4AnalysisManager*man = G4AnalysisManager::Instance();
// create the root file


man->CreateNtuple("Hits","Edep in NaI");


and in my sensitive detector class:


G4bool sensitivedetector::ProcessHits(G4Step* aStep,G4TouchableHistory* ROhist){
G4double edep= aStep->GetTotalEnergyDeposit();
// show us the edep
G4cout<< "Energy deposited is"<<edep<<G4endl;

G4AnalysisManager*man = G4AnalysisManager::Instance();



Hi, you are saving the edep of each hit in your detector. I think you should integrate the edep of the hits within one event. Look at the Sensitive Detector Class of the radioprotection advanced example. There, the edep of the hits is integrated at the end of each event.


I was trying to get gamma spectra of Co-60, but the ntuple gives me that.

Can you explain me better?
Also, I made a histogram, but it does not have sense.

It looks like you are recording each individual energy deposit from each step in the event. If your simulation is simple, where the only active volume is the detector, then what you should do is sum (integrate) all of the Edep values in each event.

The total energy will have a peak at the incident gamma energy, and will have a tail corresponding to energy which was “lost” (secondaries which escape out of the detector volume).

What is the way to do that?
I am saving edep in sensitive detector class and making ntuples with run action. I can not understand.

Should you response me, I will thank you a lot.

In your N-tuple, include the event number. Then, in your analysis code afterward, as you loop over rows, sum up all the Edep values for the same event number.

Can you show me an example please?
It is still not understood.

As mentioned in my first post, look at the radioprotection example, in the Sensitive Detector Class

See Example B3a and edit “” this line
G4int Z = 27, A = 60; \\for Co-60

Gamma spectrum of Co-60