CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
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, assert(), 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 puppiForMET_cff::weight.

Referenced by MuonResiduals5DOFFitter::fit().

57 {
58  MuonResidualsFitterFitInfo *fitinfo = (MuonResidualsFitterFitInfo*)(minuit->GetObjectFit());
59  MuonResidualsFitter *fitter = fitinfo->fitter();
60 
61  fval = 0.;
62  for (std::vector<double*>::const_iterator resiter = fitter->residuals_begin(); resiter != fitter->residuals_end(); ++resiter)
63  {
64  const double residual = (*resiter)[MuonResiduals5DOFFitter::kResid];
65  const double resslope = (*resiter)[MuonResiduals5DOFFitter::kResSlope];
66  const double positionX = (*resiter)[MuonResiduals5DOFFitter::kPositionX];
67  const double positionY = (*resiter)[MuonResiduals5DOFFitter::kPositionY];
68  const double angleX = (*resiter)[MuonResiduals5DOFFitter::kAngleX];
69  const double angleY = (*resiter)[MuonResiduals5DOFFitter::kAngleY];
70  const double redchi2 = (*resiter)[MuonResiduals5DOFFitter::kRedChi2];
71 
72  const double alignx = par[MuonResiduals5DOFFitter::kAlignX];
73  const double alignz = par[MuonResiduals5DOFFitter::kAlignZ];
74  const double alignphix = par[MuonResiduals5DOFFitter::kAlignPhiX];
75  const double alignphiy = par[MuonResiduals5DOFFitter::kAlignPhiY];
76  const double alignphiz = par[MuonResiduals5DOFFitter::kAlignPhiZ];
77  const double residsigma = par[MuonResiduals5DOFFitter::kResidSigma];
78  const double resslopesigma = par[MuonResiduals5DOFFitter::kResSlopeSigma];
79  const double alpha = par[MuonResiduals5DOFFitter::kAlpha];
80  const double residgamma = par[MuonResiduals5DOFFitter::kResidGamma];
81  const double resslopegamma = par[MuonResiduals5DOFFitter::kResSlopeGamma];
82 
83  double coeff = alpha;
86  double residpeak = residual_x(alignx, alignz, alignphix, alignphiy, alignphiz, positionX, positionY, angleX, angleY, coeff, resslope);
87  double resslopepeak = residual_dxdz(alignx, alignz, alignphix, alignphiy, alignphiz, positionX, positionY, angleX, angleY);
88 
89  double weight = (1./redchi2) * number_of_hits / sum_of_weights;
90  if (!weight_alignment) weight = 1.;
91 
92  if (!weight_alignment || TMath::Prob(redchi2*8, 8) < 0.99) // no spikes allowed
93  {
96  fval += -weight * MuonResidualsFitter_logPureGaussian(residual, residpeak, residsigma);
97  fval += -weight * MuonResidualsFitter_logPureGaussian(resslope, resslopepeak, resslopesigma);
98  }
99  else if (fitter->useRes() == MuonResidualsFitter::k1100) {
100  fval += -weight * MuonResidualsFitter_logPureGaussian(residual, residpeak, residsigma);
101  }
102  else if (fitter->useRes() == MuonResidualsFitter::k0010) {
103  fval += -weight * MuonResidualsFitter_logPureGaussian(resslope, resslopepeak, resslopesigma);
104  }
105  }
107  if (fitter->useRes() == MuonResidualsFitter::k1111 || fitter->useRes() == MuonResidualsFitter::k1110 || fitter->useRes() == MuonResidualsFitter::k1010) {
108  fval += -weight * MuonResidualsFitter_logPureGaussian2D(residual, resslope, residpeak, resslopepeak, residsigma, resslopesigma, alpha);
109  }
110  else if (fitter->useRes() == MuonResidualsFitter::k1100) {
111  fval += -weight * MuonResidualsFitter_logPureGaussian(residual, residpeak, residsigma);
112  }
113  else if (fitter->useRes() == MuonResidualsFitter::k0010) {
114  fval += -weight * MuonResidualsFitter_logPureGaussian(resslope, resslopepeak, resslopesigma);
115  }
116  }
117  else if (fitter->residualsModel() == MuonResidualsFitter::kPowerLawTails) {
118  fval += -weight * MuonResidualsFitter_logPowerLawTails(residual, residpeak, residsigma, residgamma);
119  fval += -weight * MuonResidualsFitter_logPowerLawTails(resslope, resslopepeak, resslopesigma, resslopegamma);
120  }
121  else if (fitter->residualsModel() == MuonResidualsFitter::kROOTVoigt) {
122  fval += -weight * MuonResidualsFitter_logROOTVoigt(residual, residpeak, residsigma, residgamma);
123  fval += -weight * MuonResidualsFitter_logROOTVoigt(resslope, resslopepeak, resslopesigma, resslopegamma);
124  }
126  fval += -weight * MuonResidualsFitter_logGaussPowerTails(residual, residpeak, residsigma);
127  fval += -weight * MuonResidualsFitter_logGaussPowerTails(resslope, resslopepeak, resslopesigma);
128  }
129  else { assert(false); }
130  }
131  }
132 }
double MuonResidualsFitter_logGaussPowerTails(double residual, double center, double sigma)
float alpha
Definition: AMPTWrapper.h:95
double MuonResidualsFitter_logPureGaussian2D(double x, double y, double x0, double y0, double sx, double sy, double r)
assert(m_qm.get())
MuonResidualsFitter * fitter()
double MuonResidualsFitter_logROOTVoigt(double residual, double center, double sigma, double gamma)
double MuonResidualsFitter_logPowerLawTails(double residual, double center, double sigma, double gamma)
std::vector< double * >::const_iterator residuals_end() const
int useRes(int pattern=-1)
std::vector< double * >::const_iterator residuals_begin() const
double MuonResidualsFitter_logPureGaussian(double residual, double center, double sigma)