Ejemplo n.º 1
0
void lblShowMuonPartPointSrc(const qlat::Geometry& geo, const int tsnk,
                             const int tsrc,
                             const qlat::Array<qlat::SpinMatrix, 3>& bs,
                             const qlat::Coordinate& xg1, const int mu1,
                             const qlat::Coordinate& xg2, const int mu2,
                             const qlat::Coordinate& xg3, const int mu3,
                             const double mass,
                             const std::array<double, qlat::DIMN>& momtwist)
{
  TIMER("lblShowMuonPartPointSrc");
  qlat::DisplayInfo(cname, fname, "mass = %.2f\n", mass);
  qlat::DisplayInfo(cname, fname, "xg1 = %s ; xg2 = %s ; xg3 = %s .\n",
                    qlat::show(xg1).c_str(), qlat::show(xg2).c_str(),
                    qlat::show(xg3).c_str());
  qlat::DisplayInfo(cname, fname, "mu1 = %d ; mu2 = %d ; mu3 = %d .\n", mu1,
                    mu2, mu3);
  qlat::SpinMatrix muonline = lblMuonPartPointSrc(
      geo, tsnk, tsrc, xg1, mu1, xg2, mu2, xg3, mu3, mass, momtwist);
  muonline = projPositiveState(muonline);
  qlat::DisplayInfo(cname, fname, "qnorm(muonline) = %.16e\n",
                    qlat::qnorm(muonline));
  if (qlat::qnorm(muonline) < 1.0e-30) {
    return;
  }
  qlat::DisplayInfo(cname, fname, "muonline =\n%s\n",
                    qlat::show(muonline).c_str());
  qlat::DisplayInfo(cname, fname, "linearFit[0] = %s\n",
                    qlat::show(linearFit(muonline, bs[0])).c_str());
  qlat::DisplayInfo(cname, fname, "linearFit[1] = %s\n",
                    qlat::show(linearFit(muonline, bs[1])).c_str());
  qlat::DisplayInfo(cname, fname, "linearFit[2] = %s\n",
                    qlat::show(linearFit(muonline, bs[2])).c_str());
  qlat::DisplayInfo(
      cname, fname, "linearFitUni = %s\n",
      qlat::show(
          linearFit(muonline,
                    projPositiveState(qlat::SpinMatrixConstants::get_unit())))
          .c_str());
  qlat::DisplayInfo(cname, fname, "linearFit[0] * 1e9 = %10.2f\n",
                    1e9 * linearFit(muonline, bs[0]).real());
  qlat::DisplayInfo(cname, fname, "linearFit[1] * 1e9 = %10.2f\n",
                    1e9 * linearFit(muonline, bs[1]).real());
  qlat::DisplayInfo(cname, fname, "linearFit[2] * 1e9 = %10.2f\n",
                    1e9 * linearFit(muonline, bs[2]).real());
}
Ejemplo n.º 2
0
void TrackMaker::fitTrackToClusters(Track* track)
{
  const unsigned int npoints = track->getNumClusters();
  double* dependant = new double[npoints];
  double* independant = new double[npoints];
  double* uncertainty = new double[npoints];

  // Prepare variables for the regression output
  double originX = 0, originY = 0;
  double originErrX = 0, originErrY = 0;
  double slopeX = 0, slopeY = 0;
  double slopeErrX = 0, slopeErrY = 0;
  double chi2X = 0, chi2Y = 0;
  double covarianceX = 0, covarianceY = 0;

  for (unsigned int axis = 0; axis < 2; axis++)
  {
    // Fill the arrays with the points dependint on the loop (x or y axis)
    for (unsigned int npoint = 0; npoint < npoints; npoint++)
    {
      if (!axis)
      {
        dependant[npoint] = track->getCluster(npoint)->getPosX();
        uncertainty[npoint] = track->getCluster(npoint)->getPosErrX();
	//std::cout << "Point: " << npoint << "track->getCluster(npoint)->getPosErrX(): " << track->getCluster(npoint)->getPosErrX() << " hits: " << track->getCluster(npoint)->getNumHits() << std::endl;
      }
      else
      {
        dependant[npoint] = track->getCluster(npoint)->getPosY();
        uncertainty[npoint] = track->getCluster(npoint)->getPosErrY();
	//std::cout << "Point: " << npoint << "track->getCluster(npoint)->getPosErrY(): " << track->getCluster(npoint)->getPosErrY()<< " hits: " << track->getCluster(npoint)->getNumHits() << std::endl;	
      }
      independant[npoint] = track->getCluster(npoint)->getPosZ();
    }

    // Perform the regression
    if (!axis)
    {
      linearFit(npoints, independant, dependant, uncertainty,
                slopeX, slopeErrX, originX, originErrX, chi2X, covarianceX);
    }
    else
    {
      linearFit(npoints, independant, dependant, uncertainty,
                slopeY, slopeErrY, originY, originErrY, chi2Y, covarianceY);
    }
  }

  // Get a chi2 normalized to the number of DOF
  const double chi2 = (chi2X + chi2Y) / (2.0 * (double)(npoints - 2));

  track->setOrigin(originX, originY);
  track->setOriginErr(originErrX, originErrY);
  track->setSlope(slopeX, slopeY);
  track->setSlopeErr(slopeErrX, slopeErrY);
  track->setChi2(chi2);
  track->setCovariance(covarianceX, covarianceY);

  delete[] dependant;
  delete[] independant;
  delete[] uncertainty;
}