Scoring variance

Hello!

I am a relatively new user of Geant4, and need some help with the primitive scorers.

In the example extended/biasing/B01, eight scorers were defined. In order to suit my needs, I have changed one of them from G4PSTrackLength to G4PSEnergyDeposit, in order to score the energy deposited. Now, I would like to calculate the variance of this Dose. Is it possible to square the dose deposited for each event before it gets summed up? Or is there another way to find the uncertainty of the dose deposited at the end of a run?

Thank you and best regards,
Tan

Hello TgTAN.
The scorers used in that example are “primitive scorers”, which do their job just fine, unless, as in your case, you want some additional fine control over what happens on detector hit.
For that purpose, you’d want to implement your very own SensitiveDetector, by inheriting from G4VSensitiveDetector, and defining what exact procedures are to be performed on each detector hit via overriding the ProcessHits virtual function.
The ProcessHits function has G4Step as an argument, and is called by system on every detector hit (on every step in the detector volume, actually). The G4Step variable supplied can be used to extract all sorts of information about the current track, including energy, current coordinate, particle type, etc. You then use what is relevant to you, and add an entry to the HitCollection.

Hello akimzav,

Thank you for the quick and helpful reply! I saw that G4PSTrackLength has multiple options to weigh the hits with energy or divide by velocity, and was hoping that I could do something similar on G4PSEnergyDeposit. I see now that you are right; defining my own sensitive detector is probably the best way to go about this.

Thank you once again for your quick and helpful suggestion!

Best regards,
Tan