  The lines of HOC$^+$, HCO and CO$^+$ are considered good tracers of
photon-dominated regions (PDRs) and X-ray dominated regions. We study these
tracers towards regions of the Sgr B2 cloud selected to be affected by
different heating mechanisms. We find the lowest values of the column density
ratios of HCO$^+$ versus HOC$^+$, HCO and CO$^+$ in dense HII gas, where UV
photons dominate the heating and chemistry of gas. HOC$^+$, HCO and CO$^+$
abundances and the above ratios are compared with those of chemical modeling,
finding that high temperature chemistry, a cosmic-ray ionization rate of
10$^{-16}$ s$^{-1}$ and timescales $>$10$^{5.0}$ years explain well the HOC$^+$
abundances in quiescent Sgr B2 regions, while shocks are also needed to explain
the highest HCO abundances derived for these regions. CO$^+$ is mainly formed
in PDRs since the highest CO$^+$ abundances of $\sim$(6-10)$\times$10$^{-10}$
are found in HII regions with electron densities $>$540 cm$^{-3}$ and that
CO$^+$ emission is undetected in quiescent gas. Between the ratios, the
HCO$^+$/HCO ratio is sensitive to the electron density as it shows different
values in dense and diffuse HII regions. We compare SiO J=2-1 emission maps of
Sgr B2 with X-ray maps from 2004 and 2012. One known spot shown on the 2012
X-ray map is likely associated with molecular gas at velocities of 15-25 km
s$^{-1}$. We also derive the X-ray ionization rate of $\sim$10$^{-19}$ s$^{-1}$
for Sgr B2 regions pervaded by X-rays in 2004, which is quite low to affect the
chemistry of the molecular gas.
