  A measurement of the J/psi and psi(2S) production cross sections in pp
collisions at sqrt(s)=7 TeV with the CMS experiment at the LHC is presented.
The data sample corresponds to an integrated luminosity of 37 inverse
picobarns. Using a fit to the invariant mass and decay length distributions,
production cross sections have been measured separately for prompt and
non-prompt charmonium states, as a function of the meson transverse momentum in
several rapidity ranges. In addition, cross sections restricted to the
acceptance of the CMS detector are given, which are not affected by the
polarization of the charmonium states. The ratio of the differential production
cross sections of the two states, where systematic uncertainties largely
cancel, is also determined. The branching fraction of the inclusive B to
psi(2S) X decay is extracted from the ratio of the non-prompt cross sections to
be:
  BR(B to psi(2S) X) = (3.08 +/- 0.12(stat.+syst.) +/- 0.13(theor.) +/-
0.42(BR[PDG])) 10^-3
