CMS 3D CMS Logo

Functions

/data/refman/pasoursint/CMSSW_5_3_3/src/Alignment/MuonAlignmentAlgorithms/src/MuonResiduals6DOFrphiFitter.cc File Reference

#include "Alignment/MuonAlignmentAlgorithms/interface/MuonResiduals6DOFrphiFitter.h"
#include "TH2F.h"
#include "TMath.h"
#include "TTree.h"
#include "TFile.h"

Go to the source code of this file.

Functions

void MuonResiduals6DOFrphiFitter_FCN (int &npar, double *gin, double &fval, double *par, int iflag)

Function Documentation

void MuonResiduals6DOFrphiFitter_FCN ( int &  npar,
double *  gin,
double &  fval,
double *  par,
int  iflag 
)

Definition at line 80 of file MuonResiduals6DOFrphiFitter.cc.

References alpha, MuonResidualsFitterFitInfo::fitter(), MuonResidualsFitter::k0010, MuonResidualsFitter::k1010, MuonResidualsFitter::k1100, MuonResidualsFitter::k1110, MuonResidualsFitter::k1111, MuonResiduals6DOFrphiFitter::kAlignPhiX, MuonResiduals6DOFrphiFitter::kAlignPhiY, MuonResiduals6DOFrphiFitter::kAlignPhiZ, MuonResiduals6DOFrphiFitter::kAlignX, MuonResiduals6DOFrphiFitter::kAlignY, MuonResiduals6DOFrphiFitter::kAlignZ, MuonResiduals6DOFrphiFitter::kAlpha, MuonResiduals6DOFrphiFitter::kAngleX, MuonResiduals6DOFrphiFitter::kAngleY, MuonResidualsFitter::kGaussPowerTails, MuonResiduals6DOFrphiFitter::kPositionX, MuonResiduals6DOFrphiFitter::kPositionY, MuonResidualsFitter::kPowerLawTails, MuonResidualsFitter::kPureGaussian, MuonResidualsFitter::kPureGaussian2D, MuonResiduals6DOFrphiFitter::kRedChi2, MuonResiduals6DOFrphiFitter::kResid, MuonResiduals6DOFrphiFitter::kResidGamma, MuonResiduals6DOFrphiFitter::kResidSigma, MuonResiduals6DOFrphiFitter::kResSlope, MuonResiduals6DOFrphiFitter::kResSlopeGamma, MuonResiduals6DOFrphiFitter::kResSlopeSigma, MuonResidualsFitter::kROOTVoigt, MuonResidualsFitter_logGaussPowerTails(), MuonResidualsFitter_logPowerLawTails(), MuonResidualsFitter_logPureGaussian(), MuonResidualsFitter_logPureGaussian2D(), MuonResidualsFitter_logROOTVoigt(), MuonResidualsFitter::residuals_begin(), MuonResidualsFitter::residuals_end(), MuonResidualsFitter::residualsModel(), MuonResidualsFitter::useRes(), and CommonMethods::weight().

Referenced by MuonResiduals6DOFrphiFitter::fit().

