CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Classes | Functions
MuonResidualsFitter.h File Reference
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "Alignment/MuonAlignmentAlgorithms/interface/MuonChamberResidual.h"
#include "CommonTools/UtilAlgos/interface/TFileService.h"
#include "Alignment/CommonAlignment/interface/Alignable.h"
#include "TMinuit.h"
#include "TH1F.h"
#include "TProfile.h"
#include "TF1.h"
#include "TMath.h"
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>

Go to the source code of this file.

Classes

class  MuonResidualsFitter
 
class  MuonResidualsFitterFitInfo
 

Functions

void MuonResidualsAngleFitter_FCN (int &npar, double *gin, double &fval, double *par, int iflag)
 
double MuonResidualsFitter_compute_log_convolution (double toversigma, double gammaoversigma, double max=1000., double step=0.001, double power=4.)
 
Double_t MuonResidualsFitter_GaussPowerTails_TF1 (Double_t *xvec, Double_t *par)
 
double MuonResidualsFitter_integrate_pureGaussian (double low, double high, double center, double sigma)
 
double MuonResidualsFitter_logGaussPowerTails (double residual, double center, double sigma)
 
double MuonResidualsFitter_logPowerLawTails (double residual, double center, double sigma, double gamma)
 
double MuonResidualsFitter_logPureGaussian (double residual, double center, double sigma)
 
double MuonResidualsFitter_logROOTVoigt (double residual, double center, double sigma, double gamma)
 
Double_t MuonResidualsFitter_powerLawTails_TF1 (Double_t *xvec, Double_t *par)
 
Double_t MuonResidualsFitter_pureGaussian_TF1 (Double_t *xvec, Double_t *par)
 
Double_t MuonResidualsFitter_ROOTVoigt_TF1 (Double_t *xvec, Double_t *par)
 
void MuonResidualsPositionFitter_FCN (int &npar, double *gin, double &fval, double *par, int iflag)
 

Function Documentation

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

Definition at line 9 of file MuonResidualsAngleFitter.cc.

References MuonResidualsFitterFitInfo::fitter(), MuonResidualsAngleFitter::kAngle, MuonResidualsAngleFitter::kGamma, MuonResidualsFitter::kGaussPowerTails, MuonResidualsFitter::kPowerLawTails, MuonResidualsFitter::kPureGaussian, MuonResidualsAngleFitter::kResidual, MuonResidualsFitter::kROOTVoigt, MuonResidualsAngleFitter::kSigma, MuonResidualsAngleFitter::kXAngle, MuonResidualsAngleFitter::kXControl, MuonResidualsAngleFitter::kYAngle, MuonResidualsAngleFitter::kYControl, MuonResidualsAngleFitter_TMinuit, MuonResidualsFitter_logGaussPowerTails(), MuonResidualsFitter_logPowerLawTails(), MuonResidualsFitter_logPureGaussian(), MuonResidualsFitter_logROOTVoigt(), MuonResidualsFitter::residuals_begin(), MuonResidualsFitter::residuals_end(), and MuonResidualsFitter::residualsModel().

Referenced by MuonResidualsAngleFitter::fit().

9  {
11  MuonResidualsFitter *fitter = fitinfo->fitter();
12 
13  fval = 0.;
14  for (std::vector<double*>::const_iterator resiter = fitter->residuals_begin(); resiter != fitter->residuals_end(); ++resiter) {
15  const double residual = (*resiter)[MuonResidualsAngleFitter::kResidual];
16  const double xangle = (*resiter)[MuonResidualsAngleFitter::kXAngle];
17  const double yangle = (*resiter)[MuonResidualsAngleFitter::kYAngle];
18 
19  double center = 0.;
21  center += par[MuonResidualsAngleFitter::kXControl] * xangle;
22  center += par[MuonResidualsAngleFitter::kYControl] * yangle;
23 
26  }
29  }
30  else if (fitter->residualsModel() == MuonResidualsFitter::kROOTVoigt) {
32  }
35  }
36  else { assert(false); }
37  }
38 }
double MuonResidualsFitter_logGaussPowerTails(double residual, double center, double sigma)
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
std::vector< double * >::const_iterator residuals_begin() const
static TMinuit * MuonResidualsAngleFitter_TMinuit
double MuonResidualsFitter_logPureGaussian(double residual, double center, double sigma)
const double par[8 *NPar][4]
double MuonResidualsFitter_compute_log_convolution ( double  toversigma,
double  gammaoversigma,
double  max = 1000.,
double  step = 0.001,
double  power = 4. 
)

Definition at line 30 of file MuonResidualsFitter.cc.

References funct::exp(), funct::log(), M_PI, max(), funct::pow(), mathSSE::sqrt(), and ExpressReco_HICollisions_FallBack::step.

