@khushbakht123, I would suggest that a better way to handle the finite detector resolution is to add noise to the signals after the detection, rather than modifying the energy of the incident gammas.
In the real world, the gammas are actually monochromatic. If you modify their energy, their interactions with the environment and your detector will not be correct. Granted, the energy resolution of a germanium detector is very small, so the effect would be very minor in this case. But as a general practice itβs better to add the resolution afterwards, since this is the way it actually occurs in nature.
You have (at least) two options for implementing the resolution, depending on your needs. If you care only about the spectrum and you plan to simulate large numbers of events (as you showed) so that the noise in the spectrum is very low, then a simple approach is to take a convolution of your spectrum with a Gaussian having the desired standard deviation, representative of the noise.
Alternatively, if you are interested in the event-by-event effect of finite resolution, then you need to add a random number to the energy deposited in the detector. You would choose the random number from a Gaussian distribution having the desired width.
I hope this is helpful. Best of luck!