CMS 3D CMS Logo

Functions

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/Alignment/MuonAlignmentAlgorithms/src/MuonResiduals5DOFFitter.cc File Reference

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

Go to the source code of this file.

Functions

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

Function Documentation

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

Definition at line 56 of file MuonResiduals5DOFFitter.cc.

References alpha, MuonResidualsFitterFitInfo::fitter(), MuonResidualsFitter::k0010, MuonResidualsFitter::k1010, MuonResidualsFitter::k1100, MuonResidualsFitter::k1110, MuonResidualsFitter::k1111, MuonResiduals5DOFFitter::kAlignPhiX, MuonResiduals5DOFFitter::kAlignPhiY, MuonResiduals5DOFFitter::kAlignPhiZ, MuonResiduals5DOFFitter::kAlignX, MuonResiduals5DOFFitter::kAlignZ, MuonResiduals5DOFFitter::kAlpha, MuonResiduals5DOFFitter::kAngleX, MuonResiduals5DOFFitter::kAngleY, MuonResidualsFitter::kGaussPowerTails, MuonResiduals5DOFFitter::kPositionX, MuonResiduals5DOFFitter::kPositionY, MuonResidualsFitter::kPowerLawTails, MuonResidualsFitter::kPureGaussian, MuonResidualsFitter::kPureGaussian2D, MuonResiduals5DOFFitter::kRedChi2, MuonResiduals5DOFFitter::kResid, MuonResiduals5DOFFitter::kResidGamma, MuonResiduals5DOFFitter::kResidSigma, MuonResiduals5DOFFitter::kResSlope, MuonResiduals5DOFFitter::kResSlopeGamma, MuonResiduals5DOFFitter::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 MuonResiduals5DOFFitter::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)[MuonResiduals5DOFFitter::kResid];
    const double resslope = (*resiter)[MuonResiduals5DOFFitter::kResSlope];
    const double positionX = (*resiter)[MuonResiduals5DOFFitter::kPositionX];
    const double positionY = (*resiter)[MuonResiduals5DOFFitter::kPositionY];
    const double angleX = (*resiter)[MuonResiduals5DOFFitter::kAngleX];
    const double angleY = (*resiter)[MuonResiduals5DOFFitter::kAngleY];
    const double redchi2 = (*resiter)[MuonResiduals5DOFFitter::kRedChi2];

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

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

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

    if (!weight_alignment  ||  TMath::Prob(redchi2*8, 8) < 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); }
    }
  }
}