  In order to better understand energy estimation of electromagnetic showers in
segmented calorimeters, detailed Geant4 simulation studies of electromagnetic
showers in the energy range 1--100 GeV in CsI have been performed. When sampled
in layers of 1.99 cm thickness, corresponding to 1.08 radiation lengths, the
energy fluctuations in the samples show distributions that vary significantly
with depth. The energy distributions are similar for incident electrons and
photons and were found to change systematically along the shower, varying
little with the initial energy. Three probability distributions have been
fitted to the data: negative binomial, log-normal and Gaussian distributions,
none of which gives a good fit over the full shower length. The obtained
parameterizations might be useful in the use of the maximum likelihood method
for estimating the energy. Two methods for estimating the energy have also been
studied. One method is based on fitting individual longitudinal shower profiles
with a $\Gamma$-function, the other one corrects the measured energy for
leakage by utilizing the energy deposited in the last layer. Our simulations
indicate that the last-layer correction method applied to photons and electrons
of 1 and 10 GeV gives about a factor of 2 improvement in the energy resolution.
