I think 

  return  d->get_spacing()*counter/1.21;

should be replaced by

  double s=d->get_spacing();
  return  s*s*s*counter/1.21;

   --Ben