#include "JReconstruction/JEvt.hh"
#include "JLang/JManip.hh"


/**
 * Write fit results to output.
 *
 * \param  out      output stream
 * \param  fit      fit results
 * \return          output stream
 */
std::ostream& operator<<(std::ostream& out, const JRECONSTRUCTION::JFit& fit)
{
  using namespace std;
  using namespace JPP;
    
  const JHistory& history = fit.getHistory();

  out << "history:";

  for (JHistory::const_reverse_iterator i = history.rbegin(); i != history.rend(); ++i) {
    out << ' ' << i->type;
  }

  out << endl;
      
  out << "x    " << FIXED(7,2) << fit.getX()  << endl;
  out << "y    " << FIXED(7,2) << fit.getY()  << endl;
  out << "z    " << FIXED(7,2) << fit.getZ()  << endl;
  out << "dx   " << FIXED(7,3) << fit.getDX() << endl;
  out << "dy   " << FIXED(7,3) << fit.getDY() << endl;
  out << "dz   " << FIXED(7,3) << fit.getDZ() << endl;

  out << "Q    " << FIXED(12,5) << fit.getQ()   << endl;
  out << "NDF  " << setw(5)     << fit.getNDF() << endl;

  out << "status " << fit.getStatus() << endl;

  for (int i = 0; i != fit.getN(); ++i) {
    out << "W[" << i << "] = " << FIXED(10,5) << fit.getW(i) << endl;
  }

  return out;
}