Please fill out the following information to help in answering your question, and also see tips for posting code snippets. If you don’t provide this information it will take more time to help with your problem!
_Geant4 Version: 11.1
_Operating System: Ubuntu 20.04
Compiler/Version:
CMake Version:
Dear all,
I want to simulate HPGe detector response by using Geant4. Does anyone have a way to generate Gauss peaks? I tried to use Root to read results and add a sigma factor, but it was incorrect. So is there any way to directly handle the results of each step or event?
Root file analysis:
void readNTuple()
{
gROOT->Reset();
gROOT->SetStyle("Plain");
TFile* f = new TFile("defaultFilename.root", "READ");
// list all Tree and Historgram
f->ls();
TTree* tree = (TTree*)f->Get("HPGe;1");
tree->Print();
double eDep;
tree->SetBranchAddress("fEdep", &eDep);
int entries;
entries = tree->GetEntries();
cout << "Number of entries: " << entries << endl;
TH1D* eDepHist = new TH1D("HPGe Histogram", "Deposition Energies", 200, 0., 2.);
TH1D* eDepFittedHist = new TH1D("HPGe Histogram", "Deposition Energies", 200, 0., 2.);
double Ei;
double sigma;
for(int i=0; i<entries; ++i)
{
tree->GetEntry(i);
Ei = (eDep + gRandom->Rndm());
sigma = (0.5/100)*Ei; // 0.5%
eDepHist->Fill(eDep);
eDepFittedHist->Fill(gRandom->Gaus(Ei,sigma));
}
// Draw
TCanvas* c1 = new TCanvas("c1", " ", 20, 20, 800, 1000);
c1->Divide(1, 2);
// Draw pad 1
c1->cd(1);
// gPad->SetLogy(1);
eDepHist->SetTitle("HPGe Spectrum ");
eDepHist->GetXaxis()->CenterTitle(true);
eDepHist->GetYaxis()->CenterTitle(true);
eDepHist->GetXaxis()->SetTitle("MeV");
eDepHist->GetYaxis()->SetTitle("Counts");
eDepHist->Draw("HIST");
// Draw pad 2
c1->cd(2);
eDepFittedHist->SetTitle("HPGe Fitted Spectrum");
eDepFittedHist->GetXaxis()->CenterTitle(true);
eDepFittedHist->GetYaxis()->CenterTitle(true);
eDepFittedHist->GetXaxis()->SetTitle("MeV");
eDepFittedHist->GetYaxis()->SetTitle("Counts");
eDepFittedHist->Draw("HIST");
}