%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                 %
%  GEANT manual in LaTeX form                              %
%                                                                 %
%  Michel Goossens (for translation into LaTeX)                   %
%  Version 1.00                                                   %
%  Last Mod. Jan 24 1991  1300   MG + IB                          %
%                                                                 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Origin{L. Urb\'{a}n}
\Version{Geant 3.16}\Routid{PHYS340}
\Submitted{28.05.86} \Revised{16.12.93}
\Makehead{Total cross-section and energy loss for bremsstrahlung
by e-e+}

\section{Subroutines}
\Shubr{GBRELA}{}
\Rind{GBRELA} fills the tables for the energy loss of electrons,
positrons and muons due to
bremsstrahlung at initialisation time for different materials.
The energy
binning is set within the array \texttt{ELOW} (common \FCind{/CGMULO/}) in the
routine \Rind{GPHYSI}. In the tables, the dE/dx due to bremsstrahlung
is summed with that due to the ionisation. For energy loss
of electrons and positrons, \Rind{GBRELA} calls the function \Rind{GBRELE}.
Following pointers are used:
\begin{DLtt}{MMMMMMMMMMMMMMMMM}
\item[JMA = LQ(JMATE-I)] pointer to the I$^{th}$ material;
\item[JEL1 = LQ(JMA-1)]  pointer to $dE/dx$ for $\Pem$;
\item[JEL1+NEK1]           pointer to $dE/dx$ for $\Pep$.
\end{DLtt}
\Rind{GBRELA} is called at initialisation time by \Rind{GPHYSI}.
\Sfunc{GBRELE}{VALUE = GBRELE(ZZ,T,BCUT)}
\Rind{GBRELE} calculates the energy loss due to bremsstrahlung
of an electron with kinetic energy {\tt T} in material
with atomic number {\tt ZZ}.
It is called by \Rind{GBRELA} and for energies below the cut
{\tt BCUT} it adds the contribution of bremsstrahlung to.
Above this cut, the bremsstrahlung process is simulated
explicitly (see {\tt [PHYS341]}) and tabulation of these continuous losses
is not needed. \Rind{GBRELE} is called by \Rind{GBRELA}.
\Sfunc{GBFLOS}{VALUE = GBFLOS(T,C)}
\Rind{GBFLOS} calculates a weight factor for the positron continuous
bremsstrahlung energy loss. {\tt T} is the kinetic energy in GeV of the
positron and C is the energy cut for bremsstrahlung ({\tt BCUTE}). The
value is the ratio of the energy loss due to bremsstrahlung of the
positron to that of the electron so that:
$<${\it positron loss}$>$ = \Rind{GBFLOS} $\times$ $<${\it electron loss}$>$.
\Rind{GBFLOS} is called by \Rind{GBRELA}.
\Shubr{GBRSGA}{}
\Rind{GBRSGA} calculates the total cross-section for bremsstrahlung
in all materials. It tabulates the mean free path, $\lambda =
\frac{1}{\Sigma}$ (in cm) as a function of medium and energy. The energy
binning is set within the array {\tt ELOW} (common \FCind{/CGMULO/}) in the
routine \Rind{GPHYSI}. The following pointers are used:
\begin{DLtt}{MMMMMMMMMMMMMMMMMMN}
\item[JMA = LQ(JMATE-I)]pointer to the I$^{th}$ material
\item[JBREM = LQ(JMA-9)]pointer to bremsstrahlung cross-sections
\item[JBREM            ]pointer for  $\Pem$
\item[JBREM+NEK1       ]pointer for  $\Pep$
\item[JBREM+2*NEK1     ]pointer for $\mu^+/\mu^-$
\end{DLtt}
\Rind{GBRSGA} is called at initialisation time by \Rind{GPHYSI}.
\Sfunc{GBRSGE}{VALUE = GBRSGE(ZZ,T,BCUT)}
\Rind{GBRSGE} calculates the total cross-section of
bremsstrahlung of an electron with kinetic energy {\tt T}
in material with atomic number {\tt ZZ}.
It is called by \Rind{GBRSGA}. For kinetic energies
which are below the cut {\tt BCUT} or
for which bremsstrahlung process is not simulated
explicitly (see {\tt [PHYS341]}) it returns 0.
\Sfunc{GBFSIG}{VALUE = GBFSIG(T,C)}
\Rind{GBFSIG} calculates a
weight factor for the positron discrete (hard) bremsstrahlung cross section.
{\tt T} is the kinetic energy in GeV of the
positron and C is the energy cut for bremsstrahlung ({\tt BCUTE}). The
value returned is the ratio of the positron bremsstrahlung cross-section
to that of the electron so that:
<{\it positron cross-section}> = \Rind{GBFSIG} $\times$ <{\it electron
cross-section}>.  \Rind{GBFSIG} is called by \Rind{GBRSGA}.
\section{Method}
Let's call $d\sigma(Z,T,k)/dk$ the differential cross-section for
production of a photon of energy $k$ by an electron of kinetic energy
$T$ in the field of an atom of charge $Z$, and
$k_c$ the energy cut-off below which the soft photons are treated
as continuous energy loss ({\tt BCUTE} in the program).
Then the mean value of the energy lost by the electron due
to soft photons is
\begin{equation}
  E_{Loss}^{brem} (Z,T,k_c ) =
\int_{0}^{k_ c}k\frac{d \sigma (Z,T,k)}{dk}dk
\end{equation}
whereas the total cross-section for the emission of
a photon of energy larger than $k_c$ is
\begin{equation}
 \sigma_{brem} (Z,T,k_c ) = \int_{k_c}^{T}\frac{d \sigma (Z,T,k)}{dk} dk
\end{equation}
Many theories of the bremsstrahlung process exist, each with its own
limitations and regions of applicability. Perhaps the best synthesis
of these theories can be found in the paper of S.M. Seltzer and M.J.
Berger \cite{bib-SEL1}. The authors give a tabulation of the
bremsstrahlung cross-section $d\sigma/dk$ differential in the photon
energy $k$, for electrons with kinetic energies $T$ from 1 keV to 10
GeV. For electron energies above 10 GeV the screened Bethe-Heitler
differential cross-section can be used
\latexhtml{\cite{bib-EGS3,bib-NELS}}{\cite{bib-EGS3}, \cite{bib-NELS}}
together with the Midgal
corrections~\latexhtml{\cite{bib-MES1,bib-MIGD}}%
                      {\cite{bib-MES1}, \cite{bib-MIGD}}.
The first of the two Migdal corrections is
important for very high electron energies only ($T \geq$ 1 TeV) and
has the effect of reducing the cross-section.  The second Migdal
correction is effective even at ``ordinary'' energies (100 MeV -- 1
GeV) and it decreases the differential cross-section at photon
energies below a certain fraction of the incident electron energy
($d\sigma/dk$ decreases significantly if $ k/T \leq 10^{-4}$.)

\subsection{Parameterisation of energy loss and total cross-section}
Using the tabulated cross-section values of Seltzer and Berger together
with the Migdal corrected Bethe-Heitler formula we have computed
$\sigma(Z,T,k_c ) $
and we have used these computed values as ``data points''
in the fitting procedure.
Calculating the ``low energy'' ($T\leq 10$ GeV) data we have applied the
second Midgal correction to the results of Seltzer and Berger.
We have chosen the parameterisations:
\begin{equation}
\label{eq:phys340-1}
\sigma (Z,T,k_c ) =\frac{Z(Z+\xi_{\sigma} )(T+m)^2}
     {T(T+2m)}[ \ln (T/k_c )]^\alpha F_{\sigma} (Z,X,Y)
\mbox{\quad(barn)}\\
\end{equation}
and
\begin{equation}
\label{eq:phys340-2}
E_{Loss}^{brem} (Z,T,k_c ) =\frac{Z(Z+ \xi_l)(T+m)^2 }
      {(T+2m)}\left[\frac{k_c C_ M }{T}\right]^\beta
      F_{l} (Z,X,Y) \mbox{\quad(GeV barn)}
\end{equation}
where  $m$ is the mass of the electron,
\[
\begin{array}{LLL}
X = \ln(E/m), & Y = \ln (v_{\sigma} E/k_c) &
\mbox{\quad for the total cross-section }\sigma \\
X = \ln(T/m), & Y = \ln(k_c/v_lE)       &
\mbox{\quad for the energy loss }  E_{Loss}^{brem}  \\
\end{array}
\]
with $E=T+m$.
The constants $\xi_{\sigma},\ \xi_l,\ \alpha,\ \beta,\ v_{\sigma},\ v_l$
are parameters to be fitted.
\begin{eqnarray*}
C_M &=&\frac{\Dstm 1}{1+\frac{\Tstm n r_0 \lambdar^2  (T+m)^2}{\Tstm\pi k^2_c}}
\end{eqnarray*}
is the Midgal correction factor, with
\begin{DLtt}{MM}
\item[$r_o$] classical electron radius;
\item[$\lambdar$] reduced electron Compton wavelength;
\item[$n$] electron density in the medium.
\end{DLtt}
The factors $(T+m)^2/T(T+2m)$ and $(T+m)^2/(T+2m)$ come from
the scaled cross-section computed by Seltzer and Berger:
\[
f(k/T) = \frac{\beta^2}{Z^2 }k\frac{d \sigma}{dk}
       = \frac{T(T+2m)} {(T+m)^2 Z^2}  k \frac{d \sigma}{dk}
\]

The functions $F_i(Z,X,Y)$ ($ i=\sigma,l $) have the form
\begin{equation}
 F_i(Z,X,Y) = F_{i0}(X,Y)+ZF_{i1}(X,Y)
\end{equation}
where $\Dstm F_{ij}(X,Y)$ are polynomials of the variables $\Dstm X,Y$
\begin{eqnarray}
F_{i0}(X,Y) & = &  (C_1+C_2X+\ldots+C_6X^5)+(C_7+C_8X+\ldots+C_{12}X^5)Y
                                                             \nonumber \\
          &   & +(C_{13}+C_{14}X+\ldots + C_{18}X^5)Y^2+\ldots
                +(C_{31}+C_{32}X+\ldots+C_{36}X^5)Y^5                  \\
          &   & \mbox{\hspace{11cm}} \Bbfm Y\leq 0  \Ebfm    \nonumber \\
          & = &  (C_1+C_2X+\ldots+C_6X^5)+(C_7+C_8X+\ldots+C_{12}X^5)
                                                             \nonumber \\
          &   & +(C_{37}+C_{38}X+\ldots+C_{42}X^5)Y^2+\ldots+
                 (C_{55}+C_{56}X+\ldots+C_{60}X^5)Y^5        \nonumber \\
          &   & \mbox{\hspace{11cm}} \Bbfm Y > 0\Ebfm        \nonumber \\
F_{i1}(X,Y) & = &  (C_{61}+C_{62}X+\ldots+C_{65}X^4)
                +(C_{66}+C_{67}X+\ldots+C_{70}X^4)Y          \nonumber \\
          &   & +(C_{71}+C_{72}X+\ldots+C_{75}X^4)Y^2+\ldots
                +(C_{81}+C_{82}X+\ldots+C_{85}X^4) Y^4                 \\
          &   &   \mbox{\hspace{11cm}} \Bbfm Y\leq 0\Ebfm    \nonumber \\
          & = &  (C_{61}+C_{62}X+\ldots+C_{65}X^4)
                +(C_{66}+C_{67}X+\ldots+C_{70}X^4)Y          \nonumber \\
          &   & +(C_{86}+C_{87}X+\ldots+C_{90}X^4)Y^2+\ldots
                +(C_{96}+C_{97}X+\ldots+C_{100}X^4)Y^4       \nonumber  \\
          &   &  \mbox{\hspace{11cm}} \Bbfm Y>0 \Ebfm        \nonumber \\
\end{eqnarray}
$F_{ij}(X,Y)$ denotes in fact a function constructed from two
polynomials
\[
F_{ij}(X,Y) = \left \{
\begin{array}{ll}
F_{ij}^{neg}(X,Y) & \mbox{for\hspace{0.5cm}} Y\leq 0 \\
F_{ij}^{pos}(X,Y) & \mbox{for\hspace{0.5cm}} Y>0
\end{array} \right .
\]
where the polynomials $F_{ij}$ fulfil the conditions
\[
F_{ij}^{neg}(X,Y)_{Y=0} = F_{ij}^{pos}(X,Y)_{Y=0}   \hspace{2cm}
\left ( \frac{\partial F_{ij}^{neg}}{\partial Y} \right )_{Y=0} =
\left ( \frac{\partial P_{ij}^{pos}}{\partial Y} \right )_{Y=0}
\]
We have computed 4000 ``data points'' in the range
\[
Z = 6  ;  13  ;  29  ;  47  ;  74  ;  92  \hspace{1cm}
10 \: \mbox{keV} \leq T \leq 10 \: \mbox{TeV}  \hspace{1cm}
10 \: \mbox{keV} \leq k_c \leq T
\]
and we have performed a least-squares fit to determine the parameters.

The values of the parameters ($\xi_{\sigma}$, $\alpha$,
$v_{\sigma}$, $C_i $ for $\sigma$ and
$\xi_l$, $\beta$, $V_l$, $C$ for $E_{Loss}^{brem}$)
can be found in the {\tt DATA}
statement within the functions
\Rind{GBRSGE} and \Rind{GBRELE}  which compute the formula (\ref{eq:phys340-1})
and (\ref{eq:phys340-2}) respectively.

The errors of the parameterisations (\ref{eq:phys340-1}) and (\ref{eq:phys340-2})
can be estimated as

\begin{eqnarray*}
\frac{\Delta\sigma} {\sigma} & = & \left \{
\begin{array}{llr}
        12-15\%    & \mbox{for    } & T \leq 1 MeV \\
        \leq 5-6\% & \mbox{for    } & 1 MeV < T \leq 10 TeV
\end{array}
\right . \\[1cm]
\frac{\Delta E_{Loss}^{brem}}
     {E_{Loss}^{brem}} & = & \left \{
\begin{array}{llr}
        10-15\%    & \mbox{for    } & T \leq1 MeV  \\
        5-6\%      & \mbox{for    } & 1 MeV < T \leq 100 GeV\\
        10\%       & \mbox{for    } & 100 GeV < T \leq10 TeV
\end{array}
\right .
\end{eqnarray*}

We have performed a fit to the ``data'' without the Midgal corrections, too.
In this case we used the data of Seltzer and Berger without any
correction for $T \leq 10$ GeV and we used the Bethe-Heitler cross-section
for $T \geq 10$ GeV. The parameterised forms of the cross-section and
energy loss are the same as they were in the first fit (i.e. (\ref{eq:phys340-1})
and (\ref{eq:phys340-2})), only the numerical values of the parameters
have changed.
These values are in {\tt DATA} statements in the functions \Rind{GBRSGE}
and \Rind{GBRELE} and this second kind of parameterisation can be activated
using the \Rind{PATCHY} switch {\tt +USE,BETHE}. (The two
parameterisations give different results for high electron energy.)

The energy loss due to soft photon bremsstrahlung is tabulated at
initialisation time as a function of the medium and of the energy by
routine \Rind{GBRELA} (see {\tt JMATE} data structure).

The mean free path for discrete bremsstrahlung is tabuled at initialisation
time as a function
of the medium and of the energy by routine \Rind{GBRSGA} (see
{\tt JMATE} data structure).

\subsection{Corrections for $\Pem/\Pep$ differences}

The radiative energy loss for electrons or positrons is:

\begin{eqnarray*}
-\frac{1}{\rho} \left ( \frac{dE}{dx} \right )_{rad}^{\pm} & = &
\frac{N_{Av} \alpha r_e^2}{A} (T+m) Z^2 \Phi_{rad}^{\pm}(Z,T) \\
\Phi^{\pm}_{rad}(Z,T) & = & \frac{1}{\alpha r_{e}^2 Z^2 (T+m)}
\int^{T}_{0}{k\frac{d\sigma^{\pm}}{dk}dk}
\end{eqnarray*}

Reference \cite{bib-KIM1} says that: \\
{\it ``The differences between the radiative loss of positrons
and electrons are considerable and cannot be disregarded.

[...] The ratio of the radiative energy loss for positrons
to that for electrons obeys a simple scaling law, [...] is a
function only of the quantity $T/Z^2$''}

In other words:

\begin{eqnarray*}
\eta & = & \frac{\Phi_{rad}^{+}(Z,T)}{\Phi_{rad}^{-}(Z,T)} =
\eta \left (\frac{T}{Z^2}\right )
\end{eqnarray*}

The authors have calculated this function in the range $10^{-7}
\leq \frac{T}{Z^2} \leq 0.5$ (here the kinetic energy T is
expressed in MeV). Their {\it data} can be fairly accurately
reproduced using a parametrisation:

\begin{eqnarray*}
\eta & = & \left \{
\begin{array}{llr}
0 & \mbox{if   } & x \leq -8 \\
\frac{1}{2} + \frac{1}{\pi} \arctan \left( a_1 x + a_3 x^3
+ a_5 x^5 \right ) & \mbox{if  } & -8 < x < 9 \\
1 & \mbox{if   } & x \geq 9
\end{array}
\right .
\end{eqnarray*}

where:

\begin{eqnarray*}
x & = & \log \left ( C \frac{T}{Z^2} \right ) \mbox{(T in GeV)} \\
C & = & 7.5221 \times 10^{6} \\
a_1 & = & 0.415 \\
a_3 & = & 0.0021 \\
a_5 & = & 0.00054
\end{eqnarray*}

This $\Pem/\Pep$ energy loss difference is not a pure low-energy
phenomenon (at least for high Z), as it can be seen from
Tables~\ref{tb:phys340-1}, \ref{tb:phys340-2} and \ref{tb:phys340-3}.

\begin{table}[hbt]
\begin{centering}
\begin{tabular}{rr|r|r} \hline
\multicolumn{1}{c}{$\frac{T}{Z^2} (GeV)$}
& \multicolumn{1}{c|}{T}
& \multicolumn{1}{c|}{$\eta$}
& \multicolumn{1}{c}{$\left ( \frac{rad. \ loss}{total \ loss}
\right )_{e^-}$} \\[3mm] \hline
$10^{-9}$ & $\sim 7 keV$ & $\sim 0.1$ & $\sim 0\%$ \\
$10^{-8}$ & $67 keV $ & $\sim 0.2$ & $\sim 1\%$ \\
$2 \times 10^{-7}$ & $1.35 MeV$ & $\sim 0.5$ & $\sim 15\%$ \\
$2 \times 10^{-6}$ & $13.5 MeV$ & $\sim 0.8$ & $\sim 60\%$ \\
$2 \times 10^{-5}$ & $135. MeV$ & $\sim 0.95$ & $> 90\%$ \\ \hline
\end{tabular}
\caption{ratio of the $\Pem/\Pep$ radiative energy loss in lead
(Z=82).}
\label{tb:phys340-1}
\end{centering}
\end{table}

The scaling holds for the ratio of the total radiative energy
losses, but it is significantly broken for the photon spectrum
in the screened case.
In case of a point Coulomb charge the
scaling would hold also for the spectrum.
The scaling can be expressed by:

\begin{eqnarray*}
\frac{\Phi^+}{\Phi^-} = \eta \left ( \frac{T}{Z^2} \right )
& \hspace{3cm} &
\frac{\frac{d\sigma^+}{dk}}{\frac{d\sigma^-}{dk}} =
\mbox{does not scale}
\end{eqnarray*}

If we consider the photon spectrum from bremsstrahlung reported
in \cite{bib-KIM1} we see that:

\begin{eqnarray*}
\frac{d\sigma^{\pm}}{dk} = S^{\pm} \left( \frac{k}{T} \right )
\hspace{2cm}
\frac{S^{+}(k)}{S^{-}(k)} \leq 1 & \hspace{1cm} & S^{+}(1) = 0
\hspace{2cm} S^{-}(1)  >  0
\end{eqnarray*}

\begin{table}[hbt]
\begin{centering}
\begin{tabular}{l|rrr|rrr}
\hline
\multicolumn{1}{c}{T(MeV)}
& \multicolumn{3}{|c|}{C}
& \multicolumn{3}{c}{Pb} \\[2mm]
\hspace{1cm}
& $\Delta E^{0}_{l}$ & $\Delta E_{l}$ & $\Delta \sigma_{l}$
& $\Delta E^{0}_{l}$ & $\Delta E_{l}$ & $\Delta \sigma_{l}$ \\
\hline
0.02   & -2.86 & -2.86 & +52.00 & -4.89 & -4.69 & +99.80 \\
0.1    & -0.33 & -0.33 & +21.10 & -0.52 & -0.47 & +81.08 \\
1      & +0.07 & +0.07 &  +6.49 & +0.11 & +0.11 & +48.99 \\
10     &  0.00 &  0.00 &  +1.75 &  0.00 & +0.01 & +23.89 \\
$10^2$ &  0.00 &  0.00 &   0.00 &  0.00 &  0.00 &  +9.00 \\
$10^3$ &  0.00 &  0.00 &   0.00 &  0.00 &  0.00 &  +2.51 \\
$10^4$ &  0.00 &  0.00 &   0.00 &  0.00 &  0.00 &  +0.00 \\
\hline
\multicolumn{7}{c}{\hspace{1cm}} \\
\multicolumn{7}{c}{
$\displaystyle{\Delta E_{l} =
100 \frac{E^{-}_{l}-E^{+}_{l}}{E^{-}_{l}}\%}$ \hspace{5mm} and
\hspace{5mm}
$\displaystyle{\Delta \sigma_{l} =
100 \frac{\sigma^{-}_{l}-\sigma^{+}_{l}}{\sigma^{-}_{l}}\%}$
}
\end{tabular}
\caption{Difference in the energy loss and bremsstrahlung
cross-section for $\Pem/\Pep$ in Carbon and Lead with a
cut for $\gamma$ and $e^{\pm}$ of 10keV. $\Delta E^{0}_{l}$ is
the value without the correction for the difference
$\Pem/\Pep$.}
\label{tb:phys340-2}
\end{centering}
\end{table}

We further assume that:

\begin{eqnarray}
\frac{d\sigma^+}{dk} = f(\epsilon) \frac{d\sigma^-}{dk}
& \hspace{2cm} &
\epsilon = \frac{k}{T}
\label{eq:phys340-3}
\end{eqnarray}

In order to satisfy approximately the scaling law for the ratio
of the total radiative energy loss, we require for $f(\epsilon)$:

\begin{eqnarray}
\int^{1}_{0}{f(\epsilon)d\epsilon} & = & \eta
\label{eq:phys340-4}
\end{eqnarray}

From the photon spectra we require:

\begin{eqnarray}
\left .
\begin{array}{l}
f(0) = 1 \\
f(1) = 0
\end{array}
\right \} \hspace{2cm} \mbox{for all $Z,T$}
\label{eq:phys340-5}
\end{eqnarray}

We have chosen a simple function $f$:

\begin{eqnarray}
f(\epsilon) & = & C (1-\epsilon)^{\alpha} \hspace{3cm} C,\alpha > 0
\label{eq:phys340-6}
\end{eqnarray}

\begin{table}[hbt]
\begin{centering}
\begin{tabular}{l|rrr|rrr}
\hline
\multicolumn{1}{c}{T(MeV)}
& \multicolumn{3}{|c|}{C}
& \multicolumn{3}{c}{Pb} \\[2mm]
\hspace{1cm}
& $\Delta E^{0}_{l}$ & $\Delta E_{l}$ & $\Delta \sigma_{l}$
& $\Delta E^{0}_{l}$ & $\Delta E_{l}$ & $\Delta \sigma_{l}$ \\
\hline
2      & +4.19 & +4.21 &  +7.29 & +4.47 & +6.88 & +61.78 \\
10     & +0.87 & +0.87 &  +1.93 & +0.87 & +1.14 & +26.29 \\
$10^2$ & +0.08 & +0.08 &   0.00 & +0.06 & +0.06 &  +9.10 \\
$10^3$ &  0.00 &  0.00 &   0.00 &  0.00 &  0.00 &  +2.42 \\
$10^4$ &  0.00 &  0.00 &   0.00 &  0.00 &  0.00 &  +0.00 \\
\hline
\multicolumn{7}{c}{\hspace{1cm}} \\
\multicolumn{7}{c}{
$\displaystyle{\Delta E_{l} =
100 \frac{E^{-}_{l}-E^{+}_{l}}{E^{-}_{l}}\%}$ \hspace{5mm} and
\hspace{5mm}
$\displaystyle{\Delta \sigma_{l} =
100 \frac{\sigma^{-}_{l}-\sigma^{+}_{l}}{\sigma^{-}_{l}}\%}$
}
\end{tabular}
\caption{Difference in the energy loss and bremsstrahlung
cross-section for $\Pem/\Pep$ in Carbon and Lead with a
cut for $\gamma$ and $e^{\pm}$ of 1MeV. $\Delta E^{0}_{l}$ is
the value without the correction for the difference
$\Pem/\Pep$.}
\label{tb:phys340-3}
\end{centering}
\end{table}

\begin{table}[hbt]
\begin{centering}
\begin{tabular}{r|rr|rr}
\multicolumn{5}{c}{$\displaystyle{100 \frac{E^{+}_{dep}-E^{-}_{dep}}
{\sqrt{\sigma_{+}^{2}+\sigma_{-}^{2}}} (\%)}$} \\[5mm]
\hline
\multicolumn{1}{c}{Depth}
& \multicolumn{2}{c}{C}
& \multicolumn{2}{|c}{Pb} \\
\multicolumn{1}{c|}{($X_{0}$ units)} &
No $e^{\pm}$ diff & $e^{\pm}$ diff &
No $e^{\pm}$ diff & $e^{\pm}$ diff \\
\hline
0.5 &   -11.7 & -13.0 &  -0.8 &  -3.9 \\
1.0 &    -5.3 &  -4.9 &  -1.0 &  -4.1 \\
1.5 &    +7.3 &  +8.0 &  -1.4 &  -3.5 \\
2.0 &    +7.1 &  +5.3 &  -0.7 &  -0.0 \\
2.5 &    +4.9 &  +4.3 &  +1.7 &  +3.6 \\
3.0 &    +4.8 &  +4.1 &  +1.1 &  +4.3 \\
3.5 &    +3.3 &  +2.7 &  +2.7 &  +3.1 \\
4.0 &    +3.6 &  +5.3 &  +2.9 &  +3.0 \\
4.5 &    +1.7 &  +2.8 &  +0.5 &  +2.3 \\
5.0 &    +3.4 &  +3.5 &  -1.9 &  +1.8 \\
\hline
\end{tabular}
\caption{Difference in the shower development
for $\Pem/\Pep$ in Carbon and Lead.
{\it No diff} refers to the
value without the correction for the difference
$\Pem/\Pep$.}
\label{tb:phys340-4}
\end{centering}
\end{table}

from the conditions (\ref{eq:phys340-4}), (\ref{eq:phys340-5}) we get:

\begin{eqnarray*}
C & = & 1 \\
\alpha & = & \frac{1}{\eta} - 1 \hspace{2cm}
\mbox{($\alpha > 0$ because $\eta < 1$)} \\
f(\epsilon) & = & (1-\epsilon)^{\frac{1}{\eta}-1}
\end{eqnarray*}

We have defined weight factors $F_{l}$ and $F_{\sigma}$ for the
positron continuous energy loss and discrete bremsstrahlung cross
section:

\begin{eqnarray}
F_{l} = \frac{1}{\epsilon_{0}} \int^{\epsilon_{0}}_{0}
{f(\epsilon)d\epsilon} & \hspace{3cm} &
F_{\sigma} = \frac{1}{1-\epsilon_{0}} \int^{1}_{\epsilon_{0}}
{f(\epsilon)d\epsilon}
\label{eq:phys340-7}
\end{eqnarray}

where $\epsilon_{0} = \frac{k_c}{T}$ and $k_c$ is the photon
cut {\tt BCUTE}. In this scheme the positron energy loss and
discrete bremsstrahlung can be calculated as:

\begin{eqnarray*}
\left ( - \frac{dE}{dx} \right )^{+} = F_{l}
\left ( - \frac{dE}{dx} \right )^{-} & \hspace{2cm} &
\sigma^{+}_{brems} = F_{\sigma} \sigma^{-}_{brems}
\end{eqnarray*}

As in this approximation the photon spectra are identical, the
same SUBROUTINE is used for generating $\Pem/\Pep$ bremsstrahlung.
The following relations hold:

\begin{eqnarray*}
F_{\sigma} & = & \eta (1-\epsilon_{0})^{\frac{1}{\eta}-1}
< \eta \\
\epsilon_{0} F_{l} + (1-\epsilon_{0}) F_{\sigma} & = & \eta
\hspace{6cm} \mbox{from the def (\ref{eq:phys340-7})} \\
\Rightarrow F_{l} & = & \eta \frac{1-(1-\epsilon_{0})^{\frac{1}
{\eta}})}{\epsilon_{0}} > \eta \frac{1-(1-\epsilon_{0})}
{\epsilon_{0}} = \eta  \hspace{1cm}
\Rightarrow   \left \{
\begin{array}{l}
F_{l} > \eta \\
F_{\sigma} < \eta
\end{array} \right .
\end{eqnarray*}

which is consistent with the spectra.

The effect of this $\Pem/\Pep$ bremsstrahlung difference can be also
seen in e.m. shower development, when the primary energy is not too
high. An example can be found in table~\ref{tb:phys340-4}.


\lab{Getting Started}{Getting Started}
\objective{Introduce basic coding procedures and objects usage in Python.}
\label{lab:Essential_Python}

\section*{Python}
Python is a powerful general-purpose programming language. As an interpreted
language, it can be used interactively.
It is quickly gaining momentum as a fundamental tool in scientific computing because it has the following features:
\begin{itemize}
\item Clear, readable syntax
\item Full object orientation
\item Complete memory management (via garbage collection)
\item High level, dynamic datatypes
\item Extensibility via C
\item Ability to interface with other languages such as R, C, C++, and Fortran
\item Embeddability in applications
\item Portability across many platforms (Linux, Windows, Mac OSX)
\item Open source
\end{itemize}
In addition to these, Python is freely available and can also be freely distributed.

\section*{Running Python}
Python 2.7 is required for the labs in this text and can be downloaded from \url{http://www.python.org/}. Although later versions of
Python are available, they do not have many of the features needed for scientific computing.

Many free IDEs (Integrated Development Environments) and text editors are compatible with Python. We recommend you use IPython, which provides three different interfaces: commandline, QTConsole, and Notebook. You can open these interfaces by running \li{ipython}, \li{ipython qtconsole}, or \li{ipython notebook} respectively.
The commandline interface is the simplest of the three, as it merely adds colored syntax to the text in the terminal window.
The QTConsole provides some extra features not available in the commandline interface.
The Notebook interface has the most features and is displayed in a web browser.

For more information on installing Python and various libraries, see Appendices \ref{win64install} and \ref{pythoninstall}.

\section*{Learning Python}
The remainder of this lab will introduce you to some basic Python data types and control flow blocks. The text for this lab is intended to tell you just enough so that you can create these objects and experiment with them. Each section has additional required readings, listed at its end. Moreover, as you begin your study of Python, we \emph{strongly} suggest you read the following:
\begin{enumerate}
\item Chapters 3, 4, and 5 of the Official Python Tutorial \\
        (\url{http://docs.python.org/2.7/tutorial/introduction.html}).
\item Section 1.2 of the SciPy Lecture Notes\\
        (\url{http://scipy-lectures.github.io/}).
\item PEP8 - Python Style Guide \\
        (\url{http://www.python.org/dev/peps/pep-0008/}).
\end{enumerate}

In addition to these resources, there are other ways to learn Python. One useful aspect of the IPython interfaces is \emph{object introspection}, which allows you to see all the methods associated to an object. Also, you can use a question mark to learn about an object or method.

\begin{lstlisting}
# You can use a pound sign to write a single-line comment.

# To see the methods associated to an object, type the object name followed by a period, and press tab.
>>> list.
list.append   list.extend   list.insert   list.pop      list.reverse
list.count    list.index    list.mro      list.remove   list.sort

# To learn about a method, use "?".
>>> list.append?
Type:       method_descriptor
Base Class: <type 'method_descriptor'>
String Form:<method 'append' of 'list' objects>
Namespace:  Python builtin
Docstring:  L.append(object) -- append object to end
\end{lstlisting}

Finally, if you cannot answer your question using these strategies, try googling it. Many common questions about Python programming have been answered on internet forums.

\section*{Data Types}
\subsection*{Numerical Types}
There are four numerical data types, \li{int}, \li{long},
\li{float}, and \li{complex}, each of which stores a certain kind of number.

\begin{lstlisting}
>>> type(3)
int

>>> type(3.0)
float
\end{lstlisting}

Python can be used as a calculator. Use \li{**} for exponentiation.
\begin{lstlisting}
>>> 3**2 + 2*5
19
\end{lstlisting}

We can also create and manipulate variables with Python.

\begin{lstlisting}
# Use a SINGLE equals sign to create a variable.
>>> x = 12
>>> y = 2 * 6

# Use a DOUBLE equals sign to check equality of variables.
>>> x == y
True
\end{lstlisting}

Required readings:
\begin{itemize}
\item \url{http://scipy-lectures.github.io/intro/language/basic_types.html#numerical-types}
\item \url{https://docs.python.org/2.7/tutorial/introduction.html#numbers}
\item \url{https://docs.python.org/2.7/library/stdtypes.html#typesnumeric}
\end{itemize}

\begin{problem}
Use the required readings and the strategies listed in the section ``Learning Python'' to help you answer the questions in this lab.
\begin{enumerate}

\item How do you convert an integer to a float? (This is called \emph{casting}.)
\item What are the two ways to create a complex number?
How do you extract the real part or the imaginary part?
\item The way the operator \li{/} behaves depends on the types of its operands.
\begin{enumerate}
\item Why does \li{7/3} return 2?
\item How can you get decimal answers to a division problem like $7/3$?
\item How can you get integer answers when you divide floats?
\end{enumerate}
\end{enumerate}
\end{problem}

\subsection*{Strings}
A Python \li{string} can be created with either single or double quotes. They can be concatenated with the \li{+} operator.
\begin{lstlisting}
>>> str1 = "I love"
>>> str2 = 'the ACME program'
>>> my_string = str1 + " " + str2 + "!"
>>> mystring
'I love the ACME program!'
\end{lstlisting}

We can access single characters of strings using brackets and a range of characters using \emph{slicing}. Slicing syntax is \li{[start:stop:step]}. The parameters \li{start} and \li{stop} default to the beginning and end of the string, respectively. The parameter \li{step} defaults to 0. For more information on slicing, see the section ``Lists.''

\begin{lstlisting}
# Indexing begins at 0 and negative numbers count backwards from the end.
>>> my_string[-1]
'!'

# Pick out every other character in a string.
>>> my_string[::2]	# string[start:stop:step]
'Ilv h CEporm'
\end{lstlisting}

Required readings:
\begin{itemize}
\item \url{http://scipy-lectures.github.io/intro/language/basic_types.html#strings}
\item \url{https://docs.python.org/2.7/tutorial/introduction.html#strings}
\end{itemize}

\begin{problem}
Answer the following questions about strings.
\begin{enumerate}
\item Suppose \li{my_string = "I love the new ACME program\!"}. What output is produced by \li{my_string[::3]} and \li{my_string[::-1]}?
\item How can you print a \li{string} backwards?
\end{enumerate}
\end{problem}

\subsection*{Lists}
A Python \li{list} is created by enclosing comma-separated values with square brackets. You can access a single entry of a \li{list} or a range of entries with the same indexing or slicing operations as we used on strings.
\begin{lstlisting}
>>> my_list = ["Remi", 21, "08/06", 1993]
>>> my_list
['Remi', 21, '08/06', 1993]
>>> my_list[-2]
'08/06'
\end{lstlisting}

Whenever possible, you should create your lists using a \emph{list comprehension}, which is demonstrated below.
\begin{lstlisting}
# The command range(n) produces the list [0, 1, 2, . . . , n-1].
>>> [x**2 for x in range(10)]
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
\end{lstlisting}

Required readings:
\begin{itemize}
\item \url{http://scipy-lectures.github.io/intro/language/basic_types.html#lists}
\item \url{https://docs.python.org/2.7/tutorial/introduction.html#lists}
\item \url{https://docs.python.org/2.7/tutorial/datastructures.html#list-comprehensions}
\end{itemize}

\begin{problem}
Answer the following questions about lists.

\begin{enumerate}
\item If \li{my_list = ["mushrooms", "rock climbing", 1947, 1954, "yoga"]}, write a sequence of commands that does the following:
\begin{enumerate}
\item Finds the length of the list,
\item Appends ``Jonathan, my pet fish'' to the end of the list,
\item Inserts \li{'pizza'} at index 3, and
\item Clears the entire list.
\end{enumerate}
\item Write a sequence of commands that does the following:
\begin{enumerate}
\item Creates an empty list called \li{num},
\item Adds the integers \li{3}, \li{5}, \li{19}, \li{20}, and \li{4} to \li{num},
\item Replaces the integer at index 3 with itself converted to a string,
\item Removes the integer at index 2, and
\item Sorts \li{num} backwards.
\end{enumerate}
\item Using a list comprehension, create a list that has the elements of \li{num} converted into strings. For example, if \li{num = [ 5, 4, 3, 2, 1]}, write a list comprehension that outputs \li{num=['5', '4', '3', '2', '1']}.
\end{enumerate}

\end{problem}

\subsection*{Sets}
A Python \li{set} is an unordered collection of distinct objects, and can be created from a list. We can add or remove members from a set after its creation.
\begin{lstlisting}
>>> gym_members = set(["Doe, John", "Doe, John", "Smith, Jane", "Brown, Bob"])
>>> gym_members
set(['Brown, Bob', 'Doe, John', 'Smith, Jane'])
>>> gym_members.discard("Doe, John");
>>> gym_members
set(['Brown, Bob', 'Smith, Jane'])
>>> gym_members.add("Lytle, Josh")
>>> gym_members
set(['Brown, Bob', 'Lytle, Josh', 'Smith, Jane'])
\end{lstlisting}

Like mathematical sets, a \li{set} has operations like union, intersection,
difference, and symmetric difference.

\begin{lstlisting}
# Set intersection returns a new set object.
>>> library_members = set(["Lytle, Josh", "Henriksen, Ian", "Grout, Ryan"])
>>> set.intersection(gym_members, library_members)
set(['Lytle, Josh'])
\end{lstlisting}

Required readings:
\begin{itemize}
\item \url{http://scipy-lectures.github.io/intro/language/basic_types.html#more_container_types}
\item \url{https://docs.python.org/2.7/tutorial/datastructures.html#sets}
\end{itemize}

\begin{problem}
Answer the following questions about sets.
\begin{enumerate}
\item What are two ways to create sets? How do you create an empty set?
\item Define two sets and use a Python command to find their union.
\end{enumerate}
\end{problem}

\subsection*{Dictionaries}
Like a \li{set}, a Python \li{dictionary} is an unordered data type.  A \li{dictionary} stores \li{key:value} pairs, which are called \emph{items}. The values of a dictionary are indexed by its keys.
\begin{lstlisting}
>>> tel = {"marriott": 4121, "math": 2061, "visual arts" : 7321}
>>> tel["math"]
2061
\end{lstlisting}

The keys of a dictionary must be \emph{immutable}, which means that they must be objects that cannot be modified after creation. Numerical types and strings are immutable objects. Lists, dictionaries, and sets are mutable.

Required readings:
\begin{itemize}
\item \url{http://scipy-lectures.github.io/intro/language/basic_types.html#dictionaries}
\item \url{https://docs.python.org/2.7/tutorial/datastructures.html#dictionaries}
\end{itemize}

\begin{problem}
Answer the following questions about dictionaries.
\begin{enumerate}
\item What are two ways to create dictionaries? How do you create an empty dictionary?
\item How do you delete a key-value pair from a dictionary?
\item How do you access a list of all the values in your dictionary?
How do you access a list of all the items?
\end{enumerate}
\end{problem}

\section*{Control Flow Tools}
Control flow blocks control the order in which your code is executed.
Python supports the usual control flow statements
including while loops, if statements, for loops, and function definitions. For examples besides those in this lab, see the following resources:

\begin{itemize}
\item Sections 1.2.3.1-1.2.3.4 of \url{http://scipy-lectures.github.io/intro/language/control_flow.html}
\item \url{http://scipy-lectures.github.io/intro/language/functions.html}
\item \url{https://docs.python.org/2.7/tutorial/introduction.html#first-steps-towards-programming}
\item Sections 4.1-4.3, 4.6, and 4.7.1-4.7.2 of \url{https://docs.python.org/2.7/tutorial/controlflow.html}
\end{itemize}

\subsection*{The While Loop}
Python uses indentation to identify the beginning and end of blocks of code, so you must indent each line of an execution block the same way.
The convention is to indent blocks of code with four spaces. A \li{while} loop executes an indented block of code \emph{while} the given condition holds.

\begin{lstlisting}
>>> i = 0
>>> while i < 10:           # The colon is required.
...     print i,             # This indented line is executed if b<10.
...     i = i+1       # This indented line is also executed if b<10.
...
0 1 2 3 4 5 6 7 8 9
\end{lstlisting}
In the above example, the comma in the line \li{print i,} makes Python print all the numbers on the same line (by stripping off newline characters). Try running this example without the comma and see what happens.

\subsection*{The If Statement}
An \li{if} statement executes the
indented code \emph{if} the given condition holds.
The \li{elif} statement is short for ``else if'' and can be used multiple times following an \li{if} statement, or not at all.
The \li{else} keyword may be used at most once at the end of a series of \li{if}/\li{elif} statements.
\begin{lstlisting}
>>> food = "bagel"         # Use a SINGLE equals sign create variables
>>> if food == "apple":    # Use a DOUBLE equals sign to check equality
...     print "72 calories"
... elif food == "banana":
...     print "105 calories"
... elif food == "egg":
...     print "102 calories"
... else:
...     print "calorie count unavailable"
...
calorie count unavailable
\end{lstlisting}

\subsection*{The For Loop}
A \li{for} loop iterates over the items in any \emph{iterable}. Iterables include lists, sets, and dictionaries.

\begin{lstlisting}
>>> for i in range(10):
...     print i,
...
0 1 2 3 4 5 6 7 8 9
\end{lstlisting}

\subsection*{Function Definition}
To define a function, use the \li{def} keyword followed by the function name and a parenthesized list of formal parameters. Then indent the function body.
\begin{lstlisting}
# Compute the area of a rectangle
>>> def area(width, height):
...     return width*height
...
>>> area(2, 5)
10
\end{lstlisting}

We define a function with \emph{parameters} and call it with \emph{arguments}.
In the example above, \li{width} and \li{height} are parameters for the function \li{area}. The values \li{2} and \li{5} are the arguments that we pass when calling the function. In practice, the terms \emph{parameter} and \emph{argument} are often used interchangeably.

It is also possible to specify default values for formal parameters, as in the following example.
\begin{lstlisting}
>>> def fn(a, b, c=0):
...    print a, b, c
\end{lstlisting}
The function \li{fn} has three formal parameters, and the value of \li{c} defaults to 0.
We can pass arguments to \li{fn} based on position (positional arguments) or name (named arguments or keyword arguments). We must define positional arguments before keyword arguments.
\begin{lstlisting}
# Call fn with 2 positional arguments (c=0 by default)
>>> fn(1, 2)
1 2 0

# Call fn with 3 positional arguments
>>> fn(4, 5, 6)
4 5 6

# Call fn with 1 positional argument and 2 named arguments
>>> fn(1, c=2, b=3)
1 3 2
\end{lstlisting}
The final example demonstrates the flexibility of Python but is somewhat confusing. Whenever possible, you should pass arguments to a function in the order they are defined in the function. Thus, do the following.
\begin{lstlisting}
# Call fn with 1 positional argument and 2 named arguments
>>> fn(1, b=3, c=2)
1 3 2
\end{lstlisting}

\begin{problem}
Define the following function in your interpreter.
\begin{lstlisting}
>>> def track(n, my_list=[]):
...    my_list.append(n)
...    return my_list
\end{lstlisting}
\begin{enumerate}
\item Now execute the following commands in your interpreter: \li{track(1)}, \li{track(2)}, \li{track(3)} and  \li{track(1, [1, 2, 3])}. What outputs do you get?
\item The default values of a function are only evaluated once.
This means that when you call \li{track} with the default value for \li{my_list}, the same list is used each time.
Modify \li{track} so that the default value for \li{my_list} is not shared between calls.
With your modified function, the outputs in part (a) should be \li{[1]}, \li{[2]}, \li{[3]} and \li{[1, 2, 3, 1]}. Hint: Read here about the Python constant \li{None}: \url{https://docs.python.org/2/library/constants.html}.
\end{enumerate}
\end{problem}

The most general form of a function definition is as follows.
\begin{lstlisting}
def fn(*args, **kwargs):
\end{lstlisting}
This means that ``\li{fn} takes some arguments and keyword arguments.''
The arguments, \li{args}, are stored as a tuple; and the keyword arguments, \li{kwargs}, are stored in a dictionary.
The function \li{fn} can accept any number of arguments and keyword arguments.
\begin{lstlisting}
>>> def fn(*args, **kwargs):
...     print "Positional: ", args
...     print "Keyword: ", kwargs
...
>>> fn("Hello", 2, 1, apples = 3, oranges = 2)
Positional: ('Hello', 2, 1)
Keyword: {'apples': 3, 'oranges': 2}
\end{lstlisting}

\begin{problem}

\begin{enumerate}
\item Explain what the \li{print} and \li{return} statements do. How are they different?
\item Modify the code below so that it produces the desired output.
\begin{lstlisting}
Grocery List = ['pineapple', 'orange juice', "avocados", "pesto sauce"]
for i in range(Grocery List)
if i % 2 = 0
print i, Grocery List(i)
\end{lstlisting}
Desired output:
\begin{lstlisting}
0 pineapple
2 avocados
\end{lstlisting}
\item When you call the function ``groceries'' below, it returns an error. Why?
\begin{lstlisting}
>>> def groceries(food, drink):
...     print food
...     print drink

>>> groceries(food="Bananas", "Juice")
\end{lstlisting}
\end{enumerate}
\end{problem}

\begin{comment}
\section*{Specifications}
We suggest that you submit your solutions in a file called \li{solutions.py}, using the following format.
\lstinputlisting[language=, abovecaptionskip=2pt, belowcaptionskip=2pt]{template.txt}
\end{comment}