I modeled b1 and defined a variable to store the energy deposition in the grid as
std::vector<G4Accumulable<G4double>> fEdep= std::vector<G4Accumulable<G4double>>(5000, 0.0f);
and fill the energy deposition in the step.
if (volume == fEdpVolume1) {
G4double energyDeposit = step->GetTotalEnergyDeposit();
G4ThreeVector point = step->GetPostStepPoint()->GetPosition();
G4double gridSizeX = (radius * 2) / 100; //
G4double gridSizeZ = thickness / 50; //
G4double offsetX = point.x() + radius; //
G4double offsetZ = point.z() - 1*cm; //
G4int i = static_cast<G4int>(offsetX / gridSizeX)+1;
G4int k = static_cast<G4int>(offsetZ / gridSizeZ)+1;
G4int index = (i-1) * 50 + k;
// G4cout<<"i is " <<i<<" k is "<<k<<" index is "<<index<<G4endl;
if (0 <= i && i < 101&& 0 <= k && k < 51)
fEventAction->AddEdep(energyDeposit, index - 1);
fEventAction->AddEdp(energyDeposit);
}
}
However, the deposition in some grids will be greater than the total energy deposition in the geometry.
Please help!