{
  MuonResidualsFitterFitInfo *fitinfo = (MuonResidualsFitterFitInfo*)(minuit->GetObjectFit());
  MuonResidualsFitter *fitter = fitinfo->fitter();

  fval = 0.;
  for (std::vector<double*>::const_iterator resiter = fitter->residuals_begin();  resiter != fitter->residuals_end();  ++resiter)
  {
    const double residual = (*resiter)[MuonResiduals6DOFrphiFitter::kResid];
    const double resslope = (*resiter)[MuonResiduals6DOFrphiFitter::kResSlope];
    const double positionX = (*resiter)[MuonResiduals6DOFrphiFitter::kPositionX];
    const double positionY = (*resiter)[MuonResiduals6DOFrphiFitter::kPositionY];
    const double angleX = (*resiter)[MuonResiduals6DOFrphiFitter::kAngleX];
    const double angleY = (*resiter)[MuonResiduals6DOFrphiFitter::kAngleY];
    const double redchi2 = (*resiter)[MuonResiduals6DOFrphiFitter::kRedChi2];

    const double alignx = par[MuonResiduals6DOFrphiFitter::kAlignX];
    const double aligny = par[MuonResiduals6DOFrphiFitter::kAlignY];
    const double alignz = par[MuonResiduals6DOFrphiFitter::kAlignZ];
    const double alignphix = par[MuonResiduals6DOFrphiFitter::kAlignPhiX];
    const double alignphiy = par[MuonResiduals6DOFrphiFitter::kAlignPhiY];
    const double alignphiz = par[MuonResiduals6DOFrphiFitter::kAlignPhiZ];
    const double residsigma = par[MuonResiduals6DOFrphiFitter::kResidSigma];
    const double resslopesigma = par[MuonResiduals6DOFrphiFitter::kResSlopeSigma];
    const double alpha = par[MuonResiduals6DOFrphiFitter::kAlpha];
    const double residgamma = par[MuonResiduals6DOFrphiFitter::kResidGamma];
    const double resslopegamma = par[MuonResiduals6DOFrphiFitter::kResSlopeGamma];

    double coeff = alpha;
    if (fitter->residualsModel() == MuonResidualsFitter::kPureGaussian ||
        fitter->residualsModel() == MuonResidualsFitter::kPureGaussian2D) coeff = 0.;
    double effr = effectiveR(positionX, positionY);
    double residpeak = getResidual(alignx, aligny, alignz, alignphix, alignphiy, alignphiz, positionX, positionY, angleX, angleY, effr, coeff, resslope);
    double resslopepeak = getResSlope(alignx, aligny, alignz, alignphix, alignphiy, alignphiz, positionX, positionY, angleX, angleY, effr);

    double weight = (1./redchi2) * number_of_hits / sum_of_weights;
    if (!weight_alignment) weight = 1.;

    if (!weight_alignment  ||  TMath::Prob(redchi2*6, 6) < 0.99) // no spikes allowed
    {
      if (fitter->residualsModel() == MuonResidualsFitter::kPureGaussian) {
        if (fitter->useRes() == MuonResidualsFitter::k1111 || fitter->useRes() == MuonResidualsFitter::k1110 || fitter->useRes() == MuonResidualsFitter::k1010) {
          fval += -weight * MuonResidualsFitter_logPureGaussian(residual, residpeak, residsigma);
          fval += -weight * MuonResidualsFitter_logPureGaussian(resslope, resslopepeak, resslopesigma);
        }
        else if (fitter->useRes() == MuonResidualsFitter::k1100) {
          fval += -weight * MuonResidualsFitter_logPureGaussian(residual, residpeak, residsigma);
        }
        else if (fitter->useRes() == MuonResidualsFitter::k0010) {
          fval += -weight * MuonResidualsFitter_logPureGaussian(resslope, resslopepeak, resslopesigma);
        }
      }
      else if (fitter->residualsModel() == MuonResidualsFitter::kPureGaussian2D) {
        if (fitter->useRes() == MuonResidualsFitter::k1111 || fitter->useRes() == MuonResidualsFitter::k1110 || fitter->useRes() == MuonResidualsFitter::k1010) {
          fval += -weight * MuonResidualsFitter_logPureGaussian2D(residual, resslope, residpeak, resslopepeak, residsigma, resslopesigma, alpha);
        }
        else if (fitter->useRes() == MuonResidualsFitter::k1100) {
          fval += -weight * MuonResidualsFitter_logPureGaussian(residual, residpeak, residsigma);
        }
        else if (fitter->useRes() == MuonResidualsFitter::k0010) {
          fval += -weight * MuonResidualsFitter_logPureGaussian(resslope, resslopepeak, resslopesigma);
        }
      }
      else if (fitter->residualsModel() == MuonResidualsFitter::kPowerLawTails) {
        fval += -weight * MuonResidualsFitter_logPowerLawTails(residual, residpeak, residsigma, residgamma);
        fval += -weight * MuonResidualsFitter_logPowerLawTails(resslope, resslopepeak, resslopesigma, resslopegamma);
      }
      else if (fitter->residualsModel() == MuonResidualsFitter::kROOTVoigt) {
        fval += -weight * MuonResidualsFitter_logROOTVoigt(residual, residpeak, residsigma, residgamma);
        fval += -weight * MuonResidualsFitter_logROOTVoigt(resslope, resslopepeak, resslopesigma, resslopegamma);
      }
      else if (fitter->residualsModel() == MuonResidualsFitter::kGaussPowerTails) {
        fval += -weight * MuonResidualsFitter_logGaussPowerTails(residual, residpeak, residsigma);
        fval += -weight * MuonResidualsFitter_logGaussPowerTails(resslope, resslopepeak, resslopesigma);
      }
      else { assert(false); }
    }
  }
}