Referenced by MuonResidualsFitter::initialize_table().

30  {
31  if (gammaoversigma == 0.) return (-toversigma*toversigma/2.) - log(sqrt(2*M_PI));
32 
33  double sum = 0.;
34  double uplus = 0.;
35  double integrandplus_last = 0.;
36  double integrandminus_last = 0.;
37  for (double inc = 0.; uplus < max; inc += step) {
38  double uplus_last = uplus;
39  uplus = pow(inc, power);
40 
41  double integrandplus = exp(-pow(uplus - toversigma, 2)/2.) / (uplus*uplus/gammaoversigma + gammaoversigma) / M_PI / sqrt(2.*M_PI);
42  double integrandminus = exp(-pow(-uplus - toversigma, 2)/2.) / (uplus*uplus/gammaoversigma + gammaoversigma) / M_PI / sqrt(2.*M_PI);
43 
44  sum += integrandplus * (uplus - uplus_last);
45  sum += 0.5 * fabs(integrandplus_last - integrandplus) * (uplus - uplus_last);
46 
47  sum += integrandminus * (uplus - uplus_last);
48  sum += 0.5 * fabs(integrandminus_last - integrandminus) * (uplus - uplus_last);
49 
50  integrandplus_last = integrandplus;
51  integrandminus_last = integrandminus;
52  }
53  return log(sum);
54 }
Exp< T >::type exp(const T &t)
Definition: Exp.h:22
const T & max(const T &a, const T &b)
T sqrt(T t)
Definition: SSEVec.h:28
#define M_PI
Definition: BFit3D.cc:3
Log< T >::type log(const T &t)
Definition: Log.h:22
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
Double_t MuonResidualsFitter_GaussPowerTails_TF1 ( Double_t *  xvec,
Double_t *  par 
)

Definition at line 112 of file MuonResidualsFitter.cc.

References funct::exp(), and MuonResidualsFitter_logGaussPowerTails().

Referenced by MuonResiduals1DOFFitter::plot(), MuonResidualsAngleFitter::plot(), MuonResidualsBfieldAngleFitter::plot(), MuonResidualsPositionFitter::plot(), MuonResiduals5DOFFitter::plot(), MuonResiduals6DOFrphiFitter::plot(), and MuonResiduals6DOFFitter::plot().

112  {
113  return par[0] * exp(MuonResidualsFitter_logGaussPowerTails(xvec[0], par[1], par[2]));
114 }
double MuonResidualsFitter_logGaussPowerTails(double residual, double center, double sigma)
Exp< T >::type exp(const T &t)
Definition: Exp.h:22
const double par[8 *NPar][4]
double MuonResidualsFitter_integrate_pureGaussian ( double  low,
double  high,
double  center,
double  sigma 
)

Definition at line 116 of file MuonResidualsFitter.cc.

References funct::exp(), and mathSSE::sqrt().

116  {
117  return (erf((high + center) / sqrt(2.) / sigma) - erf((low + center) / sqrt(2.) / sigma)) * exp(0.5/sigma/sigma) / 2.;
118 }
Exp< T >::type exp(const T &t)
Definition: Exp.h:22
T sqrt(T t)
Definition: SSEVec.h:28
double MuonResidualsFitter_logGaussPowerTails ( double  residual,
double  center,
double  sigma 
)

Definition at line 101 of file MuonResidualsFitter.cc.

References a, funct::exp(), funct::log(), m, M_PI, n, funct::pow(), asciidump::s, mathSSE::sqrt(), and ExpressReco_HICollisions_FallBack::x.

Referenced by MuonResiduals1DOFFitter_FCN(), MuonResiduals5DOFFitter_FCN(), MuonResiduals6DOFFitter_FCN(), MuonResiduals6DOFrphiFitter_FCN(), MuonResidualsAngleFitter_FCN(), MuonResidualsBfieldAngleFitter_FCN(), MuonResidualsFitter_GaussPowerTails_TF1(), and MuonResidualsPositionFitter_FCN().

101  {
102  double x = residual-center;
103  double s = fabs(sigma);
104  double m = 2*s;
105  double a = pow(m,4)*exp(-2);
106  double n = sqrt(2*M_PI)*s*erf(sqrt(2))+2*a*pow(m,-3)/3;
107 
108  if (fabs(x)<m) return -x*x/(2*s*s) - log(n);
109  else return log(a) -4*log(fabs(x)) - log(n);
110 }
Exp< T >::type exp(const T &t)
Definition: Exp.h:22
T sqrt(T t)
Definition: SSEVec.h:28
#define M_PI
Definition: BFit3D.cc:3
Log< T >::type log(const T &t)
Definition: Log.h:22
double a
Definition: hdecay.h:121
string s
Definition: asciidump.py:422
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
double MuonResidualsFitter_logPowerLawTails ( double  residual,
double  center,
double  sigma,
double  gamma 
)

