CMS 3D CMS Logo

Functions
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(), and MuonResidualsFitter::useRes().

Referenced by MuonResiduals6DOFrphiFitter::fit().

81 {
82  MuonResidualsFitterFitInfo *fitinfo = (MuonResidualsFitterFitInfo*)(minuit->GetObjectFit());
83  MuonResidualsFitter *fitter = fitinfo->fitter();
84 
85  fval = 0.;
86  for (std::vector<double*>::const_iterator resiter = fitter->residuals_begin(); resiter != fitter->residuals_end(); ++resiter)
87  {
88  const double residual = (*resiter)[MuonResiduals6DOFrphiFitter::kResid];
89  const double resslope = (*resiter)[MuonResiduals6DOFrphiFitter::kResSlope];
90  const double positionX = (*resiter)[MuonResiduals6DOFrphiFitter::kPositionX];
91  const double positionY = (*resiter)[MuonResiduals6DOFrphiFitter::kPositionY];
92  const double angleX = (*resiter)[MuonResiduals6DOFrphiFitter::kAngleX];
93  const double angleY = (*resiter)[MuonResiduals6DOFrphiFitter::kAngleY];
94  const double redchi2 = (*resiter)[MuonResiduals6DOFrphiFitter::kRedChi2];
95 
96  const double alignx = par[MuonResiduals6DOFrphiFitter::kAlignX];
97  const double aligny = par[MuonResiduals6DOFrphiFitter::kAlignY];
98  const double alignz = par[MuonResiduals6DOFrphiFitter::kAlignZ];
99  const double alignphix = par[MuonResiduals6DOFrphiFitter::kAlignPhiX];
100  const double alignphiy = par[MuonResiduals6DOFrphiFitter::kAlignPhiY];
101  const double alignphiz = par[MuonResiduals6DOFrphiFitter::kAlignPhiZ];
102  const double residsigma = par[MuonResiduals6DOFrphiFitter::kResidSigma];
103  const double resslopesigma = par[MuonResiduals6DOFrphiFitter::kResSlopeSigma];
104  const double alpha = par[MuonResiduals6DOFrphiFitter::kAlpha];
105  const double residgamma = par[MuonResiduals6DOFrphiFitter::kResidGamma];
106  const double resslopegamma = par[MuonResiduals6DOFrphiFitter::kResSlopeGamma];
107 
108  double coeff = alpha;
110  fitter->residualsModel() == MuonResidualsFitter::kPureGaussian2D) coeff = 0.;
111  double effr = effectiveR(positionX, positionY);
112  double residpeak = getResidual(alignx, aligny, alignz, alignphix, alignphiy, alignphiz, positionX, positionY, angleX, angleY, effr, coeff, resslope);
113  double resslopepeak = getResSlope(alignx, aligny, alignz, alignphix, alignphiy, alignphiz, positionX, positionY, angleX, angleY, effr);
114 
115  double weight = (1./redchi2) * number_of_hits / sum_of_weights;
116  if (!weight_alignment) weight = 1.;
117 
118  if (!weight_alignment || TMath::Prob(redchi2*6, 6) < 0.99) // no spikes allowed
119  {
121  if (fitter->useRes() == MuonResidualsFitter::k1111 || fitter->useRes() == MuonResidualsFitter::k1110 || fitter->useRes() == MuonResidualsFitter::k1010) {
122  fval += -weight * MuonResidualsFitter_logPureGaussian(residual, residpeak, residsigma);
123  fval += -weight * MuonResidualsFitter_logPureGaussian(resslope, resslopepeak, resslopesigma);
124  }
125  else if (fitter->useRes() == MuonResidualsFitter::k1100) {
126  fval += -weight * MuonResidualsFitter_logPureGaussian(residual, residpeak, residsigma);
127  }
128  else if (fitter->useRes() == MuonResidualsFitter::k0010) {
129  fval += -weight * MuonResidualsFitter_logPureGaussian(resslope, resslopepeak, resslopesigma);
130  }
131  }
133  if (fitter->useRes() == MuonResidualsFitter::k1111 || fitter->useRes() == MuonResidualsFitter::k1110 || fitter->useRes() == MuonResidualsFitter::k1010) {
134  fval += -weight * MuonResidualsFitter_logPureGaussian2D(residual, resslope, residpeak, resslopepeak, residsigma, resslopesigma, alpha);
135  }
136  else if (fitter->useRes() == MuonResidualsFitter::k1100) {
137  fval += -weight * MuonResidualsFitter_logPureGaussian(residual, residpeak, residsigma);
138  }
139  else if (fitter->useRes() == MuonResidualsFitter::k0010) {
140  fval += -weight * MuonResidualsFitter_logPureGaussian(resslope, resslopepeak, resslopesigma);
141  }
142  }
143  else if (fitter->residualsModel() == MuonResidualsFitter::kPowerLawTails) {
144  fval += -weight * MuonResidualsFitter_logPowerLawTails(residual, residpeak, residsigma, residgamma);
145  fval += -weight * MuonResidualsFitter_logPowerLawTails(resslope, resslopepeak, resslopesigma, resslopegamma);
146  }
147  else if (fitter->residualsModel() == MuonResidualsFitter::kROOTVoigt) {
148  fval += -weight * MuonResidualsFitter_logROOTVoigt(residual, residpeak, residsigma, residgamma);
149  fval += -weight * MuonResidualsFitter_logROOTVoigt(resslope, resslopepeak, resslopesigma, resslopegamma);
150  }
152  fval += -weight * MuonResidualsFitter_logGaussPowerTails(residual, residpeak, residsigma);
153  fval += -weight * MuonResidualsFitter_logGaussPowerTails(resslope, resslopepeak, resslopesigma);
154  }
155  else { assert(false); }
156  }
157  }
158 }
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)
MuonResidualsFitter * fitter()
Definition: weight.py:1
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)