Using Scoring Volume to get the energy deposit

Hello G4 Community,

I am trying to get the total energy deposit through scoring volume. I wrote the following code at the end of my steppingaction.cc file:

if ((volume = fScoringVolume))
{
G4double edep = step ->GetTotalEnergyDeposit();
fEventAction->AddEdep(edep);
}

My Question is that by using the above code, I am getting the energy deposit but being new to the programming, I am not sure that only β€œ=” is right in if statement. If I write

if(volume == fScoringVolume)
then I am not getting any energy deposit. I also tried,

if(volume!=fScoringVolume) but again there is no energy deposit. It is only in the first case that I am getting something.

I am not sure about the validity of the final result. I know this seems more like a programming type of question but any help would be highly appreciated.

1 Like

Hello, Rajat Aggarwal

I think, in the first case(if ((volume = fScoringVolume))), your code just puts fScoringVolume into volume, and then adds all energy deposition for all particle trajectories.

β€˜if(volume == fScoringVolume)’ will work well, but most likely there is a problem when defining the β€˜volume’. It would be better to refer to exampleB1 to find the problem.

Good luck!

Jaeyoung Jeong