CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
MuonResiduals6DOFFitter.cc File Reference
#include "Alignment/MuonAlignmentAlgorithms/interface/MuonResiduals6DOFFitter.h"
#include "TH2F.h"
#include "TMath.h"
#include "TTree.h"
#include "TFile.h"

Go to the source code of this file.

Functions

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

Function Documentation

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

Definition at line 88 of file MuonResiduals6DOFFitter.cc.

References MuonResidualsFitterFitInfo::fitter(), MuonResidualsFitter::k0010, MuonResidualsFitter::k1010, MuonResidualsFitter::k1100, MuonResidualsFitter::k1110, MuonResidualsFitter::k1111, MuonResiduals6DOFFitter::kAlignPhiX, MuonResiduals6DOFFitter::kAlignPhiY, MuonResiduals6DOFFitter::kAlignPhiZ, MuonResiduals6DOFFitter::kAlignX, MuonResiduals6DOFFitter::kAlignY, MuonResiduals6DOFFitter::kAlignZ, MuonResiduals6DOFFitter::kAlphaX, MuonResiduals6DOFFitter::kAlphaY, MuonResiduals6DOFFitter::kAngleX, MuonResiduals6DOFFitter::kAngleY, MuonResidualsFitter::kGaussPowerTails, MuonResiduals6DOFFitter::kPositionX, MuonResiduals6DOFFitter::kPositionY, MuonResidualsFitter::kPowerLawTails, MuonResidualsFitter::kPureGaussian, MuonResidualsFitter::kPureGaussian2D, MuonResiduals6DOFFitter::kRedChi2, MuonResiduals6DOFFitter::kResidX, MuonResiduals6DOFFitter::kResidXGamma, MuonResiduals6DOFFitter::kResidXSigma, MuonResiduals6DOFFitter::kResidY, MuonResiduals6DOFFitter::kResidYGamma, MuonResiduals6DOFFitter::kResidYSigma, MuonResiduals6DOFFitter::kResSlopeX, MuonResiduals6DOFFitter::kResSlopeXGamma, MuonResiduals6DOFFitter::kResSlopeXSigma, MuonResiduals6DOFFitter::kResSlopeY, MuonResiduals6DOFFitter::kResSlopeYGamma, MuonResiduals6DOFFitter::kResSlopeYSigma, MuonResidualsFitter::kROOTVoigt, MuonResidualsFitter_logGaussPowerTails(), MuonResidualsFitter_logPowerLawTails(), MuonResidualsFitter_logPureGaussian(), MuonResidualsFitter_logPureGaussian2D(), MuonResidualsFitter_logROOTVoigt(), MuonResidualsFitter::residuals_begin(), MuonResidualsFitter::residuals_end(), MuonResidualsFitter::residualsModel(), MuonResidualsFitter::useRes(), and histoStyle::weight.

Referenced by MuonResiduals6DOFFitter::fit().

