An algorithm is described for tagging the flavour content at production of neutral $B$ mesons in the LHCb experiment. The algorithm exploits the correlation of the flavour of a $B$ meson with the charge of a reconstructed secondary charm hadron from the decay of the other $b$ hadron produced in the proton-proton collision. Charm hadron candidates are identified in a number of fully or partially reconstructed Cabibbo-favoured decay modes. The algorithm is calibrated on the self-tagged decay modes $B^+ to J/psi , K^+$ and $B^0 to J/psi , K^{*0}$ using $3.0mathrm{,fb}^{-1}$ of data collected by the LHCb experiment at $pp$ centre-of-mass energies of $7mathrm{,TeV}$ and $8mathrm{,TeV}$. Its tagging power on these samples of $B to J/psi , X$ decays is $(0.30 pm 0.01 pm 0.01) %$.