Scoring Energy spectrum using primitive scorer

Dear Experts,
I am beginner in Geant4. I have modified geant4/examples/basic/B4d input to score energy spectrum in the sensitive volume. I have used the following code for energy binning
char name[16];
for (G4int i=0; i<48;i++){
std::sprintf(name,“current%03d”,i);
G4String name;
primitive= new G4PSSphereSurfaceCurrent(“current”, fcurrent_in);
G4double kmin=i0.025MeV;
G4double kmax=(i+1)0.025MeV;
G4SDParticleWithEnergyFilter*filter=new G4SDParticleWithEnergyFilter(flrname = “filter”);
filter->add(“gamma”);
filter->SetKineticEnergy(kmin,kmax);
primitive->SetFilter(filter);
logvol->RegisterPrimitive(primitive);

Now, how I will modify B4dEventAction.cc and B4dRunAction.cc to get histogram in the format of (energy-bin vs counts)?

Kindly give me some suggestion.
Thanking you in advance.

Hello,

I am not sure if G4PSSphereSurfaceCurrent scorer is the right choice for your purpose.
Did you also modify geometry and your sensitive volume is of sphere shape?

To get a histogram which will display the counts collected in the scorers per each energy, you need to define the histogram with the min,max = your energy range, and the same number of bins as for your scorers.

Then you have to fill the histogram in a similar loop to which you use to define the scorers:

for (G4int i=0; i<48;i++){
  - get the energy corresponding to this interval: Ek = (kmax-kmin)/2. 
  - get the scorer counts - countsk
  - fill your histogram where the filled value will be the energy and tge counts
     analysisManager->FillH1(histoId, Ek, countsk);
}

Best regards,

1 Like