89 {
90  MuonResidualsFitterFitInfo *fitinfo = (MuonResidualsFitterFitInfo*)(minuit->GetObjectFit());
91  MuonResidualsFitter *fitter = fitinfo->fitter();
92 
93  fval = 0.;
94  for (std::vector<double*>::const_iterator resiter = fitter->residuals_begin(); resiter != fitter->residuals_end(); ++resiter)
95  {
96  const double residX = (*resiter)[MuonResiduals6DOFFitter::kResidX];
97  const double residY = (*resiter)[MuonResiduals6DOFFitter::kResidY];
98  const double resslopeX = (*resiter)[MuonResiduals6DOFFitter::kResSlopeX];
99  const double resslopeY = (*resiter)[MuonResiduals6DOFFitter::kResSlopeY];
100  const double positionX = (*resiter)[MuonResiduals6DOFFitter::kPositionX];
101  const double positionY = (*resiter)[MuonResiduals6DOFFitter::kPositionY];
102  const double angleX = (*resiter)[MuonResiduals6DOFFitter::kAngleX];
103  const double angleY = (*resiter)[MuonResiduals6DOFFitter::kAngleY];
104  const double redchi2 = (*resiter)[MuonResiduals6DOFFitter::kRedChi2];
105 
106  const double alignx = par[MuonResiduals6DOFFitter::kAlignX];
107  const double aligny = par[MuonResiduals6DOFFitter::kAlignY];
108  const double alignz = par[MuonResiduals6DOFFitter::kAlignZ];
109  const double alignphix = par[MuonResiduals6DOFFitter::kAlignPhiX];
110  const double alignphiy = par[MuonResiduals6DOFFitter::kAlignPhiY];
111  const double alignphiz = par[MuonResiduals6DOFFitter::kAlignPhiZ];
112  const double resXsigma = par[MuonResiduals6DOFFitter::kResidXSigma];
113  const double resYsigma = par[MuonResiduals6DOFFitter::kResidYSigma];
114  const double slopeXsigma = par[MuonResiduals6DOFFitter::kResSlopeXSigma];
115  const double slopeYsigma = par[MuonResiduals6DOFFitter::kResSlopeYSigma];
116  const double alphax = par[MuonResiduals6DOFFitter::kAlphaX];
117  const double alphay = par[MuonResiduals6DOFFitter::kAlphaY];
118  const double resXgamma = par[MuonResiduals6DOFFitter::kResidXGamma];
119  const double resYgamma = par[MuonResiduals6DOFFitter::kResidYGamma];
120  const double slopeXgamma = par[MuonResiduals6DOFFitter::kResSlopeXGamma];
121  const double slopeYgamma = par[MuonResiduals6DOFFitter::kResSlopeYGamma];
122 
123  double coefX = alphax, coefY = alphay;
125  fitter->residualsModel() == MuonResidualsFitter::kPureGaussian2D) coefX = coefY = 0.;
126  double residXpeak = residual_x(alignx, aligny, alignz, alignphix, alignphiy, alignphiz, positionX, positionY, angleX, angleY, coefX, resslopeX);
127  double residYpeak = residual_y(alignx, aligny, alignz, alignphix, alignphiy, alignphiz, positionX, positionY, angleX, angleY, coefY, resslopeY);
128  double slopeXpeak = residual_dxdz(alignx, aligny, alignz, alignphix, alignphiy, alignphiz, positionX, positionY, angleX, angleY);
129  double slopeYpeak = residual_dydz(alignx, aligny, alignz, alignphix, alignphiy, alignphiz, positionX, positionY, angleX, angleY);
130 
131  double weight = (1./redchi2) * number_of_hits / sum_of_weights;
132  if (!weight_alignment) weight = 1.;
133 
134  if (!weight_alignment || TMath::Prob(redchi2*12, 12) < 0.99) // no spikes allowed
135  {
137  if (fitter->useRes() == MuonResidualsFitter::k1111) {
138  fval += -weight * MuonResidualsFitter_logPureGaussian(residX, residXpeak, resXsigma);
139  fval += -weight * MuonResidualsFitter_logPureGaussian(residY, residYpeak, resYsigma);
140  fval += -weight * MuonResidualsFitter_logPureGaussian(resslopeX, slopeXpeak, slopeXsigma);
141  fval += -weight * MuonResidualsFitter_logPureGaussian(resslopeY, slopeYpeak, slopeYsigma);
142  }
143  else if (fitter->useRes() == MuonResidualsFitter::k1110) {
144  fval += -weight * MuonResidualsFitter_logPureGaussian(residX, residXpeak, resXsigma);
145  fval += -weight * MuonResidualsFitter_logPureGaussian(residY, residYpeak, resYsigma);
146  fval += -weight * MuonResidualsFitter_logPureGaussian(resslopeX, slopeXpeak, slopeXsigma);
147  }
148  else if (fitter->useRes() == MuonResidualsFitter::k1100) {
149  fval += -weight * MuonResidualsFitter_logPureGaussian(residX, residXpeak, resXsigma);
150  fval += -weight * MuonResidualsFitter_logPureGaussian(residY, residYpeak, resYsigma);
151  }
152  else if (fitter->useRes() == MuonResidualsFitter::k1010) {
153  fval += -weight * MuonResidualsFitter_logPureGaussian(residX, residXpeak, resXsigma);
154  fval += -weight * MuonResidualsFitter_logPureGaussian(resslopeX, slopeXpeak, slopeXsigma);
155  }
156  else if (fitter->useRes() == MuonResidualsFitter::k0010) {
157  fval += -weight * MuonResidualsFitter_logPureGaussian(resslopeX, slopeXpeak, slopeXsigma);
158  }
159  //std::cout<<"FCNx("<<residX<<","<<residXpeak<<","<<resXsigma<<") = "<<MuonResidualsFitter_logPureGaussian(residX, residXpeak, resXsigma)<<std::endl;
160  //std::cout<<"FCNy("<<residY<<","<<residYpeak<<","<<resYsigma<<") = "<<MuonResidualsFitter_logPureGaussian(residY, residYpeak, resYsigma)<<std::endl;
161  //std::cout<<"FCNsx("<<resslopeX<<","<<slopeXpeak<<","<<slopeXsigma<<") = "<<MuonResidualsFitter_logPureGaussian(resslopeX, slopeXpeak, slopeXsigma)<<std::endl;
162  //std::cout<<"FCNsy("<<resslopeY<<","<<slopeYpeak<<","<<slopeYsigma<<") = "<<MuonResidualsFitter_logPureGaussian(resslopeY, slopeYpeak, slopeYsigma)<<std::endl;
163  }
165  if (fitter->useRes() == MuonResidualsFitter::k1111) {
166  fval += -weight * MuonResidualsFitter_logPureGaussian2D(residX, resslopeX, residXpeak, slopeXpeak, resXsigma, slopeXsigma, alphax);
167  fval += -weight * MuonResidualsFitter_logPureGaussian2D(residY, resslopeY, residYpeak, slopeYpeak, resYsigma, slopeYsigma, alphay);
168  }
169  else if (fitter->useRes() == MuonResidualsFitter::k1110) {
170  fval += -weight * MuonResidualsFitter_logPureGaussian2D(residX, resslopeX, residXpeak, slopeXpeak, resXsigma, slopeXsigma, alphax);
171  fval += -weight * MuonResidualsFitter_logPureGaussian(residY, residYpeak, resYsigma);
172  }
173  else if (fitter->useRes() == MuonResidualsFitter::k1100) {
174  fval += -weight * MuonResidualsFitter_logPureGaussian(residX, residXpeak, resXsigma);
175  fval += -weight * MuonResidualsFitter_logPureGaussian(residY, residYpeak, resYsigma);
176  }
177  else if (fitter->useRes() == MuonResidualsFitter::k1010) {
178  fval += -weight * MuonResidualsFitter_logPureGaussian2D(residX, resslopeX, residXpeak, slopeXpeak, resXsigma, slopeXsigma, alphax);
179  }
180  else if (fitter->useRes() == MuonResidualsFitter::k0010) {
181  fval += -weight * MuonResidualsFitter_logPureGaussian(resslopeX, slopeXpeak, slopeXsigma);
182  }
183  //std::cout<<"FCNx("<<residX<<","<<resslopeX<<","<<residXpeak<<","<<slopeXpeak<<","<<resXsigma<<","<<slopeXsigma<<","<<alphax<<") = "<<MuonResidualsFitter_logPureGaussian2D(residX, resslopeX, residXpeak, slopeXpeak, resXsigma, slopeXsigma, alphax)<<std::endl;
184  //std::cout<<"FCNy("<<residY<<","<<resslopeY<<","<<residYpeak<<","<<slopeYpeak<<","<<resYsigma<<","<<slopeYsigma<<","<<alphay<<") = "<<MuonResidualsFitter_logPureGaussian2D(residY, resslopeY, residYpeak, slopeYpeak, resYsigma, slopeYsigma, alphay)<<std::endl;
185  }
186  else if (fitter->residualsModel() == MuonResidualsFitter::kPowerLawTails) {
187  fval += -weight * MuonResidualsFitter_logPowerLawTails(residX, residXpeak, resXsigma, resXgamma);
188  fval += -weight * MuonResidualsFitter_logPowerLawTails(residY, residYpeak, resYsigma, resYgamma);
189  fval += -weight * MuonResidualsFitter_logPowerLawTails(resslopeX, slopeXpeak, slopeXsigma, slopeXgamma);
190  fval += -weight * MuonResidualsFitter_logPowerLawTails(resslopeY, slopeYpeak, slopeYsigma, slopeYgamma);
191  }
192  else if (fitter->residualsModel() == MuonResidualsFitter::kROOTVoigt) {
193  fval += -weight * MuonResidualsFitter_logROOTVoigt(residX, residXpeak, resXsigma, resXgamma);
194  fval += -weight * MuonResidualsFitter_logROOTVoigt(residY, residYpeak, resYsigma, resYgamma);
195  fval += -weight * MuonResidualsFitter_logROOTVoigt(resslopeX, slopeXpeak, slopeXsigma, slopeXgamma);
196  fval += -weight * MuonResidualsFitter_logROOTVoigt(resslopeY, slopeYpeak, slopeYsigma, slopeYgamma);
197  }
199  fval += -weight * MuonResidualsFitter_logGaussPowerTails(residX, residXpeak, resXsigma);
200  fval += -weight * MuonResidualsFitter_logGaussPowerTails(residY, residYpeak, resYsigma);
201  fval += -weight * MuonResidualsFitter_logGaussPowerTails(resslopeX, slopeXpeak, slopeXsigma);
202  fval += -weight * MuonResidualsFitter_logGaussPowerTails(resslopeY, slopeYpeak, slopeYsigma);
203  }
204  else { assert(false); }
205  }
206  }
207 /*
208  const double resXsigma = par[MuonResiduals6DOFFitter::kResidXSigma];
209  const double resYsigma = par[MuonResiduals6DOFFitter::kResidYSigma];
210  const double slopeXsigma = par[MuonResiduals6DOFFitter::kResSlopeXSigma];
211  const double slopeYsigma = par[MuonResiduals6DOFFitter::kResSlopeYSigma];
212  const double alphax = par[MuonResiduals6DOFFitter::kAlphaX];
213  const double alphay = par[MuonResiduals6DOFFitter::kAlphaY];
214  std::cout<<"fval="<<fval<<","<<resXsigma<<","<<slopeXsigma<<","<<alphax<<","<<resYsigma<<","<<slopeYsigma<<","<<alphay<<std::endl;
215 */
216 }
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)
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 weight
Definition: histoStyle.py:50
std::vector< double * >::const_iterator residuals_begin() const
double MuonResidualsFitter_logPureGaussian(double residual, double center, double sigma)