Definition at line 57 of file MuonResidualsFitter.cc.

References funct::log(), M_PI, MuonResidualsFitter_gsbinsize, MuonResidualsFitter_lookup_table, MuonResidualsFitter_numgsbins, MuonResidualsFitter_numtsbins, and MuonResidualsFitter_tsbinsize.

Referenced by MuonResiduals1DOFFitter_FCN(), MuonResiduals5DOFFitter_FCN(), MuonResiduals6DOFFitter_FCN(), MuonResiduals6DOFrphiFitter_FCN(), MuonResidualsAngleFitter_FCN(), MuonResidualsBfieldAngleFitter_FCN(), MuonResidualsFitter_powerLawTails_TF1(), and MuonResidualsPositionFitter_FCN().

57  {
58  sigma = fabs(sigma);
59  double gammaoversigma = fabs(gamma / sigma);
60  double toversigma = fabs((residual - center) / sigma);
61 
62  int gsbin0 = int(floor(gammaoversigma / MuonResidualsFitter_gsbinsize));
63  int gsbin1 = int(ceil(gammaoversigma / MuonResidualsFitter_gsbinsize));
64  int tsbin0 = int(floor(toversigma / MuonResidualsFitter_tsbinsize));
65  int tsbin1 = int(ceil(toversigma / MuonResidualsFitter_tsbinsize));
66 
67  bool gsisbad = (gsbin0 >= MuonResidualsFitter_numgsbins || gsbin1 >= MuonResidualsFitter_numgsbins);
68  bool tsisbad = (tsbin0 >= MuonResidualsFitter_numtsbins || tsbin1 >= MuonResidualsFitter_numtsbins);
69 
70  if (gsisbad || tsisbad) {
71  return log(gammaoversigma/M_PI) - log(toversigma*toversigma + gammaoversigma*gammaoversigma) - log(sigma);
72  }
73  else {
74  double val00 = MuonResidualsFitter_lookup_table[gsbin0][tsbin0];
75  double val01 = MuonResidualsFitter_lookup_table[gsbin0][tsbin1];
76  double val10 = MuonResidualsFitter_lookup_table[gsbin1][tsbin0];
77  double val11 = MuonResidualsFitter_lookup_table[gsbin1][tsbin1];
78 
79  double val0 = val00 + ((toversigma / MuonResidualsFitter_tsbinsize) - tsbin0) * (val01 - val00);
80  double val1 = val10 + ((toversigma / MuonResidualsFitter_tsbinsize) - tsbin0) * (val11 - val10);
81 
82  double val = val0 + ((gammaoversigma / MuonResidualsFitter_gsbinsize) - gsbin0) * (val1 - val0);
83 
84  return val - log(sigma);
85  }
86 }
const int MuonResidualsFitter_numgsbins
const int MuonResidualsFitter_numtsbins
const double MuonResidualsFitter_gsbinsize
const double MuonResidualsFitter_tsbinsize
#define M_PI
Definition: BFit3D.cc:3
Log< T >::type log(const T &t)
Definition: Log.h:22
double MuonResidualsFitter_lookup_table[MuonResidualsFitter_numgsbins][MuonResidualsFitter_numtsbins]
double MuonResidualsFitter_logPureGaussian ( double  residual,
double  center,
double  sigma 
)

Definition at line 20 of file MuonResidualsFitter.cc.

References funct::log(), M_PI, funct::pow(), and mathSSE::sqrt().

Referenced by MuonResiduals1DOFFitter_FCN(), MuonResiduals5DOFFitter_FCN(), MuonResiduals6DOFFitter_FCN(), MuonResiduals6DOFrphiFitter_FCN(), MuonResidualsAngleFitter_FCN(), MuonResidualsBfieldAngleFitter_FCN(), MuonResidualsFitter_pureGaussian_TF1(), and MuonResidualsPositionFitter_FCN().

20  {
21  sigma = fabs(sigma);
22  return (-pow(residual - center, 2) / 2. / sigma / sigma) + log(1. / sqrt(2.*M_PI) / sigma);
23 }
T sqrt(T t)
Definition: SSEVec.h:28
#define M_PI
Definition: BFit3D.cc:3
Log< T >::type log(const T &t)
Definition: Log.h:22
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
double MuonResidualsFitter_logROOTVoigt ( double  residual,
double  center,
double  sigma,
double  gamma 
)
Double_t MuonResidualsFitter_powerLawTails_TF1 ( Double_t *  xvec,
Double_t *  par 
)

Definition at line 89 of file MuonResidualsFitter.cc.

