CMS 3D CMS Logo

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

◆ MuonResiduals5DOFFitter_FCN()

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

Definition at line 76 of file MuonResiduals5DOFFitter.cc.

References simBeamSpotPI::alpha, cms::cuda::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(), and MuonResidualsFitter::useRes().

Referenced by MuonResiduals5DOFFitter::fit().

76  {
77  MuonResidualsFitterFitInfo *fitinfo = (MuonResidualsFitterFitInfo *)(minuit->GetObjectFit());
78  MuonResidualsFitter *fitter = fitinfo->fitter();
79 
80  fval = 0.;
81  for (std::vector<double *>::const_iterator resiter = fitter->residuals_begin(); resiter != fitter->residuals_end();
82  ++resiter) {
83  const double residual = (*resiter)[MuonResiduals5DOFFitter::kResid];
84  const double resslope = (*resiter)[MuonResiduals5DOFFitter::kResSlope];
85  const double positionX = (*resiter)[MuonResiduals5DOFFitter::kPositionX];
86  const double positionY = (*resiter)[MuonResiduals5DOFFitter::kPositionY];
87  const double angleX = (*resiter)[MuonResiduals5DOFFitter::kAngleX];
88  const double angleY = (*resiter)[MuonResiduals5DOFFitter::kAngleY];
89  const double redchi2 = (*resiter)[MuonResiduals5DOFFitter::kRedChi2];
90 
91  const double alignx = par[MuonResiduals5DOFFitter::kAlignX];
92  const double alignz = par[MuonResiduals5DOFFitter::kAlignZ];
93  const double alignphix = par[MuonResiduals5DOFFitter::kAlignPhiX];
94  const double alignphiy = par[MuonResiduals5DOFFitter::kAlignPhiY];
95  const double alignphiz = par[MuonResiduals5DOFFitter::kAlignPhiZ];
96  const double residsigma = par[MuonResiduals5DOFFitter::kResidSigma];
97  const double resslopesigma = par[MuonResiduals5DOFFitter::kResSlopeSigma];
98  const double alpha = par[MuonResiduals5DOFFitter::kAlpha];
99  const double residgamma = par[MuonResiduals5DOFFitter::kResidGamma];
100  const double resslopegamma = par[MuonResiduals5DOFFitter::kResSlopeGamma];
101 
102  double coeff = alpha;
105  coeff = 0.;
106  double residpeak = residual_x(
107  alignx, alignz, alignphix, alignphiy, alignphiz, positionX, positionY, angleX, angleY, coeff, resslope);
108  double resslopepeak =
109  residual_dxdz(alignx, alignz, alignphix, alignphiy, alignphiz, positionX, positionY, angleX, angleY);
110 
111  double weight = (1. / redchi2) * number_of_hits / sum_of_weights;
112  if (!weight_alignment)
113  weight = 1.;
114 
115  if (!weight_alignment || TMath::Prob(redchi2 * 8, 8) < 0.99) // no spikes allowed
116  {
118  if (fitter->useRes() == MuonResidualsFitter::k1111 || fitter->useRes() == MuonResidualsFitter::k1110 ||
119  fitter->useRes() == MuonResidualsFitter::k1010) {
120  fval += -weight * MuonResidualsFitter_logPureGaussian(residual, residpeak, residsigma);
121  fval += -weight * MuonResidualsFitter_logPureGaussian(resslope, resslopepeak, resslopesigma);
122  } else if (fitter->useRes() == MuonResidualsFitter::k1100) {
123  fval += -weight * MuonResidualsFitter_logPureGaussian(residual, residpeak, residsigma);
124  } else if (fitter->useRes() == MuonResidualsFitter::k0010) {
125  fval += -weight * MuonResidualsFitter_logPureGaussian(resslope, resslopepeak, resslopesigma);
126  }
127  } else if (fitter->residualsModel() == MuonResidualsFitter::kPureGaussian2D) {
128  if (fitter->useRes() == MuonResidualsFitter::k1111 || fitter->useRes() == MuonResidualsFitter::k1110 ||
129  fitter->useRes() == MuonResidualsFitter::k1010) {
131  residual, resslope, residpeak, resslopepeak, residsigma, resslopesigma, alpha);
132  } else if (fitter->useRes() == MuonResidualsFitter::k1100) {
133  fval += -weight * MuonResidualsFitter_logPureGaussian(residual, residpeak, residsigma);
134  } else if (fitter->useRes() == MuonResidualsFitter::k0010) {
135  fval += -weight * MuonResidualsFitter_logPureGaussian(resslope, resslopepeak, resslopesigma);
136  }
137  } else if (fitter->residualsModel() == MuonResidualsFitter::kPowerLawTails) {
138  fval += -weight * MuonResidualsFitter_logPowerLawTails(residual, residpeak, residsigma, residgamma);
139  fval += -weight * MuonResidualsFitter_logPowerLawTails(resslope, resslopepeak, resslopesigma, resslopegamma);
140  } else if (fitter->residualsModel() == MuonResidualsFitter::kROOTVoigt) {
141  fval += -weight * MuonResidualsFitter_logROOTVoigt(residual, residpeak, residsigma, residgamma);
142  fval += -weight * MuonResidualsFitter_logROOTVoigt(resslope, resslopepeak, resslopesigma, resslopegamma);
143  } else if (fitter->residualsModel() == MuonResidualsFitter::kGaussPowerTails) {
144  fval += -weight * MuonResidualsFitter_logGaussPowerTails(residual, residpeak, residsigma);
145  fval += -weight * MuonResidualsFitter_logGaussPowerTails(resslope, resslopepeak, resslopesigma);
146  } else {
147  assert(false);
148  }
149  }
150  }
151 }
double MuonResidualsFitter_logGaussPowerTails(double residual, double center, double sigma)
double MuonResidualsFitter_logPureGaussian2D(double x, double y, double x0, double y0, double sx, double sy, double r)
std::vector< double * >::const_iterator residuals_begin() const
MuonResidualsFitter * fitter()
Definition: weight.py:1
std::vector< double * >::const_iterator residuals_end() const
assert(be >=bs)
double MuonResidualsFitter_logROOTVoigt(double residual, double center, double sigma, double gamma)
double MuonResidualsFitter_logPowerLawTails(double residual, double center, double sigma, double gamma)
int useRes(int pattern=-1)
double MuonResidualsFitter_logPureGaussian(double residual, double center, double sigma)