References funct::exp(), and MuonResidualsFitter_logPowerLawTails().

Referenced by MuonResiduals1DOFFitter::plot(), MuonResidualsAngleFitter::plot(), MuonResidualsBfieldAngleFitter::plot(), MuonResidualsPositionFitter::plot(), MuonResiduals5DOFFitter::plot(), MuonResiduals6DOFrphiFitter::plot(), and MuonResiduals6DOFFitter::plot().

89  {
90  return par[0] * exp(MuonResidualsFitter_logPowerLawTails(xvec[0], par[1], par[2], par[3]));
91 }
Exp< T >::type exp(const T &t)
Definition: Exp.h:22
double MuonResidualsFitter_logPowerLawTails(double residual, double center, double sigma, double gamma)
const double par[8 *NPar][4]
Double_t MuonResidualsFitter_pureGaussian_TF1 ( Double_t *  xvec,
Double_t *  par 
)

Definition at line 26 of file MuonResidualsFitter.cc.

References funct::exp(), and MuonResidualsFitter_logPureGaussian().

Referenced by MuonResiduals1DOFFitter::plot(), MuonResidualsAngleFitter::plot(), MuonResidualsBfieldAngleFitter::plot(), MuonResidualsPositionFitter::plot(), MuonResiduals5DOFFitter::plot(), MuonResiduals6DOFrphiFitter::plot(), and MuonResiduals6DOFFitter::plot().

26  {
27  return par[0] * exp(MuonResidualsFitter_logPureGaussian(xvec[0], par[1], par[2]));
28 }
Exp< T >::type exp(const T &t)
Definition: Exp.h:22
double MuonResidualsFitter_logPureGaussian(double residual, double center, double sigma)
const double par[8 *NPar][4]
Double_t MuonResidualsFitter_ROOTVoigt_TF1 ( Double_t *  xvec,
Double_t *  par 
)
void MuonResidualsPositionFitter_FCN ( int &  npar,
double *  gin,
double &  fval,
double *  par,
int  iflag 
)

Definition at line 9 of file MuonResidualsPositionFitter.cc.

References MuonResidualsFitterFitInfo::fitter(), MuonResidualsPositionFitter::kAngleError, MuonResidualsPositionFitter::kGamma, MuonResidualsFitter::kGaussPowerTails, MuonResidualsPositionFitter::kPhiz, MuonResidualsPositionFitter::kPosition, MuonResidualsFitter::kPowerLawTails, MuonResidualsFitter::kPureGaussian, MuonResidualsPositionFitter::kResidual, MuonResidualsFitter::kROOTVoigt, MuonResidualsPositionFitter::kScattering, MuonResidualsPositionFitter::kSigma, MuonResidualsPositionFitter::kTrackAngle, MuonResidualsPositionFitter::kTrackPosition, MuonResidualsPositionFitter::kZpos, MuonResidualsFitter_logGaussPowerTails(), MuonResidualsFitter_logPowerLawTails(), MuonResidualsFitter_logPureGaussian(), MuonResidualsFitter_logROOTVoigt(), MuonResidualsPositionFitter_TMinuit, MuonResidualsFitter::residuals_begin(), MuonResidualsFitter::residuals_end(), and MuonResidualsFitter::residualsModel().

Referenced by MuonResidualsPositionFitter::fit().

9  {
11  MuonResidualsFitter *fitter = fitinfo->fitter();
12 
13  fval = 0.;
14  for (std::vector<double*>::const_iterator resiter = fitter->residuals_begin(); resiter != fitter->residuals_end(); ++resiter) {
15  const double residual = (*resiter)[MuonResidualsPositionFitter::kResidual];
16  const double angleerror = (*resiter)[MuonResidualsPositionFitter::kAngleError];
17  const double trackangle = (*resiter)[MuonResidualsPositionFitter::kTrackAngle];
18  const double trackposition = (*resiter)[MuonResidualsPositionFitter::kTrackPosition];
19 
20  double center = 0.;
22  center += par[MuonResidualsPositionFitter::kZpos] * trackangle;
23  center += par[MuonResidualsPositionFitter::kPhiz] * trackposition;
24  center += par[MuonResidualsPositionFitter::kScattering] * angleerror;
25 
28  }
31  }
32  else if (fitter->residualsModel() == MuonResidualsFitter::kROOTVoigt) {
34  }
37  }
38  else { assert(false); }
39  }
40 }
double MuonResidualsFitter_logGaussPowerTails(double residual, double center, double sigma)
MuonResidualsFitter * fitter()
static TMinuit * MuonResidualsPositionFitter_TMinuit
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
std::vector< double * >::const_iterator residuals_begin() const
double MuonResidualsFitter_logPureGaussian(double residual, double center, double sigma)
const double par[8 *NPar][4]